Legend (Map Service)

URL:
https://<mapservice-url>/legend
Methods:
GET
Required Capability:
Map
Version Introduced:
10.0

Description

The legend resource represents a map service's legend. It returns the legend information for all layers in the service. Each layer's legend information includes the symbol images and labels for each symbol. Each symbol is an image of size 20x20 pixels at 96 DPI. Additional information for each layer, such as the layer ID, name, and min and max scales, is also included.

While this resource returns a complete representation of the legend for all layers in the service, you can use the Query Legends operation starting at 10.7.1 to narrow the content returned by several filter parameters.

The legend symbols include the base64 encoded imageData as well as a url that could be used to retrieve the image from the server.

New in 10.6.1

  • Supports the following new parameters:

    • dpi to return legend patches at any resolution
    • size to return line and polygon legend patches at a specific size

New in 10.1 sp1

  • Legend response now includes height and width for symbols.

New in 10.1

  • Legend response contains a values JSON array for layers that are symbolized using either class breaks or unique value renderer.

    • In case of class breaks renderer, values contains the class maximum value.
    • In case of unique value renderer, values contains the list of ungrouped unique values.
  • Support for dynamicLayers was added.

Request parameters

ParameterDetails

f

The response format. The default response format is html.

Values: html | json

dynamicLayers

This option was added at 10.1.

Dynamic layers definition. This parameter is required only for generating a legend for dynamic layers.

dpi

The device resolution of the exported image in dots per inch (DPI). If dpi is not specified, an image with a default DPI of 96 will be returned for each legend patch.

Example: dpi=200

size

The size (width * height) of the exported image in device-independent units, for example, points (1 inch = 72 points). If size is not specified, an image with a default size of 15x15 points will be exported.

Syntax: <width>, <height>

Example: size=30, 20

Example usage

Example 1:

https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/legend?f=pjson

Example 2:

https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/legend?dynamicLayers=[{"id":101,"source":{"type":"mapLayer","mapLayerId":3},"drawingInfo":{"renderer":{"type":"classBreaks","field":"pop2007","normalizationType":"esriNormalizeByPercentOfTotal","normalizationTotal":306348230,"minValue":0.17077754945736098,"classBreakInfos":[{"classMaxValue":1.7498315560693791,"label":"0.969259% - 1.749832%","description":"","symbol":{"type":"esriSMS","style":"esriSMSSquare","size":10.5,"angle":23,"xoffset":-10,"yoffset":0,"color":[0,255,255,255]}},{"classMaxValue":12.235568653358957,"label":"2.902453% - 12.235569%","description":"","symbol":{"type":"esriSMS","style":"esriSMSSquare","size":10.5,"angle":23,"xoffset":-10,"yoffset":0,"color":[0,0,255,255]}}]}}}]&f=html

JSON Response syntax

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{
  "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 https://<mapservice-url>/<layerId1>/images/<imageUrl11>
          "imageData" : "<base64EncodedImageData11>",
          "contentType" : "<contentType11>",
          "height": <height>, //new at 10.1 SP1;
          "width": <width>, //new at 10.1 SP1;
          "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 https://<mapservice-url>/<layerId2>/images/<imageUrl21>
          "imageData" : "<base64EncodedImageData21>",
          "contentType" : "<contentType21>",
          "height": <height>,
          "width": <width>,
          "values": ["uniqueValue1"] //In case of uniqueValue renderer values will contain ungrouped unique values.
        },
        {
          "label": "<label22>",
          "url" : "<imageUrl22>",
          "imageData" : "<base64EncodedImageData22>",
          "contentType" : "<contentType22>",
          "height": <height>,
          "width": <width>,
          "values": ["uniqueValue2", "uniqueValue3"]
        }
      ]
    }
  ]
}

