Select to view content in your preferred language

Get Legend Symbol URL

2480
2
09-05-2012 07:39 PM
JustinShepard
Deactivated User
I'm working on a map application using the javascript api and am building a table of contents to provide some custom formatting. I am able to add the layers to the map and build a list of checkboxes using the layer id (or title). However, I can't find a clean example of how to get the url for the layer symbol.

Does anyone know of a good example on how to find the url for a layer's symbol? If I can get the symbol url then I can use innerHTML to display the symbol along with the layer id. The services are hosted on ArcGIS Server 10.0x and Legend is enabled so I can manually navigate to the URL but I need to make this dynamic.
0 Kudos
2 Replies
__Rich_
Deactivated User
I don't think there's anything out of the box (unless someones done a TOC with key/legend?) but using the metadata from the service/layer you can build the URI to retrieve the legend symbol - that's all the legend widget does.

Be aware that there's two ways to get the symbol and it depends on a number of factors e.g. browser.

You can get the actual image data and render on the client or you can request the image from the service on the server.

The legend 'service' is available at:

http://<your AGS installation>/<your service>/MapServer/legend

Or if you want the JSON:

http://<your AGS installation>/<your service>/MapServer/legend?f=json

You'll need the second one to build the URI dynamically as you'll need to append the layerId and url properties in order to get the correct symbol back.  Obviously you don't need to do that in a browser that is capable of rendering the symbol client-side using the imageData property.

Some documentation here:

http://help.arcgis.com/en/arcgisserver/10.0/apis/rest/mslegend.html

HTH

P.S. don't forget about proxies 😉
demdeberanz
Emerging Contributor
Obviously you don't need to do that in a browser that is capable of rendering the symbol client-side using the imageData property.


How to do this (in javascript)?

Thank you very much.
0 Kudos