arcgis api for flex 开发入门(二)map 的创建
arcgis api for flex 開發入門(二)map 的創建
在flex 中創建一個esri 的map ,你只需要使用<esri:Map>標簽就可以輕松完成。
在<esri:Map>標簽中可以添加屬性和響應事件的消息。
如下:
<esri:Map width="100%" height="50%" id="EsriMap" creati??resize="EsriMapResize(event);" extentChange="ESRIMapExtentChange(event);" mouseMove="OnDrawMouseMove(event)" />
width和 height定義的map 的大小,id="EsriMap" 唯一標識了這個map。
針對map 的消息也有很多,最常用的就是creationComplete,resize和鼠標消息了。
現在我們map有了,那么我們如何讓她顯示數據呢,這就需要給 <esri:Map>標簽添加一個layer 子標簽? ?。
在ags flex api 中有以下幾種類型的layer。? ?
??ArcGISDynamicMapServiceLayer :Allows you to work with a dynamic map service resource exposed by the ArcGIS Server REST API.
??ArcGISImageServiceLayer: Allows you to work with an image service resource exposed by the ArcGIS Server REST API.
??ArcGISMapServiceLayer :The base class for ArcGIS Server map services.
??ArcGISTiledMapServiceLayer :Allows you to work with a cached map service resource exposed by the ArcGIS Server REST API.
??ArcIMSMapServiceLayer :Allows you to work with an ArcIMS image service.
??GPResultImageLayer :Allows you to view a geoprocessing task result identified by jobId and parameterName.
??GraphicsLayer: A layer that contains one or more Graphic features.
其中GraphicsLayer是支持客戶端添加Graphic features的圖層,需要在客戶端表現的,或者交互操作中產生的要素都要加到這個layer 上。
下面,我們就添加一個ArcGISTiledMapServiceLayer和GraphicsLayer到map 上。
<esri:Map width="100%" height="50%" id="EsriMap" creati??resize="EsriMapResize(event);" extentChange="ESRIMapExtentChange(event);" mouseMove="OnDrawMouseMove(event)" >
<esri:ArcGISTiledMapServiceLayer? ?? ?? ???url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />
<esri:GraphicsLayer id="myGraphicsLayer" spatialReference="{sr}"/>
</esri:Map>
其中<esri:ArcGISTiledMapServiceLayer>標簽中的url 屬性為提供該服務的地址。<esri:GraphicsLayer>標簽其中的spatialReference屬性定義了該圖層的空間參考系。
創建一個空間參考系,只需要使用<esri:SpatialReference>標簽就可以了,其中wkid 是esri已經定義好的空間草考系的ID,具體ID對應的空間參考可以在http://resources.esri.com/help/9.3/arcgisserver/apis/REST/index.html?gcs.html中查找。如下為創建一個kid="4326"的空間參考系。
<esri:SpatialReference id="sr" wkid="4326"/>
那么,我們如何定義我們想顯示的范圍呢?
很簡單,在<esri:Map>下面添加<esri:extent>子標簽,我們就可以來控制當前的顯示范圍了。
? ? <esri:extent>
??<esri:Extent??id = "esriMapExtent" xmin="116" ymin="39.5" xmax="116.5" ymax="40.5"/>
</esri:extent>
其中x是經度,y 是緯度。
這樣一個北京地區的map 就可以顯示到我們面前了。
完整代碼如下
<?xml?version="1.0"?encoding="utf-8"?>
<mx:Application
????xmlns:mx="http://www.adobe.com/2006/mxml"
????xmlns:esri="http://www.esri.com/2008/ags"
????pageTitle="Using?ArcGIS?API?for?Flex?to?connect?to?a?cached?ArcGIS?Online?service"
????styleName="plain">
????<esri:SpatialReference?id="sr"?wkid="4326"/>
????<esri:Map?crosshairVisible="true">
????????<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="{sr}"/>
????</esri:Map>
</mx:Application>
?
原文地址:http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=35537&extra=page%3D4%26amp%3Borderby%3Ddateline
本文轉自溫景良(Jason)博客園博客,原文鏈接:http://www.cnblogs.com/wenjl520/archive/2009/06/02/1494536.html,如需轉載請自行聯系原作者
總結
以上是生活随笔為你收集整理的arcgis api for flex 开发入门(二)map 的创建的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大学士带你领略“大院大所”黑科技!
- 下一篇: Window10+VS2015+DevE