JSON Response example

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
{
 "layers": [
  {
   "layerId": 0,
   "layerName": "Census Block Points",
   "layerType": "Feature Layer",
   "minScale": 99999,
   "maxScale": 0,
   "legend": [
    {
     "label": "0 - 61",
     "url": "16c1750c363249f0a97da4bfd6d99a49",
     "imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAFNJREFUOI1jYaAyYBk1cNRAOPiPxGak1MD/JZsR5vX4Mv7HZyghA1EMY2BgYCjZ/B+voUM/Uhh7fBnRw5CBgYIwhBuKzKfEhUQZQo6BRINRAykHADL/FCzY81v0AAAAAElFTkSuQmCC",
     "contentType": "image/png",
     "height": 20,
     "width": 20,
     "values": [
      61
     ]
    },
    {
     "label": "62 - 264",
     "url": "96b1e45aea277d25d6759101c5a568f2",
     "imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAGRJREFUOI3t0cEJwDAMA0AZsp63yRjeJgO6v35iOU0oJZToKfA9rIKXUw74CehBJ6ug19Z7puIMzcAQA4DanKIMpNgI/cfKe4JiKukwpgJMrJyiDBuBNxr17ODJD+nxKjiV/cELXCYgLEwEnd4AAAAASUVORK5CYII=",
     "contentType": "image/png",
     "height": 20,
     "width": 20,
     "values": [
      264
     ]
    },
    {
     "label": "265 - 759",
     "url": "eec6c4375388bb67e0bd976a7476bbcf",
     "imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAIdJREFUOI3d1MEJwCAMBdAEXM9tOobbdMD0YorGH2ulIjRHTR8fEhvo4wo7QAFnPAMKEdFxtl6KrIcNjEAX0tI7BMOEPcz2pViHtKCMYgYVTbl0yq/TaZUpt+zhj0FOkacGk3dx/doQTaQs0yHwbhpB7bPzQM7Nvb9N1fsEQhjdoRoZivsxqgsOTDUsDDFUxQAAAABJRU5ErkJggg==",
     "contentType": "image/png",
     "height": 20,
     "width": 20,
     "values": [
      759
     ]
    },
    {
     "label": "760 - 1900",
     "url": "2b73fd7416e13da8cdec1865ca48ca1f",
     "imageData": "iVBORw0KGgoAAAANSUhEUgAAABUAAAAVCAYAAACpF6WWAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAIlJREFUOI3t1cENgCAMBdDfhPXYxjHYxgHxQglWWhXKwcReCy8/aQMBdmWjR1ojWNi262aKxM0L3kOzhXHxmYKfYIk+AiUu4RZ9DWowo8NgD9YGNVUBDim5OO2ypD/6EZRSJJe1SpGAlcsPOKTllC06BbegRIdgCfbQCgO3L389L3vaoKhcHPqjDhqnRC6j0pDtAAAAAElFTkSuQmCC",
     "contentType": "image/png",
     "height": 20,
     "width": 20,
     "values": [
      1900
     ]
    },
    {
     "label": "1901 - 9409",
     "url": "0f3caba8a8bff54af2f795d36fa00b64",
     "imageData": "iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAYAAACpSkzOAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAKBJREFUSInt1sENgCAMBdDfhPXYxjHYxgHxVIOVFtCiF/61TV5+gISAjxIGdrMxIw8oA8C2606KxEMVtKAmwOEdC9Sg3AM0wAtWgx4hEpSYhF4jGjZy616lhNzacMpWnzdyb8PhVr+c0YIWBACgFGnKFU+RgD8eLDChFbeR0NRIyK1V2aYGuWAS0aATA/r+DAK4IRZ0LveAFtADVUFrx8oBsCBQQjt9MuwAAAAASUVORK5CYII=",
     "contentType": "image/png",
     "height": 20,
     "width": 20,
     "values": [
      9409
     ]
    }
   ]
  },
  {
   "layerId": 1,
   "layerName": "Census Block Group",
   "layerType": "Feature Layer",
   "minScale": 1000000,
   "maxScale": 0,
   "legend": [
    {
     "label": "",
     "url": "9f9da73612bae8cabdfccb9dc9ebb5ec",
     "imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAADpJREFUOI1jYaAyYKGZgU1NTf8pNayuro6RBV2AXMNgDqKdl0cNHDVw1MBRA3EaSEmZCCv6WNAFKAUAXT0NzOV1EscAAAAASUVORK5CYII=",
     "contentType": "image/png",
     "height": 20,
     "width": 20
    }
   ]
  },
  {
   "layerId": 2,
   "layerName": "Detailed Counties",
   "layerType": "Feature Layer",
   "minScale": 0,
   "maxScale": 0,
   "legend": [
    {
     "label": "",
     "url": "98fb6d62c20377d8d861e56ede28766f",
     "imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAADZJREFUOI1jYaAyYKGlgf+pYB4jugsZKTDsPwMDjb08auCogaMGjhqI00BKykRGdAMpKQvhAABd0QNSDPGCHwAAAABJRU5ErkJggg==",
     "contentType": "image/png",
     "height": 20,
     "width": 20
    }
   ]
  },
  {
   "layerId": 3,
   "layerName": "states",
   "layerType": "Feature Layer",
   "minScale": 0,
   "maxScale": 0,
   "legend": [
    {
     "label": "",
     "url": "bb835639802a7005b5d50553e8a13dce",
     "imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAADdJREFUOI1jYaAyYIHS/6lkHiMLYTWkAXQDGck0B+5Dmrtw1MBRA0cNHB4GUlwu0syF5JaDGAAABzUDUfxbIJcAAAAASUVORK5CYII=",
     "contentType": "image/png",
     "height": 20,
     "width": 20
    }
   ]
  }
 ]
}

