Disable Info Window while Measuring

5386
17
Jump to solution
08-19-2013 02:24 PM
EmilyLaMunyon
Occasional Contributor
Hi,
I have an application that utilizes an Identify Task to select and show a popup Info Window on certain layers. This works fine until
the Measurement Widget is activated and an Info Window popups up every time a distance is measured. I have come across many threads that deal with this issue but have had no luck implementing any of them. How do I deactivate the Info Window when
using the Measure Widget? Any help is greatly appreciated!!

//Measurement Tool       var measurement = new esri.dijit.Measurement({              map: map,     defaultLengthUnit: esri.Units.FEET,      }, dojo.byId('measurementDiv'));             measurement.startup();                       dojo.connect(measurement, "onMeasureEnd", function(activeTool,geometry){          this.setTool(activeTool, false),    });  //Identify Event function executeIdentifyTask(evt) {             identifyParams.geometry = evt.mapPoint;         identifyParams.mapExtent = map.extent;         var deferred = identifyTask.execute(identifyParams);          deferred.addCallback(function(response) {              return dojo.map(response, function(result) {         var feature = new esri.Graphic(result.feature.toJson());;                        feature.attributes.layerName = result.layerName;         if(result.layerName === 'Section Corners' || result.layerName === 'Accessory Monuments'){          // console.log(feature.attributes.POINT_NAME);          var template = new esri.InfoTemplate("Monuments", "Point Name: ${POINT_NAME}<br/><a target='_blank'  href='http://surveyor.slco.org/jsapi/map/mrs_javamap.cfm?LAT=${LATITUDE}&LONG=${LONGITUDE}&POINT_NAME=${POINT_NAME}'>Mon. Ref. Sheet</a>");          feature.setInfoTemplate(template);             }             else if (result.layerName === 'Surveys'){             var template = new esri.InfoTemplate("Surveys", "${SURVEYOR}<br/> Survey Number: ${DOCUMENT_N}<br/><a target='_blank' href='http://surveyor.slco.org/jsapi/map/sire_survey_image.cfc?page_id=${page_id}'>Survey PDF Document</a>");               feature.setInfoTemplate(template);             }                 return feature;           });         });                    map.infoWindow.setFeatures([ deferred ]);         map.infoWindow.show(evt.mapPoint);       }    
0 Kudos
1 Solution

Accepted Solutions
EmilyLaMunyon
Occasional Contributor
Jason,
Your advice was great, and I appreciate your time, I just could not get it to work with my application. I did finally figure it out, and
hopefully this helps someone else with the same issue.

