[Users] Toggle Button

Smaran Harihar smaran.harihar at gmail.com
Tue Jul 17 20:47:09 CEST 2012


Hey guys,

I am using the Geoext for the first time and was going through the
tutorials. On this tutorial,
http://geoext.org/tutorials/control-button-tutorial.html, in the "There can
only be one" section, the sample code stating how to use the Toggle button,

var length = new OpenLayers.Control.Measure(OpenLayers.Handler.Path, {
    eventListeners: {
        measure: function(evt) {
            alert("The length was " + evt.measure + evt.units);
        }
    }
});

var area = new OpenLayers.Control.Measure(OpenLayers.Handler.Polygon, {
    eventListeners: {
        measure: function(evt) {
            alert("The area was " + evt.measure + evt.units);
        }
    }
});

mapPanel.map.addControl(length);
mapPanel.map.addControl(area);

var toggleGroup = "measure controls";

var lengthButton = new Ext.Button({
    text: 'Measure Length',
    enableToggle: true,
    toggleGroup: toggleGroup,
    handler: function(toggled){
        if (toggled) {
            length.activate();
        } else {
            length.deactivate();
        }
    }
});

var area = new Ext.Button({
    text: 'Measure Area',
    enableToggle: true,
    toggleGroup: toggleGroup,
    handler: function(toggled){
        if (toggled) {
            area.activate();
        } else {
            area.deactivate();
        }
    }
});

We are using the variable 'area' and 'length' for the OpenLayers Control as
well as Ext Button. If we use it like this in plain Javascript, would it
not result in an error, as the variable names are meant to be unique,
right??

-- 
Thanks & Regards
Smaran Harihar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20120717/375df2fc/attachment.htm 


More information about the Users mailing list