[OpenLayers-Trac] Re: [OpenLayers] #3180: treat UI and non-UI controls differently

OpenLayers trac-20090302 at openlayers.org
Sun Mar 20 05:26:28 EDT 2011

#3180: treat UI and non-UI controls differently
 Reporter:  erilem   |       Owner:  elemoine    
     Type:  feature  |      Status:  new         
 Priority:  minor    |   Milestone:  2.12 Release
Component:  Control  |     Version:  2.10        
 Keywords:           |       State:              

Comment(by erilem):

 With the current trunk, when a non-visual control, such as a Snapping
 control, is added to the map, a div is created and added to the map
 viewport div. This polutes the DOM for nothing. The goal of this patch is
 to avoid creating and adding DOM elements for non-visual controls.

 The patch accomplishes that by introducing the concepts of UI and non-UI
 controls. Duck-typing is used. A UI control is a control that exposes a
 "draw" function. The base control class no longer has a "draw" method.
 Instead, specific (UI) controls are responsible for implementing their own
 "draw" functions.

 The patch adds a utility function named "getDiv" to the base control
 class. This function replaces the common "draw" function,  it can be
 called by subclasses when a div is needed as the root element for the

 Non-UI controls can still provide a draw method that don't return any
 element. We advertize this technique in our "create custom controls"
 examples and in the API doc. (I'm not sure we should still encourage this
 technique though.)

 Also, it is to be noted that with this patch applied some of our addins,
 such as the LoadingPanel, will require minor modifications, basically
 calling "getDiv" in place of "draw" on the parent. This is examplified by
 the patch.

 Thanks for any feedback on the patch.

Ticket URL: <http://trac.openlayers.org/ticket/3180#comment:1>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer

More information about the Trac mailing list