[Users] Reuse GeoExt Action

Adam Ratcliffe adam at prema.co.nz
Wed Mar 9 19:54:31 CET 2011


Hi,

Each of your layers will have its own DrawFeature control.  I've
overridden GeoExt action to allow for the action's control to be
switched out when a layer is selected in the application's layer tree:

Ext.override(GeoExt.Action, {

    /**
     * Sets a new OpenLayer's control for this action
     * @param {OpenLayers.Control} control the control to set
     */
    setControl: function(control) {
        var isActive = this.control ? this.control.active : false;
        if(this.control) {
            this.unsetControl();
        }
        if(isActive) {
            control.activate();
        } else {
            control.deactivate();
        }

        control.events.on({
            activate: this.onCtrlActivate,
            deactivate: this.onCtrlDeactivate,
            scope: this
        });

        this.control = control;
    },

    /**
     * Unsets the control currently set on this action
     */
    unsetControl: function() {
        if(!this.control) {
            return;
        }

        if(this.control.events) {
            this.control.events.un({
                activate: this.onCtrlActivate,
                deactivate: this.onCtrlDeactivate,
                scope: this
            });
        }
        if(this.control.active) {
            this.control.deactivate();
        }
        this.control = null;
    }
});

Cheers
Adam

On Thu, Mar 10, 2011 at 6:17 AM, killspam killspam <01killspam at gmail.com> wrote:
> Hi List.
>
> It is possible to reuse GeoExt action for different layers?
> For example drawing linestring.
>
> Regards.
> Mario.
>
> _______________________________________________
> Users mailing list
> Users at geoext.org
> http://www.geoext.org/cgi-bin/mailman/listinfo/users
>
>


More information about the Users mailing list