Select to view content in your preferred language

Identify Results Popup

1831
18
Jump to solution
06-28-2013 05:57 AM
NicholasKnabe
Emerging Contributor
I successfully added this https://developers.arcgis.com/en/javascript/jssamples/find_popup.html to my application, but I was wondering if anybody knows if you can just get the attributes of layers that are one. Right now when I click on one of my layers it pulls up every feature within the pixel area instead of just the layers that are on...

Thank you!
0 Kudos
18 Replies
NicholasKnabe
Emerging Contributor
I still cannot get mine to just identify the visible layers.I have tried your way and my way and it still gives me results of every layer
0 Kudos
KenBuja
MVP Esteemed Contributor
Can you post more of your code (like the executeIdentifyTask) or set up a Fiddle to replicate your issue?
0 Kudos
NicholasKnabe
Emerging Contributor
 function mapReady(map) {
          dojo.connect(map, "onClick", executeIdentifyTask);
          //create identify tasks and setup parameters 
          identifyTask = new esri.tasks.IdentifyTask("http://maps101.gis.halff.com/ladon/rest/services/Lubbock/LubbockCCTVAssets/MapServer/");
          identifyParams = new esri.tasks.IdentifyParameters();
          identifyParams.tolerance = 3;
          identifyParams.returnGeometry = true;
          identifyParams.layerIds = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17];
          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) {
              // 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 === 'Survey Points') {
                      console.log(feature.attributes.OBJECTID);
                      var template = new esri.InfoTemplate("Survey Points", "<br/> Unique ID: ${UNIQUE_ID}<br/> X Coord: ${X_COORD}<br/> Y Coord: ${Y_COORD}<br/> Z Coord: ${Z_COORD}<br/> Type:${Type}<br/> Status: ${Status}<br/> Data Source: ${DATA_SOURCE}<br/> Shape: ${SHAPE}<br/> Survey Date: ${SURVEY_DATE}<br/>Alternate Name: ${ALT_NAME}");


                      feature.setInfoTemplate(template);

                  }
                  else if (result.layerName === 'CCTV Observations') {
                      var template = new esri.InfoTemplate("CCTV Observations", "<br/> CCTV Route: ${CCTV_ROUTE}<br/> CCTV Distance: ${CCTV_DISTANCE}<br/> CCTV Code: ${CCTV_CODE}<br/> CCTV Value Percent: ${CCTV_VALUE_PERCENT}<br/> CCTV Clock From: ${CCTV_CLOCK_FROM}<br/> CCTV Clock To: ${CCTV_CLOCK_TO}<br/> CCTV Grade: ${CCTV_GRADE} <br/>CCTV Continuous: ${CCTV_CONTINUOUS}<br/> CCTV Observation Type:${CCTV_OBS_TYPE}<br/> CCTV Observation:${CCTV_OBSERVATION}<br/> CCTV Remark:${CCTV_REMARK} <br/>Shape:${SHAPE}<br/> CCTV Attachment:${CCTV_Attach}");
                      feature.setInfoTemplate(template);
                  }

                  else if (result.layerName === 'Manholes') {
                      var template = new esri.InfoTemplate("Manholes", "${*}")
                      feature.setInfoTemplate(template);
                  }
                  else if (result.layerName === 'Inlets') {
                      var template = new esri.InfoTemplate("Inlets", "${*}")
                      feature.setInfoTemplate(template);
                  }
                  else if (result.layerName === 'Infalls') {
                      var template = new esri.InfoTemplate("Infalls", "${*}")
                      feature.setInfoTemplate(template);
                  }
                  else if (result.layerName === 'Outfalls') {
                      var template = new esri.InfoTemplate("Outfalls", "${*}")
                      feature.setInfoTemplate(template);
                  }
                  else if (result.layerName === 'Channel Features') {
                      var template = new esri.InfoTemplate("Channel Features", "${*}")
                      feature.setInfoTemplate(template);
                  }
                  else if (result.layerName === 'Pipe Features') {
                      var template = new esri.InfoTemplate("Pipe Features", "${*}")
                      feature.setInfoTemplate(template);
                  }
                  else if (result.layerName === 'Playa Centroids') {
                      var template = new esri.InfoTemplate("Playa Centroids", "${*}")
                      feature.setInfoTemplate(template);
                  }
                  else if (result.layerName === 'Pipes') {
                      var template = new esri.InfoTemplate("Pipes", "${*}")
                      feature.setInfoTemplate(template);
                  }
                  else if (result.layerName === 'Flumes') {
                      var template = new esri.InfoTemplate("Flumes", "${*}")
                      feature.setInfoTemplate(template);
                  }
                  else if (result.layerName === 'Dams') {
                      var template = new esri.InfoTemplate("Dams", "${*}")
                      feature.setInfoTemplate(template);
                  }
                  else if (result.layerName === 'Channels') {
                      var template = new esri.InfoTemplate("Channels", "${*}")
                      feature.setInfoTemplate(template);
                  }
                  else if (result.layerName === 'CCTV Routes') {
                      var template = new esri.InfoTemplate("CCTV Routes", "${*}")
                      feature.setInfoTemplate(template);
                  }
                  else if (result.layerName === 'Virtual Links') {
                      var template = new esri.InfoTemplate("Virtual Links", "${*}")
                      feature.setInfoTemplate(template);
                  }
                  else if (result.layerName === 'Stormwater Systems') {
                      var template = new esri.InfoTemplate("Stormwater Systems", "${*}")
                      feature.setInfoTemplate(template);
                  }
                  else if (result.layerName === 'Asset Footprints') {
                      var template = new esri.InfoTemplate("Asset Footprints", "${*}")
                      feature.setInfoTemplate(template);
                  }
                  else if (result.layerName === 'Playa Lakes') {
                      var template = new esri.InfoTemplate("Playa Lakes", "${*}")
                      feature.setInfoTemplate(template);
                  }
                  map.infoWindow.setFeatures([deferred]);
                  map.infoWindow.show(evt.mapPoint);
                  return feature;
              });
          });
