Skip To Content ArcGIS for Developers Sign In Dashboard

Map legend

A legend conveys the meaning of symbols used on the map. It associates a symbol with the real world entity that it represents. Typically, each item in the legend consists of a symbol with a label containing explanatory text.


Retrieving legend information

Starting with version 1.8 of the ArcGIS Runtime SDK for iOS API, you can retrieve legend information for the following layer types:

  • ArcGIS Dynamic Map Service layer
  • ArcGIS Tiled Map Service layer
  • ArcGIS Feature layer
  • ArcGIS Graphics layer

ArcGIS Dynamic and Tiled Map Service layers

Legend information for ArcGIS Dynamic and Tiled Map Service layers is only available if the layers are using a service from ArcGIS 10 for Server SP1 or later. This is because the REST API for services prior to version 10 SP1 did not provide legend information.

You can retrieve legend images and labels by invoking the retrieveLegendInfo method on the layer's AGSMapServiceInfo object. AGSMapServiceInfo's delegate is informed when the legend information is retrieved successfully or if an error is encountered. When successful, the legendImages and legendLabels properties of individual AGSMapServiceLayerInfo objects are populated.

func retrieveLegend {
 let msi:AGSMapServiceInfo = ...
 //set the delegate
 msi.delegate = self
 //retrieve legend
//delegate method called when error is encountered
func mapServiceInfo(mapServiceInfo: AGSMapServiceInfo!, operation op: NSOperation!, didFailToRetrieveLegendInfoWithError error: NSError!) {
 println("Error : \(error)")
//delegate method called when legend is retrieved successfully
func mapServiceInfo(mapServiceInfo: AGSMapServiceInfo!, operationDidRetrieveLegendInfo op: NSOperation!) {
 //loop through all sub-layers
 let layerInfos = mapServiceInfo.layerInfos as [AGSMapServiceLayerInfo]
 for layerInfo in layerInfos {
  //access legend information of each sub-layer
  let legendLabels = layerInfo.legendLabels as [String]
  let legendImages = layerInfo.legendImages as [UIImage]

ArcGIS Feature and Graphics layers

For an ArcGIS Feature layer, you typically display a legend item for each feature type or feature template available in the layer. For a Graphics layer, you display a legend item for each type of symbol used by the layer. Renderers are usually a good starting point for determining how many legend items should be displayed, because a renderer associates different symbols with graphics based on logical groupings.

To create legend items for ArcGIS Feature and Graphics layers, you need to retrieve images of symbols used in the layers. Both AGSRenderer and AGSSymbol provide convenience methods that return images for symbols.

let renderer:AGSRenderer = ...
let graphic:AGSGraphic = ...
//Getting legend image from a renderer
let image = renderer.swatchForFeature(graphic, size: CGSize(20, 30))
//Getting legend image from a symbol
let symbol:AGSSymbol = ...
let image = symbol.swatchForGeometryType(.Point, size: CGSize(20, 30))

Once you have the images, you need to associate them with appropriate labels in the legend.

Displaying the legend

Once you have the image and label information for each legend item, you can display the legend using a UITableView or a custom view.

See also