Skip to content

Instantly share code, notes, and snippets.

Embed
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

This comment has been minimized.

Copy link

bboyle commented Dec 6, 2012

Great gist, thanks! :)

@schnuerle

This comment has been minimized.

Copy link

schnuerle commented Sep 23, 2013

Rocks.

@sdiver78

This comment has been minimized.

Copy link

sdiver78 commented Oct 9, 2013

thanks!

@plcancelleri

This comment has been minimized.

Copy link

plcancelleri commented Apr 9, 2014

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.