We have an existing application that has a function that wraps the OpenLayers.Layer.Vector constructor, which gets its layer info from a KML source over http. Once this function completes, I need to run another function which will read some of the layers data from the map object.
Normally in JavaScript I would of course use a callback when executing a remote AJAX call like this. But in this case -- perhaps because I'm still pretty new to JavaScript -- I don't know how to delay the execution of my function until the Vector constructor is done. There doesn't seem to be any ability to pass a callback to the OpenLayers.Layer.Vector constructor. Any suggestions? Thanks.
[Addendum]
How do I add the listener to the layer before the KML is loaded?
var newLay = new OpenLayers.Layer.Vector(name, {
displayInLayerSwitcher: true,
visibility: visible,
styleMap: MapLayers.styleMaps.polygonMap,
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: url,
format: new OpenLayers.Format.KML({
maxDepth: 2,
extractAttributes: true,
extractStyles: useStyles
})
})
});
function loadEndListener() {
alert('loading ended);
}
var events = new OpenLayers.Events(newLay);
events.on({"loadend": loadEndListener});
