[英]How to avoid double click on a marker in google map?
I created a pop up box.When I single click on a marker on google map. 我创建了一个弹出框。当我单击谷歌地图上的标记时。 The popup shows with a cancel button.Clicking on cancel button just hide this popup box.My problem is when I double clicked on this marker the popup boxes are generating and overlap one by one.So Cancel is not working.
弹出窗口显示一个取消按钮。单击取消按钮只是隐藏了这个弹出框。我的问题是当我双击此标记时,弹出框正在生成并一个接一个地重叠,因此取消无法正常工作。 How to avoid this ?
如何避免这种情况?
Sample Code: 样例代码:
makeInfoWindowEvent(map, marker);
function makeInfoWindowEvent(map, marker) {
google.maps.event.addListener(marker, 'click', function() {
var markerPopup = document.createElement("div");
markerPopup.id = 'markerPopup';
markerPopup.className = 'markerPopup';
markerPopup.innerHTML = "This is a test message";
var cancel = document.createElement("div");
cancel.id = 'cancel';
cancel.className = 'cancel';
markerPopup.appendChild(cancel);
cancel.onclick= function () {
var divbg = document.getElementById('markerPopup');
divbg.style.visibility = "hidden";
}
document.getElementById('map-canvas').appendChild(markerPopup);
});
}
The events won't fire at the same time, so you can check for the presence of a markerPopup and return early if it is already there. 这些事件不会同时触发,因此您可以检查是否存在markerPopup,如果已经存在,则提早返回。
if (document.getElementById("markerPopup")) {
// they must have double clicked, so do nothing
return;
}
If you need more than one popup on the map at a time, then you will need to assign unique ids to each one that get created. 如果一次在地图上需要多个弹出窗口,则需要为创建的每个弹出窗口分配唯一的ID。 You could then attach those ids as a property on the button, which would give a way to know which one to kill.
然后,您可以将这些ID作为属性附加到按钮上,这将使您知道要杀死哪个ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.