Select to view content in your preferred language

Retrieving legend symbol info from a service that has no legend

1355
6
Jump to solution
02-19-2014 09:49 AM
BrettGreenfield__DNR_
Occasional Contributor II
I'm working on developing a custom legend for a webmap of ours by using esri.request to retrieve JSON information about the legend symbol and dynamically creating it for each of the layers in my map.  This works fine for our services: I sent the request to http://<mapservice>/legend, and I get the appropriate response.

However, this particular map is also using a few services from an external source, and when I visit the URL for those services, there's no link to "legend", and if I manually add "/legend" to the end of the service URL, I get an error saying Invalid URL.  The URL to one of the services in question is here: http://mdewin25.mde.state.md.us/ArcGIS/rest/services/Maryland_Shellfish_Closure_Areas/MapServer.

Is there a way to retrieve the legend symbol information from this service?  I'm concerned I'm going to have to just take screen shots of the legend symbols, save them as images, and add those to the map...I really don't want to have to do that.
0 Kudos
1 Solution

Accepted Solutions
BrettGreenfield__DNR_
Occasional Contributor II
Okay, looks like I figured it out.  I watched the requests made as I loaded a page that used the legend dijit via Firebug and found I can make the request to the service if I add "http://utility.arcgis.com/sharing/tools/legend?soapUrl=" before the URL to the actual service.  Tested it and this seems to work.

View solution in original post

0 Kudos
6 Replies
KenBuja
MVP Esteemed Contributor
I don't think you have that option on this service. It was created in 9.3.1 (click on the Home link to see this) and it looks like the Legend resource capability was only added in 10.0, SP 1. Take a look at the What's New page for the Rest API
0 Kudos
BrettGreenfield__DNR_
Occasional Contributor II
Thanks Ken.  I'd read that and figured that was the issue.  My next question then, how does the legend dijit request the legend information from services hosted on older versions of ArcServer?  If I use the legend dijit everything shows up fine, so there's a successful request being made somewhere.
0 Kudos
BrettGreenfield__DNR_
Occasional Contributor II
Okay, looks like I figured it out.  I watched the requests made as I loaded a page that used the legend dijit via Firebug and found I can make the request to the service if I add "http://utility.arcgis.com/sharing/tools/legend?soapUrl=" before the URL to the actual service.  Tested it and this seems to work.
0 Kudos
KenBuja
MVP Esteemed Contributor
Glad to hear you found a solution. You should mark your post as the answer.
0 Kudos
by Anonymous User
Not applicable
Hi :)...hoping you could complete your thought on retrieving the legend symbol from the server, this is the closest answer I've found in the threads so far! When using esri/request to get legend info in json, how do you then use the url to get the actual image off the server?

var legendImageRequest = esriRequest({
 url : "https://www.server.com/arcgis2/rest/services/test/test/MapServer/legend",
 content : {f : "json"},
 handleAs : "json",
});
legendImageRequest.then(function(response) {
 console.log(response.layers[0].legend[0]);
});


Thanks!
0 Kudos
by Anonymous User
Not applicable
Got it, sorry, needed to add 'images' to the api call with the image url: "https://www.server.com/arcgis2/rest/services/test/test/MapServer/0/images/8674387q2"
0 Kudos