andriatz
andriatz

Reputation: 622

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);

Upvotes: 9

Views: 6062

Answers (1)

ajashton
ajashton

Reputation: 591

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);

Upvotes: 20

Related Questions