JSON Response example (for dynamic map layers)

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{
 "layers": [
  {
   "layerId": 101,
   "layerName": "states",
   "layerType": "Feature Layer",
   "minScale": 0,
   "maxScale": 0,
   "legend": [
    {
     "label": "0.170778% - 0.441503%",
     "url": "https://sampleserver6.arcgisonline.com/arcgis/rest/directories/arcgisoutput/Census_MapServer/_ags_legend_be1f0e6f9480468a9d7e7b6f43f9dbe3.png",
     "imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAHZJREFUOI2108sOgCAMRNFpwv//cl0oCdTaB62zNZ5cAw40b6TfYDAAgEA1cELObNBCGKxV6mCwRtsOZiGlclSL5PKnLCcqb5BAXZX1wk+wUrl89o+F1T2VO9hwOD2Fr2sjH0Yrw//yAWSDWqWB+OAB5INJaO4CLn4gU6oOM3wAAAAASUVORK5CYII=",
     "contentType": "image/png",
     "height": 20,
     "width": 20,
     "values": [
      0.44150279569103434
     ]
    },
    {
     "label": "0.441504% - 0.969258%",
     "url": "https://sampleserver6.arcgisonline.com/arcgis/rest/directories/arcgisoutput/Census_MapServer/_ags_legend_b78cba0cf8ee4f2499b01018e7f43f09.png",
     "imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAHdJREFUOI2100sOgDAIRVFIunB2jgPbxCLyKfimxpNrWgc0b6TfYGIAAEDCGrggZzZoIUysVepgsEbbDmYhpXJUi+TypywnKm8QCbsq64WfYKXy8dk/FlY3K3ew4XB6Cl/XRj6MVob/5QPIBrVKA/HBA8gHk9DaBR97MNOpuBjQAAAAAElFTkSuQmCC",
     "contentType": "image/png",
     "height": 20,
     "width": 20,
     "values": [
      0.96925841549663927
     ]
    },
    {
     "label": "0.969259% - 1.749832%",
     "url": "https://sampleserver6.arcgisonline.com/arcgis/rest/directories/arcgisoutput/Census_MapServer/_ags_legend_63250b4a6f8d4c99aae77d4ca275501b.png",
     "imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAHZJREFUOI2108sOgCAMRNFpwv//cl0oCdTaB62zNZ5cAw40b6TfYGYAABHVwAk5s0ELYWatUgeDNdp2MAsplaNaJJc/ZTlReYNE1FVZL/wEK5XLZ/9YWN1TuYMNh9NT+Lo28mG0MvwvH0A2qFUaiA8eQD6YhOYuvaAwVEoxj/0AAAAASUVORK5CYII=",
     "contentType": "image/png",
     "height": 20,
     "width": 20,
     "values": [
      1.7498315560693791
     ]
    },
    {
     "label": "1.749833% - 2.902452%",
     "url": "https://sampleserver6.arcgisonline.com/arcgis/rest/directories/arcgisoutput/Census_MapServer/_ags_legend_28618eb5d5ed444c8159679a43cf0f7e.png",
     "imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAHZJREFUOI21k0sOwCAIBUvCwb05XVSTllI+PjobF8bJGJSPZrh8YohcKxEmXKIAX+hJhohVaQuTNRZPYVVkVDJapKlPWaMqZyFRVyVe+ClEKm/X/rEQZVaqd4gPp6fw9Wz0ZrYy/Zc3RL7QqnQksXBDFAuLosUJH/ow03WzBn8AAAAASUVORK5CYII=",
     "contentType": "image/png",
     "height": 20,
     "width": 20,
     "values": [
      2.9024522191624871
     ]
    },
    {
     "label": "2.902453% - 12.235569%",
     "url": "https://sampleserver6.arcgisonline.com/arcgis/rest/directories/arcgisoutput/Census_MapServer/_ags_legend_a3e7573e466c4249a41bc34d34de059e.png",
     "imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAHRJREFUOI2100EOgCAMRFGb9P5XrgskhNJCy9TZuDC+fIPyUzzOPyLSrkQg2KH9DuAOEbEqHTBWY02BWWitZLRI7+KU9ebKDySqqiwodEGkcrz2n4XoWqUC8cMpKlw+G30zWhn+l/PQAbQqfSQA5qEAmIP6Xh59IFML5CgnAAAAAElFTkSuQmCC",
     "contentType": "image/png",
     "height": 20,
     "width": 20,
     "values": [
      12.235568653358957
     ]
    }
   ]
  }
 ]
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.