0.1.2 • Published 2 years ago
@erwanlpfr/ol-mapbox-layer v0.1.2
mapbox OpenLayers layer
Render a mapbox GL JS map as an OpenLayers layer. Forked from ol-maplibre-layer.
Installation
npm i @erwanlpfr/ol-mapbox-layer
# OpenLayers and mapbox GL JS are peer dependencies, so you need to install them too.
npm i ol mapbox-gl
Code example
import mapboxLayer from '@erwanlpfr/ol-mapbox-layer';
const layer = new MapBoxLayer({
mapboxOptions: {
// style: 'mapbox://styles/mapbox/streets-v12?optimize=true',
style: 'mapbox://styles/mapbox/streets-v12',
accessToken: process.env.KEY_MAPBOX,
},
}),
// ...
map.addLayer(layer);
All the properties passed to the construction (except mapboxOptions
) are used to create the OpenLayers layer.
mapboxOptions
is used to create the mapbox map.
Only the container
property is handled internally.
The mapboxLayer exposes the underlying mapbox map as public property, so you can use it to interact with the map.
layer.mapboxMap.setStyle('https://www.example.com/path/to/other/style.json');
Live examples
No demo since an access token is required.