【发布时间】:2014-09-29 18:32:17
【问题描述】:
对我如何实施 InfoBox 有疑问,想知道是否有人对可能的解决方案有见解。
目前我有大约 1000 个客户端标记,它们都被动态添加到页面中。它们是使用以下方法生成的。
var cir = new google.maps.Marker({
position: new google.maps.LatLng(l.lat, l.lng),
map: map,
icon: icons[l.type].simple
});
addClickHandlerAjax(cir, l);
l.m = cir;
方法 addClickHandlerAjax 是单击标记时调用的方法。这是此方法的基础知识。
function addClickHandlerAjax(marker, l) {
google.maps.event.addListener(marker, "click", function () {
if(theInfoWindow){
theInfoWindow.close();
// InfoWindow = null;
}
//get content via ajax
$.ajax({
url: 'map/getInfo',
type: 'get',
data: {
'ID': l.f
},
success: function (data, status) {
if (status == "success") {
//create infowindow here..
theInfoWindow= new InfoBox({
content: document.getElementById("infobox-wrapper-hotel"),
disableAutoPan: true,
enableEventPropagation: true,
closeBoxURL: '../assets/images/info-close.png',
});
theInfoWindow.open(map, marker);
touchScroll('rab-scroll');
});
}
},
error: function (xhr, desc, err) {
console.log(xhr);
console.log("Details: " + desc + "\nError:" + err);
}
}); // end ajax call
});
}
问题是当用户非常快速地点击多个标记时。前一个标记的信息框可以保持打开状态。但它可能不包含任何内容。
有谁知道如何通过安全关闭信息框的所有实例来正确处理多个信息框?
我在这个实现中看不到这种行为Jsfiddle
【问题讨论】:
标签: javascript ajax google-maps google-maps-api-3