How to get Legend Info from web map services

11382
25
02-17-2017 06:59 AM
DavidZhong2
New Contributor II

I am creating a custom TOC which needs to have both layer toggle and legend item (image data) for the web map. But the web map service does not have Legend Info. Does anybody know how to get legend info from the web map services. Any help would be very appreciated.

25 Replies
JordanBaumgardner
Occasional Contributor III

Oh - Right. But once the map layers loads, you run through it's collection and pull the SRC url from that. Swap out the FeaturServer for MapServer and your good to make your call.

0 Kudos
JasonRainwater
New Contributor II

So I tried this.  let me know if this is what you were talking about.

I have https://services.arcgis.com/somekey/arcgis/rest/services/myname/FeatureServer/0

I tried changing to https://services.arcgis.com/somekey/arcgis/rest/services/myname/MapServer/0

I get invalid url.  Or is the url in the src after the layer loads different than this?

0 Kudos
JordanBaumgardner
Occasional Contributor III

I would have expected that to work. It worked on my servers.

Try dropping the layer ID

/services.arcgis.com/somekey/arcgis/rest/services/myname/MapServer

/services.arcgis.com/somekey/arcgis/rest/services/myname/MapServer?f=json

will return the info in a code readable format.

/services.arcgis.com/somekey/arcgis/rest/services/myname//MapServer/legend   or   /MapServer/legend?f=json

should get you what you are after

Common esri rest params

f= Return Format [HTML | JSON | PJSON | more I can't remember ]

token=  for secure services - go to "generate token" and add to your calls

0 Kudos
JasonRainwater
New Contributor II

I tried https://services.arcgis.com/thekey/arcgis/rest/services/myname/MapServer and I'm still getting invalid url.  but these are urls I'm pulling through digging down into the info of the webmap.  I'm going to debug and pull some real resolved urls out and test them

0 Kudos
JordanBaumgardner
Occasional Contributor III

Odd. You may check your security from \arcgis\manager   - go to the service and click the "Capabilities" link. You should see at least two urls. I've never seen a FeatureServer w/o a matching MapServer. 

What do you see when you go to \arcgis\rest\services?  

JordanBaumgardner
Occasional Contributor III

Oh, and Yes. The URL that loads could be different from the container document (the portal/web map). It is a collection of regular map services. So the Web Map url might be different from its contents. 

I'm getting nervous that I sound more authoritative than I feel. The Portal stuff is still pretty new to me.

But I do know that once a layer is loaded, there is a proper URL to it's no kidding source.

0 Kudos
JordanBaumgardner
Occasional Contributor III

Sorry, let me be more clear.

Load your WebMap as usual but listen for the LoadComplete (don't quote me on that exact event name), then run through the Map objects Layer list. Each one will have a source. You can then use that to complete your TOC. 

0 Kudos
SethPatrich2
New Contributor II

Is it best to use the source from the Layer List?  If the person who created that web map has made changes to the symbology in the web map, they would not show up in the actual feature service.

0 Kudos
JordanBaumgardner
Occasional Contributor III

I didn't know it held symbology as well. Excellent point.

0 Kudos
JordanBaumgardner
Occasional Contributor III

A WebMap/Portal Map is just a wrapper around "Normal" esri services. Once it loads the Map object will have the actual services that the WebMap is made up of.

0 Kudos