Mapbox GL
Categories
Component ID
2931652
Component name
Mapbox GL
Component type
module
Maintenance status
Development status
Component security advisory coverage
not-covered
Component created
Component changed
Component body
Initial code for integration with Mapbox GL JS.
This is an API only module. There is no UI. Maps can be generated using hook_mapbox_gl_info()
and calling the render method.
e.g.
function hook_mapbox_gl_map_info() {
// For options, see: https://www.mapbox.com/mapbox-gl-js/api/
return [
'Streets' =>
[
'access_token' => '<Your access token>',
'label' => 'Mapbox Streets',
'options' => [
'container' => 'mapbox-streets',
'style' => 'mapbox://styles/mapbox/streets-v9',
'zoom' => 6,
'center' => [146.315918, -41.640079],
],
'config' =>
[
'height' => '400px',
'controls' =>
[
'NavigationControl' => 'top-left',
'AttributionControl' => [
'compact' => true
]
]
],
'layers' =>
[
[
'id' => 'Ports',
'type' => 'circle',
'source' => [
'type' => 'geojson',
'data' => 'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_ports.geojson'
]
],
[
'id' => 'Terrain',
'type' => 'line',
'source' =>
[
'type' => 'vector',
'url' => 'mapbox://mapbox.mapbox-terrain-v2',
],
'source-layer' => 'contour',
'layout' => [
'line-join' => 'round',
'line-cap' => 'round',
],
'paint' => [
'line-color' => '#ff69b4',
'line-width' => 1
]
]
]
]
];
}
To display the map:
use Drupalmapbox_glControllerMapboxGlController;
$map = MapboxGlController::renderMap('Streets');