<?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:esri="http://www.esri.com/2008/ags" > <fx:Script> <![CDATA[ import com.esri.ags.events.MapEvent; import com.esri.ags.layers.ArcGISDynamicMapServiceLayer; import com.esri.ags.layers.ArcGISTiledMapServiceLayer; import mx.collections.ArrayList; private var worldurl:String = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"; private var topourl:String = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"; private var world2:String = "http://server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer"; private var dynamicurl:String ="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"; private function createDynamicLayer():void { trace('createDynamicLayer()'); var dynamicMap:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer(dynamicurl); dynamicMap.visibleLayers = new ArrayList([5]); // just the states layer mymap.addLayer(dynamicMap); } private function createTiledLayer():void { trace('createTiledLayer()'); var tiledMap:ArcGISTiledMapServiceLayer = new ArcGISTiledMapServiceLayer(worldurl ); mymap.addLayer(tiledMap); } private function addTopoMap():void { trace('addTopoMap()'); var tiledMap:ArcGISTiledMapServiceLayer = new ArcGISTiledMapServiceLayer(topourl ); mymap.addLayer(tiledMap); } private function clearLayers():void { mymap.removeAllLayers(); } protected function layerAddHandler(event:MapEvent):void { trace('Layer added'); } ]]> </fx:Script> <fx:Declarations> <esri:WebMercatorExtent id="usa" minlon="-124.493523" minlat="18.295270" maxlon="-62.135124" maxlat="53.841627"/> </fx:Declarations> <esri:Map id="mymap" extent="{usa}" wrapAround180="true" layerAdd="layerAddHandler(event)"/> <s:HGroup top ="20" left="100" gap="20"> <s:Button label="Add dynamic map" click="createDynamicLayer( )" /> <s:Button label="Clear Layers" click="clearLayers( )" /> <s:Button label="Add tiled" click="createTiledLayer()" /> <s:Button label="Add topo map" click="addTopoMap( )" /> </s:HGroup> </s:Application>
private function createTiledLayer():void { trace('createTiledLayer()'); var tiledMap:ArcGISTiledMapServiceLayer = new ArcGISTiledMapServiceLayer(worldurl ); mymap.addLayer(tiledMap); tiledMap.addEventListener(LayerEvent.LOAD, function():void{ mymap.lods = tiledMap.tileInfo.lods; }); }