Select to view content in your preferred language

How do I add a legend to my ArcGIS Server Print Service?

5692
6
Jump to solution
08-05-2015 03:59 PM
BrianHiller
Regular Contributor

I've created my own custom print service and I am successfully using with ArcGIS Online and Portal for ArcGIS, but I'm having an issue getting the legend to display or display properly.

What do I need to do in the map document / print template to make my legend show up? How can I modify the style of the legend that gets displayed?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MarkusSchenardi
Frequent Contributor

You need to create your own printing service using a python script.

Tutorial: Advanced web map printing/exporting using arcpy.mapping—Documentation (10.3 and 10.3.1) | ...

In these script you can change legend items or even change a style using a stylefile that you need to create first based on a regular style file. Use C:\Program Files
(x86)\ArcGIS\Desktop10.3\bin\MakeServerStyleSet.exe
for the export.

You'll probably find problems with legend items not shown or cut off at the layouts border. The solution is to install a printer driver for the arcgis server service account, set it as default printer and set the standard page size to a really large size.

Pythonsample to change the legend:

    #Change Legend Style so that Layernames are displayed
    legends=arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT", "Legend")
    if len(legends)>0:
        legend = legends[0]
        styleItem = arcpy.mapping.ListStyleItems(pathStyleItem, "Legend Items", "styleitemname")[0]

        for lyr in legend.listLegendItemLayers():
            print "update legend of layer " + str(lyr.name)
            legend.updateItem(lyr, styleItem)

View solution in original post

6 Replies
RebeccaStrauch__GISP
MVP Emeritus

I'll be curious to see how others have handled this.  I was never able to get the legend to behave. If I remember correctly, the first few symbols for polygons would show up nice, and the others symbols would never render correctly.

In my case, I just created a graphic and added to my custom template for that class of maps I wanted to produce.  I know this is not the answer that you want, and hopefully someone has a good solution for us both to try, but thought I'd mention this so you know "you are not alone".

JayJohnson3
Emerging Contributor

Brian,

Try configuring your legend with 2 or 3 columns, you will then be able to adjust its size in your layout.

Jay

0 Kudos
MarkusSchenardi
Frequent Contributor

You need to create your own printing service using a python script.

Tutorial: Advanced web map printing/exporting using arcpy.mapping—Documentation (10.3 and 10.3.1) | ...

In these script you can change legend items or even change a style using a stylefile that you need to create first based on a regular style file. Use C:\Program Files
(x86)\ArcGIS\Desktop10.3\bin\MakeServerStyleSet.exe
for the export.

You'll probably find problems with legend items not shown or cut off at the layouts border. The solution is to install a printer driver for the arcgis server service account, set it as default printer and set the standard page size to a really large size.

Pythonsample to change the legend:

    #Change Legend Style so that Layernames are displayed
    legends=arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT", "Legend")
    if len(legends)>0:
        legend = legends[0]
        styleItem = arcpy.mapping.ListStyleItems(pathStyleItem, "Legend Items", "styleitemname")[0]

        for lyr in legend.listLegendItemLayers():
            print "update legend of layer " + str(lyr.name)
            legend.updateItem(lyr, styleItem)

BrianHiller
Regular Contributor

Thanks Markus, I appreciate you taking the time to answer this.

Too bad you have to write code to do this, for certain maps I also like Rebecca's solution of using a graphic that way i know what the end user is going to get.

Brian

BrianO_keefe
Honored Contributor

So does this mean I have to create a custom template for every single web map I develop with WAB if I want a Legend to show up?

0 Kudos
JonathanQuinn
Esri Notable Contributor

I've had luck using the Fixed Frame option under the legend properties within the template:

What kinds of issues are you seeing with the legend items?  Are they not fitting, or the legend items not printing correctly?  If you're printing a map with a lot of distinct features using a paper size small enough so that the features have problems fitting, you could see if larger paper sizes would help.

0 Kudos