[OpenLayers-Users] Custom Controls

Eric Lemoine eric.c2c at gmail.com
Sat Dec 20 03:55:22 EST 2008


Hi

Events registration and unregistration occurs (or should occur) in
activate and deactivate, respectively.

Currently controls aren't notified when they're removed from the map,
which I think is something we should change eventually.

So right now removing a control from the map just removes the control
div from the map viewport. If you want to actually stop the control
call control.deactivate().

This discussion makes me wonder if it'd make sense to make
Map.removeControl also deactivate the control. There are controls that
are automatically activated upon being added to the map (e.g.
Navigation), and there are controls that are not (e.g. SelectFeature)
- each control is itself responsible for choosing which activation
mode it follows. For deactivate I see no cases where deactivation
after removal makes sense, so I'd be +1 on having removeControl
deactivate the control before actually removing it from the map
viewport.

Eric

2008/12/19, André Matos <andre.matos at co.sapo.pt>:
> I think it is a bug caused for it, because the destroy method or another
> method is not called to unregister events of behavior controls.
>
> For example, if you add a Navigation Control to your map, and then remove
> it, the functionality is not removed (as expected).
>
> Thanks,
> André Matos
>
>
> -----Original Message-----
> From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] On
> Behalf Of André Matos
> Sent: sexta-feira, 19 de Dezembro de 2008 10:32
> To: 'Christopher Schmidt'
> Cc: Users at openlayers.org
> Subject: Re: [OpenLayers-Users] Custom Controls
>
> Are there any method at Control class that is called when the users remove
> their controls from the map? That were nice, because when the controls are
> added to map, the draw method are called (there you register in events,
> handlers etc...), and when the control is removed was nice to unregister
> that events to stop the functionality.
>
> The description of destroy method says that:
> 	
> 	Method: destroy
> 		The destroy method is used to perform any clean up before
> the control
> 		is dereferenced.  Typically this is where event listeners
> are removed
> 		to prevent memory leaks.
>
> Typically the control is dereferenced when the programmer removes it from
> the map (map.removeControl), and it was helpful to unregister events if the
> control affect the map's behavior.
>
>
>
> Thanks
> André Matos
>
> -----Original Message-----
> From: Christopher Schmidt [mailto:crschmidt at metacarta.com]
> Sent: quinta-feira, 18 de Dezembro de 2008 18:17
> To: André Matos
> Cc: Users at openlayers.org
> Subject: Re: [OpenLayers-Users] Custom Controls
>
> On Thu, Dec 18, 2008 at 05:44:23PM -0000, André Matos wrote:
>> Hi Guys!
>>
>>
>>
>> I am starting on OpenLayers API and I have two questions…
>>
>>
>>
>> I am  studing the controls and I have notice that, there's no API methods
> or
>> API properties in Control type. That means the open layers developers can
>> change it, without any advise.
>>
>> The way I am doing my controls is this:
>>
>> Is this the best way to implement custom controls?
>
> I think so.
>
>> Will OpenLayers
>> developers change the not API methods, initialize, draw, destroy or the
> div
>> property defined at Control Class?
>
> I think it's fair to say we won't change any of those. I'll wait for
> dissenting opinions before changing the docs.
>
>> description in the Control Class destroy method:
>>
>>
>>
>> Method: destroy
>>
>>      * The destroy method is used to perform any clean up before the
> control
>>
>>      * is dereferenced.  Typically this is where event listeners are
> removed
>>
>>      * to prevent memory leaks.
>>
>>
>>
>> But it Is never called. The control is dereferenced at Map.removeControl
>> method, and this method does not call control.destroy method…
>
> Generally speaking, we try not to .destroy() anything we don't create --
> meaning it would be up to application designers to destroy things.
>
> When the map itself is destroyed, we do destroy any control associated
> with it -- but removing a control is not equivilant to wanting it
> destroyed. Instead, it's a sign that the control should no longer be
> visible on the map. The user might then take that same control and addi
> t back to the map later.
>
> So, this is just representative of our conservative destruction
> philosophy.
>
> Regards,
> --
> Christopher Schmidt
> MetaCarta
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>


More information about the Users mailing list