用flex獲取arcgis圖層每個點的信息

<?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"
      xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" initialize="application1_initializeHandler(event)">
 <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.symbols.InfoSymbol;
   import com.esri.ags.tasks.supportClasses.IdentifyParameters;
   import com.esri.ags.tasks.supportClasses.IdentifyResult;
   
   import mx.controls.Alert;
   import mx.events.FlexEvent;
   import mx.rpc.AsyncResponder;
   [Bindable]private var lastIdentifyResultGraphic:Graphic;
   protected function application1_initializeHandler(event:FlexEvent):void
   {
    // TODO Auto-generated method stub
    //https://developers.arcgis.com/en/flex/sample-code/identify-features.htm
    //<!--5944-->
   }
   
   
   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;
    
    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;
     


    
     var myPolygon:Polygon=new Polygon();
     myPolygon=resultGraphic.geometry as Polygon;
   
     var i:int=0;
     for each(var myPoint:MapPoint in myPolygon.rings[0])
     {
      i++
       if(i%10==0)//減少點,防卡
       {
      trace("<point>")
      trace("<Log>"+myPoint.x+"</Log>")
      trace("<Lat>"+myPoint.y+"</Lat>")
      trace("</point>")

       }
       
       
       
      
     }
     
    }
   }
   
   
   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" color="0x00FF00"/>
  <esri:IdentifyTask id="identifyTask"
         concurrency="last"
         url="http://lvchuang.12345.org/ArcGIS/rest/services/HeBeiSpecialMap/MapServer"/>
 </fx:Declarations>
 

 <esri:Map id="myMap"
     mapClick="mapClickHandler(event)"
     openHandCursorVisible="false">
 <esri:ArcGISDynamicMapServiceLayer url="http://lvchuang.12345.org/ArcGIS/rest/services/HeBeiSpecialMap/MapServer"/>
  <esri:GraphicsLayer graphicProvider="{lastIdentifyResultGraphic}"/>
  <esri:GraphicsLayer id="clickGraphicsLayer"/>
 
 </esri:Map>
 

 
</s:Application>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章