畢業設計要用Flex做一個地圖模組,使用ArcGIS API For Flex。今天首先做一個地圖顯示和切換,首先看運行效果:
主要就是DropdownList控制項的使用,以及如何在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:mx="library://ns.adobe.com/flex/mx" xmlns:esri="http://www.esri.com/2008/ags" minWidth="1000" minHeight="600"><fx:Script><![CDATA[import mx.collections.ArrayList;import mx.collections.XMLListCollection;import mx.controls.Alert;import mx.events.IndexChangedEvent;import spark.events.IndexChangeEvent;private var showMapName:String;private function mapSelectorChangeHandler(event:IndexChangeEvent):void{showMapName="http://service:8399/arcgis/rest/services/"+mapSelector.selectedItem.value+"/MapServer/"//Alert.show(showMapName);mapServiceLayer.url=showMapName;}]]></fx:Script><fx:Declarations><!-- 將非可視元素(例如服務、值對象)放在此處 --><s:XMLListCollection id="mapNames"><fx:XMLList xmlns=""><map><name>856農場</name><value>856</value></map><map><name>雙峰農場</name><value>ShuangFeng</value></map></fx:XMLList></s:XMLListCollection></fx:Declarations><esri:Map id="mapView" x="144" y="41" width="800" height="550"><esri:ArcGISDynamicMapServiceLayer id="mapServiceLayer" /></esri:Map><s:DropDownList id="mapSelector" left="5" top="5" height="20" fontSize="13" fontWeight="normal"dataProvider="{mapNames}" labelField="name" change="mapSelectorChangeHandler(event)" prompt="地圖切換"></s:DropDownList></s:Application>
歡迎交流~~