Solved! Go to Solution.
function addBufferTool(){ var toggleButton = new dijit.form.ToggleButton({ label: 'Buffer', title: 'Buffer', id: "bufferButton" }); var tb = new esri.toolbars.Draw(map); //After the user draws a point on the map define the buffer parameters and execute the buffer task dojo.connect(tb, "onDrawEnd", function(geometry){ //define the buffer parameters map.graphics.clear(); var params = new esri.tasks.BufferParameters(); params.distances = [5,10]; params.unit = esri.tasks.GeometryService.UNIT_KILOMETER; params.outSpatialReference = map.spatialReference; params.bufferSpatialReference = new esri.SpatialReference({wkid: 4326}); params.geometries = [esri.geometry.webMercatorToGeographic(geometry)]; //Execute the buffer task and when it successfully completes draw the results on the map esri.config.defaults.geometryService .buffer(params, function(bufferedGeometries){ dojo.forEach(bufferedGeometries, function(geometry) { var graphic = new esri.Graphic(geometry,new esri.symbol.SimpleFillSymbol()); map.graphics.add(graphic); }); }); }); //When the toggle button is active enable the draw toolbar. When it's not active deactivate the toolbar dojo.connect(toggleButton, "onClick", function () { //clear any existing buffer graphics map.graphics.clear(); //enable or disable the draw toolbar if(toggleButton.checked){ //activate the toolbar tb.activate(esri.toolbars.Draw.POINT); }else{ //deactivate the toolbar tb.deactivate(); } }); dojo.byId('webmap-toolbar-center').appendChild(toggleButton.domNode); }
function addBufferTool(){ var toggleButton = new dijit.form.ToggleButton({ label: 'Buffer', title: 'Buffer', id: "bufferButton" }); var tb = new esri.toolbars.Draw(map); //After the user draws a point on the map define the buffer parameters and execute the buffer task dojo.connect(tb, "onDrawEnd", function(geometry){ //define the buffer parameters map.graphics.clear(); var params = new esri.tasks.BufferParameters(); params.distances = [5,10]; params.unit = esri.tasks.GeometryService.UNIT_KILOMETER; params.outSpatialReference = map.spatialReference; params.bufferSpatialReference = new esri.SpatialReference({wkid: 4326}); params.geometries = [esri.geometry.webMercatorToGeographic(geometry)]; //Execute the buffer task and when it successfully completes draw the results on the map esri.config.defaults.geometryService .buffer(params, function(bufferedGeometries){ dojo.forEach(bufferedGeometries, function(geometry) { var graphic = new esri.Graphic(geometry,new esri.symbol.SimpleFillSymbol()); map.graphics.add(graphic); }); }); }); //When the toggle button is active enable the draw toolbar. When it's not active deactivate the toolbar dojo.connect(toggleButton, "onClick", function () { //clear any existing buffer graphics map.graphics.clear(); //enable or disable the draw toolbar if(toggleButton.checked){ //activate the toolbar tb.activate(esri.toolbars.Draw.POINT); }else{ //deactivate the toolbar tb.deactivate(); } }); dojo.byId('webmap-toolbar-center').appendChild(toggleButton.domNode); }