Select to view content in your preferred language

Disable Info Window while Measuring

6304
17
Jump to solution
08-19-2013 02:24 PM
EmilyLaMunyon
Deactivated User
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
17 Replies
JasonZou
Frequent Contributor
Change:
dojo.connect(measurement, "onMeasureEnd", function(activeTool,geometry){
    this.setTool(activeTool, false)
    dojo.aspect.after(measurement, "setTool", toggleIdentify, true);
});


To:
dojo.aspect.after(measurement, "setTool", toggleIdentify, true);
dojo.connect(measurement, "onMeasureEnd", function(activeTool,geometry){
    this.setTool(activeTool, false)
});
0 Kudos
EmilyLaMunyon
Deactivated User
Change:
dojo.connect(measurement, "onMeasureEnd", function(activeTool,geometry){
    this.setTool(activeTool, false)
    dojo.aspect.after(measurement, "setTool", toggleIdentify, true);
});


To:
dojo.aspect.after(measurement, "setTool", toggleIdentify, true);
dojo.connect(measurement, "onMeasureEnd", function(activeTool,geometry){
    this.setTool(activeTool, false)
});


Jason, again, thanks so much. I have no idea why, but this is still not working. This is what I have, and the popups are still appearing when I measure. Sorry to be such a pain...

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


var measurement = new esri.dijit.Measurement({ 
            map: map,
     defaultLengthUnit: esri.Units.FEET, 
     }, dojo.byId('measurementDiv')); 
               measurement.startup(); 
     
     
   dojo.aspect.after(measurement, "setTool", toggleIdentify, true);
          dojo.connect(measurement, "onMeasureEnd", function(activeTool,geometry){
          this.setTool(activeTool, false)
});
   
       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);
 
}  


//Identify Task
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);
      }    
0 Kudos
JasonZou
Frequent Contributor
Open the app in Chrome and start the Developer Tools. Set a breakpoint at the first statement inside toggleIdentify. Will the app reach the breakpoint when you click any of the measurement tools?
0 Kudos
EmilyLaMunyon
Deactivated User
I put the break point on:
 if (activate && identifyHandler) {


and the app reaches it, but in the scope variables in Chrome developer it says that activate is undefined.
0 Kudos
JasonZou
Frequent Contributor
Ok. After some testing, this should work. Change toggleIdentify function as below.

function toggleIdentify(toolName) {
    var isMeasurementActive = measurement[toolName].checked;

    // disable identifyHandler when measurement tool is set and activated
    if (isMeasurementActive) {
        dojo.disconnect(identifyHandler);
        identifyHandler = null;
    }
    // activate identify tool otherwise
    else {
        identifyHandler = map.on("click", executeIdentifyTask);
    }
}
0 Kudos
EmilyLaMunyon
Deactivated User
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);       }     } 
AdrianMarsden
Honored Contributor
Oddly my code I had a different approach, which broke when I moved to API 3.7

I had hooked the onclick of the tool to a routine, disableID(), that set a global variable - which I then checked against on my id function

        dojo.connect(measurement, "onClick", function() {           
            navToolbar.deactivate();
            ClearAllButtonsIcon();
            disableID();
        });


Since 3.7 none of this event gets triggered - using your method of checking works fine - so many thanks.

Anyone any ideas why my old code broke at 3.7? I haven't tried using the newer style "on" way of linking to events yet.

Cheers

ACM
0 Kudos
VincentAwino
Deactivated User
Hi jason,

I'm quit new to ArcGIS JavaScript API, so its a little difficult to follow the thread here. could you get me a simple example where you use a PopupTemplate  and disable the Popup when using the Measurement widget. id greatly appreciate. thanks a lot. In case you need to check out my code view here http://jsfiddle.net/vince_awino/D3J8H/15/
0 Kudos