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);
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);
Share
Improve this question
edited Feb 26, 2014 at 9:26
Francois Borgies
2,40832 silver badges39 bronze badges
asked Feb 26, 2014 at 9:22
andriatzandriatz
6222 gold badges9 silver badges22 bronze badges
1 Answer
Reset to default 20These 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);