Select to view content in your preferred language

urgent >> problem in using identify Task (identifying using multiple layers) in flex

1298
12
04-28-2010 05:23 AM
mohamedbakri
Emerging Contributor
Dear all,

I???m using flex builder version 3 (SDK 3.3) and ARCGIS Flex APIs version 1.2 
I tried to build identify module using identify task but I have big problem when I using it to identify on multiple layers as follows:

private function doIdentify(graphic:Graphic):void
{
if (identifyByAllLayers)
                {
                                                var LayerObject:Object=null;
                                                if (identifyBy == "Point")
                                                                LayerObject=servicesCombobox_Point.selectedItem;
                                                else if (identifyBy == "Polygon" && drawMode == "notBuffer")
                                                                LayerObject=servicesCombobox_Polygon.selectedItem;
                                                else if ((identifyBy == "Point" && drawMode == "buffer") || (identifyBy == "Polygon" && drawMode == "buffer"))
                                                                LayerObject=servicesCombobox_Buffer.selectedItem;


                                                for (var y:int=0; y < map.layers.length; y++)
                                                {
                                                                if (map.layers.url.indexOf(LayerObject.mapServiceName, 0) != -1)
                                                                {
                                                                                for (var x:int=0; x < map.layers.visibleLayers.length; x++)
                                                                                  {
                                                                                                arrLayerIds.push(Number(map.layers.visibleLayers));
                                                                                 }
break;
                                                                }
                                                }
                }
identifyParams.layerIds=arrLayerIds;
                identifyParams.width=map.width;
                identifyParams.height=map.height;
                identifyParams.geometry=graphic.geometry;
                identifyParams.mapExtent=map.extent;
                identifyParams.tolerance=2;
                identifyParams.spatialReference=map.spatialReference;
                identifyTask.execute(identifyParams, new AsyncResponder(myResultFunction, myFaultFunction, graphic));
}

The error occur in this case is faultCode:500 faultString:'Unable to perform identify. Please check your parameters' faultDetail:''

Please help me urgently in this issue
Tags (2)
0 Kudos
12 Replies
BenFerguson
Occasional Contributor
Try specifying the identifyParams.layerOption = "all"
0 Kudos
mohamedbakri
Emerging Contributor
I already use this option but line of code is missing .... thanks for your help
0 Kudos
MehulChoksey
Esri Contributor
Mohamed,

Could you post the REST request and Response(captured using firefox/fiddler etc)?
0 Kudos
RhysDonoghue
Deactivated User
Hi Mohamed

I'm trying to build a simple identify tool that brings up the details of multiple layers.  Have you succeeded in being able to do this?

I look forward to hearing from you.

Rhys
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rhys,

   If you want to identify multiple layers than all you have to do is set the identifyParams.layerOption = "all".
0 Kudos
RhysDonoghue
Deactivated User
Thanks Robert but I still haven't got far.  I tried modifying Mohamed's code but no success.  My original code that shows one layer is below.  Is there some way I can modify this code to show info for all layers or should I be approaching it differently?

private function mapClickHandler(event:MapMouseEvent):void
   {
   
    clickGraphicsLayer.clear();
   
    var identifyParams:IdentifyParameters = new IdentifyParameters();
    identifyParams.returnGeometry = true;
    identifyParams.tolerance = 3;
    identifyParams.width = myMap.width;
    identifyParams.height = myMap.height;
    identifyParams.geometry = event.mapPoint;
    identifyParams.mapExtent = myMap.extent;
    identifyParams.spatialReference = myMap.spatialReference;
    identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
   
    var clickGraphic:Graphic = new Graphic(event.mapPoint, clickPtSym);
   
    clickGraphicsLayer.add(clickGraphic);
   
    identifyTask.execute(identifyParams, new AsyncResponder(myResultFunction, myFaultFunction, clickGraphic));
   }
  
   private function myResultFunction(results:Array, clickGraphic:Graphic = null):void
   {
    if (results && results.length > 0)
    {
     var result:IdentifyResult = results[0];
     var resultGraphic:Graphic = result.feature;
     switch (resultGraphic.geometry.type)
     {
      case Geometry.MAPPOINT:
      {
       resultGraphic.symbol = smsIdentify;
       break;
      }
      case Geometry.POLYLINE:
      {
       resultGraphic.symbol = slsIdentify;
       break;
      }
      case Geometry.POLYGON:
      {
       resultGraphic.symbol = sfsIdentify;
       break;
      }
     }
     lastIdentifyResultGraphic = resultGraphic;   
    
     clickGraphic.symbol = new InfoSymbol(); // use default renderer
     clickGraphic.attributes = resultGraphic.attributes;
    }
   }
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rhys,

   The code you are using will work fine for one result because of this line:

