[OpenLayers-Users] Understanding events
Stephen Woodbridge
woodbri at swoodbridge.com
Tue Dec 8 20:49:17 EST 2009
Ivan Grcic wrote:
> 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
Yves,
Is oFeatures a global var? What happens if your add:
> layers[0].events.register("loadend", layers[0], function(evt){
> //do what you have to do here...
alert(Features[0].fid);
> selectFeature(layers[0],oFeatures[0].fid));
> });
Does this show the variable? does it highlight after you close the alert
box?
-Steve
> 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
>>
>
>
>
More information about the Users
mailing list