Serious issues with Measurement widget.

1126
8
11-14-2011 04:01 AM
SanajyJadhav
Occasional Contributor II
Hi,

Its hard time for me to fix this issue. I am using Navigation toolbar and measure widget.

My problem is, my navigation is not getting deactivated while measurement is being performed. I click on area button in the measure widget and click on the map to draw a polygon.Suddenly, map is zoomed to the full extent with a scale of Nan.

I have called following methods to disable this sort of navigation but no use.
 map.disableClickRecenter();
 map.disableDoubleClickZoom();


Even I disabled the complete navigation but still map is getting zoomed in or to the full extent. Is this a bug or what I don't really understand.

If I can hook to the click event of 3 buttons in the widget (area/length/location), I could disable the navigation.I got reference to these buttons, but their click events fire randomly.I can't control them.Also, Measurement widget exposes only one event,i.e. MeasurementCompleted.So, I can't find a point where I can deactivate the navigation.

Any help is appreciated on this issue.
0 Kudos
8 Replies
derekswingley1
Frequent Contributor
As an app developer, it's up to you to manage the state of the various controls you're using in your app. That being said, I'd like to try to help as much as possible.

One thing that is confusing is that you talk about a nav toolbar but then mention navigation methods on the map itself. If I understand correctly, you should be calling navigationToolbar.deactivate() when your measurement widget is activated. Then call navigationToolbar.activate() when onMeasureEnd fires.

How are you activating the measurement widget?
0 Kudos
SanajyJadhav
Occasional Contributor II
Thanks Derek for getting back to me.

Here is the code that activates the measurement widget.

//Measure button click handler.
function MeasureBtnClickHandler()
{
    doIdentify = false;

        if (dijit.byId('dFloatingPane02').open==false)
        {
            createMeasure();
            this.navToolbar.deactivate(); //I am calling this method as you mentioned
        }         
}

//CreateMeasure function
function createMeasure()
{

    measurement = new esri.dijit.Measurement({
        map: map
    }, dojo.create('measure'));
    dojo.place(measurement.domNode,dojo.byId('measurementDiv'));
    measurement.startup();

    dijit.byId('dFloatingPane02').show();
    dijit.byId('dijit_DialogUnderlay_0').hide();
   
}


Just calling navToolbar.deactivate() was doing nothing.So, I am calling disable methods on map (as mentioned in my earlier post). When user clicks on NavToolbar Tool like Zoom in/out or pan, I calling following method to destroy the measurement widget.

function tglMeasurementOff() {
    measurement.destroy();
    dijit.byId('dFloatingPane02').hide();
    //map.enableMapNavigation()();
}


Even, when Measurement panel is closed by user, I am calling the tglMeasurementOff() method.I tried to call following function to deactivate the measurement, but it was giving me issues while doing Identify.

//When any navigation tool is clicked, following method is called.
function DeactivateMeasure()
{
    measurement.setTool("location",false);
    measurement.setTool("area",false);
    measurement.setTool("distance",false);
}


If you need any further information, please let me know. Thanks.
0 Kudos
derekswingley1
Frequent Contributor
It seems like you've got too many things going on to successfully troubleshoot this via a forum thread. I have a feeling there are some bigger app development issues but I'll try to help where I can. Here are the things that jump out at me:


//Measure button click handler.
function MeasureBtnClickHandler()
{
    doIdentify = false;

        if (dijit.byId('dFloatingPane02').open==false)
        {
            createMeasure();
            this.navToolbar.deactivate(); //I am calling this method as you mentioned
        }         
}
...<snip>...


Just calling navToolbar.deactivate() was doing nothing.So, I am calling disable methods on map (as mentioned in my earlier post).

The navigation toolbar's deactivate method works so you should address this before moving on. I have a feeling it's a scope related issue and that this.navToolbar isn't actually pointing to your navigation toolbar. If you put a console.log(this.navToolbar); statement just before your deactivate call, what does it show?


    measurement = new esri.dijit.Measurement({
        map: map
    }, dojo.create('measure'));



dojo.create('measure') does not create valid markup. You probably want dojo.create('div').

Instead of continuously creating/destroying the measurement widget, have you tried re-using the same instance of the widget?
0 Kudos
JohnGrayson
Esri Regular Contributor
The new 'Basic Viewer' app template on ArcGIS.com has some related code (see 'addMeasurementWidget' and 'toggleMeasure' methods).  Even though it uses UI elements specific to this app and does other things you might not need, there is some code that might be relevant:

measure.clearResult();
if(measure.activeTool){
  measure.setTool(measure.activeTool, false);
}
0 Kudos
SanajyJadhav
Occasional Contributor II
Thanks Derek and jgrayson for the reply.

#1. I put console.log(NavToolbar); as you had asked and I Got [object Object] in the log. I have attached the screen shot for the same.Please have a look at it.

#2. If I do not destroy the Measurement widget every time, I get a problem in the other operations like Identify.

Consider this sequence
    a. Measurement done by drawing polygon or line on map.Its active now.
   b. Navigation tool clicked and map zoomed in. (I just call following lines and am not destroying the measurement.)
measurement.setTool("location",false);
    measurement.setTool("area",false);
    measurement.setTool("distance",false);
This is fine.
    c. I click on Identify button and do Identify.This is fine as well as all measurement buttons          are deactive
    d. I again click on Measurement to do measurement.Map is identified along with measurement.I have no place to write DoIdentify=false.

I hope you could understand my problem now. Thanks once again.
0 Kudos
JianHuang
Occasional Contributor III
What you can do is to listen to the �??onClick�?� event for each tool in the measurement widget. Here is the code:

dojo.connect(measurement["distance"], "onClick", function(){/*deactivate the navigation or identify tools*/"});

Hope this helps.
0 Kudos
SanajyJadhav
Occasional Contributor II
Thanks Jian for the reply.

I had already tried to implment what you are suggesting that but that click event was getting fired randomly.I did not have much control on it.

Anyways, I created my own control by giving calls to the Geometry service.It is not as fine as Measurement Widget, but I have full control on it and it does what I asks it to do.:)

Thanks.
0 Kudos
KhmelevskiyAndrey
New Contributor
Thanks Jian for the reply.

I had already tried to implment what you are suggesting that but that click event was getting fired randomly.I did not have much control on it.

Anyways, I created my own control by giving calls to the Geometry service.It is not as fine as Measurement Widget, but I have full control on it and it does what I asks it to do.:)

Thanks.


Hi I had similar problem but finally I fount a solution which take me a bit of time:

Right after identify button activation you should disactivate measurementwidget like this:
  measurement.clearResult();
  if(measurement.activeTool){
   measurement.setTool(measurement.activeTool, false);
  }

From other side after click on any of measurementwidget buttones you should disactivate all other buttones and its listeners like that:

dojo.connect(dojo.byId('dijit_form_ToggleButton_1'), "onclick", deactivatenoMeasureButtones);

//dijit_form_ToggleButton_1 - here is id of Distance measurement widget button

function deactivatenoMeasureButtones(){
   //disconnect all buttones listeners
   dojo.disconnect(esriEPOPButtonListener);  

Right after it everythink go back under control.
0 Kudos