Select to view content in your preferred language

How to include the legend in the ArcGISDynamicMapServiceLayer?

2418
4
03-01-2011 11:42 AM
JamesAdams
Emerging Contributor
I'm using an ArcGISDynamicMapServiceLayer to display points on a map.  The points are colorized according to a scale specified in an MXD file which defines the service.  I want to include a corresponding legend showing the colors and their associated value ranges whenever the ArcGISDynamicMapServiceLayer is rendered, but I don't see anything in the API which provides for this (I see the getLegendInfos() function mentioned but the documentation is so minimal that it's useless for a beginner like me).  Can this be done, and if so then how would I go about it?

Thanks in advance for any suggestions, examples, etc.
Tags (2)
0 Kudos
4 Replies
DasaPaddock
Esri Regular Contributor
0 Kudos
JamesAdams
Emerging Contributor
Thanks for the reference, Dasa.  I was using version 2.1 so this gives me a reason to move up to 2.2 (and explains why I didn't see this in the documentation for version 2.1).

The Legend component looks like a good solution to my problem.  However it looks like it will require much more effort than simply using the Legend component and specifying the relevant map and map service layer.  It seems that I do not get a legend for free from the map service layer based on the color ramp and value range, and that you have to create and insert a legend into each layer.  This would be tedious and tiresome in my case because my map service layer contains 85 layers (17 layer groups, each with 5 layers), but doable nevertheless; however it turns out that you can't cook up the sort of legend I'm after anyway via the Layout editor of ArcMap.  All I want is a legend with a title and then one column displaying a colorized rectangle for each of the 5 breaks (Jenks) and a corresponding column displaying the value range for the break (these are specified for the various layers in the Layer Properties -> Symbology -> Quantities -> Graduated Colors -> Color Ramp and Range).  For example, something like this:

Annual Icing Days

red            0 - 15
orange       16 - 45
yellow        46 - 120
green         121 - 200
blue           201 - 365


Can anyone suggest how I could generate a legend like the above from my map service layer?  The ArcMap layout editor allows you to generate a legend with a custom title, the layer name, the field, the colorized symbols and value ranges; however I only need a subset of these (title, color, and value range).  If I can't get ArcMap to generate these for me then I will have to create my own images for legends, but I'm no graphic designer so I'm hoping to avoid this.
0 Kudos
DasaPaddock
Esri Regular Contributor
Are you using ArcGIS Server 10 SP 1? If you are, can you check if the legend resource has what you want?

e.g.
http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/legend

This is what the Legend component relies on to show the legend for a ArcGISDynamicMapServiceLayer.
0 Kudos
JamesAdams
Emerging Contributor
Yes, we are using ArcGIS Server 10 SP 1.  I have created an test service layer MXD with a legend included and I'm now waiting for it to be deployed so I can test this out.  Unfortunately I still don't see how I can create the sort of legend I want using the Layout View of ArcMap (i.e. the wizard you get when you click into Insert -> Legend).  Below is an example of what I want my legends to look like:



and as close as I can get to this by inserting a legend to my layer within ArcMap looks like this:



My understanding is that when you use the Legend component you essentially get the image of the legend you see when you add one to your layer in ArcMap (i.e. the second example above), so until ArcMap provides the ability to select which parts of the layer's symbology in the legend it creates (for example I don't want to see my field name or the round symbols) then this is not yet a complete solution for me and I will have to resort to cooking up my own legend images and using those instead.  Have I misunderstood how this works, and/or is there actually a way to create the sort of legend I want via ArcMap?
0 Kudos