Select to view content in your preferred language

Identify and Limit Number of Services Layers and Fields

1439
13
06-09-2010 11:41 AM
BrettFlodine
Emerging Contributor
Hello, I am using Robert Scheitlin's version 1.3 custom identify tool and I have 2 base map services and 1 live map service being used in my flex project.  When I use the identify tool it will select features from all 3 map services.  I would like to customize it to just identify on 2 layers in the one live map service.  Any suggestions would be appreciated.
Tags (2)
0 Kudos
13 Replies
RobertScheitlin__GISP
MVP Emeritus
Brett,

    I created about a half a dozen different IdentifyWidget version (probably not the best idea :eek: ). Now I am struggling to know which source code to go to when people are having issues or need a minor tweak. It would probally be best for you to attach the version you are working with and I will take a look. I am not use I made one yet that allows multiple layers to be specified. I know I have a version that allows you to limit the identify to one specific layer and which fields (that is the one I use).
0 Kudos
BrettFlodine
Emerging Contributor
Hello Robert,
I know how many versions because I searched through all the threads looking for a solution! I use another one of them for a couple of services that identify a single layer both with and without the hyperlink feature. Your source code is great, thanks so much for all of the information you have posted it has proved invaluable.......I have attached the xml and mxml files for your review.

Brett

Brett Flodine
GIS Manager
City of Hartford
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Brett,

  Try this function replacement.

//identify features
   private function identifyFeatures():void
   {
    var identifyParams : IdentifyParameters = new IdentifyParameters();
                identifyParams.returnGeometry = false;
                identifyParams.tolerance = identifyTolerance;
                identifyParams.geometry = identifyPoint;
                identifyParams.width = map.width;
                identifyParams.height = map.height;
                identifyParams.mapExtent = map.extent;
                identifyParams.spatialReference = map.spatialReference;
                
                for (var i:Number = map.layerIds.length -1; i >= 0; i--)
    {
     identifyParams.layerOption = identifyLayerOption;
     identifyParams.layerIds = null
     var layer:Layer = map.getLayer(map.layerIds);
     var url:String;
     if (layer.visible)
     {
                  if (layer is ArcGISDynamicMapServiceLayer)
                  {
                   var dynamicLayer:ArcGISDynamicMapServiceLayer = layer as ArcGISDynamicMapServiceLayer;
                   url = dynamicLayer.url;
                   if(identifyLayerOption == "visible")
                   {
                    identifyParams.layerIds = dynamicLayer.visibleLayers.source;
                    identifyParams.layerOption = "all";
                    if(dynamicLayer.visible == false)
                     url="";
                   }
                   //This is the new code
                   //Change Parcel Data to the map service name of yours you want to use
                   //and change 67,68 to the layer numbers of yours
                   //in the else url=""; is what makes it ignore all other map services
                   //if there name is not (in my example) Parcel Data.
                   if (layer.id == "Parcel Data")
                   {
                    identifyParams.layerIds = [67,68];
                   } else {
                    identifyParams.layerIds = null;
                    url="";
                   }
                  }
                  else if (layer is ArcGISTiledMapServiceLayer)
                  {
                   var tiledLayer:ArcGISTiledMapServiceLayer = layer as ArcGISTiledMapServiceLayer;
                   url = tiledLayer.url;
                   if(identifyLayerOption == "visible")
                   {
                    if(tiledLayer.visible == false)
                     url="";
                   }
                  }
         
                  if(url)
                  {
                   var identifyTask:IdentifyTask = new IdentifyTask(url);
                   identifyTask.addEventListener(IdentifyEvent.IDENTIFY_COMPLETE, onResult);
                   identifyTask.addEventListener(FaultEvent.FAULT, onFault);
                   identifyTask.execute(identifyParams);
        showMessage(loadingLabel, true); 
       showStateResults(null);   
                  }
         }
                }
   }
