1 | <?php |
||
14 | class OpenLayers extends Widget |
||
15 | { |
||
16 | /** |
||
17 | * @var array the HTML attributes for the container div of this widget. |
||
18 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
||
19 | */ |
||
20 | public $options = []; |
||
21 | /** |
||
22 | * The properties to be passed to the OpenLayers Map() constructor. In order to ease passing complex JavaScript structures, some simplifications are supported. |
||
23 | * See {@link OpenLayers::processMapOptions} for details on simplified option specification. |
||
24 | * @var array |
||
25 | */ |
||
26 | public $mapOptions = []; |
||
27 | /** |
||
28 | * The scripts that operate with the olwidget.js module, e. g. to apply map configuration in plain JavaScript. |
||
29 | * Can be array to register multiple scripts. If the array is given string keys, they will be passed to [[yii\web\View::registerJsFile()]]. |
||
30 | * @var string|array |
||
31 | */ |
||
32 | public $mapOptionScript = []; |
||
33 | |||
34 | public function init() |
||
43 | |||
44 | public function run() |
||
61 | |||
62 | /** |
||
63 | * Checks whether several "complex" options have been specified as a key => value pair where key is a string. |
||
64 | * If found, those properies will be automatically turned into the JavaScript expression that instantiates the corresponding OpenLayers object, thus eliminating the need to manually create a JsExpression object. |
||
65 | * The value for these processed keys will be passed as options to the constructor of the OpenLayers object. |
||
66 | * Supported simplified properties are: |
||
67 | * <ul> |
||
68 | * <li><b>view</b>: Can be specified as 'view' => $optionArray. |
||
69 | * For example, <code>['view' => ['center'=>[0,0],'zoom'=>2]]</code> will produce this JS: <code>new ol.View({"center":[0,0], "zoom":2})</code> |
||
70 | * <li><b>layers</b>: Each layer in the array can be specified as $type => $options, where $type is a string. |
||
71 | * For example, <code>['layers' => ['Tile' => ['visible' => false]</code> will produce this JS: <code>new ol.layer.Tile({"visible": false})</code> |
||
72 | * <li><b>layer sources</b>: In addition, when a layer's $type => $option pair are both strings, the $option is considered the layer's "source", and will also be converted to the corresponding object. |
||
73 | * For example, <code>['layers' => ['Tile' => 'OSM']</code> will produce this JS: <code>new ol.layer.Tile({"source": new ol.source.OSM()})</code> |
||
74 | * </li> |
||
75 | * </ul> |
||
76 | * If these simplifications are not enough to avoid using complex JsExpression structures, make sure to see the {@link OL} class for an abbreviated way of specifying OpenLayers object instances. |
||
77 | * @see OL |
||
78 | */ |
||
79 | protected function processMapOptions() |
||
89 | |||
90 | /** |
||
91 | * Takes each key => value pair in $this->mapOptions['layers'] and checks if key is a string. In that case, a new Layer OL object will created for this layer. |
||
92 | * Then, if the value is also a string, the corresponding Source OL object is created as well. |
||
93 | */ |
||
94 | protected function processSimplifiedLayers() |
||
109 | } |
||
110 |