ArcGIS Server » Web Applications » Javascript APIs » ArcGIS
 
 

Code Gallery

Custom REST Service - Map Service Legends

The ArcGIS Server REST API does not support map service legends. The SOAP API does. This is a custom REST service written in Java that provides this functionality.

Web clients (JavaScript, Flex, etc.) can use the JSON response of this service to include legends in their applications.

[UPDATE #3: The .NET version of this sample is available here: http://resources.esri.com/arcgisserver/apis/silverlight/index.cfm?fa=codeGalleryDetails&scriptID=16800]

[UPDATE #2: Fixed a bug with null legend classes reported by Dave Bouwman.]

[UPDATE: The dev summit demos from the advanced JS API session are available in this code gallery. It includes a simple JS client that accesses this custom service. Download the samples from here: http://resources.esri.com/arcgisserver/apis/javascript/arcgis/index.cfm?fa=codeGalleryDetails&scriptID=16092 ]

This service supports 3 parameters:

soapUrl - Required. URL of the SOAP endpoint of the map service.

f - The response format: html, json, pjson (pretty json). The default format is html.

callback - The JavaScript callback method for the JSON response.

This service uses the JSON in Java library from: http://www.json.org/java/

It also uses the ArcGIS Server SOAP client library that you can reference from your ArcGIS Server installation.
Author ArcGIS Server Development Team
Date Submitted 03-19-2009
Date Last Updated 02-09-2010
Language JavaScript
Product/Version ArcGIS Server 9.3
Views 9187
Downloads 1404
License Type ESRI Attribution and License Agreement
(2 ratings)

Report Inappropriate Content: This Code Gallery is intended for the free exchange of code related to ESRI software products. Let us know if this entry is inappropriate (e.g., a download for a commercial product).

 

How about including a JS API client in sample?   posted by dpmarley on Mar 26, 2009 9:06 PM

Nice sample, but it would be much more helpful if the sampple included a JS web client calling the REST service, rather than a JSP, which is not a very realistic scenario.

OK, found an example in the Code Samples from Dev Summit   posted by dpmarley on Mar 26, 2009 9:18 PM

OK, I think I found an example of calling this REST service from Javascript...in the Dev Summit Code Samples downloaded from Code Gallery. (mapLegend.html, restLegends.html, js/RestLegends.js)

some instructions on how to deploy the app would be nice   posted by clj2289 on Apr 01, 2009 8:58 AM

Does this require that you have the Java version of AGS? Or can you make it work just using the few jar files that imported in the jsp?

Deploying the App   posted by rahulr on Apr 01, 2009 1:35 PM

@clj2289 You will need to refer/use to the ArcGIS Server Java SOAP API jars. The ArcGIS server can be either a Java or a .NET server.

Install/Help Documentation   posted by blaird on Apr 02, 2009 8:20 AM

Is there a install document available for this sample? I am not seeing one. Thanks.

Instructions   posted by hbostic on Apr 02, 2009 1:27 PM

Can anybody provide instructions on how to get this setup?

.NET version?   posted by xqin on Apr 03, 2009 10:12 AM

Is there any plan to provide one in .NET?

Installing the Custom REST service   posted by rahulr on Apr 04, 2009 6:11 AM

@blaird, @hbostic There is no install document. All you need to do is to copy your ArcGIS server SOAP API proxies and related jars (arc objects, axis jars etc.) to the WEB-INF\lib folder. Create a WAR and deploy it on your app-server / Servlet container. Please let us know if you need more information. @xqin Currently there is no .NET version of this sample. However it should be fairly easily to write by adapting to the given source code. Would you like us to write one?

.NET version should be availabe too   posted by xqin on Apr 04, 2009 6:56 PM

It would be great if the ArcGIS Server Development Team can provide a .NET version. And YES, I'd like to see you guys write one. Many thanks.

.NET version request   posted by hbostic on Apr 07, 2009 4:50 AM

I too was asking for directions on how to get this setup under the .NET environment. If you could provide the solution that would be a great help. Thanks

Request for complete WAR package   posted by CGIS-Tech on Apr 13, 2009 10:26 AM

I have a request from a developer to stand up this SOAP web service for AGS legends. It would really help me, as a Systems Administrator, if I could get a complete WAR package. Would this be possible? Also, it would be very helpful if the necessary AGS JAVA JARS are documented to support this web service. Thank you for your assistance.

More complete installation instructions   posted by kenbuja on Apr 20, 2009 11:48 AM

The instructions posted on April 4 were not very informative (to me or to a colleague with much more ArcGIS Server experience). Can you supply more information on how to get this installed?

Another Vote for a .NET version...   posted by gtraber on Apr 22, 2009 4:31 PM

I had been trying to write one myself, but ran into a couple snags. A sample would be great. Thanks.

installation - jar file doesn't have constructor   posted by c_r_b on Apr 26, 2009 7:13 PM

The legend source code from this website has a constructor call to MapServerBindingStub(soapUrl) where soapUrl is a string. Unfortunately, the jar file that we're using ($ARCGIS_HOME\java\ejb\lib\arcgis_agsws_stubs.jar) doesn't have this constructor. This may be caused by a version conflict between the jar and the sample code? We're using v9.3 SP1. The jar that we have only allows for a Service, or a Url and Service (none of them are strings). Has anyone else been able to get this to work? Are there other jar files we should be using?

re: installation - jar file doesn't have constructor   posted by rahulr on Apr 27, 2009 9:49 AM

We used the Web services jars based on a new faster toolkit that are being shipped with v9.3.1. However you can simply replace that call with the old Axis call:: new MapServerBindingStub(new java.net.URL(wsService), null);

Hosting Map Service Legend   posted by bbinckes on May 11, 2009 11:45 AM

Given this code, any detail instructions to host this on our server? Thanks.

@Hosting Map Service Legend   posted by rahulr on May 12, 2009 9:55 AM

To host this code, on your own web server: You need to copy $[ARCGISHOME]/java/lib/webservices/arcgis_agsws_stubs.jar and arcgis_ws_runtime.jar to this web projects /WEB-INF/lib folder. Please bear in mind that the jar files that we have used are those that shipped with v9.3.1 which is based on a faster Webservices toolkit. So if you are compiling with v9.3 / v9.3 SP1, you have to replace the call to 'new MapServerBindingStub(soapUrl)' where soapUrl is a String, with 'new MapServerBindingStub(new java.net.URL(soapUrl), null)'; Once you have compiled this web project after adding the dependent jars, all you need to do is to export this web project as a WAR and deploy it on Tomcat or a similar servlet container and then you are done.

Check out the blog post for help on getting the sample to run   posted by sathyaprasad on May 19, 2009 1:52 PM

Check out the blog post for help on getting the sample to run: http://arkblog.wordpress.com/2009/05/19/installing-and-running-the-custom-rest-service-mapservice-legends-sample/

.NET version and limitation   posted by zj_zou on May 27, 2009 6:42 AM

I echo the request for a .NET version. Another limitation of this version: it does not take consideration of the map scale and the layer visibility. If the map document is designed to organize the visible layers in scale group layers that only one group layer is visible at each map scale, it will generate the legend for all layers in all groups, which takes much more time to generate multiple duplicate layer legends.

.Net version   posted by mfrias on Jun 30, 2009 4:08 AM

Has anyone written a .Net adaptation of this?

yes! .NET version please!   posted by carlson1se on Jul 13, 2009 1:30 PM

Also requesting .NET version with detailed instructions. The Java stuff is gobbledygook to me. I would also like to see the ability to take into account layer visibility and map scales. Thank you.

WebSphere v6.1   posted by c3719 on Jul 17, 2009 2:41 PM

Has anyone successfully ran this example under WebSphere v6.1? I'm having problems and I believe it's due to jar conflicts. Which jars are absolutely necessary?

ArrayStoreException on MapServerLegendInfo   posted by agha on Aug 02, 2009 6:04 AM

Hi I am trying to get the legend in my application. will use this in FLEX but right now using the same JSP as provided with the sample. The problem is that the line throws the java.lang.ArrayStoreException. I have tried to get the class type of the array but same exception. Have you encountered such scenario. I have 9.3.1 server, eclipse, tomcat, and jsdk 1.5 or 1.6, but in vain. MapServerLegendInfo[] legends = ms.getLegendInfo(map, null, createPatch(96, 20, 20), createImageType())) System.out.println(ms.getLegendInfo(map, null, createPatch(96, 20, 20), createImageType()).getClass())

Couple Tweaks Needed   posted by jbradfor on Aug 05, 2009 7:25 AM

Thanks, nicely done. A couple of changes I had to make to get the service to run: 1) There was no default (index.html) page included in the download, so I copied the online default page here (http://orthogonal.esri.com/restlegends/) and created my own. 2) In the index.html you have to add an action attr to the form tag that points to the servlet (action=”legends”). 3) In the jsps/legends-html.jsp page you also have to add an action attr to the form tag that points to the servlet (action=”../../legend/legends”).

Problem with GetLegendInfo WS   posted by feyster69 on Aug 17, 2009 9:13 AM

Hi everybody, I am a beginner in using ArcGis APIs and I encountered some difficulties... I must develop a legend on an application base on the flexviewer. My problem is that I try to call the service GetLegendInfo as a web service from my flex application but it doesn't work. I am always getting a timeout error... Can someone help me please?

Flex version request   posted by feyster69 on Aug 20, 2009 4:31 AM

Hi, Is there any flex version of this rest service ? Thanks.

ArrayStoreException   posted by mrr on Sep 10, 2009 3:08 AM

I have the same error ArrayStoreException when executing the line: MapServerLegendInfo[] legends = mapservice.getLegendInfo(map, null, legendpacht, tipoImagen); AGS 9.3.1 Tomcat5 and Tomcat6 JRE6 Any luck with 9.3.1 version?

Has anyone made this work in Flex yet?   posted by dwwheelock on Nov 05, 2009 1:54 PM

Has anyone made this work in Flex yet?

Has anyone made this work in Silverlight yet?   posted by dwwheelock on Nov 05, 2009 1:55 PM

Has anyone made this work in Flex yet?