[OpenLayers-Dev] A generic button class:

Paul Spencer pspencer at dmsolutions.ca
Tue Jul 31 07:41:18 EDT 2007


On 30-Jul-07, at 4:50 PM, Jeff Dege wrote:

>> From: dev-bounces at openlayers.org
>> [mailto:dev-bounces at openlayers.org] On Behalf Of Tim Schaub
>> Sent: Monday, July 30, 2007 2:50 PM
>> Cc: dev at openlayers.org
>> Subject: Re: [OpenLayers-Dev] A generic button class:
>>
>> Finally, for documentation sake alone, it makes sense to define an
> empty
>> onClick method on the prototype (onClick: function() {}). Document
> that
>> and have your trigger method always call it.
>
> If we do that, then the trigger function no longer seems meaningful.
>
> Instead of my:
>     onClick: null,
>     type: OpenLayers.Control.TYPE_BUTTON,
>     trigger: function() {
>         if (this.onClick)
>            this.onClick();
>     },
>
> We'd have:
>
>     onClick: function() {},
>     type: OpenLayers.Control.TYPE_BUTTON,
>     trigger: function() {
>         this.onClick();
>     },
>
> In which case, we could just as easily leave out the onClick()  
> function,
> altogether, and instead of using the class thus:
>
>     panel.addControls([nav,
>         new OpenLayers.Control.Button(
>           {'displayClass': 'MyButton', 'onClick': myFunction});
>         ]);
>
> do this:
>
>     panel.addControls(new OpenLayers.Control.GenericButton(
>         {'displayClass': 'MyButton', 'trigger': myFunction});
>     ]);
>
> And from that, we could skip the Button control entirely:
>
>     panel.addControls(new OpenLayers.Control({type:
> OpenLayers.Control.TYPE_BUTTON,
>         'displayClass': 'MyButton', 'trigger': myFunction});
>     ]);
>
> At which point, things are simple enough that I'm not at all sure that
> we gain anything by defining a separate Button class.
>

Jeff,

are you going to modify your own code to stop using the Button  
control and use the last case, or do you still see it as being  
desirable to have a separate 'Button' control?  Given that OL is  
usually fairly semantically verbose already, I don't see a real  
problem with having a distinct Button control.

Paul

+-----------------------------------------------------------------+
|Paul Spencer                          pspencer at dmsolutions.ca    |
+-----------------------------------------------------------------+
|Chief Technology Officer                                         |
|DM Solutions Group Inc                http://www.dmsolutions.ca/ |
+-----------------------------------------------------------------+








More information about the Dev mailing list