You are here

function hook_leaflet_map_info in Leaflet 2.1.x

Same name and namespace in other branches
  1. 8 leaflet.api.php \hook_leaflet_map_info()
  2. 7 leaflet.api.php \hook_leaflet_map_info()
  3. 2.0.x leaflet.api.php \hook_leaflet_map_info()

Define map definitions to be used when rendering a map.

The leaflet_map_get_info() will grab every defined map, and the returned associative array is then passed to \Drupal::service('leaflet.service')->leafletRenderMap(), along with a collection of features.

The settings array maps to the settings available to the leaflet map object, see http://leafletjs.com/reference.html#map-property.

Layers are the available base layers for the map and, if you enable the layer control, can be toggled on the map.

Return value

array The definitions array.

1 function implements hook_leaflet_map_info()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

leaflet_leaflet_map_info in ./leaflet.module
Implements hook_leaflet_map_info().
2 invocations of hook_leaflet_map_info()
LeafletService::leafletMapGetInfo in src/LeafletService.php
Get all available Leaflet map definitions.
leaflet_map_get_info in ./leaflet.module
Get all available Leaflet map definitions.

File

./leaflet.api.php, line 30
API documentation for Administration menu.

Code

function hook_leaflet_map_info() {
  return [
    'OSM Mapnik' => [
      'label' => 'OSM Mapnik',
      'description' => t('Leaflet default map.'),
      'settings' => [
        'dragging' => TRUE,
        'touchZoom' => TRUE,
        'scrollWheelZoom' => TRUE,
        'doubleClickZoom' => TRUE,
        'zoomControl' => TRUE,
        'attributionControl' => TRUE,
        'trackResize' => TRUE,
        'fadeAnimation' => TRUE,
        'zoomAnimation' => TRUE,
        'closePopupOnClick' => TRUE,
        // Sets the map min max and starting zoom,
        // 'minZoom' => 10,
        // 'maxZoom' => 15,
        // 'zoom' => 15,
        //
        // Specific of the Drupal Leaflet module
        // Enables Layer Control in case of multiple layers, and add options.
        'layerControl' => TRUE,
        'layerControlOptions' => [
          'position' => 'topright',
        ],
      ],
      'layers' => [
        'earth' => [
          'urlTemplate' => '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
          'options' => [
            'attribution' => 'OSM Mapnik',
          ],
        ],
      ],
      // Uncomment the lines below to use a custom path style for geometries.

      /*'path' => [
          "color" => "black",
          "opacity" => "0.8",
          "stroke" => 2,
          "fill" => TRUE,
          "fillColor" => "blue",
          "fillOpacity" => "0.1",
        ],*/

      // Uncomment the lines below to use a custom icon.

      /*'icon' => array(
          'iconUrl'       => '/sites/default/files/icon.png',
          'iconSize'      => array('x' => '20', 'y' => '40'),
          'iconAnchor'    => array('x' => '20', 'y' => '40'),
          'popupAnchor'   => array('x' => '-8', 'y' => '-32'),
          'shadowUrl'     => '/sites/default/files/icon-shadow.png',
          'shadowSize'    => array('x' => '25', 'y' => '27'),
          'shadowAnchor'  => array('x' => '0', 'y' => '27'),
        ),*/

      // Enable and configure plugins in the plugins array.
      'plugins' => [],
    ],
  ];
}