function executeIdentifyTask(evt) {        var measureMode =   dojo.query(".esriButton .dijitButtonNode").some(function(node, index, arr){             if(node.childNodes[0].checked){             //at least one of the measure tools is active so disable identify             return true;                        }        });        if(! measureMode){         map.graphics.clear();         identifyParams.geometry = evt.mapPoint;         identifyParams.mapExtent = map.extent;          var deferred = identifyTask.execute(identifyParams);         deferred.addCallback(function(response) {              return dojo.map(response, function(result) {         var feature = new esri.Graphic(result.feature.toJson());;               feature.attributes.layerName = result.layerName;             if(result.layerName === 'Section Corners' || result.layerName === 'Accessory Monuments'){                         var template = new esri.InfoTemplate("Monuments", "Point Name: ${POINT_NAME}<br/><a target='_blank' href='../../mrs_javamap.cfm?LAT=${LATITUDE}&LONG=${LONGITUDE}&POINT_NAME=${POINT_NAME}'>Mon. Ref. Sheet</a>");               feature.setInfoTemplate(template);             }             else if (result.layerName === 'Surveys'){           var template = new esri.InfoTemplate("Surveys", "${SURVEYOR}<br/> Survey Number: ${DOCUMENT_N}<br/>Address: ${ADDRESS_OF_SURVEY}<br/><a target='_blank' href='../../sire_survey_image.cfc?page_id=${page_id}'>Survey PDF Document</a>");               feature.setInfoTemplate(template);             }                 return feature;           });         });                    map.infoWindow.setFeatures([ deferred ]);         map.infoWindow.show(evt.mapPoint);       }     } 

View solution in original post

17 Replies
ZachLiu1
Occasional Contributor II
When you set up your event handlers for your Identify Task, you can assign it to a variable, like,
 var identifyHandler = map.on("click", executeIdentifyTask);


Then your measurement dijit can start like this,
$(".measure_trigger").click(function(e){
                e.preventDefault();
                dojo.disconnect(identifyHandler);
                return false;
            });


So the basic idea is you can add and remove the event listener for your Identify Task as you need.

Hope this may help.
0 Kudos
Quynh_NhuMai
New Contributor III

I know this is a javascript question and not arcgis--but, wondering how you reconnect a saved handler? Not able to figure that out with the docs...

I save my handler like this:

window.myHandler = dojo.connect(window.myMap, "onClick", runIdentifies)

Later, I do:

dojo.disconnect(window.myHandler);

Is there any way to do the following:

dojo.connect(window.myHandler)

This is because i'm having issues accessing the runIdentifies function from where I want to reconnect.

0 Kudos
KenBuja
MVP Esteemed Contributor

Instead of using dojo.connect, you should be using dojo/on, the preferred way of dealing with events. In the documentation, you'll see that there is a pausable method, which allows you to stop listening to an event but start again later.

Quynh_NhuMai
New Contributor III

Okay, that's perfect. Thank you.

0 Kudos
JasonZou
Occasional Contributor III
Try this:

// invoke toggleIdentify after measurement.setTool is called.
// The last parameter "true" means to pass the setTool parameter to toggleIdentify 
dojo.aspect.after(measurement, "setTool", toggleIdentify, true);

function toggleIdentify(toolName, activate) {
    // disable identifyHandler when measurement tool is set and activated
    if (activate && identifyHandler) {
        dojo.disconnect(identifyHandler);
        identifyHandler = null;
    }
    // activate identify tool otherwise
    else {
        identifyHandler = map.on("click", executeIdentifyTask);
    }
}
0 Kudos
EmilyLaMunyon
Occasional Contributor
Thank you both so much for your helpful responses!

I have tried to integrate the advice provided into my code and it still is not working, I am sure I am close but still missing something.

var identifyHandler = (map,"onClick",executeIdentifyTask);



var measurement = new esri.dijit.Measurement({ 
           map: map,
    defaultLengthUnit: esri.Units.FEET, 
 }, dojo.byId('measurementDiv')); 
           measurement.startup(); 
  
   dojo.connect(measurement, "onMeasureEnd", function(activeTool,geometry){
   dojo.disconnect(identifyHandler);
   return false;
   this.setTool(activeTool, false)
   });
0 Kudos
JasonZou
Occasional Contributor III
Have you tried my approach? My approach assumes that identifyHandler is a global variable. You will need to change it if not.
0 Kudos
ZachLiu1
Occasional Contributor II
Emily, I think you should try Jason's approach for your purpose.

to make it clear,

My approach works in a control system with something like a menu or control buttons. So when you trigger your measurement dijit you can disconnect the handler for identify. And when you trigger your identify function, you can again add the listener for it to work. So functions won't bother each other.
0 Kudos
EmilyLaMunyon
Occasional Contributor
Jason,
Thanks again for getting back to me. I have tried to implement your advice into my code and am still having the popup window appear when measuring. I am sure I am missing something obvious. I added in my identify code in case I am missing something there.
var identifyHandler = (map,"onClick",executeIdentifyTask);
  
 
  var measurement = new esri.dijit.Measurement({ 
                map: map,
  defaultLengthUnit: esri.Units.FEET, 
  }, dojo.byId('measurementDiv')); 
                measurement.startup(); 
     
     
   dojo.connect(measurement, "onMeasureEnd", function(activeTool,geometry){
   this.setTool(activeTool, false)
   dojo.aspect.after(measurement, "setTool", toggleIdentify, true);

   });
   
       function toggleIdentify(measurement, activate) {
    // disable identifyHandler when measurement tool is set and activated
    if (activate && identifyHandler) {
        dojo.disconnect(identifyHandler);
        identifyHandler = null;
    }
    // activate identify tool otherwise
    else {
        identifyHandler = (map, "onClick", executeIdentifyTask);
    }
}

    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);
 
}  


function mapReady(map){
  
    var identifyHandler = (map,"onClick",executeIdentifyTask);
       dojo.connect(map,"onClick",executeIdentifyTask);
       //create identify tasks and setup parameters 
       identifyTask = new esri.tasks.IdentifyTask("http://gis10.slco.org/SLCOGIS/rest/services/public/Surveyor_New/MapServer");
       
       identifyParams = new esri.tasks.IdentifyParameters();
       identifyParams.tolerance = 8;
       identifyParams.returnGeometry = true;
       identifyParams.layerIds = [1,2,4];
       identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
       identifyParams.width  = map.width;
       identifyParams.height = map.height;
      }
      
   
      function executeIdentifyTask(evt) {
   
        identifyParams.geometry = evt.mapPoint;
        identifyParams.mapExtent = map.extent;
        var deferred = identifyTask.execute(identifyParams);

        deferred.addCallback(function(response) {     
        return dojo.map(response, function(result) {
        var feature = new esri.Graphic(result.feature.toJson());;
    
         
            feature.attributes.layerName = result.layerName;
            if(result.layerName === 'Section Corners' || result.layerName === 'Accessory Monuments'){
             // console.log(feature.attributes.POINT_NAME);
               var template = new esri.InfoTemplate("Monuments", "Point Name: ${POINT_NAME}<br/><a target='_blank' href='http://surveyor.slco.org/jsapi/map/mrs_javamap.cfm?LAT=${LATITUDE}&LONG=${LONGITUDE}&POINT_NAME=${POINT_NAME}'>Mon. Ref. Sheet</a>");
              feature.setInfoTemplate(template);
            }
            else if (result.layerName === 'Surveys'){
              var template = new esri.InfoTemplate("Surveys", "${SURVEYOR}<br/> Survey Number: ${DOCUMENT_N}<br/>Address: ${ADDRESS_OF_SURVEY}<br/><a target='_blank' href='http://surveyor.slco.org/jsapi/map/sire_survey_image.cfc?page_id=${page_id}'>Survey PDF Document</a>");
              feature.setInfoTemplate(template);
            }
   
            return feature;
          });
        });
   
      
        map.infoWindow.setFeatures([ deferred ]);
        map.infoWindow.show(evt.mapPoint);
      }