function leaflet_mapbox_leaflet_map_info in Leaflet MapBox 7
Same name and namespace in other branches
- 8 leaflet_mapbox.module \leaflet_mapbox_leaflet_map_info()
Implements hook_leaflet_map_info().
File
- ./
leaflet_mapbox.module, line 26 - "Leaflet Mapbox" adds integration for Leftlet module and Mapbox tiles.
Code
function leaflet_mapbox_leaflet_map_info() {
$settings = array(
'attributionControl' => TRUE,
'closePopupOnClick' => TRUE,
'doubleClickZoom' => TRUE,
'dragging' => TRUE,
'fadeAnimation' => TRUE,
'layerControl' => FALSE,
'maxZoom' => 19,
'minZoom' => 0,
'scrollWheelZoom' => TRUE,
'touchZoom' => TRUE,
'trackResize' => TRUE,
'zoom' => variable_get('leaflet_mapbox_zoomlevel', 2),
'zoomAnimation' => TRUE,
'zoomControl' => TRUE,
);
// Get access token.
$token = variable_get('leaflet_mapbox_token', '');
$options = array(
'attribution' => '',
);
switch (variable_get('leaflet_mapbox_api_version', '3')) {
case '3':
$code = variable_get('leaflet_mapbox_code', '');
// Build urlTemplate.
$url_template = "//{s}.tiles.mapbox.com/v4/{$code}/{z}/{x}/{y}.png?access_token={$token}";
break;
case '4':
// Extract username and styleid from style url.
$style_url = variable_get('leaflet_mapbox_style_url', '');
preg_match('/^mapbox:\\/\\/styles\\/(\\S*)\\/(\\S*)$/', $style_url, $matches);
if (count($matches)) {
$username = $matches[1];
$styleid = $matches[2];
}
// Build urlTemplate.
$url_template = "//api.mapbox.com/styles/v1/{$username}/{$styleid}/tiles/{z}/{x}/{y}?access_token={$token}";
// Mapbox v4 tiles are 512px by 512px and offset by 1 zoom level.
$options += array(
'tileSize' => 512,
'zoomOffset' => -1,
);
break;
}
$map_info['leaflet-mapbox'] = array(
'label' => variable_get('leaflet_mapbox_label', ''),
'description' => variable_get('leaflet_mapbox_description', ''),
'settings' => $settings,
'layers' => array(
'earth' => array(
'urlTemplate' => $url_template,
'options' => $options,
),
),
);
return $map_info;
}