Select to view content in your preferred language

Identify All on multiple map services

3373
2
Jump to solution
07-18-2012 03:42 PM
MayJeff
Deactivated User
I try to identify all the layers on different map services to showed the result in the same info window but the results from the code below keep showing separate info window  on top of each one.  Do you know how to show all the result on the same info window when you identify all the layers from different map services?  Thank you.

See code below:


<?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:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:esri="http://www.esri.com/2008/ags">

<fx:Script>       
  <![CDATA[
 
  import mx.events.EventListenerRequest;
  import mx.controls.Alert;
  import mx.collections.ArrayCollection;
  import mx.rpc.events.FaultEvent;
  import com.esri.ags.geometry.MapPoint;
  import com.esri.ags.events.MapMouseEvent;           
  import com.esri.ags.Graphic;           
  import com.esri.ags.events.DrawEvent;           
  import com.esri.ags.events.IdentifyEvent;           
  import com.esri.ags.geometry.Geometry;           
     import com.esri.ags.symbols.InfoSymbol;
  import com.esri.ags.tasks.supportClasses.IdentifyParameters;
     import com.esri.ags.tasks.supportClasses.IdentifyResult; 
  import mx.events.ItemClickEvent;
  import com.esri.ags.layers.ArcGISDynamicMapServiceLayer;
  import com.esri.ags.layers.GraphicsLayer;
  import com.esri.ags.layers.Layer;
  import mx.controls.TextArea;
  import com.esri.ags.tasks.IdentifyTask
 
  [Bindable]
  private var msgVisible:Boolean = false;
 
  [Bindable]
  private var identifyArrayCollection:ArrayCollection;
 
  private var identifyPoint:MapPoint;
 
  //identifyFeatures();
  private function myClickHandler(event:MapMouseEvent):void
  {
  identifyPoint = event.mapPoint;
  var myGraphic:Graphic = new Graphic(null,null,null);
  var identifyParams : IdentifyParameters = new IdentifyParameters();
  identifyParams.returnGeometry = false;
  identifyParams.tolerance = 5;
  identifyParams.geometry = identifyPoint;
  identifyParams.width = myMap.width;
  identifyParams.height = myMap.height;
  identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
  identifyParams.mapExtent = myMap.extent;
 
  for (var i:Number = myMap.layerIds.length -1; i >= 0; i--)
  {
  var layer:Layer = myMap.getLayer(myMap.layerIds);
  var url:String;
  if (layer.visible)
  {
  if (layer is ArcGISDynamicMapServiceLayer)
  {
  var dynamicLayer:ArcGISDynamicMapServiceLayer = layer as ArcGISDynamicMapServiceLayer;
  url = dynamicLayer.url ;
  }
 
  if(url)
  {
  var identifyTask:IdentifyTask = new IdentifyTask(url);
  identifyTask.addEventListener(IdentifyEvent.EXECUTE_COMPLETE, onResult);
  identifyTask.addEventListener(FaultEvent.FAULT, onFault);
  identifyTask.execute(identifyParams);
  showMessage("", true);
  }
  }
  }
  myMap.infoWindow.show(event.mapPoint);
  }
 
  private function drawEndHandler(event:DrawEvent):void
   { 
   myGraphicsLayer.add(event.graphic);
   identifyPoint = event.graphic.geometry as MapPoint;
   }
 
  private function identifyFeatures():void
   {
   //setMapAction(Draw.MAPPOINT, status, drawEndHandler);; 
   }
 
  private function processIdentifyResults(identifyResults:Array):void
  {
   if(!identifyArrayCollection)
   identifyArrayCollection = new ArrayCollection();
    for each (var identifyResult:IdentifyResult in identifyResults)
     {
      var title:String = identifyResult.layerName;
      var obj:Object = identifyResult.feature.attributes;
 
      var content:String = "";
      var fld:String;
      var value:String;
      for (fld in obj)
      {
      value = obj[fld].toString();
      content += fld + ": " + value + "\n";
     
      var text:TextArea = new TextArea();
      text.text = content ;
      myMap.infoWindow.label = "Results"
      myMap.infoWindow.content=text;
      myMap.infoWindow.height = 5000;
      }
     }
     //grid.da
     clearMessage();
  }  
  private function clearMessage():void
  {
   msgVisible = false;
  }
 
  private function onResult(event:IdentifyEvent):void               
  {  
   try
    {
    processIdentifyResults(event.identifyResults);
   
    }
     catch (error:Error)
     {
     showMessage(error.message, false);
    }
 
  }
 
  private function showMessage(msg:String, swfVisible:Boolean):void
  {
   msgVisible = true;
  }
 
  //on fault
  private function onFault(event:FaultEvent):void
  {                   
   showMessage(event.fault.faultDetail, false);        
  }  
 
  ]]>   
</fx:Script>
<fx:Declarations>
<esri:DrawTool id="drawToolbar" map="{myMap}" graphicsLayer="{myGraphicsLayer}" drawEnd="drawEndHandler(event)"/>           
   <!-- Symbol for Point -->           
