<?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" xmlns:samples="com.*" pageTitle="Layers and Legends"> <fx:Script> <![CDATA[ import mx.events.FlexEvent; protected function application1_initializeHandler(event:FlexEvent):void { myLegend.layers = [ myDynamicService ]; } ]]> </fx:Script> <s:layout> <s:VerticalLayout horizontalAlign="center" paddingBottom="20" paddingLeft="20" paddingRight="20" paddingTop="20"/> </s:layout> <mx:HDividedBox width="100%" height="100%"> <esri:Map id="myMap"> <esri:ArcGISDynamicMapServiceLayer id="myDynamicService" name=" " load="myDynamicService.defaultVisibleLayers()" url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/MapServer"/> </esri:Map> <mx:VBox width="40%" height="100%"> <mx:Panel width="100%" height="50%" borderVisible="true" borderColor="#030303" title="Layers"> <samples:LayerTOC mapLayer="{myDynamicService}"/> </mx:Panel> <mx:Panel width="100%" height="50%" borderVisible="true" borderColor="#030303" title="Legend"> <esri:Legend id="myLegend" width="100%" height="100%" map="{myMap}" respectCurrentMapScale="true"/> </mx:Panel> </mx:VBox> </mx:HDividedBox> </s:Application>