1 | |
---|
2 | Raw layers are an addition to OpenLayers post-alpha7 which allow users to |
---|
3 | manually add points to a layer type. In comparison to the layer_type |
---|
4 | method of pulling in custom data, this allows you to 'push' data into the |
---|
5 | layer data array itself. In any case where reusability is a priority, |
---|
6 | layer_types should be utilized (as documented in LAYER_TYPES.txt). However, |
---|
7 | this is a quick method for success that may be more accessible to more |
---|
8 | developers. |
---|
9 | |
---|
10 | A brief, example-only implementation of an arbitrary layer is below. |
---|
11 | |
---|
12 | /** |
---|
13 | * Implementation of hook_ctools_plugin_api(). |
---|
14 | * Required to provide layers |
---|
15 | */ |
---|
16 | function geolocator_ctools_plugin_api($module, $api) { |
---|
17 | if ($module == "openlayers") { |
---|
18 | switch ($api) { |
---|
19 | case 'openlayers_layers': |
---|
20 | return array('version' => 1); |
---|
21 | } |
---|
22 | } |
---|
23 | } |
---|
24 | |
---|
25 | /** |
---|
26 | * One can have the 'features' => element point to a function |
---|
27 | * or be built on the fly within the _layers method. However, |
---|
28 | * close attention must be paid to ctools caching in order to |
---|
29 | * insure that dynamic data stays dynamic |
---|
30 | */ |
---|
31 | function geolocator_openlayers_layers() { |
---|
32 | $layers = array(); |
---|
33 | $layer = new stdClass(); |
---|
34 | $layer->api_version = 1; |
---|
35 | $layer->name = 'afghanistan'; |
---|
36 | $layer->title = 'One Point on Afghanistan'; |
---|
37 | $layer->description = ''; |
---|
38 | $layer->data = array( |
---|
39 | 'layer_type' => 'openlayers_layer_type_raw', |
---|
40 | 'projection' => array('900913'), |
---|
41 | 'features' => array( |
---|
42 | array( |
---|
43 | "wkt"=> "POINT(65 33)", |
---|
44 | "projection"=> "4326", |
---|
45 | "attributes"=> |
---|
46 | array( |
---|
47 | "name"=> "Afghanistan", |
---|
48 | "description"=> "248" |
---|
49 | ) |
---|
50 | ) |
---|
51 | ) |
---|
52 | ); |
---|
53 | $layers[$layer->name] = $layer; |
---|
54 | return $layers; |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * map_preprocess_alter allows one to add a new layer to a map |
---|
59 | * before layers are rendered and data is pulled from them. |
---|
60 | */ |
---|
61 | function geolocator_openlayers_map_preprocess_alter(&$map) { |
---|
62 | $map['layers']['afghanistan'] = 'afghanistan'; |
---|
63 | $map['layer_activated']['afghanistan'] = 'afghanistan'; |
---|
64 | $map['layer_switcher']['afghanistan'] = 'afghanistan'; |
---|
65 | } |
---|