function _leaflet_more_maps_assemble_default_map_info in Leaflet More Maps 2.1.x
Same name and namespace in other branches
- 8 leaflet_more_maps.module \_leaflet_more_maps_assemble_default_map_info()
- 7 leaflet_more_maps.module \_leaflet_more_maps_assemble_default_map_info()
Function to add info for all available maps.
Parameters
array $map_info: Map info to add to.
array $default_settings: Default settings to add to the map.
2 calls to _leaflet_more_maps_assemble_default_map_info()
- leaflet_more_maps_leaflet_map_info in ./
leaflet_more_maps.module - Implements hook_leaflet_map_info().
- SettingsForm::buildForm in src/
Form/ SettingsForm.php - Form constructor.
File
- ./
leaflet_more_maps.module, line 79
Code
function _leaflet_more_maps_assemble_default_map_info(array &$map_info, array $default_settings = []) {
// Use headless protocol rather than logic based on global $is_https;
$prot = '//';
// As used by most.
$zxy = '{z}/{x}/{y}.png';
// As used by Esri.
$zyx = '{z}/{y}/{x}.png';
$config_settings = Drupal::config('leaflet_more_maps.settings');
// Google and Yandex also use x, y and z, but require different URL query
// templates, see below.
// Bing uses the quadtree system whereby x, y and z are encoded in a sequence
// of digits in the range 0..3. See leaflet_more_maps.js for the conversion
// algorithm.
$attr_bing = 'Tiles <a href="https://www.bing.com/maps">Bing</a> © Microsoft and suppliers';
$map_info['bing'] = [
'label' => 'Bing road + satellite + hybrid (zoom 1..18)',
'description' => t('Bing road, satellite and hybrid layers'),
'settings' => [
'minZoom' => 1,
'layerControl' => TRUE,
] + $default_settings,
'layers' => [
'hybrid layer' => [
'type' => 'quad',
'urlTemplate' => $prot . 't{s}.ssl.ak.dynamic.tiles.virtualearth.net/comp/ch/{q}?it=A,G,L&shading=hill',
'options' => [
'attribution' => $attr_bing,
'subdomains' => [
0,
1,
2,
3,
],
],
],
'satellite layer' => [
'type' => 'quad',
'urlTemplate' => $prot . 'ecn.t{s}.tiles.virtualearth.net/tiles/a{q}?g=1236',
'options' => [
'attribution' => $attr_bing,
'subdomains' => [
0,
1,
2,
3,
],
],
],
'road layer' => [
'type' => 'quad',
'urlTemplate' => $prot . 'ecn.t{s}.tiles.virtualearth.net/tiles/r{q}?g=1236',
'options' => [
'attribution' => $attr_bing,
'subdomains' => [
0,
1,
2,
3,
4,
5,
6,
7,
],
],
],
],
];
// Esri https://esri.com
$attr_esri = 'Tiles © <a href="https://esri.com">Esri</a>';
$esri_names = [
// Zoom 0..17.
'World Imagery',
// Zoom 0..12.
'NatGeo World Map',
// Zoom 0..8.
'World Physical Map',
// Zoom 0..10.
'Ocean BaseMap',
'World Topo Map',
'World Street Map',
];
$settings = $default_settings;
foreach ($esri_names as $esri_name) {
$code = str_replace(' ', '_', $esri_name);
$url_template = $prot . "server.arcgisonline.com/ArcGIS/rest/services/{$code}/MapServer/tile/{$zyx}";
switch ($esri_name) {
case 'NatGeo World Map':
$label = 'Esri National Geographic (zoom 0..12)';
$settings['maxZoom'] = 12;
break;
case 'World Imagery':
$label = 'Esri World Imagery (zoom 0..17)';
$settings['maxZoom'] = 17;
break;
case 'World Physical Map':
$label = 'Esri Physical (zoom 0..8)';
$settings['maxZoom'] = 8;
break;
case 'Ocean BaseMap':
$label = 'Esri Ocean (zoom 0..10)';
$settings['maxZoom'] = 10;
break;
default:
$label = "Esri {$esri_name} (zoom 0..18)";
$settings['maxZoom'] = 18;
}
$map_info['esri-' . mb_strtolower($code)] = [
'label' => $label,
'description' => $label,
'settings' => $settings,
'layers' => [
'layer' => [
'urlTemplate' => $url_template,
'options' => [
'attribution' => $attr_esri,
],
],
],
];
}
$attr_google = 'Map data © <a href="https://googlemaps.com">Google</a>';
$map_info['google-hybrid'] = [
'label' => 'Google hybrid (zoom 0..18)',
'description' => t('Google hybrid'),
'settings' => $default_settings,
'layers' => [
'layer' => [
'type' => 'google',
'urlTemplate' => $prot . 'mt{s}.google.com/vt/lyrs=y&x={x}&y={y}&z={z}',
'options' => [
'attribution' => $attr_google,
// 'detectRetina' => TRUE,
'subdomains' => [
0,
1,
2,
3,
],
],
],
'overlay' => [
'type' => 'google',
// Note 'lyrs=h' for transparent overlay.
'urlTemplate' => $prot . 'mt{s}.google.com/vt/lyrs=h&x={x}&y={y}&z={z}',
'options' => [
'attribution' => $attr_google,
'detectRetina' => TRUE,
'subdomains' => [
0,
1,
2,
3,
],
],
],
],
];
$map_info['google-satellite'] = [
'label' => 'Google satellite (zoom 0..18)',
'description' => t('Google satellite'),
'settings' => $default_settings,
'layers' => [
'layer' => [
'type' => 'google',
'urlTemplate' => $prot . 'mt{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',
'options' => [
'attribution' => $attr_google,
// 'detectRetina' => TRUE,
'subdomains' => [
0,
1,
2,
3,
],
],
],
],
];
$map_info['google-roadmap'] = [
'label' => 'Google roadmap (zoom 0..17)',
'description' => t('Google roadmap'),
'settings' => [
'maxZoom' => 17,
] + $default_settings,
'layers' => [
'layer' => [
'type' => 'google',
'urlTemplate' => $prot . 'mt{s}.google.com/vt/x={x}&y={y}&z={z}',
'options' => [
'attribution' => $attr_google,
'detectRetina' => TRUE,
'subdomains' => [
0,
1,
2,
3,
],
],
],
],
];
$map_info['google-high-res'] = [
'label' => 'Google high-res road & terrain (zoom 0..17)',
'description' => t('Google road & terrain layers, with high-res (Retina) support'),
'settings' => [
'layerControl' => TRUE,
'maxZoom' => 17,
] + $default_settings,
'layers' => [
'terrain' => [
'type' => 'google',
'urlTemplate' => $prot . 'mt{s}.google.com/vt/lyrs=t,r&x={x}&y={y}&z={z}',
'options' => [
'attribution' => $attr_google,
'detectRetina' => TRUE,
'subdomains' => [
0,
1,
2,
3,
],
],
],
'roadmap' => [
'type' => 'google',
// For retina displays we append '&style=high_dpi&w=512',
// see leaflet_more_maps_preprocess_leaflet_map()
'urlTemplate' => $prot . 'mt{s}.google.com/vt/x={x}&y={y}&z={z}',
'options' => [
'attribution' => $attr_google,
'detectRetina' => TRUE,
'subdomains' => [
0,
1,
2,
3,
],
],
],
],
];
$mapbox_access_token = $config_settings
->get('mapbox_access_token');
if (empty($mapbox_access_token)) {
// MapBox as used on leafletjs.com
$mapbox_access_token = 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw';
}
$attr_mapbox = 'Map data © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>';
$url_template_mapbox = $prot . "api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}";
$mapbox_names = [
'Dark',
'Light',
//'Outdoors',
'Satellite-Streets',
'Streets',
];
foreach ($mapbox_names as $mapbox_name) {
switch ($mapbox_name) {
case 'Dark':
$id = 'mapbox/dark-v10';
break;
case 'Light':
$id = 'mapbox/light-v10';
break;
case 'Outdoors':
$id = 'mapbox/outdoors-v11';
break;
case 'Satellite-Streets':
$id = 'mapbox/satellite-streets-v11';
break;
default:
// Streets
$id = 'mapbox/streets-v11';
}
$code = mb_strtolower($mapbox_name);
$label = t("mapbox @name (zoom 0..17), requires access token", [
'@name' => $mapbox_name,
]);
$map_info["mapbox-{$code}"] = [
'label' => $label,
'description' => $label,
'settings' => $default_settings,
'layers' => [
'layer' => [
'urlTemplate' => $url_template_mapbox,
'options' => [
'id' => $id,
'tileSize' => 512,
'zoomOffset' => -1,
'accessToken' => $mapbox_access_token,
'attribution' => $attr_mapbox,
],
],
],
];
}
// Note: OpenStreetMap OSM Mapnik classic map is available via leaflet.module
$attr_osm = 'Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> and contributors';
// OSM Thunderforest.
// Maps still display without API key, but appear with API KEY watermark.
$attr_thunderforest = '<a href="https://www.thunderforest.com">Thunderforest</a>. ' . $attr_osm;
$thunderforest_api_key = trim($config_settings
->get('thunderforest_api_key'));
$thunderforest_api_key = empty($thunderforest_api_key) ? '' : '?apikey=' . $thunderforest_api_key;
$map_info['osm-cycle'] = [
'label' => 'Thunderforest Cycle (zoom 0..18)',
'description' => t('OpenStreetMap for cyclists'),
'settings' => $default_settings,
'layers' => [
'layer' => [
'urlTemplate' => $prot . 'tile.thunderforest.com/cycle/' . $zxy . $thunderforest_api_key,
'options' => [
'attribution' => $attr_thunderforest,
],
],
],
];
$map_info['osm-transport'] = [
// See https://thunderforest.com.
'label' => 'Thunderforest Transport (zoom 0..18)',
'description' => t('OpenCycleMap with train & tram lines'),
'settings' => $default_settings,
'layers' => [
'layer' => [
'urlTemplate' => $prot . 'tile.thunderforest.com/transport/' . $zxy . $thunderforest_api_key,
'options' => [
'attribution' => $attr_thunderforest,
],
],
],
];
$map_info['osm-landscape'] = [
// See https://thunderforest.com.
'label' => 'Thunderforest Landscape (zoom 0..18)',
'description' => t('OpenCycleMap with landscape'),
'settings' => $default_settings,
'layers' => [
'layer' => [
'urlTemplate' => $prot . 'tile.thunderforest.com/landscape/' . $zxy . $thunderforest_api_key,
'options' => [
'attribution' => $attr_thunderforest,
],
],
],
];
$map_info['osm-outdoors'] = [
// See https://thunderforest.com.
'label' => 'Thunderforest Outdoors (zoom 0..18)',
'description' => t('OpenStreetMap for outdoor activities'),
'settings' => $default_settings,
'layers' => [
'layer' => [
'urlTemplate' => $prot . 'tile.thunderforest.com/outdoors/' . $zxy . $thunderforest_api_key,
'options' => [
'attribution' => $attr_thunderforest,
],
],
],
];
$map_info['osm-transport-dark'] = [
// See https://thunderforest.com.
'label' => 'Thunderforest Transport Dark (zoom 0..18)',
'description' => t('A dark variant of OSM Thunderforest Transport'),
'settings' => $default_settings,
'layers' => [
'layer' => [
'urlTemplate' => $prot . 'tile.thunderforest.com/transport-dark/' . $zxy . $thunderforest_api_key,
'options' => [
'attribution' => $attr_thunderforest,
],
],
],
];
$map_info['osm-spinal-map'] = [
// See https://thunderforest.com.
'label' => 'Thunderforest Spinal Map (zoom 0..18)',
'description' => t('A perfect map style for all your heavy-rock needs, based on OSM'),
'settings' => $default_settings,
'layers' => [
'layer' => [
'urlTemplate' => $prot . 'tile.thunderforest.com/spinal-map/' . $zxy . $thunderforest_api_key,
'options' => [
'attribution' => $attr_thunderforest,
],
],
],
];
$map_info['osm-pioneer'] = [
// See https://thunderforest.com.
'label' => 'Thunderforest Pioneer (zoom 0..18)',
'description' => t('A turn-of-the-century railroad map style, evoking a sense of bygone mapping, based on OSM'),
'settings' => $default_settings,
'layers' => [
'layer' => [
'urlTemplate' => $prot . 'tile.thunderforest.com/pioneer/' . $zxy . $thunderforest_api_key,
'options' => [
'attribution' => $attr_thunderforest,
],
],
],
];
$map_info['osm-mobile-atlas'] = [
// See https://thunderforest.com.
'label' => 'Thunderforest Mobile Atlas (zoom 0..18)',
'description' => t('A new map style by Thunderforest, based on OSM'),
'settings' => $default_settings,
'layers' => [
'layer' => [
'urlTemplate' => $prot . 'tile.thunderforest.com/atlas/' . $zxy . $thunderforest_api_key,
'options' => [
'attribution' => $attr_thunderforest,
],
],
],
];
$map_info['osm-neighbourhood'] = [
// See https://thunderforest.com.
'label' => 'Thunderforest Neighbourhood (zoom 0..18)',
'description' => t('Another new map style by Thunderforest, based on OSM'),
'settings' => $default_settings,
'layers' => [
'layer' => [
'urlTemplate' => $prot . 'tile.thunderforest.com/neighbourhood/' . $zxy . $thunderforest_api_key,
'options' => [
'attribution' => $attr_thunderforest,
],
],
],
];
// Wikimedia
$attr_wiki = 'Wikimedia maps | ' . $attr_osm;
$map_info['wikimedia'] = [
'label' => 'Wikimedia (zoom 0..18)',
'description' => t('Wikimedia Maps'),
'settings' => $default_settings,
'layers' => [
'layer' => [
'urlTemplate' => $prot . "maps.wikimedia.org/osm-intl/{$zxy}",
'options' => [
'attribution' => $attr_wiki,
],
'detectRetina' => TRUE,
],
],
];
// Stamen https://stamen.com
$attr_stamen = 'Tiles by <a href="https://stamen.com">Stamen Design</a> under <a href="https://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. ' . $attr_osm;
$stamen_names = [
//'Toner',
'Terrain',
'Toner-Lite',
'Toner-Labels',
'Watercolor',
];
foreach ($stamen_names as $stamen_name) {
$code = mb_strtolower($stamen_name);
$max_zoom = $code == 'terrain' || $code == 'watercolor' ? 17 : 18;
$label = t('Stamen @name (zoom 0..@zoom)', [
'@name' => $stamen_name,
'@zoom' => $max_zoom,
]);
$url_template = $prot . "stamen-tiles-{s}.a.ssl.fastly.net/{$code}/{$zxy}";
$map_info["stamen-{$code}"] = [
'label' => $label,
'description' => $label,
'settings' => [
'maxZoom' => $max_zoom,
] + $default_settings,
'layers' => [
'layer' => [
'urlTemplate' => $url_template,
'options' => [
'attribution' => $attr_stamen,
],
],
],
];
}
// HERE maps.
$attr_here = 'Data © <a href="https://here.com">HERE</a> maps.';
$here_api_key = trim($config_settings
->get('here_api_key'));
$code = 'base';
// also 'traffic' and 'aerial'
$tile_size = 256;
// or 512
$format = 'png8';
// or png or jpg (best for satellite)
// Protocol must be HTTPS for HERE maps.
$url_template_here = "https://{s}.{$code}.maps.ls.hereapi.com/maptile/2.1/maptile/newest/normal.day/{z}/{x}/{y}/{$tile_size}/{$format}?apiKey={$here_api_key}";
$label = t('HERE Base map (zoom 0..18), requires API key');
$map_info["here-{$code}"] = [
'label' => $label,
'description' => $label,
'settings' => $default_settings,
'layers' => [
'layer' => [
'urlTemplate' => $here_api_key ? $url_template_here : '',
'options' => [
'attribution' => $attr_here,
'subdomains' => [
1,
2,
3,
4,
],
],
],
],
];
/*
$attr_yandex = 'Map data © <a href="https://maps.yandex.ru">Yandex.Maps</a>';
$map_info['yandex'] = [
'label' => 'Yandex Maps (zoom 0..7 in many areas)',
'description' => t('Yandex roadmap'),
'settings' => $default_settings,
'layers' => [
'layer' => [
'urlTemplate' => $prot . 'vec0{s}.maps.yandex.net/tiles?l=map&x={x}&y={y}&z={z}',
'options' => [
'attribution' => $attr_yandex,
'subdomains' => [0, 1, 2, 3],
],
],
],
];
*/
// Get Navionics token.
$token = _leaflet_more_maps_get_navionics_navtoken();
$attr_navionics = "Map data © <a href='https://www.navionics.com'>Navionics</a>";
$label = t('Navionics (zoom 0..18), requires API key and authorized domain');
$map_info['navionics'] = [
// See https://www.navionics.com
'label' => $label,
'description' => $label,
'settings' => $default_settings,
'layers' => [
'nautical-non-transparent' => [
'urlTemplate' => !$token ? '' : $prot . 'tile{s}.navionics.com/tile/' . $zxy . '?LAYERS=config_1_1_0&TRANSPARENT=TRUE&theme=0&navtoken=' . $token,
'options' => [
'attribution' => $attr_navionics,
'subdomains' => [
1,
2,
3,
4,
5,
],
],
],
'sonar' => [
'urlTemplate' => !$token ? '' : $prot . 'tile{s}.navionics.com/tile/' . $zxy . '?LAYERS=config_1_1_1&TRANSPARENT=TRUE&theme=0&navtoken=' . $token,
'options' => [
'attribution' => $attr_navionics,
'subdomains' => [
1,
2,
3,
4,
5,
],
],
],
'ski' => [
'urlTemplate' => !$token ? '' : $prot . 'tile{s}.navionics.com/tile/' . $zxy . '?LAYERS=config_1_0_0_1&TRANSPARENT=TRUE&theme=0&navtoken=' . $token,
'options' => [
'attribution' => $attr_navionics,
'subdomains' => [
1,
2,
3,
4,
5,
],
],
],
],
];
}