abrown31

Switching between two drawing tools

Discussion created by abrown31 on May 4, 2011
Latest reply on May 5, 2011 by abrown31
Hello,

I'm trying to build a measuring toolbar that allows the user to measure a distance or an area by using the freehand tool. Currently, there is a button with a dynamically-created menu and the properties are being set inside an array before being created.

Everything works fine except for one part: When the user selects and uses the "Measure by distance" tool initially, and then uses the "Measure by area" tool, you cannot go back to using the distance tool. However, if you select and use the "Measure by area" tool first, you cannot use the distance tool, the drawing shape is still a polygon.

How would I clear the session so the two tools won't get intertwined? This is my first attempt at building an application and using javascript, so sorry for any dumb questions.

Code is below:

measureTools = [{label:"Measure an area", 
        onClick: dojo.hitch(function(){
              
              dijit.byId("measureButton").set("label","Measure an area");
              tb = new esri.toolbars.Draw(map);
              dojo.connect(tb, "onDrawEnd", getAreaAndLength)
              map.graphics.clear();
              //tb.deactivate();
              tb.activate(esri.toolbars.Draw.FREEHAND_POLYGON);
              })},
        {label: "Measure a distance", 
        onClick: dojo.hitch(function(){
              
              dijit.byId("measureButton").set("label","Measure a distance");
              tb = new esri.toolbars.Draw(map);
              lengthParams = new esri.tasks.LengthsParameters();
              dojo.connect(tb, "onDrawEnd", function(geometry) {
                map.graphics.clear();
                lengthParams.polylines = [geometry];
                lengthParams.lengthUnit = esri.tasks.GeometryService.UNIT_METER;
                lengthParams.geodesic = true;
                geometryService.lengths(lengthParams);
                var graphic = map.graphics.add(new esri.Graphic(geometry, new esri.symbol.SimpleLineSymbol()));
              })
              //tb.deactivate();
              tb.activate(esri.toolbars.Draw.FREEHAND_POLYLINE);
              })}];


Thanks,

Andrew

Outcomes