0 Kudos
BrettFlodine
Emerging Contributor
Robert, I replaced the code and changed the layer numbers and the map service name.  I removed any group layers in my map service . I am getting the following error... Identify operation not supported on this service.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Brett,

   Can you post what you changed the code to? Did you can the name of the map service to the label in the config.xml?
0 Kudos
BrettFlodine
Emerging Contributor
Well Robert I did that at first and my basemap stopped displaying........so I had changed it back to the map service name in the rest service properties.......after that I had stopped and restarted my map service and cleared my map cache.  SO when you sent your post I changed it back to the name in the config.xml and everything works great.

thank you very much for your help!
0 Kudos
SpencerLace
Occasional Contributor
Would it be possible to do the same multi-layer, specific fields identify as your sample single-layer, specific fields, using only the XML to pass the fields?  I was think of trying tags such as
<layer>SLO</layer>
<fields>message</fields>
<layer2>FPZ Overlay</layer2>
<fields>message</fields>
<layer3>ECPZ Overlay</layer3>
<fields>message</fields>

Below is the "latest" code you posted on point:

//identify features
   private function identifyFeatures():void
   {
    var identifyParams : IdentifyParameters = new IdentifyParameters();
                identifyParams.returnGeometry = false;
                identifyParams.tolerance = identifyTolerance;
                identifyParams.geometry = identifyPoint;
                identifyParams.width = map.width;
                identifyParams.height = map.height;
                identifyParams.mapExtent = map.extent;
                identifyParams.spatialReference = map.spatialReference;
                
                for (var i:Number = map.layerIds.length -1; i >= 0; i--)
    {
     identifyParams.layerOption = identifyLayerOption;
     identifyParams.layerIds = null
     var layer:Layer = map.getLayer(map.layerIds);
     var url:String;
     if (layer.visible)
     {
                  if (layer is ArcGISDynamicMapServiceLayer)
                  {
                   var dynamicLayer:ArcGISDynamicMapServiceLayer = layer as ArcGISDynamicMapServiceLayer;
                   url = dynamicLayer.url;
                   if(identifyLayerOption == "visible")
                   {
                    identifyParams.layerIds = dynamicLayer.visibleLayers.source;
                    identifyParams.layerOption = "all";
                    if(dynamicLayer.visible == false)
                     url="";
                   }
                   //This is the new code
                   //Change Parcel Data to the map service name of yours you want to use
                   //and change 67,68 to the layer numbers of yours
                   //in the else url=""; is what makes it ignore all other map services
                   //if there name is not (in my example) Parcel Data.
                   if (layer.id == "Parcel Data")
                   {
                    identifyParams.layerIds = [67,68];
                   } else {
                    identifyParams.layerIds = null;
                    url="";
                   }
                  }
                  else if (layer is ArcGISTiledMapServiceLayer)
                  {
                   var tiledLayer:ArcGISTiledMapServiceLayer = layer as ArcGISTiledMapServiceLayer;
                   url = tiledLayer.url;
                   if(identifyLayerOption == "visible")
                   {
                    if(tiledLayer.visible == false)
                     url="";
                   }
                  }
         
                  if(url)
                  {
                   var identifyTask:IdentifyTask = new IdentifyTask(url);
                   identifyTask.addEventListener(IdentifyEvent.IDENTIFY_COMPLETE, onResult);
                   identifyTask.addEventListener(FaultEvent.FAULT, onFault);
                   identifyTask.execute(identifyParams);
        showMessage(loadingLabel, true); 
       showStateResults(null);   
                  }
         }
                }
   }
0 Kudos
BrettFlodine
Emerging Contributor
Spencer,

The line in the mxml file that is
identifyParams.layerIds = [67,68];
is giving the layers that you are identifying. my identify works on two seperate layers but I could have included as many as I wanted. If you look at the code Robert provided me it also includes a hyperlink field for each layer as well.

Brett
0 Kudos
BrettFlodine
Emerging Contributor
Spencer you cant use just the xml file you also need to modify the mxml.file as well
0 Kudos