[OpenLayers-Dev] A generic button class:

Erik Uzureau erik.uzureau at metacarta.com
Mon Jul 30 15:17:36 EDT 2007


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
>



More information about the Dev mailing list