0 Kudos
KenBuja
MVP Esteemed Contributor
Add the line in red to your executeIdentifyTask. Every time you turn on/off a layer using the TOC control, the visibleLayers property of the layer "lubbock" will change. So every time you click on the map, triggering the executeIdentifyTask event, you'll have to update identifyParams.layerIds

      function executeIdentifyTask(evt) {
          identifyParams.geometry = evt.mapPoint;
          identifyParams.mapExtent = map.extent;
          identifyParams.layerIds = lubbock.visibleLayers;
          var deferred = identifyTask.execute(identifyParams);
0 Kudos
NicholasKnabe
Emerging Contributor
Thank you I added that, but I'm still getting the results of all my features...
0 Kudos
KenBuja
MVP Esteemed Contributor
Take a look at this Fiddle, which uses the TOC control. The IdentifyTask will only show the layers turned on in the TOC.
0 Kudos
NicholasKnabe
Emerging Contributor
Thanks again for the help I just cannot seem to integrate anything I have read or seen into my code. I modify everything and change it to my stuff and it still ID's everything no matter if it is turned on or off in the TOC...
0 Kudos
TracySchloss
Honored Contributor
I have a similar situation, where I'm using the TOC widget and saw that my identify was returning everything.  I added the current layer Ids in my IdentifyParameters and that made it stop identifying layers that weren't turned on, even though I had it set to esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE .

I thought it was totally working, until I tried unchecking all the boxes associated with a layer in my TOC, while leaving the name of the layer checked (my district layer has 3 different districts within it for house, senate and congressional) .  When I went to define my IdentifyParameters,  the array of visible layers ended up as [-1].  That wasn't an acceptable input for layerIds.  Neither is an empty array.   So I changed it to

var visLayers = layer.visibleLayers;
 if (visLayers !== -1) {
 identifyParams.layerIds = layer.visibleLayers;
 }


So only layers that have anything visible in them will have a layerIds parameter defined.  My identifyParameters definition is now happy, but my identify still fails. 

Should I be digging into the TOC code?  I noticed that if I uncheck the layer name too, I don't get the error.  The default behavior in the TOC is if uncheck everything within a layer, the layer still stays checked as on.
0 Kudos
TracySchloss
Honored Contributor
Never mind, I figured out a work around.  I'm using a deferred list to execute my identify tasks.  In that code, I just checked to see if the layer had any visible layers.  If it didn't , I don't create an identify task in the first place.
0 Kudos