arcgis api for flex 开发入门(一)

1.利用FlashBuilder 创建一个FLEX项目,这个在此不再说明,应该没人不会吧。

2.http://resources.esri.com/arcgisserver/apis/flex/index.cfm?fa=home下载源码和SWC文件,把 agslib.swc导入项目中(也可直接复制到项目的libs文件夹下)。

3.在项目的主应用文件件下输入如下代码:

<?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" pageTitle="ArcGis"
      xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:esri="http://www.esri.com/2008/ags">
 
 
 <fx:Declarations>
  <!--空间参考系-->
  <esri:SpatialReference id="sf" wkid="4326"/>
   <!--画图工具,用于在地图中画点,线。。。-->
  <esri:DrawTool id="drawToolbar" map="{myMap}"
        graphicsLayer="{myGraphicsLayer}" />
 </fx:Declarations>


  <!--引入Map-->
 <esri:Map crosshairVisible="true" id="myMap" keyboardNavigationEnabled="true">
  <!--定义MAP显示范围-->
  <esri:extent>
   <esri:Extent  id = "esriMapExtent" xmin="116" ymin="39.5" xmax="116.5" ymax="40.5"/>
  </esri:extent>
   <!--图层-->
  <esri:ArcGISTiledMapServiceLayer   url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
 

 <esri:GraphicsLayer id="myGraphicsLayer" spatialReference="{sf}"/>
 </esri:Map>
 
 
 <mx:ControlBar horizontalGap="0" paddingBottom="0" paddingTop="0"> 

 <!--注意此click事件与FLEX3中的不一样-->
  <mx:Button label="放大"   click="myMap.zoomIn()"/>
  <mx:Button label="缩小"   click="myMap.zoomOut()"  /> 
  <mx:Button label="拖放"   click="myMap.panLowerLeft()"  /> 
  <mx:Button label="漫游"   click="myMap.panDown()"  />         
  
  <mx:Button label="点"   click="drawToolbar.activate
       (DrawTool.MAPPOINT)"/>
  <mx:Button label="线"   click="button1_clickHandler(event)"/>
 </mx:ControlBar>
</s:Application>