I am trying to create an animation using geoxml3, google maps and javascript and I can't figure out how to get the changes to the map markers to refresh mid-loop.
Here is my code for the animation piece:
function useTheData(doc){
geoXmlDoc = doc[0];
for (var i = 0; i < geoXmlDoc.markers.length; i++) {
google.maps.event.addListener(geoXmlDoc.markers[i], 'click', function(kmlEvent) {
google.setOnLoadCallback(drawChart(kmlEvent));
})
if (animation == true && $.inArray(geoXmlDoc.markers[i].title, point_names) >= 0) {
var num = getanimateData(position);
geoXmlDoc.markers[i].icon = pinSymbol(getColor(num));
position++;
if (position >= 8) {
position = 0;
}
} else {
geoXmlDoc.markers[i].icon = pinSymbol("#999999");
}
}
};
function reload_kml(){
geoXml.hideDocument();
delete geoXml;
completed = false;
geoXml = new geoXML3.parser({
map: map,
singleInfoWindow: true,
suppressInfoWindows: true,
afterParse: function (doc) {
useTheData(doc);
completed = true;
}
});
geoXml.parse(baseurl + kmlIntersectionPoints);
geoXml.showDocument();
}
function animate() {
animation = true;
position = 0;
do {
if (completed) {
reload_kml();
total_iterations++;
position = total_iterations;
}
}
while (total_iterations < 8);
alert(total_iterations);
}
The function animate is called by an html button, and the loop then proceeds to call the reload_kml function which calls the useTheData function after parsing is complete. Somehow after the 'useTheData' function is called, I need the map to refresh so that the changes to the markers can be seen.
Maybe I am missing something obvious, but I've tried refreshing the page, refreshing google maps by triggering the resize event, setting a timer in javascript on the reload_kml function, and calling the geoxml.ShowDocument() function on the parser but nothing is working.
I've even thought about preloading all the animations as separate layers, but I still would need to be able to show and hide them in some kind of sequence - and the map doesn't automatically refresh after each 'geoxml.ShowDocument()' and 'geoxml.HideDocument()' call.
Any help would be greatly appreciated.