Search code examples
javascriptdictionaryzoomingmapbox

mapbox.js 3.3.0 — How to add "max" et "min" zoom


I would like to add a "min-zoom" and "max-zoom" to my map builded with mapbox.js 3.3.0 (and not Mapbox-GL-JS).

My code is the same than the official example of the API: https://jsfiddle.net/omgjtnkx/.

L.mapbox.accessToken = 'pk.eyJ1IjoianVsZXN2YXVsb250IiwiYSI6ImNrN2NnY2VybTBuNngzbG56Y3Nzeno0czUifQ.dGyxSFyanB-Kbit0wvsZCQ';
var map = L.mapbox.map('map')
    .setView([40, -74.50], 9)
    .addLayer(L.mapbox.styleLayer('mapbox://styles/mapbox/streets-v11'));

Any idea?


Solution

  • As specified in the API documentation for the Map class, you can add minZoom and maxZoom options upon Map initialization. That is, something like:

    L.mapbox.accessToken = '* YOUR MAPBOX ACCESS TOKEN HERE */;
    var map = L.map('map', {
        minZoom: 5,
        maxZoom: 16
      })
      .setView([40, -74.50], 9)
      .addLayer(L.mapbox.styleLayer('mapbox://styles/mapbox/streets-v11'));