Query Legends
- URL:http:// <mapservice-url>/queryLegends
- Version Introduced:10.7.1
Description
Available starting at 10.7.1, this operation is performed on a map service to return information about the map service's legend by layer. As opposed to the Legend resource, which provides a complete representation of the map legend, this operation allows you to filter the results by specifying parameters.
Each layer's legend information includes the symbol images and labels for each symbol. You can specify an image size for the symbol images. They include the base64-encoded imageData, as well as a URL that can be used to retrieve the image from the server site.
Additional information for each layer, such as the layer ID, name, and scale, is also included.
Most of the available request parameters are also found in the Export Map operation.

This is a relative URL. It can be dereferenced by accessing the map layer image resource.
Request parameters
JSON parameter | HTML parameter |
Details |
---|---|---|
f | Format |
The response format. Only json can be specified for this value. |
returnVisibleOnly | Return Visible Only | If set to true, as by default, a legend item class will only appear in the legend if a feature from that item class is included in the current extent. If set to false, all items in the legend will be included in the operation results. This is the same result as when using the static Legend resource. Because that resource is static, it performs faster than this operation; it's better to use the Legend resource if you want to obtain all legend items. |
bbox | Bounding Box | (Required) The extent (bounding box) of the exported image. Unless the bboxSR parameter has been specified, the bbox is assumed to be in the spatial reference of the map. Syntax: <xmin>, <ymin>, <xmax>, <ymax> Example: bbox=-104,35.6,-94.32,41 The bbox coordinates should always use a period as the decimal separator, even in countries where traditionally a comma is used. |
bboxSR | Bounding Box Spatial Reference | The spatial reference of the bbox. The spatial reference can be specified as either a well-known ID or as a spatial reference JSON object. If the bboxSR parameter is not specified, the bbox parameter is assumed to be in the spatial reference of the map. |
layers | Layers | Determines which layers appear on the exported map. There are four ways to specify which layers are shown:
Syntax: [show | hide | include | exclude]:layerId1,layerId2 Where layerId1, layerId2 are the layer IDs returned by the map service resource. Example: layers=show:2,4,7 ![]() Showing or excluding group layers also shows or excludes all groups and sublayers within the group layer (assuming they draw by default). For example, if you want to show group layer 0 and layer 2 is a sublayer of this group, layer 2 will also display. The same logic applies when excluding a group layer. |
layerDefs | Layer Definitions | Allows you to filter the features of individual layers in the exported map by specifying definition expressions for those layers. Definition expressions for a layer that is published with the service will be always honored. ![]() When filtering the features of individual layers in a mosaic dataset, the client must explicitly specify the definition expression on the parent mosaic dataset layer. The definition expression will not be honored if it is specified on any of the child layers. Syntax: { "<layerId1>" : "<layerDef1>" , "<layerId2>" : "<layerDef2>" } Where layerId1, layerId2 are the layer IDs returned by the map service resource. |
size | Image Size |
The size (width and height) of the exported image in pixels. If the size parameter is not specified, an image with a default size of 400 by 400 pixels will be exported. Syntax: <width>, <height> Example: size=600,550 |
imageSR |
Image Spatial Reference | The spatial reference of the exported image. The spatial reference can be specified as either a well-known ID or as a spatial reference json object. If the imageSR parameter is not specified, the image will be exported in the spatial reference of the map. |
historicMoment | Historic Moment | Returns an output image with features from a specific epoch time. This parameter applies only if the layer is archiving enabled and the supportsQueryWithHistoricMoment property is set to true. This property is provided in the layer resource. If historicMoment is not specified, the current features are drawn. Syntax: historicMoment=<Epoch time in milliseconds> Example: historicMoment=1199145600000 |
format | Image Format | The format of the exported image. The default format is .png. Values: png | png8 | png24 | jpg | pdf | bmp | gif | svg | svgz | emf | ps | png32 |
transparent | Background Transparent | If set to true, the image will be exported with the background color of the map set as its transparent color. The default is false. Only the .png and .gif formats support transparency. Internet Explorer 6 does not display transparency correctly for png24 image formats. Values: true | false |
dpi | DPI | The device resolution of the exported image (dots per inch). If the dpi parameter is not specified, an image with a default DPI of 96 will be exported. Example: dpi=200 |
time | Time | The time instant or time extent of the exported map image. Time instant syntax: time=<timeInstant> Time instant example: time=1199145600000 (1 Jan 2008 00:00:00 GMT) Time extent syntax: time=<startTime>, <endTime> Time extent example: time=1199145600000, 1230768000000 (1 Jan 2008 00:00:00 GMT to 1 Jan 2009 00:00:00 GMT) A null value specified for start time or end time will represent infinity for start or end time, respectively (for example, time=null,1230768000000). |
layerTimeOptions | Layer Time Options | The time options per layer. Users can indicate whether the layer should use the time extent specified by the time parameter, whether to draw the layer features cumulatively, and the time offsets for the layer. Syntax:
Example:
|
dynamicLayers | Dynamic Layers | Use this parameter to modify the layer drawing order, change layer drawing info, and change the layer data source version for this request. New layers (dataLayer) can also be added to the dynamicLayers based on the map service registered workspaces. The order of the dynamicLayers array defines the layer drawing order. The first element of the dynamicLayers array draws on top of all other layers. ![]()
Syntax:
See the Dynamic Layers code block examples section below for examples. |
gdbVersion | Geodatabase Version Name | Use this parameter to specify the geodatabase version. Syntax: gdbVersion=<geodatabase version> Example: gdbVersion=sde.USER1 |
mapScale | Map Scale | Use this parameter to export a map image at a specific scale, with the map centered at the center of the specified bounding box (bbox). Where scale is typically represented as 1:x, this value is x. Syntax: mapScale=<scale> Examples: mapScale=5000000, mapScale=5E6 |
rotation | Rotation | Use this parameter to export a map image rotated at a specific angle, with the map centered at the center of the specified bounding box (bbox). It could be a positive or negative number. Syntax: rotation=<degree> Examples: rotation=45 returns a map image rotated 45 degrees counterclockwise. |
datumTransformations | Datum Transformations | Use this parameter to apply one or more datum transformations to the map when imageSR is different than the map service's spatial reference. It is an array of transformation elements. Transformations specified here are used to project features from layers within a map service to imageSR. ![]() While specifying transformation, you need to think about which datum transformation is most applicable to project a layer to the imageSR. The sourceSpatialReference property for each a layer resource reports which spatial reference features are stored in the source dataset. For a list of valid datum transformation ID values and well-known ID (WKID) text strings, see Geographic transformations. Syntax with WKID: datumTransformations=[wkid1, wkid2] Examples with WKID: datumTransformations=[1623, 4078] to apply multiple transformations Syntax with datum: datumTransformations=[{<dt1>}, {<dt2>}] Examples with datum: datumTransformations=[{"wkid":108889}, {"geoTransforms":[{"wkid":108889,"transformForward":true},{"wkid":1622,"transformForward":false}]}] to apply multiple transformations including a composite transformation For more information on datum transformation, see the transformation parameter in Project operation. |
layerParameterValues | Layer Parameter Values | This parameter allows you to filter the features of individual layers in the exported map by specifying values to an array of preauthored parameterized filters for those layers. When this value is not specified for any parameter in a request, the default value assigned during authoring time is used instead. When a parameterInfo parameter allows multiple values, you must pass them in an array. ![]() Check parameterInfos at the layer resources for the available parameterized filters, their default values, and the expected data type. Syntax:
Example:
|
mapRangeValues | Map Range Values | This parameter allows you to filter features in the exported map from all layers that are within the specified range instant or extent. ![]() Check rangeInfos at the layer resources for the available ranges. Syntax:
Example:
|
layerRangeValues | Layer Range Values | This parameter allows you to filter the features of individual layers in the exported map by specifying values to an array of preauthored parameterized filters for those layers. When this value is not specified for any parameter in a request, the default value assigned during authoring time is used instead. When a parameterInfo parameter allows multiple values, you must pass them in an array. ![]() Check parameterInfos at the layer resources for the available parameterized filters, their default values, and the expected data type. Syntax:
Example:
|
patchSize | Patch Size | The dimensions of the exported image for each symbol in the legend. This is specified in device-independent units of points (1 inch = 72 points). If this parameter is not specified, the default size of 15 by 15 points (20 by 20 pixels at 96 DPI) will be exported. Note that this property has no effect on the point or marker legend patches, as those depend on the actual marker size in the legend. Syntax: <width>, <height> |
Response properties
Property | Details |
---|---|
layerId | The unique order ID number for the layer, as given in the map service resource. |
layerName | The name of the layer. |
minScale | The minimum scale extent for the layer. Where scale is typically expressed as 1:x, this value is x. |
maxScale | The maximum scale extent for the layer. |
legend | Provides a representation of each entry in the legend. The following properties are given for each entry:
|
JSON Response syntax
{
"layers": [
{
"layerId": <layerId1>,
"layerName": "<layerName1>",
"layerType" : "<layerType1>",
"minScale": <minScale1>,
"maxScale": <maxScale1>,
"legend": [
{
"label": "<label11>",
"url" : "<imageUrl11>", //Relative URL for static layers and full URL for dynamic layers. Access relative URL using http://<mapservice-url>/<layerId1>/images/<imageUrl11>
"imageData" : "<base64EncodedImageData11>",
"contentType" : "<contentType11>",
"height": <height>,
"width": <width>,
"values": [<maximum value1>] //In case of classBreaks renderer values will contain classMaxValue
},
{
"label": "<label12>",
"url" : "<imageUrl12>",
"imageData" : "<base64EncodedImageData12>",
"contentType" : "<contentType12>",
"height": <height>,
"width": <width>,
"values": [<maximum value2>]
}
]
},
{
"layerId": <layerId2>,
"layerName": "<layerName2>",
"layerType" : "<layerType2>",
"minScale": <minScale2>,
"maxScale": <maxScale2>,
"legend": [
{
"label": "<label21>",
"url" : "<imageUrl21>", //Relative URL for static layers and full URL for dynamic layers. Access relative URL using http://<mapservice-url>/<layerId2>/images/<imageUrl21>
"imageData" : "<base64EncodedImageData21>",
"contentType" : "<contentType21>",
"height": <height>,
"width": <width>,
"values": ["uniqueValue1"] //In case of uniqueValue renderer values, this will contain ungrouped unique values.
},
{
"label": "<label22>",
"url" : "<imageUrl22>",
"imageData" : "<base64EncodedImageData22>",
"contentType" : "<contentType22>",
"height": <height>,
"width": <width>,
"values": ["uniqueValue2", "uniqueValue3"]
}
]
}
]
}