Mapbox GL JS Zoom – Max Zoom Level Not Working in Mapbox GL JS

javascriptmapboxmapbox-gl-jsweb-mappingzoom

I cant seem to get my map to set a max zoom level.

Here is a snippit of my code –

var map = new mapboxgl.Map({
container: 'map', 
style: 'mapbox://styles/cdickinson11/cjg49l1f305ou2rls3hd65a6s', 
center: [-77.034084142948, 38.909671288923], 
zoom: 10
options.maxZoom: 13
});

I also tried this, adapted from here. It did not work either, I'm guessing because it is from mapbox js instead of mapbox gl js.

var options = {
maxZoom: 13
};
mapObject = L.mapbox.map('mapDiv', undefined, options);

I'm fairly new to this type of thing. I'm pretty sure my issue lies in a lack of basic understanding about javascript, and about the difference between mapbox gl js and mapbox js. Any help?

Best Answer

Did you try just (edit: I missed a comma, fixed it now)

var map = new mapboxgl.Map({
container: 'map', 
style: 'mapbox://styles/cdickinson11/cjg49l1f305ou2rls3hd65a6s', 
center: [-77.034084142948, 38.909671288923], 
zoom: 10,
maxZoom: 13
});

Here is a JSBin demonstrating it: https://jsbin.com/qodovogevi/1/edit?html,output