对于我的Google Maps API项目,有太多标记可以同时加载所有这些标记,因此我首先在每个状态中放置一个区域标记,并将现有标记的计数作为标记。< / p>
我试图创建一个过程,如果用户处于某个缩放级别,并且状态标记位于视口中,则加载该状态内的所有标记。
但是,目前我不能让这个过程不止一次。以下是以下流程:
我已尝试将以下功能附加到Google地图事件,例如空闲事件或tileloaded事件,但我已决定尝试使用以下内容处理此过程:
var processingRequest = false;
window.setInterval(function () {
if (processingRequest == false) {
markerZoomTrigger();
}
}, 2000);
请注意变量processingRequest,这是使用的,因此markerZoomTrigger函数仅在前一个请求完成后运行。我这样做是为了解决我遇到的错误。
这里是markerZoomTrigger函数:
function markerZoomTrigger() {
console.log("Marker zoom triggered!");
if (geoLocMap.getMap().getZoom() < 8) {
console.log("Zoom is less than 8");
return;
}
var count = 0;
//Gives us markers in window
//TODO
/*
If zoom level is x, then getDetailedInfo for each marker in region. mailingID == 0 means its a region marker
*/
var markers = geoLocMap.getRegionMarkers();
for (var i = 0; i < markers.length; i++) {
if (geoLocMap.getMap().getBounds().contains(markers[i].getPosition())) {
var zoomLevel = geoLocMap.getMap().getZoom();
console.log("[" + count + "] Marker " + markers[i].getPosition() + " is in the selection");
console.log("[" + count + "] is region marker: " + markers[i].isRegionMarker);
console.log("[" + count + "] Zoom level: " + zoomLevel);
if (typeof markers[i] == 'undefined' || typeof markers[i].state == 'undefined') {
console.log("Marker found with undefined state property");
continue;
}
//Make sure the marker is a region marker, and it hasn't been generated
if (markers[i].isRegionMarker == true && markers[i].generated == false) {
console.log("Marking processingRequest as true...");
processingRequest = true;
if (typeof markers[i].state == 'undefined') {
console.log("Marker passed to httpPostCoordCount is undefined");
continue;
}
httpPostCoordCount(markers[i].state);
document.getElementById("load").style.visibility = "hidden";
geoLocMap.setGeneratedMarker(markers[i], true);
}
count++;
}
}
}
就像一些背景一样,geoLocMap
是我创建的用于存放地图和其他项目特定数据的类。对regionMarker
的任何引用都是我在第一段中讨论过的标记。最后,httpPostCoordCount
是一个AJAX请求,用于检索给定状态的标记,如下所示:
function httpPostCoordCount(state) {
$.post(postRequestCoordCountURL,
{
state: state,
debug: debug
},
function (data, status) {
console.log("Status of Coord Count Post: " + status);
//Adds markers from request JSON
addMarkersToMap(JSON.parse(data), state);
console.log("Marking processingRequest as false...");
processingRequest = false;
});
}
目前,在状态标记成功加载一次后,控制台消息&#34;标记缩放触发!&#34;不断印刷,没有其他信息。