Hi Ian,what you can do is assign the event listener to some variable and use dojo.disconnect method to remove the eventlistener on the button click.here's an example://global variablevar PSFLEventListener;var NewEventListener;//use the below to attach the event listenerPSFLEventListener = dojo.connect(plantingsitesFL, "onClick", function(evt) { dojo.stopEvent(evt); activateEditToolbar(evt.graphic); activeFeatureLayer = plantingsitesFL; });//use the below to disconnect on button click and attach the new using the same method.function button_onclick(){ dojo.disconnect(PSFLEventListener); NewEventListener = dojo.connect(publictreeinventoryFL, "onClick", function(evt) { dojo.stopEvent(evt); activateEditToolbar(evt.graphic); activeFeatureLayer = publictreeinventoryFL; });}Hope this helps.Regards,Manish
// EDITING - CONNECT MAP WITH EDITOR TOOLBAR dojo.connect(map, "onLoad", createEditToolbar); // EDITING - CONNECT MAP WITH DELETE FEATURE TOOL dojo.connect(map, "onLayersAddResult", editingDeleteFeature); // ***************************************************************************** // * EDIT FEATURES - MOVE, EDIT VERTICES, SCALE, ROTATE, OPTIONS * // ***************************************************************************** function createEditToolbar() { var activeFeatureLayer = null; var landuseLayerFL = map.getLayer("landuseLayer"); var militaryareasFL = map.getLayer("militaryareas"); editModifyFeaturesTools = new esri.toolbars.Edit(map); // ACTIVATE TOOLBAR WHEN CLICKING ON LAND USE dojo.connect(landuseLayerFL, "onClick", function(evt) { dojo.stopEvent(evt); activateEditToolbar(evt.graphic); activeFeatureLayer = landuseLayerFL; }); // ACTIVATE TOOLBAR WHEN CLICKING ON MILITARY SITES dojo.connect(militaryareasFL, "onClick", function(evt) { dojo.stopEvent(evt); activateEditToolbar(evt.graphic); activeFeatureLayer = militaryareasFL; }); // DEACTIVATE TOOLBAR dojo.connect(map,"onClick", function(evt){ editModifyFeaturesTools.deactivate(); }); // POST EDITS AFTER TOOL IS DEACTIVATED dojo.connect(editModifyFeaturesTools, "onDeactivate", function(editTool,graphic) { activeFeatureLayer.applyEdits(null, [graphic], null); alert("Feature successfully updated."); }); } // ACTIVATE TOOLBAR EDITING function activateEditToolbar(graphic) { var editTool = 0; if (dijit.byId("tool_move").checked) { editTool = editTool | esri.toolbars.Edit.MOVE; } if (dijit.byId("tool_vertices").checked) { editTool = editTool | esri.toolbars.Edit.EDIT_VERTICES; } if (dijit.byId("tool_scale").checked) { editTool = editTool | esri.toolbars.Edit.SCALE; } if (dijit.byId("tool_rotate").checked) { editTool = editTool | esri.toolbars.Edit.ROTATE; } // SPECIFY TOOLBAR OPTIONS var options = { allowAddVertices: dijit.byId("vtx_ca").checked, allowDeleteVertices: dijit.byId("vtx_cd").checked, uniformScaling: dijit.byId("uniform_scaling").checked }; editModifyFeaturesTools.activate(editTool, graphic, options); } // ***************************************************************************** // * DELETE FEATURES * // ***************************************************************************** function editingDeleteFeature(results) { var layers = dojo.map(results, function (result) { return result.layer; }); // DELETE FEATURE USING ONCLICK dojo.forEach(layers, function (deleteFeatureslLayer) { dojo.connect(deleteFeatureslLayer, "onClick", function (evt) { dojo.stopEvent(evt); // DELETE FEATURE IS DELETE BUTTON IS CHECKED (ACTIVE) if (dijit.byId("tool_delete").checked) { deleteFeatureslLayer.applyEdits(null, null, [evt.graphic], function () { operation = new esri.dijit.editing.Delete({ featureLayer: deleteFeatureslLayer, deletedGraphics: [evt.graphic] }); // ALERT WHEN FEATURE IS DELETED alert("Feature deleted.") }); } }); }); }
I have two toolsets. . one is used to modify features (move, rotate, scale, edit vertices) on the map and the other is used to delete features on the map. The problem is that my delete tool will not work with the modify features toolset. If the move feature button is checked from the modify features toolset, then I can delete a feature, but I want these tools to work separately.My question is, can I disable a tool using a button?I have attached a code sample. Any feedback will greatly be appreciated.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.