1

I'm trying to prepare mapboxgl app which works offline, I want to use only javascript engine, local rasters and geojsons. How to avoid connection to mapbox tiles?

<script>
mapboxgl.accessToken = 'myToken';
var map = new mapboxgl.Map({
container: 'map',
style: 'MyStyle.json',  // local style with connection to mapboxstyle. How to avoid it?
center: [-87.61694, 41.86625],
zoom: 15.99,
pitch: 40,
bearing: 20
});

map.on('load', function() {
map.addLayer({
'id': 'room-extrusion',
'type': 'fill-extrusion',
'source': {
'type': 'geojson',
'data': 'myData.geojson'
},
'paint': {

'fill-extrusion-color': ['get', 'color'],
'fill-extrusion-height': ['get', 'height'],
'fill-extrusion-base': ['get', 'base_height'],
'fill-extrusion-opacity': 0.5
}
});
});
</script>
3
  • What do you mean with "local style with connection to mapboxstyle"?
    – pathmapper
    Commented Jun 18, 2019 at 7:12
  • My aim is to build offline app without any underlay from mapbox or OSM, just want to use mapbox library with one or two geojsons with buildings.
    – pawaelus
    Commented Jun 18, 2019 at 11:06
  • As I understand style: 'MyStyle.json' contains information about "how map looks and connection to data stored in mapbox". The first step of my application is to run mapbox engine without any map :).
    – pawaelus
    Commented Jun 18, 2019 at 11:12

1 Answer 1

2

You may use just an empty style as map option, there is no need for mapboxgl.accessToken = 'myToken'; :

<script>
var map = new mapboxgl.Map({
container: 'map',
style: {
        version: 8,
        sources: {},
        layers: []
       },
center: [-87.61694, 41.86625],
zoom: 15.99,
pitch: 40,
bearing: 20
});
1
  • Thank you, it's easy now :)
    – pawaelus
    Commented Jun 19, 2019 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.