百度地图提供的区域限制 是在拖动结束后判断是否超过区域然后回到(计算出可视区域的中心点)。
怎么实现像图片放大查看的时候那样,拖动到一个边界的时候就不能继续向那一个方向拖动?
参考:
<script type="text/javascript">
//百度地图API功能
var map = new BMap.Map("allmap");
map.centerAndZoom(new BMap.Point(116.404, 39.915), 13);
// map.centerAndZoom(new BMap.Point(116.027143, 39.772348),13); // 测试为左下角的位置
// map.centerAndZoom(new BMap.Point(116.832025, 40.126349),13); // 测试为右上角的位置
map.enableScrollWheelZoom(); // 允许滚动
var b = new BMap.Bounds(new BMap.Point(116.027143, 39.772348),new BMap.Point(116.832025, 40.126349)); // 范围 左下角,右上角的点位置
try { // js中尽然还有try catch方法,可以避免bug引起的错误
BMapLib.AreaRestriction.setBounds(map, b); // 已map为中心,已b为范围的地图
} catch (e) {
// 捕获错误异常
alert(e);
}
</script>