You are here

openlayers.module in Openlayers 8.4

Contains the openlayers.module file.

File

openlayers.module
View source
<?php

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

/**
 * Implements hook_theme().
 */
function openlayers_theme() {
  return [
    'openlayers_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 openlayers_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 XXleaflet_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
openlayers_map_get_info Get all available Leaflet map definitions.
openlayers_theme Implements hook_theme().
XXleaflet_leaflet_map_info Implements hook_leaflet_map_info().