/* $Id */ /** * Chunk Markerloader * This is a simple marker loader to load markers from the map settings array in chunks, * so that the browser doesn't appear to have crashed while it freezes the UI and loads many markers. */ // Add a gmap handler Drupal.gmap.addHandler('gmap', function(elem) { var obj = this; var markers = obj.vars.markers; if (markers) { // Start loading chunks of markers as soon as the icons are ready. obj.bind('iconsready', function(){ obj.loadChunkMarkers(); }); // The number of markers to add in each chunk. var chunkSize = Drupal.settings.loadChunkMarkers.chunkSize; var chunkIndex = 0; // Loads chunks of markers, recursively, until there are no more markers left. obj.loadChunkMarkers = function() { // For each marker in this chunk. for (var i = chunkIndex * chunkSize; i < markers.length; i++) { if (i >= chunkIndex * chunkSize + chunkSize) { // We've reached the end of this chunk, kill the loop. break; } // Get this marker. var marker = markers[i]; // Clean the marker before passing around for bindings to modify. if (!marker.opts) marker.opts = {}; obj.change('preparemarker',-1,marker); // Add the marker. obj.change('addmarker',-1,marker); } // Increment the chunkIndex counter. chunkIndex++; // Are there more chunks to load? if (i < markers.length) { // Wait a few seconds then invoke loadChunkMarkers recursively. setTimeout(function(){ obj.loadChunkMarkers(); }, Drupal.settings.loadChunkMarkers.chunkDelay); } else { // We've finished loading all of the markers. Let the bindings know. obj.change('markersready',-1); } } } });