<esri:SimpleMarkerSymbol style="x" color="0xFF0000" size="12" />        
</fx:Declarations>
<esri:Map id="myMap" mapClick="myClickHandler(event)">           
  <esri:ArcGISDynamicMapServiceLayer url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/M..." />           
  <esri:ArcGISDynamicMapServiceLayer  url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_PublicSafety_Louisville/..."/>
  <esri:GraphicsLayer id="myGraphicsLayer" />       
</esri:Map>


</s:Application>
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Drew
by
Frequent Contributor
I hacked around with your code a little and got it to work. All code commented is the stuff i added or moved.
Your logic was close, but I had to move variables out of some functions.
The code below should work.

 <?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:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:esri="http://www.esri.com/2008/ags">    <fx:Script>   <![CDATA[        import com.esri.ags.Graphic;    import com.esri.ags.events.DrawEvent;    import com.esri.ags.events.IdentifyEvent;    import com.esri.ags.events.MapMouseEvent;    import com.esri.ags.geometry.MapPoint;    import com.esri.ags.layers.ArcGISDynamicMapServiceLayer;    import com.esri.ags.layers.GraphicsLayer;    import com.esri.ags.layers.Layer;    import com.esri.ags.tasks.IdentifyTask;    import com.esri.ags.tasks.supportClasses.IdentifyParameters;    import com.esri.ags.tasks.supportClasses.IdentifyResult;        import mx.collections.ArrayCollection;    import mx.controls.TextArea;    import mx.rpc.events.FaultEvent;         [Bindable]    private var msgVisible:Boolean = false;        [Bindable]    private var identifyArrayCollection:ArrayCollection;        private var identifyPoint:MapPoint;            //DECLARE CONTENT VARIABLE     [Bindable]    private var content:String = "";        private function myClickHandler(event:MapMouseEvent):void    {     //CLEAR CONTENT VARIABLE     this.content = "";          identifyPoint = event.mapPoint;     var myGraphic:Graphic = new Graphic(null,null,null);     var identifyParams : IdentifyParameters = new IdentifyParameters();     identifyParams.returnGeometry = false;     identifyParams.tolerance = 5;     identifyParams.geometry = identifyPoint;     identifyParams.width = myMap.width;     identifyParams.height = myMap.height;     identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;     identifyParams.mapExtent = myMap.extent;          for (var i:Number = myMap.layerIds.length -1; i >= 0; i--)     {      var layer:Layer = myMap.getLayer(myMap.layerIds);      var url:String;      if (layer.visible)      {       if (layer is ArcGISDynamicMapServiceLayer)       {        var dynamicLayer:ArcGISDynamicMapServiceLayer = layer as ArcGISDynamicMapServiceLayer;        url = dynamicLayer.url ;       }              if(url)       {        var identifyTask:IdentifyTask = new IdentifyTask(url);        identifyTask.addEventListener(IdentifyEvent.EXECUTE_COMPLETE, onResult);        identifyTask.addEventListener(FaultEvent.FAULT, onFault);        identifyTask.execute(identifyParams);        showMessage("", true);       }      }     }     myMap.infoWindow.show(event.mapPoint);    }        private function drawEndHandler(event:DrawEvent):void    {     myGraphicsLayer.add(event.graphic);     identifyPoint = event.graphic.geometry as MapPoint;    }        private function identifyFeatures():void    {         }        private function processIdentifyResults(identifyResults:Array):void    {     if(!identifyArrayCollection)      identifyArrayCollection = new ArrayCollection();          for each (var identifyResult:IdentifyResult in identifyResults)     {      var title:String = identifyResult.layerName;      var obj:Object = identifyResult.feature.attributes;                  var fld:String;      var value:String;      for (fld in obj)      {       value = obj[fld].toString();              //APPEND TO CONTENT VARIABLE       content += fld + ": " + value + "\n";      }            //ADD LINE TO SEPERATE      content += "\n------------------------\n";           }          //PROCESS INFO WINDOW     var text:TextArea = new TextArea();     text.text = content ;     text.width = 300;     text.height = 300;     myMap.infoWindow.label = "Results"     myMap.infoWindow.content=text;          clearMessage();    }    private function clearMessage():void    {     msgVisible = false;    }        private function onResult(event:IdentifyEvent):void    {     try     {      processIdentifyResults(event.identifyResults);           }     catch (error:Error)     {      showMessage(error.message, false);     }    }        private function showMessage(msg:String, swfVisible:Boolean):void    {     msgVisible = true;    }        private function onFault(event:FaultEvent):void    {     showMessage(event.fault.faultDetail, false);    }       ]]>  </fx:Script>  <fx:Declarations>           <esri:DrawTool id="drawToolbar" map="{myMap}" graphicsLayer="{myGraphicsLayer}" drawEnd="drawEndHandler(event)"/>   <!-- Symbol for Point -->   <esri:SimpleMarkerSymbol style="x" color="0xFF0000" size="12" />  </fx:Declarations>  <esri:Map id="myMap" mapClick="myClickHandler(event)">   <esri:ArcGISDynamicMapServiceLayer url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/MapServer" />   <esri:ArcGISDynamicMapServiceLayer url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_PublicSafety_Louisville/MapServer"/>   <esri:GraphicsLayer id="myGraphicsLayer" />  </esri:Map>     </s:Application>  


Drew

View solution in original post

0 Kudos
2 Replies
Drew
by
Frequent Contributor
I hacked around with your code a little and got it to work. All code commented is the stuff i added or moved.
Your logic was close, but I had to move variables out of some functions.
The code below should work.

 <?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:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:esri="http://www.esri.com/2008/ags">    <fx:Script>   <![CDATA[        import com.esri.ags.Graphic;    import com.esri.ags.events.DrawEvent;    import com.esri.ags.events.IdentifyEvent;    import com.esri.ags.events.MapMouseEvent;    import com.esri.ags.geometry.MapPoint;    import com.esri.ags.layers.ArcGISDynamicMapServiceLayer;    import com.esri.ags.layers.GraphicsLayer;    import com.esri.ags.layers.Layer;    import com.esri.ags.tasks.IdentifyTask;    import com.esri.ags.tasks.supportClasses.IdentifyParameters;    import com.esri.ags.tasks.supportClasses.IdentifyResult;        import mx.collections.ArrayCollection;    import mx.controls.TextArea;    import mx.rpc.events.FaultEvent;         [Bindable]    private var msgVisible:Boolean = false;        [Bindable]    private var identifyArrayCollection:ArrayCollection;        private var identifyPoint:MapPoint;            //DECLARE CONTENT VARIABLE     [Bindable]    private var content:String = "";        private function myClickHandler(event:MapMouseEvent):void    {     //CLEAR CONTENT VARIABLE     this.content = "";          identifyPoint = event.mapPoint;     var myGraphic:Graphic = new Graphic(null,null,null);     var identifyParams : IdentifyParameters = new IdentifyParameters();     identifyParams.returnGeometry = false;     identifyParams.tolerance = 5;     identifyParams.geometry = identifyPoint;     identifyParams.width = myMap.width;     identifyParams.height = myMap.height;     identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;     identifyParams.mapExtent = myMap.extent;          for (var i:Number = myMap.layerIds.length -1; i >= 0; i--)     {      var layer:Layer = myMap.getLayer(myMap.layerIds);      var url:String;      if (layer.visible)      {       if (layer is ArcGISDynamicMapServiceLayer)       {        var dynamicLayer:ArcGISDynamicMapServiceLayer = layer as ArcGISDynamicMapServiceLayer;        url = dynamicLayer.url ;       }              if(url)       {        var identifyTask:IdentifyTask = new IdentifyTask(url);        identifyTask.addEventListener(IdentifyEvent.EXECUTE_COMPLETE, onResult);        identifyTask.addEventListener(FaultEvent.FAULT, onFault);        identifyTask.execute(identifyParams);        showMessage("", true);       }      }     }     myMap.infoWindow.show(event.mapPoint);    }        private function drawEndHandler(event:DrawEvent):void    {     myGraphicsLayer.add(event.graphic);     identifyPoint = event.graphic.geometry as MapPoint;    }        private function identifyFeatures():void    {         }        private function processIdentifyResults(identifyResults:Array):void    {     if(!identifyArrayCollection)      identifyArrayCollection = new ArrayCollection();          for each (var identifyResult:IdentifyResult in identifyResults)     {      var title:String = identifyResult.layerName;      var obj:Object = identifyResult.feature.attributes;                  var fld:String;      var value:String;      for (fld in obj)      {       value = obj[fld].toString();              //APPEND TO CONTENT VARIABLE       content += fld + ": " + value + "\n";      }            //ADD LINE TO SEPERATE      content += "\n------------------------\n";           }          //PROCESS INFO WINDOW     var text:TextArea = new TextArea();     text.text = content ;     text.width = 300;     text.height = 300;     myMap.infoWindow.label = "Results"     myMap.infoWindow.content=text;          clearMessage();    }    private function clearMessage():void    {     msgVisible = false;    }        private function onResult(event:IdentifyEvent):void    {     try     {      processIdentifyResults(event.identifyResults);           }     catch (error:Error)     {      showMessage(error.message, false);     }    }        private function showMessage(msg:String, swfVisible:Boolean):void    {     msgVisible = true;    }        private function onFault(event:FaultEvent):void    {     showMessage(event.fault.faultDetail, false);    }       ]]>  </fx:Script>  <fx:Declarations>           <esri:DrawTool id="drawToolbar" map="{myMap}" graphicsLayer="{myGraphicsLayer}" drawEnd="drawEndHandler(event)"/>   <!-- Symbol for Point -->   <esri:SimpleMarkerSymbol style="x" color="0xFF0000" size="12" />  </fx:Declarations>  <esri:Map id="myMap" mapClick="myClickHandler(event)">   <esri:ArcGISDynamicMapServiceLayer url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/MapServer" />   <esri:ArcGISDynamicMapServiceLayer url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_PublicSafety_Louisville/MapServer"/>   <esri:GraphicsLayer id="myGraphicsLayer" />  </esri:Map>     </s:Application>  


Drew
0 Kudos
MayJeff
Deactivated User
Thank you very much.  It works!
0 Kudos