Hi all,
A developer has provided me with some scripts that display clusters of markers and info windows on a Google Map (v3 API). The markers side of things works well but there is a problem with the info windows. Unfortunately I didn't notice until after I paid him and I've been trying without success to get him to fix it for six weeks now.
I've narrowed the problem down to a javascript file. It's 654 lines long so I won't paste it all in here, but if anyone wants me to put up any other sections please ask.
The info windows appear at a pre-determined interval, fading in and out using jquery I believe. It is supposed to be a random sample of 30 that loads when the map loads, and then they should just cycle through the list one by one. The script triggers a php file to run, and this fetches the data from a MySQL table.
It all works - I can see in Firebug that the php file requests the marker clusters and gets the data back fine. The problem is that it asks for the sample of 30 for the info windows thousands of times. I can see that the same sample of 30 is always returned. If I refresh the page, a different sample of 30 gets hammered. What usually happens is that the firewall on my server cuts this process off. There are also tons of aborted requests, which surely cannot be right.
I've tried lots of things to fix it, but I am pretty much a novice when it comes to javascript.
fetch: function(zoom){
if(!this.gmap) return ;
this.clearPopup();
this.fetchMarkersInfo();
this.clearOverlays();
var category = this.selectedCategories();
var params = 'q=cluster&'+ this.fetchBounds2Param(this.fetchBound())+'&zoom='+this.gmap.getZoom()+(this.gmap.getZoom() == this.gmap.maxZoom? '&markers=1' : '')+(category == '' ? '' : '&cat=' +escape(category));
var obj = this;
if(this.ajaxConn){
this.ajaxConn.abort();
this.ajaxConn = null;
}
this.enableGMap(false);
this.ajaxConn = $.ajax({url: URL_API,
data: params,
type: 'POST',
dataType: 'json',
success: function(json){
obj.showResults(json);
},
complete: function(jqXHR, textStatus){
obj.enableGMap(true);
if(obj.popupActive) return ;
obj.popupActive = true;
if(obj.popupTimeout)
clearTimeout(obj.popupTimeout);
obj.popupTimeout = setTimeout('Clusters.popupNext();', POPUP_DELAY);
}
});
},
fetchMarkersInfo: function(){
if(!this.gmap) return ;
if(this.markerInfoCompleted) return ;
var lastId = (this.markersInfo.length > 0 ? this.markersInfo[this.markersInfo.length-1].id+1 : 1);
var category = this.selectedCategories();
var obj = this;
var params = 'q=list&from='+ lastId+ '&'+ this.fetchBounds2Param(this.fetchBound())+(category == '' ? '' : '&cat=' +escape(category))+'&lmt=30';
if(this.ajaxConnPopup){
this.ajaxConnPopup.abort();
this.ajaxConnPopup = null;
}
this.ajaxConnPopup = $.ajax({url: URL_API,
data: params,
type: 'POST',
dataType: 'json',
success: function(json){
obj.addPopupMarkers(json);
if(!obj.markersInfoCompleted)
obj.fetchMarkersInfo();
}
});
},
I have wondered about those last two lines – if I disable them, the php file only asks for the list once. But then the info windows don't get displayed (although I can still click on a marker and get one that way), and there are still several aborted requests.
Any help would be much appreciated!