1 | <?php |
||
14 | class OL extends JsExpression |
||
15 | { |
||
16 | /** |
||
17 | * Must include the full namespace path, excluding 'ol.'. For example, "layer.Tile". |
||
18 | * @var string the classname to be instantiated. |
||
19 | */ |
||
20 | protected $class; |
||
21 | /** |
||
22 | * @var array|null the properties to be passed to the constructor of $class. |
||
23 | */ |
||
24 | protected $properties; |
||
25 | |||
26 | /** |
||
27 | * The OL class takes a classname and an optional property array as constructor arguments. Then, when an OL object is passed to Json::encode(), the following expression will be generated: |
||
28 | * <code>new ol.$class($properties)</code>. |
||
29 | * Therefore, the need for JsExpression is eliminated, and the 'ol.' namespace, the 'new' keyword and constructor call are automatically added. |
||
30 | * For example, the following mapOptions array: |
||
31 | * <pre>//... |
||
32 | * 'layers' => [ |
||
33 | * new OL('layer.Tile', [ |
||
34 | * 'source' => new OL('source.MapQuest', [ |
||
35 | * 'layer' => 'sat', |
||
36 | * ]), |
||
37 | * ]), |
||
38 | * ], |
||
39 | * 'view' => [ |
||
40 | * new OL('View', [ |
||
41 | * 'center' => [0, 0], |
||
42 | * 'zoom' => 4, |
||
43 | * ], |
||
44 | * ] |
||
45 | * /...</pre> |
||
46 | * Will be encoded as follows: |
||
47 | * <pre> |
||
48 | * { |
||
49 | * "layers": [ |
||
50 | * new ol.layer.Tile({ |
||
51 | * "source": new ol.source.MapQuest({ |
||
52 | * "layer": "sat" |
||
53 | * }) |
||
54 | * }) |
||
55 | * ], |
||
56 | * "view": new ol.View({ |
||
57 | * "center": [0, 0], |
||
58 | * "zoom": 4 |
||
59 | * }) |
||
60 | * } |
||
61 | * </pre> |
||
62 | * @param string $class |
||
63 | * @param mixed $properties |
||
64 | */ |
||
65 | public function __construct($class, $properties = null) |
||
71 | |||
72 | /** |
||
73 | * Generates the JavaScript expression that correspond with this object's $class and $properties. |
||
74 | * @return string |
||
75 | */ |
||
76 | protected function generateExpression() |
||
84 | |||
85 | public function __toString() { |
||
88 | |||
89 | } |