leaflet.api.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * @file
  4. * API documentation for Administration menu.
  5. */
  6. /**
  7. * Define one or map definitions to be used when rendering a map.
  8. *
  9. * leaflet_map_get_info() will grab every defined map, and the returned
  10. * associative array is then passed to leaflet_render_map(), along with a
  11. * collection of features.
  12. *
  13. * The settings array maps to the settings available to leaflet map object,
  14. * http://leafletjs.com/reference-1.0.2.html#map
  15. *
  16. * Layers are the available base layers for the map and, if you enable the
  17. * layer control, can be toggled on the map. On top of layers, you can add
  18. * overlays. Overlays are defined just a layers, but have their 'layer_type'
  19. * set to 'overlay'. See drupal.org/project/leaflet_more_maps for examples.
  20. *
  21. * @return array
  22. * Associative array containing a complete leaflet map definition.
  23. */
  24. function hook_leaflet_map_info() {
  25. return array(
  26. 'OSM Mapnik' => array(
  27. 'label' => 'OSM Mapnik',
  28. 'description' => t('Leaflet default map.'),
  29. 'settings' => array(
  30. 'dragging' => TRUE,
  31. 'touchZoom' => TRUE,
  32. 'scrollWheelZoom' => TRUE,
  33. 'doubleClickZoom' => TRUE,
  34. 'zoomControl' => TRUE,
  35. 'attributionControl' => TRUE,
  36. 'trackResize' => TRUE,
  37. 'fadeAnimation' => TRUE,
  38. 'zoomAnimation' => TRUE,
  39. 'closePopupOnClick' => TRUE,
  40. 'layerControl' => TRUE,
  41. // 'minZoom' => 10,
  42. // 'maxZoom' => 15,
  43. // 'zoom' => 15, // set the map zoom fixed to 15
  44. ),
  45. 'layers' => array(
  46. 'earth' => array(
  47. 'urlTemplate' => '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
  48. 'options' => array(
  49. 'attribution' => 'OSM Mapnik',
  50. // The switchZoom controls require multiple layers, referencing one
  51. // another as "switchLayer".
  52. 'switchZoomBelow' => 15,
  53. 'switchLayer' => 'satellite',
  54. ),
  55. ),
  56. 'satellite' => array(
  57. 'urlTemplate' => '//otile{s}.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.png',
  58. 'options' => array(
  59. 'attribution' => 'OSM Mapnik',
  60. 'subdomains' => '1234',
  61. 'switchZoomAbove' => 15,
  62. 'switchLayer' => 'earth',
  63. ),
  64. ),
  65. ),
  66. // Uncomment the lines below to use a custom icon
  67. // 'icon' => array(
  68. // 'iconUrl' => '/sites/default/files/icon.png',
  69. // 'iconSize' => array('x' => '20', 'y' => '40'),
  70. // 'iconAnchor' => array('x' => '20', 'y' => '40'),
  71. // 'popupAnchor' => array('x' => '-8', 'y' => '-32'),
  72. // 'shadowUrl' => '/sites/default/files/icon-shadow.png',
  73. // 'shadowSize' => array('x' => '25', 'y' => '27'),
  74. // 'shadowAnchor' => array('x' => '0', 'y' => '27'),
  75. // ),
  76. ),
  77. );
  78. }
  79. /**
  80. * Alters the js settings passed to the leaflet map.
  81. *
  82. * This hook is called when the leaflet map is being rendered and attaching the
  83. * client side javascript settings.
  84. *
  85. * @param $settings
  86. * A javascript settings array used for building the leaflet map.
  87. *
  88. * @see leaflet_map_get_info()
  89. * @see hook_leaflet_map_info()
  90. */
  91. function hook_leaflet_map_prebuild_alter(&$settings) {
  92. $settings['mapId'] = 'my-map-id';
  93. $settings['features']['icon'] = 'my-icon-url';
  94. }