This page describes an older version, please see latest API at http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/components/Legend.html.
Packagecom.esri.ags.components
Classpublic class Legend
InheritanceLegend Inheritance spark.components.supportClasses.SkinnableComponent

The Legend component displays labels and symbols for some or all of the layers in the map. By default the legend will respect scale dependencies and only display layers and sublayers that are currently visible in the map. Optionally, you can set the respectCurrentMapScale property to false to show all layers at all scales, then layers that are not in scale will be shown - with 50% transparency. The legend automatically updates if the visibility of a layer or sublayer changes.

The legend supports the following layer types: ArcGISDynamicMapServiceLayer, ArcGISTiledMapServiceLayer, FeatureLayer, GraphicsLayer and KMLLayer (KML added in version 2.4). If the layer is an ArcGISDynamicMapServiceLayer or ArcGISTiledMapServiceLayer created using ArcGIS Server 10.0 SP1 or higher the legend is generated using the REST Map Service legend resource of that service, for example, http://server.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Unemployment_Rate/MapServer/legend. If the layers are version 10 or lower the legend is created using the ArcGIS.com legend service. In order to use the ArcGIS.com legend service your map service needs to be publicly accessible and your application must be able to access ArcGIS.com.

The legend for feature layers is created using the layer's drawing info, for example: http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/EarthquakesFromLastSevenDays/MapServer/0.

See also

Live sample - Basic Legend


Public Properties
 PropertyDefined By
  layers : Array
Specify a subset of layer instances in the map to display in the component.
Legend
  map : Map
The Map that the legend is associated with.
Legend
  respectCurrentMapScale : Boolean
When true the legend will update with every scale change and display only the layers and sub layers that are visible in the current map scale.
Legend
Public Methods
 MethodDefined By
  
Legend(layers:Array = null, map:Map = null, respectCurrentMapScale:Boolean = true)
Creates a new Legend component.
Legend
Skin States

To skin the component, implement a skin that defines the following states. Although you must implement all skin states, a skin state can be empty. An empty skin state specifies no changes to the default skin state.


 Skin State Description Defined By
  
disabled
The disabled state of the Legend component. Legend
  
loading
The loading state of the Legend component. Legend
  
normal
The default (i.e., "normal") state of the Legend component. Legend
Property Detail
layersproperty
layers:Array

Specify a subset of layer instances in the map to display in the component. If not set, all layers in the map will be displayed.

This property can be used as the source for data binding.


Implementation
    public function get layers():Array
    public function set layers(value:Array):void

See also

mapproperty 
map:Map

The Map that the legend is associated with.

This property can be used as the source for data binding.


Implementation
    public function get map():Map
    public function set map(value:Map):void
respectCurrentMapScaleproperty 
respectCurrentMapScale:Boolean

When true the legend will update with every scale change and display only the layers and sub layers that are visible in the current map scale. When false, the legend does not update on every scale change and all layers and sub layers will be displayed.

The default value is true.

This property can be used as the source for data binding.


Implementation
    public function get respectCurrentMapScale():Boolean
    public function set respectCurrentMapScale(value:Boolean):void
Constructor Detail
Legend()Constructor
public function Legend(layers:Array = null, map:Map = null, respectCurrentMapScale:Boolean = true)

Creates a new Legend component.

Parameters
layers:Array (default = null) — Specify a subset of layers in the map to display in the component.
 
map:Map (default = null) — The Map associated.
 
respectCurrentMapScale:Boolean (default = true) — When true the legend will update with every scale change and display only the layers and sub layers that are visible in the current map scale. When false, the legend does not update on every scale change and all layers and sub layers will be displayed.