[OpenLayers-Users] Understanding events

Ivan Grcic igrcic at gmail.com
Tue Dec 8 18:06:34 EST 2009


Hi,

On Tue, Dec 8, 2009 at 11:26 PM, Stephen Woodbridge
<woodbri at swoodbridge.com> wrote:
> Yves Moisan wrote:
>>> Try calling your select function using a timer delay from loadend event.
>>
>> I tried looking for examples.  I saw the obvious controls for which a
>> delay makes sense (hover, WMSGetFeatureInfo) but I didn't find a way to
>> set a delay in some arbitrary location in the code.  setTimer, timer ?
>
> Wrap your selectFeature() in a setTimer()
>
Using delay is very wrong thing to do with events. Never use that.
Wrap your function in anonymous instead.

BTW map doesnt have loadend event but on vector layer
http://dev.openlayers.org/docs/files/OpenLayers/Map-js.html#OpenLayers.Map.EVENT_TYPES
http://dev.openlayers.org/docs/files/OpenLayers/Layer-js.html#OpenLayers.Layer.EVENT_TYPES

layers[0].events.register("loadend", layers[0], function(evt){
  //do what you have to do here...
   selectFeature(layers[0],oFeatures[0].fid));
});

Cheers
>> However, it pretty much defeats the purpose of waiting for loadend if
>> one adds a delay on top of it.
>
> Yes and no, it gets you closer to the time that you need so there less
> likely going to be a problem with you setting a delay, that may get
> impacted by a garbage collection of some other thing making the
> sensitivity of when you can fire the selectFeature.
>
> Maybe is doesn't help, but try it and see if it solves the problem.
> Maybe someone needs to file a bug against the loadend event.
>
> I don't like the answer, but if is works you have another data point
> that might lead someone to fix the problem once and for all. ;)
>
> -Steve
>
>> Thanx,
>>
>> Yves
>>
>>> I have found that sometimes events fire but the thread adding stuff to
>>> the DOM or something like that has not completed yet and adding a
>>> 30-50ms delay before calling my code solved the problem.
>>>
>>> Yeah, I know it ugly, but give it a try and see if it helps.
>>>
>>> -Steve W
>>
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>



-- 
Ivan Grcic



More information about the Users mailing list