ArcGIS Viewer for Flex绘点,连线

前言,如何加载ArcGIS类库及地图服务参见<ArcGIS Viewer for Flex加载地图服务>

1 定义坐标点

1 private var arr:Array=
2                 [
3                     new MapPoint(114.06,30.74,new SpatialReference(4326)),
4                     new MapPoint(114.41,30.55,new SpatialReference(4326))
5                 ];

2 建立map

 1 <esri:Map crosshairVisible="true" width="100%" height="100%" id="EsriMap">
 2         
 3         <!-- 加载已有的地图服务 -->
 4         <esri:ArcGISTiledMapServiceLayer 
 5             url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
 6         
 7         <!-- 定义图层 -->
 8         <esri:GraphicsLayer id="EsriGraphicsLayer" spatialReference="{sr}" />
 9         
10         <!-- 锁定初始的地图位置,当前为武汉,坐标系为4326(经纬度坐标系) -->
11         <esri:extent>
12             <esri:Extent id="mapExtent" xmin="112.00" ymin="29.50" xmax="116.50" ymax="31.65" />
13         </esri:extent>
14         
15     </esri:Map>

3 定义绘点,连线方法

 1 //绘点
 2 private function myPoint():void{
 3                 if(0 == arr.length){
 4                     return;
 5                 }
 6                 EsriGraphicsLayer.clear();
 7                 var i:int=0;
 8                 var timer:Timer = new Timer(500, arr.length);
 9                 timer.addEventListener(TimerEvent.TIMER, TimerMethod);
10                 timer.start();
11                 function TimerMethod(event:TimerEvent):void
12                 {
13                     var mps:Array=new Array;
14                     var mpStat:MapPoint=arr[i] as MapPoint;
15                     
16                     
17                     grahpic=new Graphic(mpStat,sps);
18                     
19                     EsriGraphicsLayer.add(grahpic);
20                     i=i+1;
21                 }
22             }
23             //连线
24             private function myLine():void{
25                 if(0 >= arr.length-1){
26                     return;
27                 }
28                 polyine=new Polyline();
29                 var i:int=0;
30                 var timer:Timer = new Timer(1000, arr.length-1);
31                 timer.addEventListener(TimerEvent.TIMER, TimerMethod);
32                 timer.start();
33                 function TimerMethod(event:TimerEvent):void
34                 {
35                     var mps:Array=new Array;
36                     var mpStat:MapPoint=arr[i] as MapPoint;
37                     var mpEnd:MapPoint=arr[i+1] as MapPoint;
38                     mps.push(mpStat);
39                     mps.push(mpEnd);
40                     polyine.addPath(mps);
41                     
42                     grahpic=new Graphic(polyine,sls);
43                     
44                     EsriGraphicsLayer.add(grahpic);
45                     i=i+1;
46                 }
47             }

4 调用

1 <s:HGroup>
2         <s:Button label="点" click="PlayPoint(event)"/>
3         
4         <s:Button label="线"  width="100" fontSize="12" click="PlayLine(event)"/>
5     </s:HGroup>

 5 定义线和点的图形

<esri:PictureMarkerSymbol id="sps" source="img/redPoint.jpg" width="20" height="20"/>    //加载点图片

<esri:SimpleLineSymbol id="sls" width="3" color="0x00FF00"/>  //绘线
//画圆点
<esri:SimpleMarkerSymbol id="circleSymbol" color="0x00FF00" style="circle" size="12" alpha="0.5" >   
  <esri:SimpleLineSymbol/> 
</esri:SimpleMarkerSymbol> 

 

 

posted on 2013-05-07 15:55  看天空的星星  阅读(338)  评论(0)    收藏  举报

导航