Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mapbox.js: set map limit bounds

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);
like image 842
andriatz Avatar asked Feb 26 '14 09:02

andriatz


1 Answers

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);
like image 82
ajashton Avatar answered Sep 28 '22 03:09

ajashton