[OpenLayers-Users] Custom Controls

André Matos andre.matos at co.sapo.pt
Fri Dec 19 05:32:08 EST 2008


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




More information about the Users mailing list