Using 传单.js http://leafletjs.com/reference.html对于开源地图项目,但我需要设置用户无法超越的特定界限。地图对象的 maxBounds 属性在北、东、西方向上按预期工作,但它让我永远向南滚动。
在小提琴中,绿色背景揭示了边界的位置should结束,我添加了一个用于检查纬度的点击警报。
http://jsfiddle.net/7m7n7/ http://jsfiddle.net/7m7n7/
var map = L.map('map', {
maxZoom: 4,
minZoom: 1,
maxBounds: [
//south west
[-85.07815906717186, -179.97802734374997],
//north east
[-60.413852350464914, 39.8583984375]
]
}).setView([-72.5, -110], 1);
L.tileLayer(
'http://{s}.tile.cloudmade.com/{API}/998/256/{z}/{x}/{y}.png',
{ maxZoom: 18 }).addTo(map);
当你使用setBounds
然后传单叫L.Map.panInsideBounds https://github.com/Leaflet/Leaflet/blob/v0.5.1/src/map/Map.js#L114根据你的界限,你想在哪里获得投影:viewSw = this.project(viewBounds.getSouthWest())
,其中使用下一个代码 https://github.com/Leaflet/Leaflet/blob/v0.5.1/src/geo/projection/Projection.SphericalMercator.js#L8对于默认投影:
project: function (latlng) { // (LatLng) -> Point
var d = L.LatLng.DEG_TO_RAD,
max = this.MAX_LATITUDE,
lat = Math.max(Math.min(max, latlng.lat), -max),
x = latlng.lng * d,
y = lat * d;
y = Math.log(Math.tan((Math.PI / 4) + (y / 2)));
return new L.Point(x, y);
}
所以有Math.max(Math.min(max, latlng.lat), -max)
不能大于最大值或最小值并且viewSw
变得等于最大值并且实际边界不固定。
这个问题已修复 https://github.com/Leaflet/Leaflet/commit/db6d689ad898caa18cb6db7c6df1632eb6b7114f。您可以使用来自master的版本 https://github.com/Leaflet/Leaflet/tree/master/dist或者等待下一次意识到的时候。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)