Deactivate ESRI measurement widget?

8023
11
05-24-2011 04:25 AM
ChrisBuckmaster1
Occasional Contributor
Hi

I am wondering if there is an easy way to deactivate/disable the measurement widget?

The only way I can see is clicking back onto the icon that was selected but this isn't that obvious for users so I would like to include a button to disable it (if identify / other tools are then activated).

There is a destroy method but I cannot seem to activate the tool after this, any ideas?
0 Kudos
11 Replies
DanielNieto_Jr
New Contributor
I have a similar question, after using the destroy method, I am unable to recreate the measurement widget.  Does anyone have an easy solution?
0 Kudos
JeffPace
MVP Alum
We massively customized the Sample Viewer, so we reopen widgets alot.  ESRI does not seem to handle this the same way in all cases.

In particular, I have alot of issues with the ESRI dijits.  The legend, for example, destroys its container, and cant be reopened.

For the measurement widget, i try just about everything to get it to "destroy" cleanly.  it would not. However, for some reason (the complete opposite of the legend dijit).  You dont have to destroy it.  (just never call the destroy method).  You can just close and reopen it.
0 Kudos
NeilGreatorex
New Contributor
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);
}
0 Kudos
HemingZhu
Occasional Contributor III
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);
}


Extra info in case you are interested. you can also do it  by the following.
locationBtn.setActive(false);
distanceBtn.setActive(false);
areaBtn.setActive(false);
setActive to false will deselect those button, therefore no action will be taken.
0 Kudos
GISAdmin1
New Contributor III
You can also deactivate the tool after measuring:

  dojo.connect(measurement, "onMeasureEnd", function(activeTool,geometry){
  this.setTool(activeTool, false);
});
0 Kudos
Shingo-Ikeda
New Contributor III
I am also seeing the similar issue. In my case, I have a function to switch map to load another AGS dynamic layer. After a map is destroyed and recreated, measurement widget loses all of its events such as onClick, onMeasureEnd and _switchUnit. Instead, it is showing "typeError: map.navigationManager is null" message.

Destroying measurement widget and recreate causes function to bail out at startup() call. Skipping recreation and recreating events shows measurement panel, but does not activate measurement on button click.
Shingo Ikeda
Geospatial Data Scientist/Developer - Geographical Information Platform
Global Power Generation - Digital Satellite USA and Canada
0 Kudos
JianHuang
Occasional Contributor III
Are you using 3.5?
0 Kudos
Shingo-Ikeda
New Contributor III
Hi Jian,

Yes. I am using the 3.5 and I noticed that when I was destroying the measure object, I was also removing the parent div as well.

<div id="floater">     
<div id="measureDiv"></div>
</div>


meas = dijit.byId('measureTool');
    if (meas) {
        meas.destroy();        
    }


By placing the measureDiv again, I as able to restore the measure tool.

var measure = new esri.dijit.Measurement({
            map: currentmap,
            id: 'measureTool'
        }, dojo.create('measurement'));    
        dojo.place(measure.domNode,dojo.byId('measureDiv')); 


Thanks to the solution provided by Kelly @ esri.

Shttp://forums.arcgis.com/threads/42208-toggle-measurement-dijit-(startup-amp-destroy)hingo
Shingo Ikeda
Geospatial Data Scientist/Developer - Geographical Information Platform
Global Power Generation - Digital Satellite USA and Canada
0 Kudos
behsoh
by
New Contributor II

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

0 Kudos