Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is there an event fired when a kml layer has finished loading in google maps?

Google maps api version 3

To add a layer I have code like:

var layer = new google.maps.KmlLayer(layerUrl, { map: map, preserveViewport : true });

To remove a layer, I have code like:

layer.setMap(null);
layer = null;

The kml are rendered by google maps as images on the clients machine (i.e. the polygons are not created on the client).

I have a number of kml files displayed on a map. When the user clicks a button, I remove those KML layers, and replace them with other similar KML layers (depending on user input).

The transition is a bit slow. The user sees the map without any KML layer for about 30 seconds.

I would like to display a loading sign, from the moment the user clicks the button, to the time that the KML layer finally appears. I need some way to decide when to remove the loading sign.

Thanks

edit:

Looking at stackoverflow (I should have checked), they suggest using:

google.maps.event.addListener(layer, 'metadata_changed', function () {

e.g. here:

http://stackoverflow.com/questions/5668816/google-maps-api-3-loading-icon

On my first draft, that event seems to fire some time before the layer is actually displayed, but I shall investigate further.

share|improve this question
1  
If you have a large number of KML features to display, metadata_changed will fire before the features are displayed, because metadata_changed is fired after the information about the Kml Layer is loaded, but there may be a delay before many features are actually rendered on the client. The lag is due to hardware/software on the client, so I don't think you can get any better than metadata_changed. –  Gady Jun 30 '11 at 17:12
1  
@Guddie - Thanks. If you make this an answer, I shall accept it as I think it answers my question. –  zod Jul 6 '11 at 11:38
    
Copied comment to answer. –  Gady Jul 25 '11 at 23:18
add comment

1 Answer 1

up vote 2 down vote accepted

If you have a large number of KML features to display, metadata_changed will fire before the features are displayed, because metadata_changed is fired after the information about the Kml Layer is loaded, but there may be a delay before many features are actually rendered on the client. The lag is due to hardware/software on the client, so I don't think you can get any better than metadata_changed.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.