Question

I'm working on a map with mapbox.js but I want to set a limit to map bounds and zoom. What code I've to add to this script?

var map = L.mapbox.map('map', 'examples.map-9ijuk24y').setView([40, -74.50], 9);
Was it helpful?

Solution

These are options you can put in an object to pass to L.mapbox.map as the third argument. The documentation for L.mapbox.map says that is can take all the same options as Leaflet's L.map, which are documented here. The options you want are minZoom, maxZoom, and maxBounds. Eg:

var map = L.mapbox.map('map', 'examples.map-9ijuk24y', {
        minZoom: 5,
        maxZoom: 12,
        maxBounds: [[30.0,-85.0],[50.0,-65.0]]
    }).setView([40, -74.50], 9);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top