最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - mapbox.js: set map limit bounds - Stack Overflow

programmeradmin1浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 20

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);
发布评论

评论列表(0)

  1. 暂无评论