[OpenLayers-Dev] A generic button class:
Tim Schaub
tschaub at openplans.org
Mon Jul 30 15:50:27 EDT 2007
Hey Jeff-
Yes, thanks for contributing. I'll add in a couple other comments here.
As Paul mentioned, we're using a new syntax for documentation. Please
see the source and the wiki page on Natural Docs for our convention.
Also (as Paul mentioned), since you are subclassing OpenLayers.Control,
you can give it a name and CLASS_NAME that reflect this. I'd vote for
OpenLayers.Control.Button. (I don't think names like "generic" or
"default" are useful. A specialized button [if there is ever a need]
inherits from Button.)
Also, note that we are using a new class syntax.
OpenLayers.Control.Button = OpenLayers.Class(OpenLayers.Control, {
// class def here
});
The above would follow the new syntax - creating a class that inherits
from control.
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.
Thanks,
Tim
Erik Uzureau wrote:
> Hi Jeff, this looks like an interesting bit of code that some other
> people might find interesting.
>
> Could you make a ticket and patch for this?
>
> Also, according to my records, we don't have an ICLA or CCLA from you.
> We'd definitely need that before it could go into trunk. See
> http://trac.openlayers.org/wiki/HowToContribute for information on how
> to get that to us.
>
> Thanks for doing this, for your desire to give back to the community.
> We are hoping to improve the process for incorporating things like
> this in the future. :-)
>
> Erik
>
> On 7/27/07, Jeff Dege <jdege at korterra.com> wrote:
>> The OpenLayers source is collecting a useful bunch of controls, but most
>> of them are designed to do something specific.
>>
>> What I've found is a need for generic buttons - click on them, and they
>> do something. But what they do is different, and specific to the
>> particular application. I've been adding them to a Panel control,
>> alongside Navigation, Zoombox, etc. But building a distinct class
>> seemed like overkill, and taking advantage of Javascripts ability to
>> extend an object at runtime struck me as a nightmare for future
>> maintainers.
>>
>> So I built a very simple little control:
>>
>> /**
>> * @class
>> *
>> */
>> GenericButton = OpenLayers.Class.create();
>> GenericButton.prototype =
>> OpenLayers.Class.inherit( OpenLayers.Control, {
>> onClick: null,
>> type: OpenLayers.Control.TYPE_BUTTON,
>>
>> trigger: function() {
>> if (this.onClick)
>> this.onClick();
>> },
>> /**
>> * @param {Event} evt
>> */
>> /** @final @type String */
>> CLASS_NAME: "OpenLayers.Class.GenericButton"
>> });
>>
>>
>> Usage is simple:
>>
>> var nav = new OpenLayers.Control.Navigation();
>> var panel = new OpenLayers.Control.Panel({defaultControl: nav});
>> panel.addControls([nav,
>> new OpenLayers.Class.GenericButton(
>> {'displayClass': 'MyGenericButton', 'onClick': myFunction});
>> ]);
>>
>> openLayersMap.addControl(panel);
>>
>> The 'displayClass' option is what is used in building the className,
>> which you'd used in the css to set the background image, etc. In this
>> case, it'd be .MyGenericButtonItemInactive. (These buttons never become
>> active, so there's no need for .MyGenericButtonItemActive. The
>> 'onClick' function is a javascript function that's called when the
>> button is clicked.
>>
>> It's pretty simple stuff, and I'm sure everyone has their own ways of
>> handling this problem. But I thought I'd throw out mine.
>>
>> _______________________________________________
>> Dev mailing list
>> Dev at openlayers.org
>> http://openlayers.org/mailman/listinfo/dev
>>
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
>
> !DSPAM:4033,46ae3975273845210051143!
>
More information about the Dev
mailing list