Legend (Image Service)

Description

The legend resource represents an image service's legend. The legend information includes the symbol images and labels for each symbol. Each symbol is generally an image of size 20 x 20 pixels at 96 DPI. Symbol sizes may vary slightly for some renderer types (e.g., Vector Field Renderer). Additional information in the legend response will include the service name, service type, label, and content type.

The legend symbols include the base64 encoded imageData. The symbols returned in response to an image service legend request reflect the default renderer of the image service or the renderer defined by the rendering rule and bandIds.

Resource hierarchy

Legend

Request parameters

Parameter

Details

f

Description: The response format. The default response format is html.

Values: html | json

bandIds

Description: If there are multiple bands, you can specify a single band, or you can change the band combination (red, green, blue) by specifying the band ID. Band ID is 0 based. This is an optional parameter.

Example: bandIds=2,1,0

renderingRule

Description: Specifies the rendering rule for how the requested image should be rendered. This is an optional parameter.

See Raster function JSON objects for the syntax and examples.

Example usage

Example 1: JSON response for an image service; default legend is returned.

http://myserver:6080/arcgis/rest/services/onebandcolormap/ImageServer/legend?f=pjson

Example 2: JSON response for an image service; a different rendering rule is used.

http://myserver:6080/arcgis/rest/services/Legend_1/ImageServer/legend?f=pjson&renderingRule={"rasterFuncton":"MyHillshadeRFT"}

JSON response syntax

{
  "layers": [
    {
      "layerId": <layerId1>,
      "layerName": "<layerName1>",
      "layerType" : "<layerType1>",
      "minScale": <minScale1>,
      "maxScale": <maxScale1>,
      "legendType": <legendType>, //e.g. RGB Composite, Stretched, Unique Values, Colormap, Classified, Vector Field Renderer
      "legend": [
        {
          "label": "<label11>",
          "url" : "<imageUrl11>",  
          "imageData" : "<base64EncodedImageData11>", 
          "contentType" : "<contentType11>",
          "height": <height>,
          "width": <width>,
          "values": [<maximum value1>] //optional. array of variant type. In case of classBreaks renderer "values" will contain classMaxValue, In case of uniqueValue renderer "values" will contain ungrouped unique values. 
        },
        {
          "label": "<label12>",
          "url" : "<imageUrl12>",
          "imageData" : "<base64EncodedImageData12>", 
          "contentType" : "<contentType12>",
          "height": <height>,
          "width": <width>,
          "values": [<maximum value2>]
        }
      ]
    }
  ]
}

JSON response example

{
  "layers": [
  {
      "layerId": 0;,
      "layerName": "NLCD",
      "layerType": "Raster Layer",
      "minScale": 0,
      "maxScale": 0,
      "legendType": "Unique Values",
      "legend": [
        {
          "label": "WATER",
          "url": "deb6a75248269275154096a102200343",
          "imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAHUlEQVQ4jWNkYDjBQC5gIlvnqOZRzaOaRzVTRTMAGxgA8IzR4/kAAAAASUVORK5CYII="
          "contentType": "image/png",
          "height": 20,
          "width": 20,
          "values": ["WATER"]
        },
        {
          "label": "AGRICULTURE",
          "url": "09b59498dceabd1da48e8ad3943cc0e3",
          "imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAAAAAAAAAHqZRakAAAAIklEQVQ4jWNsymL4z0BFwERNw0YNHDVw1MBRA0cNHEoGAgCjYgITjF/2XAAAAABJRU5ErkJggg==",
          "contentType": "image/png",
          "height": 20,
          "width": 20,
          "values": ["AGRICULTURE"]
        },
        {
          "label": "GRASS",
          "url": "1d768a27a62203e9b26c147d0969356e",
          "imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAAAAAAAAAHqZRakAAAAIklEQVQ4jWNk+L/qPwMVARM1DRs1cNTAUQNHDRw1cCgZCABNCwLQa4XoegAAAABJRU5ErkJggg==",
          "contentType": "image/png",
          "height": 20,
          "width": 20,
          "values": ["GRASS"]
        }
      ]
    }
  ]
}

3/3/2017