Solved! Go to Solution.
<?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" pageTitle="Legend Component" initialize="application1_initializeHandler(event)"> <s:layout> <s:HorizontalLayout gap="0"/> </s:layout> <fx:Script> <![CDATA[ import mx.events.FlexEvent; protected function application1_initializeHandler(event:FlexEvent):void { myLegend.layers = [legendLayer]; } ]]> </fx:Script> <esri:Legend id="myLegend" width="250" height="100%" map="{myMap}" respectCurrentMapScale="false"/> <esri:Map id="myMap"> <esri:ArcGISDynamicMapServiceLayer id="legendLayer" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"/> </esri:Map> </s:Application>
<?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.LayerEvent; import com.esri.ags.layers.supportClasses.LayerLegendInfo; import mx.rpc.AsyncResponder; import mx.rpc.Fault; protected function legendLayer_loadHandler(event:LayerEvent):void { legendLayer.getLegendInfos(new AsyncResponder(getLegendResult, getLegendFault)); } private function getLegendResult(layerLegendInfos:Array, token:Object = null):void { for each(var layerLegendInfo:LayerLegendInfo in layerLegendInfos) { if (layerLegendInfo.layerLegendInfos) // group layer { trace(layerLegendInfo); for each(var subLayerLegendInfo:LayerLegendInfo in layerLegendInfo.layerLegendInfos) { trace(subLayerLegendInfo); } } else { // directly look at legenItemInfos } } // trace results(for group layer): // (com.esri.ags.layers.supportClasses::LayerLegendInfo)#0 // layerId = "2" // layerLegendInfos = (Array)#1 // [0] (com.esri.ags.layers.supportClasses::LayerLegendInfo)#2 // layerId = "3" // layerLegendInfos = (null) // layerName = "Coarse Counties" // layerType = "Feature Layer" // legendItemInfos = (Array)#3 // [0] (com.esri.ags.layers.supportClasses::LegendItemInfo)#4 // label = "" // symbol = (com.esri.ags.symbols::PictureMarkerSymbol)#5 // angle = 0 // height = 0 // source = (flash.utils::ByteArray)#6 // bytesAvailable = 142 // endian = "bigEndian" // length = 142 // objectEncoding = 3 // position = 0 // width = 0 // xoffset = 0 // yoffset = 0 // values = (null) // maxScale = 1000001 // minScale = 0 // visible = true // [1] (com.esri.ags.layers.supportClasses::LayerLegendInfo)#7 // layerId = "4" // layerLegendInfos = (null) // layerName = "Detailed Counties" // layerType = "Feature Layer" // legendItemInfos = (Array)#8 // [0] (com.esri.ags.layers.supportClasses::LegendItemInfo)#9 // label = "" // symbol = (com.esri.ags.symbols::PictureMarkerSymbol)#10 // angle = 0 // height = 0 // source = (flash.utils::ByteArray)#11 // bytesAvailable = 142 // endian = "bigEndian" // length = 142 // objectEncoding = 3 // position = 0 // width = 0 // xoffset = 0 // yoffset = 0 // values = (null) // maxScale = 0 // minScale = 1000000 // visible = true // layerName = "Counties" // layerType = "Group Layer" // legendItemInfos = (null) // maxScale = 0 // minScale = 1000000 // visible = true } private function getLegendFault(fault:Fault, token:Object = null):void { // check for fault } ]]> </fx:Script> <esri:Map id="myMap"> <esri:ArcGISDynamicMapServiceLayer id="legendLayer" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer" load="legendLayer_loadHandler(event)"/> </esri:Map> </s:Application>