You are here

leaflet.module in Leaflet 2.0.x

Same filename and directory in other branches
  1. 8 leaflet.module
  2. 7 leaflet.module
  3. 2.1.x leaflet.module

Contains the leaflet.module file.

File

leaflet.module
View source
<?php

/**
 * @file
 * Contains the leaflet.module file.
 */

/**
 * Implements hook_theme().
 */
function leaflet_theme() {
  return [
    'leaflet_map' => [
      'variables' => [
        'map_id' => NULL,
        'height' => '400px',
        'map' => [],
      ],
    ],
  ];
}

/**
 * Get all available Leaflet map definitions.
 *
 * @param string $map
 *   The specific map definition string.
 *
 * @return array
 *   The leaflet maps definition array.
 */
function leaflet_map_get_info($map = NULL) {
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['leaflet_map_info'] =& drupal_static(__FUNCTION__);
  }
  $map_info =& $drupal_static_fast['leaflet_map_info'];
  if (empty($map_info)) {
    if ($cached = \Drupal::cache()
      ->get('leaflet_map_info')) {
      $map_info = $cached->data;
    }
    else {
      $map_info = \Drupal::moduleHandler()
        ->invokeAll('leaflet_map_info');

      // Let other modules alter the map info.
      \Drupal::moduleHandler()
        ->alter('leaflet_map_info', $map_info);
      \Drupal::cache()
        ->set('leaflet_map_info', $map_info);
    }
  }
  if (empty($map)) {
    return $map_info;
  }
  else {
    return isset($map_info[$map]) ? $map_info[$map] : [];
  }
}

/**
 * Implements hook_leaflet_map_info().
 */
function leaflet_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,
      ],
      'layers' => [
        'earth' => [
          'urlTemplate' => '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
          'options' => [
            'attribution' => '&copy; <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors',
          ],
        ],
      ],
    ],
  ];
}

Functions

Namesort descending Description
leaflet_leaflet_map_info Implements hook_leaflet_map_info().
leaflet_map_get_info Get all available Leaflet map definitions.
leaflet_theme Implements hook_theme().