[OpenLayers-Users] Understanding events
Scott Lewis
scott.lewis at nsidc.org
Tue Dec 8 12:52:49 EST 2009
Can you provide the code where the layer is created and added to the
map? I think from there, I can help show you how to add a listener to
the layer to call a method when it's done loading.
Yves Moisan wrote:
> Hi List,
>
> I'm trying to wrap my head around OpenLayers events. Here's code that
> works if I uncomment the first line (alert) :
>
> // alert("Highlight on")
>
> function selectFeature(layer, fid)
> {
> for(var i = 0; i<DEFANGED_layer.features.length;++i)
> {
> if (layer.features[i].fid == fid)
> {
> FeatureSelectControl.select(layer.features[i]);
> break;
> }
> }
> }
>
> FeatureSelectControl = new OpenLayers.Control.SelectFeature( layers[0], {});
> MyMap.addControl(FeatureSelectControl);
>
> FeatureSelectControl.activate();
>
> if(oFeatures && oFeatures.length > 0)
>
> {
> var bounds = oFeatures[0].geometry.getBounds();
>
> // next line works if alert is "on"
> // selectFeature(layers[0],oFeatures[0].fid);
>
> // how do I register an event to wait until layer ends loading ? Tried variations of the following commands :
>
> // MyMap.events.register("zoomend", layers[0], selectFeature(layers[0],oFeatures[0].fid));
> // layer.events.register("loadend", layers[0], selectFeature(layers[0],oFeatures[0].fid));
>
> ...
>
> Problem is if I don't leave enough time for the layer to load, my
> selectFeature function doesn't work.
>
> I've seen there are different event types on different OL objects, so I
> tried registering events on the map and the layer objects (e.g. above),
> but obviously I do not understand how the event mechanism works. Any
> tutorial on events that could help me understand events ?
>
> TIA,
>
> Yves
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
More information about the Users
mailing list