Identify Results Popup

889
18
Jump to solution
06-28-2013 05:57 AM
NicholasKnabe
New 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
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
Try changing

identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;

to

identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;

Also, did you set the layerIds property to use only the visible layers?

identifyParams.layerIds = yourLayer.visibleLayers;

FYI, using the layerOption property along with the layerIds property will be important if you have layers are visible only at certain scales.

View solution in original post

0 Kudos
18 Replies
KenBuja
MVP Esteemed Contributor
Try changing

identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;

to

identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;

Also, did you set the layerIds property to use only the visible layers?

identifyParams.layerIds = yourLayer.visibleLayers;

FYI, using the layerOption property along with the layerIds property will be important if you have layers are visible only at certain scales.
0 Kudos
NicholasKnabe
New Contributor
I had just found that in the resources and I changed it and it still ID's all the layers. I'm using the Legend widget and then a TOC tab with check boxes to turn the layers on and off.
0 Kudos
KenBuja
MVP Esteemed Contributor
Take a look at the additional edit I made to my previous post about using layerIds.
0 Kudos
NicholasKnabe
New Contributor
I just noticed that one. I have 15 layers. Right now I have
identifyParams.layerIds = SurveyPoints.visibleLayers;
That only returns my survey points popup and is correct how do I go about having all my layers be set to visiblelayers

Thanks for all the help the past couple days
0 Kudos
KenBuja
MVP Esteemed Contributor
In that case, you'll have to set the array yourself, like

identifyParams.layerIds = [0, 1, 4, 7, 17];

or you'll have to write some code to build the array according to how they are turned on by the TOC
0 Kudos
NicholasKnabe
New Contributor
Yeah that is how I had it before is with the array, but then it still ID's all of them even if they are turned on or off. The layer_Option_Visible doesn't seem to catch anything
0 Kudos
KenBuja
MVP Esteemed Contributor
That leads to the question of why you have the 15 different layers. Is that required by the TOC control you're using? I'm using this TOC control and use it with only one layer (layerDynamic) with many sublayers. Thus when I use the code

identifyParams.layerIds = layerDynamic.visibleLayers;
identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;


it only returns the attributes for the sublayers I have turned on through the TOC.
0 Kudos
NicholasKnabe
New Contributor
I had not seen that TOC yet so I just switched mine to that format here is my current code
   var lubbock = new esri.layers.ArcGISDynamicMapServiceLayer("http://maps101.gis.halff.com/ladon/rest/services/Lubbock/LubbockCCTVAssets/MapServer", {
              id: 'lubbock',
              opacity: 0.8
          });

          dojo.connect(map, 'onLayersAddResult', function (results) {
              var toc = new agsjs.dijit.TOC({
                  map: map,
                  layerInfos: [{
                      layer: lubbock,
                      title: "Lubbock CCTV Assets"
                  }, ]
              }, 'tocDiv');
              toc.startup();

              lubbock.setVisibleLayers([9]);

          });
          map.addLayers([lubbock]);


Now getting down to the Identify part

  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 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]
              identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
              identifyParams.width = map.width;
              identifyParams.height = map.height;

          }


I should be able to set layerIds=lubbock.visibleLayers;

Correct?
0 Kudos
KenBuja
MVP Esteemed Contributor
I have mine set up slightly differently where I load and set the visibleLayers of the layer, then wait until the load is complete before initializing the TOC.

And now that I think back, I also discovered that I should have been setting the visibleLayers in the executeIdentifyTask function. That would change the visible layers when you turned various layers on and off using the TOC tool for each time you click on the map.  I believe that's why you were originally having the problem with the LAYER_OPTION_VISIBLE giving you all the layers.


    layerDynamic= new esri.layers.ArcGISDynamicMapServiceLayer(parameters.url, {
        id: 'Dynamic'
    });
    map.addLayers([layerDynamic]);
    layerDynamic.setVisibleLayers(parameters.visibleLayers);

    map.on("layers-add-result", function (event) {

        try {
            var toc = new agsjs.dijit.TOC({
                map: map,
                layerInfos: [{
                    layer: layerDynamic,
                    title: "Legend",
                    slider: true
                }]
            }, 'tocDiv');
            toc.startup();
        }
        catch (e) {
            console.log(e.message);
        }
        mapReady(map);
    });

    function mapReady(map) {
        map.on("click", executeIdentifyTask);
        identifyTask = new esri.tasks.IdentifyTask(parameters.url);
        identifyParams = new esri.tasks.IdentifyParameters();
        identifyParams.tolerance = 3;
        identifyParams.returnGeometry = true;
        //identifyParams.layerIds = [0, 117];
        identifyParams.layerIds = layerDynamic.visibleLayers;
        identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
        identifyParams.width = map.width;
        identifyParams.height = map.height;

        map.infoWindow.resize(415, 200);
        map.infoWindow.setContent(tc.domNode);
        map.infoWindow.setTitle("Results");
    }

    function executeIdentifyTask(evt) {
        map.graphics.clear();
        identifyParams.geometry = evt.mapPoint;
        identifyParams.mapExtent = map.extent;
        identifyParams.layerIds = layerDynamic.visibleLayers;
0 Kudos