RAW_LAYERS.txt 2.0 KB

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