Quynh,
The way you have your code written the on event handler is added each time toggle is clicked on which results in multiple handlers being added. You need to have you code check for the existence of the window.idHandler and if it exists then do not recreate it.
This works very well to deactivate the measure tool--I am trying to use it to deactivate the measure tool when an identify button is toggled. However, I'm getting some conflict with the identify handler I'm using. The code below starts and pauses the identify handler when the identify button is toggled (identify does not work and console prints out "Identify started" followed by "Identify paused". Can anyone see why this may be happening with the code posted below?
var idButton = new ToggleButton({ label: "Identifier les entités", showLabel: false, iconClass: "identifyIcon", checked: false, onChange: function (val) { if (val) { window.idHandler = on.pausable(window.myMap, "click", runIdentifies); //runIdentifies is the identify function console.log("Identify started"); measurementActiveButton = dojo.query(".esriMeasurement .esriButton.esriButtonChecked .dijitButtonNode")[0] if(measurementActiveButton){ measurementActiveButton.click(); } } else { window.idHandler.pause(); console.log("Identify paused"); } } }, "id_button"); idButton.startup();
for those who still haven't find any solution for this, and problems like that, here's what I've done.
you can simply simulate the CLICK trigger which deactivates the activated task, or whatever.
use dojo query to target the activated element, then .click() on it.
measurementActiveButton = dojo.query(".esriMeasurement .esriButton.esriButtonChecked .dijitButtonNode")[0] if(measurementActiveButton){ measurementActiveButton.click(); }
hope you find it helpful.
cheers developers
<div id="floater"> <div id="measureDiv"></div> </div>
meas = dijit.byId('measureTool'); if (meas) { meas.destroy(); }
var measure = new esri.dijit.Measurement({ map: currentmap, id: 'measureTool' }, dojo.create('measurement')); dojo.place(measure.domNode,dojo.byId('measureDiv'));
I have written the following hacked together function which will deactivate the measurement widget. Calling measurement.deactivate() will deselect any selected function and return to the usual map tools. Hope it's useful to others. var measurement = new esri.dijit.Measurement({ map: map }, dojo.byId('measurement')); measurement.deactivate = function() { var locationBtn = dijit.byId('location'), distanceBtn = dijit.byId('distance'), areaBtn = dijit.byId('area') this.closeTool(); locationBtn.setAttribute('checked', false); distanceBtn.setAttribute('checked', false); areaBtn.setAttribute('checked', false); }
var measurement = new esri.dijit.Measurement({ map: map }, dojo.byId('measurement')); measurement.deactivate = function() { var locationBtn = dijit.byId('location'), distanceBtn = dijit.byId('distance'), areaBtn = dijit.byId('area') this.closeTool(); locationBtn.setAttribute('checked', false); distanceBtn.setAttribute('checked', false); areaBtn.setAttribute('checked', false); }
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.