google-maps - 将标记拖动到 Google map 边缘附近时如何禁用 "auto panning"?

标签 google-maps google-maps-api-3

基本上,我不希望 map 在有人拖动标记时自动开始平移。如今,每当有人将标记拖动到 map 边缘附近时, map 就会开始平移,甚至当标记位于 map Canvas 边界之外时还会继续平移。

非常确定这种“自动”平移是任何具有可拖动标记和“正常”平移功能的 map (Google javascript Maps API 3.x)的默认设置。

我想保留使用鼠标平移 map 的功能,但我需要禁用当有人在 map 边缘附近拖动标记时发生的“自动”平移。 (还需要保留可拖动标记)。

提前致谢。

最佳答案

使用标记的 dragstartdragend 事件来打开和关闭 map 的可拖动属性。 map 对象没有 setDraggable 方法,因此您需要使用 set 方法。

google.maps.event.addListener(marker, 'dragstart', function(){
    map.set('draggable', false);
});
google.maps.event.addListener(marker, 'dragend', function(){
    map.set('draggable', true);
}); 

关于google-maps - 将标记拖动到 Google map 边缘附近时如何禁用 "auto panning"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9841059/

相关文章:

javascript - 相当于 v3 Maps API 中的 GMap2.savePosition?

javascript - 向现有标记集添加新的独特标记(谷歌地图)

javascript - 为什么 "BESbewy"出现在我的站点跨度中?

javascript - 具有多个地址的 Google map AngularJS

google-maps - Google Maps v3 map.getBounds().containsLatLng 不是函数

php - Google map API 商业搜索

javascript - Google Maps API v3 标记有时仅加载

javascript - Google map 融合表 API SQL "LIKE"命令不起作用

javascript - 谷歌地图标记Javascript

javascript - 谷歌地图标记动画的IE问题