Select to view content in your preferred language

How to NOT SHOW/HIDE infowindow/popup if identify results = No Info Avai.?

5645
5
03-17-2012 11:18 AM
ChristopherPollard
Regular Contributor
So I have an application where I only want the popup to open when identifying 1 visible layer.
How do I have the popup close or not even display if the results are NULL or return "No information Available"?
Here's some of my code.Thanks...

function mapReady(map){
   
       dojo.connect(map,'onClick',executeIdentifyTask);
       
       //create identify tasks and setup parameters 
       identifyTask = new esri.tasks.IdentifyTask("http://gis.dvrpc.org/ArcGIS/rest/services/Ci2_raster/MapServer");
       
       identifyParams = new esri.tasks.IdentifyParameters();
       identifyParams.tolerance = 3;
       identifyParams.returnGeometry = true;
  //     identifyParams.layerIds = [6];
       identifyParams.layerIds = cii.visibleLayers;
       identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
       identifyParams.width  = map.width;
       identifyParams.height = map.height;

      }
    
   
     function updateDynLayerVisibility() {
                var inputs = dojo.query(".dyn_item");
                visible = [];
                for (var i = 0, il = inputs.length; i < il; i++) {
                    if (inputs.checked) {
                        visible.push(inputs.id);
                    }
                }
                // If no layers are visible set the array value to = -1
                // and disconnect the identify task
                if (visible.length === 0) {
                    visible = [-1];
                    map.infoWindow.hide();
                }
                // Update Identifys layers
                identifyParams.layerIds = visible;
                // Update layer visiblity
                cii.setVisibleLayers(visible);
            } 
      
   function executeIdentifyTask(evt) {  
      // custom code to only identify visible layers
  // start
      if (visible.length === 1 && visible[0] == -1){
                    map.infoWindow.clearFeatures();
                    map.infoWindow.show(evt.mapPoint);
 
                } else {
                    identifyParams.geometry = evt.mapPoint;
                    identifyParams.mapExtent = map.extent;
 //end   
        var deferred = identifyTask.execute(identifyParams);

        deferred.addCallback(function(response) {     
          // response is an array of identify result objects    
          // Let's return an array of features.
          return dojo.map(response, function(result) {
            var feature = result.feature;
            feature.attributes.layerName = result.layerName;
    if (result.layerName === 'CIIndex'){
        var template = new esri.dijit.PopupTemplate();
     var attr = feature.attributes;
       content = "<B>Community Investment Index:</B><br>"
      +"<FONT color=red><B>${Pixel value:Numberformat(value:0)}</B></FONT><br>";
              template.setContent(content); 
   //   template.setContent("${*}"); 
              feature.setInfoTemplate(template);
            }
            return feature;
          });
        });
  
        map.infoWindow.setFeatures([ deferred ]);
        map.infoWindow.show(evt.mapPoint);
      }
   
// add for Visible code   
  } 
0 Kudos
5 Replies
StephenLead
Honored Contributor
How do I have the popup close or not even display if the results are NULL or return "No information Available"?


 deferred.addCallback(function(response) {     
// response is an array of identify result objects    


Try if(response.length <1)

Steve
0 Kudos
GregYoung
Occasional Contributor

An old thread, but I just encountered this issue myself and have something to add.  Using "if (response.length < 1)" will allow one to hide the InfoWindow if there is no data returned, but it doesn't stop the popup from appearing in the first place.  Move the location of the map.infoWindow.show() statement to inside the deferred object just before the first return statement (leaving map.infoWindow.setFeatures([Deferred]) where it is) and only run it if response.length > 0;

    

deferred.addCallback(function(response) {       
 // response is an array of identify result objects       

// Let's return an array of features. 
   if (response.length > 0) { 
        
        map.infoWindow.show(evt.mapPoint);
        return dojo.map(response, function(result) {  
BenCamp
Deactivated User

THANK YOU GREG! This has been annoying me for years! It's great to have a solution!

0 Kudos
JasonJaworski
Emerging Contributor

Thank you Greg! This was definitely a big help, but I want to extend this a little further and I am having some trouble.

Do you know of a way to hide the infoWindow when the standard measurement widget is active?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jason,

   Take a look at this thread:

Measurement Widget and Popups