var result:IdentifyResult = results[0];


results[0] means that you are only going to get the first result... You need to do a for loop to get the rest of the results, and add each results to a graphics layer. The sample that you are starting with is not designed to multiple results so you have to combine it with portions of other samples that demonstrate how to add multiple results to a graphics layer.
0 Kudos
RhysDonoghue
Deactivated User
thanks Robert, that's what I thought I needed to do.  I should be ok with the For loop but not sure how to add the multiple layers to the graphic.  Once I get the For loop in there, I should be able to just change clickGraphic.attributes = resultGraphic.attributes; right?  I'm not sure of the syntax for this as I'm still a Flex newbie.  Any pointers?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rhys,

   Here is the sample complete code for identifying multiple features.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:esri="http://www.esri.com/2008/ags"
      pageTitle="Identify Features on the Map">
 <!--
 This sample shows how to identify features with a MapClick and the Identify task.
 
 The IdentifyParameters designate which layers are being identified.
 Identify operations can potentially return a lot of information
 depending on the number of layers being identified and a given tolerance.
 The tolerance is the number of pixels a feature is allowed to lie away
 from the clicked point in order to be counted as a result.
 
 In this sample, when user clicks the map, an "Identify" task is executed.
 
 When the task finishes executing, the executeCompleteHandler function loops
 through the features in the IdentifyResult and adds them to the map.
 -->
 <fx:Script>
  <![CDATA[
   import com.esri.ags.Graphic;
   import com.esri.ags.events.MapMouseEvent;
   import com.esri.ags.geometry.Geometry;
   import com.esri.ags.geometry.MapPoint;
   import com.esri.ags.geometry.Polygon;
   import com.esri.ags.geometry.Polyline;
   import com.esri.ags.symbols.InfoSymbol;
   import com.esri.ags.tasks.supportClasses.IdentifyParameters;
   import com.esri.ags.tasks.supportClasses.IdentifyResult;
   
   import mx.controls.Alert;
   import mx.controls.DataGrid;
   import mx.rpc.AsyncResponder;
   
   [Bindable]private var lastIdentifyResultGraphic:Graphic;
   
   private function mapClickHandler(event:MapMouseEvent):void
   {
    clickGraphicsLayer.clear();
    lastIdentifyResultGraphic = null;
    var identifyParams:IdentifyParameters = new IdentifyParameters();
    identifyParams.returnGeometry = true;
    identifyParams.tolerance = 3;
    identifyParams.width = myMap.width;
    identifyParams.height = myMap.height;
    identifyParams.geometry = event.mapPoint;
    identifyParams.mapExtent = myMap.extent;
    identifyParams.spatialReference = myMap.spatialReference;
    
    var clickGraphic:Graphic = new Graphic(event.mapPoint, clickPtSym);
    clickGraphicsLayer.add(clickGraphic);
    
    identifyTask.execute(identifyParams, new AsyncResponder(myResultFunction, myFaultFunction, clickGraphic));
   }
   
   private function myResultFunction(results:Array, clickGraphic:Graphic = null):void
   {
    resultGraphicsLayer.clear();
    if (results && results.length > 0)
    {
     for each (var identifyResult:IdentifyResult in results)
     {
      var resultGraphic:Graphic = identifyResult.feature;
      switch (resultGraphic.geometry.type)
      {
       case Geometry.MAPPOINT:
       {
        resultGraphic.symbol = smsIdentify;
        break;
       }
       case Geometry.POLYLINE:
       {
        resultGraphic.symbol = slsIdentify;
        break;
       }
       case Geometry.POLYGON:
       {
        resultGraphic.symbol = sfsIdentify;
        break;
       }
      }
      resultGraphic.addEventListener(MouseEvent.MOUSE_OVER, onMouseOverHandler);
      resultGraphic.addEventListener(MouseEvent.MOUSE_OUT, onMouseOutHandler);
      resultGraphicsLayer.add(resultGraphic);
     }
    }
   }
   
   private function onMouseOutHandler(event:MouseEvent):void
   {
    myMap.infoWindow.hide();
   }
   
   private function onMouseOverHandler(event:MouseEvent):void
   {
    var gr:Graphic = Graphic(event.target);
    lastIdentifyResultGraphic = new Graphic(getGeomCenter(gr),new InfoSymbol,gr.attributes);
   }
   
   //get geom center
   private function getGeomCenter(graphic:Graphic):MapPoint
   {
    var pt:MapPoint;
    switch (graphic.geometry.type)
    {
     case Geometry.MAPPOINT:
     {
      pt = graphic.geometry as MapPoint;
      break;
     }
     case Geometry.POLYLINE:
     {
      const pl:Polyline = graphic.geometry as Polyline;
      const pathCount:Number = pl.paths.length;
      const pathIndex:int = int((pathCount / 2) - 1);
      const midPath:Array = pl.paths[pathIndex];
      const ptCount:Number = midPath.length;
      const ptIndex:int = int((ptCount / 2) - 1);
      pt = pl.getPoint(pathIndex, ptIndex);
      break;
     }
     case Geometry.POLYGON:
     {
      const poly:Polygon = graphic.geometry as Polygon;
      pt = poly.extent.center;
      break;
     }
    }
    return pt;
   }
   
   private function myFaultFunction(error:Object, clickGraphic:Graphic = null):void
   {
    Alert.show(String(error), "Identify Error");
   }
  ]]>
 </fx:Script>
 
 <fx:Declarations>
  <!-- Symbol for where the user clicked -->
  <esri:SimpleMarkerSymbol id="clickPtSym"
         color="0xFF0000"
         size="12"
         style="x"/>
  
  <!-- Symbol for Identify Result as Polyline -->
  <esri:SimpleLineSymbol id="slsIdentify"
          width="2"
          alpha="1"
          color="0x00FF00"
          style="solid"/>
  
  <!-- Symbol for Identify Result as Point -->
  <esri:SimpleMarkerSymbol id="smsIdentify"
         color="0x00FF00"
         size="15"
         style="diamond"/>
  
  <!-- Symbol for Identify Result as Polygon -->
  <esri:SimpleFillSymbol id="sfsIdentify"/>
  
  <!-- Identify Task -->
  <esri:IdentifyTask id="identifyTask"
         concurrency="last"
         url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer"/>
 </fx:Declarations>
 
 <esri:Map id="myMap"
     mapClick="mapClickHandler(event)"
     openHandCursorVisible="false">
  <esri:extent>
   <esri:WebMercatorExtent minlon="-120" minlat="30" maxlon="-100" maxlat="50"/>
  </esri:extent>
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
  <esri:GraphicsLayer id="resultGraphicsLayer"/>
  <esri:GraphicsLayer graphicProvider="{lastIdentifyResultGraphic}"/>
  <esri:GraphicsLayer id="clickGraphicsLayer"/>
 </esri:Map>
 
</s:Application>
0 Kudos