下面的步骤将引导你在你的flex应用中添加一个底图(basemap layer)。我们假设你已经建立了一个空白 的工程,已经引入了arcgis for flex api的库。没有引入自己去引入。
通过地图展示地理信息是最简单直接的方法,arcgis for flex api提供了一套地图用户组件,该api支持各种主流类型的地图服务,用来展示地图功能,地图服务可以是ARCGIS Server map、image services、Open Street Map、Bing Maps、OGC WMS 等,也可以是ArcGIS Online的地图服务,或者是自己的arcgis账户中的地图服务 。
Flex开发使用的是MXML 和actionscript语言。MXML与HTML类似,用来布局页面。as与javascript类似,代码逻辑也是嵌在标签中使用。
第一步:
添加库引用在要编码的MXML文档中,作为命名空间的引用声明。
代码示例如下:
<span style="color:#ff0000;"><?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" minWidth="955" minHeight="600"
xmlns:esri="http://www.esri.com/2008/ags">
</s:Application></span>
接下来就可以编码了
添加地图:
第二步,添加地图控件标签:
代码如下:
<?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/halo"
xmlns:esri="http://www.esri.com/2008/ags">
<span style="color:#ff0000;"><esri:Map level="3" wrapAround180="true">
<esri:center>
<esri:WebMercatorMapPoint lon="0" lat="0"/>
</esri:center>
</esri:Map></span>
</s:Application>
代码中,level属性指的是地图默认显示的绽放等级,wrapAround180是设置地图显示范围是否重复平铺显示地图,即地图绽放至最小比例尺可以看到全球时,边界会连续显示接到地图边界的另一边。<esri:center>是设置地图默认显示的中心位置。
接下来,可以添加一个瓦片地图服务(ArcGISTiledMapServiceLayer)作为显示用的底图。再添加一个动态地图服务(ArcGISDynamicMapServiceLayer)显示在底图上面
示例代码如下:
<esri:Map level="3" wrapAround180="true">
<esri:center>
<esri:WebMercatorMapPoint lon="0" lat="0"/>
</esri:center>
<span style="color:#ff0000;"><esri:ArcGISTiledMapServiceLayer
url="http://server.arcgisonline.com/ArcGIS/rest/services/
World_Street_Map/MapServer"/>
<esri:ArcGISDynamicMapServiceLayer
url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/
Demographics/ESRI_Population_World/MapServer"
alpha=".70"/></span>
</esri:Map>
运行测试应用。
下一节: