Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Making sure KML layers display in order
// Set the KML path
kml_path = "http://www.nhc.noaa.gov/storm_graphics/api/AL092011_019adv_"
// Load the KML files (must be publically available)
coneLayer = new google.maps.KmlLayer(
kml_path + "CONE.kmz",
{preserveViewport: true}
);
warningsLayer = new google.maps.KmlLayer(
kml_path + "WW.kmz",
{preserveViewport: true}
);
trackLayer = new google.maps.KmlLayer(
kml_path + "TRACK.kmz",
{preserveViewport: true}
);
// BEGIN SEQUENTIAL KML LOADING CODE
// This ensures the layers are drawn in order: cone, warnings, track
// Draw coneLayer
coneLayer.setMap(map);
// Listen for when coneLayer is drawn
var listener1 = google.maps.event.addListener(coneLayer, 'metadata_changed', function() {
// When it's drawn (metadata changed), clear listener, draw warningsLayer ...
google.maps.event.clearListeners(coneLayer, 'metadata_changed');
warningsLayer.setMap(map);
// .. and listen for when warningsLayer is drawn
var listener2 = google.maps.event.addListener(warningsLayer, 'metadata_changed', function() {
// When it's drawn, clear listener, draw trackLayer ...
google.maps.event.clearListeners(warningsLayer, 'metadata_changed');
trackLayer.setMap(map);
// ... and listen for when trackLayer is drawn
var listener3 = google.maps.event.addListener(trackLayer, 'metadata_changed', function() {
// When it's drawn, clear listener and blank out the map-loading sign
google.maps.event.clearListeners(trackLayer, 'metadata_changed');
$('#loadingIndicator').html("");
});
});
});
// END SEQUENTIAL KML LOADING CODE

bboyle commented Dec 6, 2012

Great gist, thanks! :)

Rocks.

sdiver78 commented Oct 9, 2013

thanks!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment