禁用可移动的Gmap [英] Disable movable Gmap
问题描述
是否有可能在我拖动标记的时候禁用Google mal(v3)内部的移动?
我不想使用静态地图。我需要运动的一般功能,但现在我拖动一个标记,地图不应该移动。
is it possible to disable the move inside of a google mal (v3) for the time i drag a marker? I don't want to use i.e. the static map. I need the generall function of movement, but for the moment I drag a marker, the map should not move.
非常感谢!
推荐答案
标记具有 dragstart和dragend事件。在 dragstart
上,通过设置各种 MapOptions 至 false ,如
draggable
,滚轮
等。在
dragend
中,将MapOptions设置回 true
。
Markers have dragstart and dragend events. On dragstart
, disable the "movement" functionality on the Map by setting various MapOptions to false
, like draggable
, scrollwheel
, etc. On dragend
, set the MapOptions back to true
.
以下是一个可用于基于布尔值禁用或启用地图移动的功能。它假设你的Map变量是 map
。
Here is a function you can use to disable or enable map movement based on a boolean. It assumes your Map variable is map
.
function disableMovement(disable) {
var mapOptions;
if (disable) {
mapOptions = {
draggable: false,
scrollwheel: false,
disableDoubleClickZoom: true,
zoomControl: false
};
} else {
mapOptions = {
draggable: true,
scrollwheel: true,
disableDoubleClickZoom: false,
zoomControl: true
};
}
map.setOptions(mapOptions);
}
然后你在这样的事件中使用它( marker
是您的标记变量):
And then you use this in your events like this (marker
is your Marker variable):
google.maps.event.addListener(marker, 'dragstart', function() {
disableMovement(true);
});
google.maps.event.addListener(marker, 'dragend', function() {
disableMovement(false);
});
这篇关于禁用可移动的Gmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!