Map service GetLegendInfo method
Gets legend information, such as layer name, group heading, classification labels and symbol swatches, for layers in a map.
GetLegendInfo(string MapName, int[ ] LayerIDs, MapServerLegendPatch LegendPatch, ImageType ImageType)
Parameter |
Description |
---|---|
MapName |
The name of the map (data frame) that will be used to generate legend info. |
LayerIDs |
An array of layer ids for which legend information will be returned. If empty or null, all layers will be included. |
LegendPatch |
Specifies the symbol swatch properties for legend classifications. If empty or null, the default patch properties defined in the map will be used. |
ImageType |
Defines the image type and method for returning the image content for the symbol swatches. Supported image types are bmp, jpg, tif, png/png8, png24, emf, ps, pdf, ai, gif, and svg/svgz. Image content can be returned as a URL or as a MIME data stream. |
Return Value
An array of MapServerLegendInfo objects, one for each layer specified in the method call. Group layers in a map service are not recognized.
Remarks
A map service does not have the ability to generate a single legend image with all legend content. Instead, this method provides access to legend content which can be used to construct a single consolidated legend.
Each MapServerLegendInfo object contains one or more MapServerLegendGroup objects, each containing one or more MapServerLegendClass objects.
The relationship between value objects and legend content is illustrated in the following diagram. Note that each MapServerLegendClass contains a classification label and symbol swatch.
Examples
C#
MapService_MapServer mapservice = new MapService_MapServer();
mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";
string mapname = mapservice.GetDefaultMapName();
MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);
MapDescription mapdesc = mapinfo.DefaultMapDescription;
ImageType imgtype = new ImageType();
imgtype.ImageFormat = esriImageFormat.esriImagePNG;
imgtype.ImageReturnType = esriImageReturnType.esriImageReturnURL;
LayerDescription[] layerdescriptions = mapdesc.LayerDescriptions;
int[] layerids = new int[layerdescriptions.Length];
int i = 0;
foreach (LayerDescription layerdesc in layerdescriptions)
{
layerids.SetValue(layerdesc.LayerID, i++);
}
MapServerLegendPatch legendpatch = new MapServerLegendPatch();
legendpatch.ImageDPI = 96;
legendpatch.Height = 24;
legendpatch.Width = 24;
MapServerLegendInfo[] legendinfo = mapservice.GetLegendInfo(mapname, layerids, legendpatch, imgtype);
VB.NET
Dim mapservice As MapService_MapServer = New MapService_MapServer()
mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer"
Dim mapname As String = mapservice.GetDefaultMapName()
Dim mapinfo As MapServerInfo = mapservice.GetServerInfo(mapname)
Dim mapdesc As MapDescription = mapinfo.DefaultMapDescription
Dim imgtype As ImageType = New ImageType()
imgtype.ImageFormat = esriImageFormat.esriImagePNG
imgtype.ImageReturnType = esriImageReturnType.esriImageReturnURL
Dim layerdescriptions() As LayerDescription = mapdesc.LayerDescriptions
Dim layerids(layerdescriptions.Length-1) As Integer
Dim i As Integer = 0
Dim layerdesc As LayerDescription
For Each layerdesc In layerdescriptions
layerids.SetValue(layerdesc.LayerID, i)
i = i + 1
Next
Dim legendpatch As MapServerLegendPatch = New MapServerLegendPatch()
legendpatch.ImageDPI = 96
legendpatch.Height = 24
legendpatch.Width = 24
Dim legendinfo As MapServerLegendInfo() = mapservice.GetLegendInfo(mapname, layerids, legendpatch, imgtype)
Java
String serviceURL = "http://localhost:6080/arcgis/services/MapService/MapServer";
MapServerBindingStub mapService = new MapServerBindingStub(serviceURL);
String mapName = mapService.getDefaultMapName();
MapServerInfo mapInfo = mapService.getServerInfo(mapName);
MapDescription mapDesc = mapInfo.getDefaultMapDescription();
ImageType imgType = new ImageType();
imgType.setImageFormat(EsriImageFormat.esriImagePNG);
imgType.setImageReturnType(EsriImageReturnType.esriImageReturnURL);
LayerDescription[] layerDescriptions = mapDesc.getLayerDescriptions();
int[] layerIDs = new int[layerDescriptions.length];
int i = 0;
for(LayerDescription layerDesc:layerDescriptions)
{
layerIDs[i++]= layerDesc.getLayerID();
}
MapServerLegendPatch legendPatch = new MapServerLegendPatch();
legendPatch.setImageDPI(96);
legendPatch.setHeight(24);
legendPatch.setWidth(24);
MapServerLegendInfo[] legendInfo = mapService.getLegendInfo(mapName, layerIDs, legendPatch, imgType);
for (MapServerLegendInfo mapLegend : legendInfo) {
System.out.println("Layer ID: " + mapLegend.getLayerID());
System.out.println("Layer Name: " + mapLegend.getName());
}