[OpenLayers-Users] Event registration in activate function

Alexandre Dube adube at mapgears.com
Thu Jan 8 08:25:22 EST 2009


Eric Lemoine wrote:
> On Wed, Jan 7, 2009 at 10:02 PM, Alexandre Dube <adube at mapgears.com> wrote:
>   
>> Dear list,
>>
>>  I'm writing my own Control and I need to register some events.  Doing
>> so in the initialize function isn't good because some objects are not
>> created yet ( like the map object ).  So I thought I could register them
>> in the activate() func and unregister them in the deactivate() func.
>>
>>  So far it was ok to do so, but now I'm facing a problem.  I need to
>> register events that, when triggered, deactivate the control, and other
>> events that, when triggered, reactivate the control. It's a control
>> that can contain multiple layers that come from the same source but have
>> been normalized to render faster, so the user sees no difference when
>> zooming.  The control change the opacity of a layer when the mouse is
>> over it and because the features generated come from different sources,
>> I need to deactivate the control while I'm zooming ( deactivate on
>> loadstart, activate on loadend ).  This looks like this :
>>
>> // inside the activate function()
>>        for (var key in this.layers){
>>            this.layers[key].events.register(
>>                "loadstart", this, this.deactivate);
>>            this.layers[key].events.register(
>>                "loadend", this, this.activate);
>>        }
>>
>>  So basically I should unregister them in the deactivate function(),
>> right ?  The problem is : if I deactivate the control, it will
>> unregister the loadend event so it will not be reactivated in the end.
>> Is there an other place I should register my events to avoid that
>> behavior ?  I see in some other control registration on events in a
>> draw() function.  Could I do something similar ?
>>     
>
> Defining events that activate and deactivate a control in the control
> itself seems weird to me. Have you thought about implementing an
> external component controlling your control?
>
> --
> Eric
>   
Eric : Yeah, it seems weird doing so but I want the control to be 
independent.  External component : I think that's what I'm actually 
doing in my init() function, or do you mean something else ?

Andreas : that's a great idea.  Event registration on the map object can 
be set in the setMap() function and others, like on layers, can be in 
the initialize().

Thanks a lot,

-- 
Alexandre Dubé
Mapgears
www.mapgears.com




More information about the Users mailing list