var extent = new Object();
extent.minlng = 116.12476436506583;//左滑限制
extent.maxlng = 117.35172235235119;//右滑限制
extent.minlat = 38.38157198603861; //下滑限制
extent.maxlat = 40.07866287058457; //上滑限制
map.addEventListener("dragging", function (type, target) {
console.log(this.getBounds().getSouthWest().lng);
//下滑不能超过extent.minlat
if (extent.minlat > this.getBounds().getSouthWest().lat) {
map.centerAndZoom(new BMap.Point(this.getBounds().getCenter().lng, 38.9157198603861), this.getZoom());
};
//上滑不能超过extent.maxlat
if (extent.maxlat < this.getBounds().getSouthWest().lat) {
map.centerAndZoom(new BMap.Point(this.getBounds().getCenter().lng, 39.77866287058457), this.getZoom());
};
//左滑不能超过extent.minlng
if (extent.minlng > this.getBounds().getSouthWest().lng) {
map.centerAndZoom(new BMap.Point(116.92476436506583, this.getBounds().getCenter().lat), this.getZoom());
};
//右滑滑不能超过extent.maxlng
if (extent.maxlng < this.getBounds().getSouthWest().lng) {
map.centerAndZoom(new BMap.Point(117.34172235235119, this.getBounds().getCenter().lat), this.getZoom());
};
});
限制地图拖拽范围 超出后返回某个点
最新推荐文章于 2024-04-05 23:05:12 发布