Saturday 22 October 2016

openlayers 2 - register event "loadend" on layer


I'm trying to register a listener event on "loadend" for my google maps layer on OpenLayers. But for some reason it's not firing. There must be something small i'm overlooking. What is wrong with my code?


Code:


 






OpenLayers Google (v3) Layer Example















Answer



OftenThe Google layers work differently from other layer types as they are loaded through the Google API rather than OpenLayers code.



The loadend issue is logged as a bug in the OpenLayers bug tracker, but its status has since been changed to a (non-completed) feature.


Instead you could try capturing the tilesloaded event from the Google API, and put your custom function when this event is called.


If you have a Google map layer, then you also have the Google API loaded, and access to the Google map object so you should be able to use something like:


GEvent.addListener(gmaplayer.mapObject, "tilesloaded", function() {
console.log("Tiles loaded");
});

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...