Potential Bug in Print Task?

1139
6
Jump to solution
07-17-2012 06:30 AM
AlanRussian
New Contributor III
Let's say you have a map service structured as follows and you want to display and print a map with only "Item 1" visible:

Item Name (ID)

  • Folder 1 (0)


    • Item 1 (1)

    • Item 2 (2)

If you want just "Item 1" (ID = 1) to display, you set the visible layers to [1].  Everything's perfect on the web map.  If you now try to print the map, "Item 1" will display on the printed map; however, it will not display on the legend.

So, I thought maybe I needed to set "Folder 1" as visible in order to get "Item 1" to show up on the legend.  This time, I set the visible items to [0, 1].  The printed map displays just like I wanted with "Item 1" in the map and legend and without "Item 2" displaying; however, "Item 2" displays on the web map.

There appears to be an inconsistency between the JavaScript API and the PrintTask when it comes to handling this situation.  Is this a bug, or am I don't something wrong?

--Alan
0 Kudos
1 Solution

Accepted Solutions
JianHuang
Occasional Contributor III
Alan,

I agree, will fix it soon. Thanks for letting me know this.

View solution in original post

0 Kudos
6 Replies
JianHuang
Occasional Contributor III
Alan,

You only need to set the visibleLayer as [1]. When creating the print widget, assign the esri.tasks.PrintTemplate.layoutOptions.legend as an array of esri.tasks.LegendLayer objects.
Hope this helps.
0 Kudos
AlanRussian
New Contributor III
Jian,

I was having the PrintTask do this.  Since I wasn't setting the legendLayers, this would happen automatically.  The documentation says, "If legendLayers is not specified, all operational layers will be present in the legend."

So I was setting the visibleLayers on the layer to [1], and the PrintTask would set the visible layers in the legend to [1].  However, as I was saying in the OP, the visibleLayers parameter for the legend must include the parent layer in order for it to show up on the legend.  That is, I have to tell the legend that the visible layers are [0,1] in this example.

I've come up with code to generate a new list of visible layers that include the parent layer ids.  With help from your post, I then tell the PrintTask to use these IDs.  This solves the issue, but I still think this might be a bug with the legend.

Thanks for your help!
0 Kudos
JianHuang
Occasional Contributor III
Alan,

I agree, will fix it soon. Thanks for letting me know this.
0 Kudos
MichaelPorter1
New Contributor III
I am having a similar problem.  My map has a DynamicMapServiceLayer (id="dynamicLayer") with two group layers - LayerA (id=0) and LayerB (id=4).  LayerA has three subLayers (ids=1,2,3) and LayerB has three subLayers (ids=4,5,6).  In my map layerA and subLayers 1 and 3 are visible and everything else is not so dynamicLayer's visibleLayers attribute equals [0,1,3].

Below is my pseudo code for printing the map:

var legendLayer = new esri.tasks.LegendLayer();
legendLayer.layerId = "dynamicLayer";
legendLayer.subLayerIds = [0,1,3];

var printTemplate = new esri.tasks.PrintTemplate();
printTemplate.format = "JPG";
printTemplate.layout = "Letter ANSI A Landscape";
var layoutOptions = {TitleText: "Test Map",    scalebarUnit: 'Miles', legendLayers: [legendLayer]};
printTemplate.layoutOptions = layoutOptions;

var printParams = new esri.tasks.PrintParameters();
printParams.map = map;
printParams.outSpatialReference = map.spatialReference;           
printParams.template = printTemplate;

var printURL = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export Web Map Task";
var printTask = new esri.tasks.PrintTask(printURL);
printTask.execute(printParams, function(result) {
window.open(result.url + "?timestamp="+(new Date().getTime()));
});

The problem is that the resulting map will include a legend with layers 1,2, and 3 in it even though they are not visible or in the legendLayer.subLayerIds.  If I change the legendLayer.subLayerIds to [1,3] nothing in the legend shows up.
0 Kudos
AdrianMarsden
Occasional Contributor III
Same here - before I try another route has anyone got any news about this bug?  Is it likely to be sorted in 3.3?

Cheers

ACM
0 Kudos
MichaelParry
New Contributor II
I am having a similar problem.  My map has a DynamicMapServiceLayer (id="dynamicLayer") with two group layers - LayerA (id=0) and LayerB (id=4).  LayerA has three subLayers (ids=1,2,3) and LayerB has three subLayers (ids=4,5,6).  In my map layerA and subLayers 1 and 3 are visible and everything else is not so dynamicLayer's visibleLayers attribute equals [0,1,3].

Below is my pseudo code for printing the map:

var legendLayer = new esri.tasks.LegendLayer();
legendLayer.layerId = "dynamicLayer";
legendLayer.subLayerIds = [0,1,3];

var printTemplate = new esri.tasks.PrintTemplate();
printTemplate.format = "JPG";
printTemplate.layout = "Letter ANSI A Landscape";
var layoutOptions = {TitleText: "Test Map",    scalebarUnit: 'Miles', legendLayers: [legendLayer]};
printTemplate.layoutOptions = layoutOptions;

var printParams = new esri.tasks.PrintParameters();
printParams.map = map;
printParams.outSpatialReference = map.spatialReference;           
printParams.template = printTemplate;

var printURL = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export Web Map Task";
var printTask = new esri.tasks.PrintTask(printURL);
printTask.execute(printParams, function(result) {
window.open(result.url + "?timestamp="+(new Date().getTime()));
});

The problem is that the resulting map will include a legend with layers 1,2, and 3 in it even though they are not visible or in the legendLayer.subLayerIds.  If I change the legendLayer.subLayerIds to [1,3] nothing in the legend shows up.


I was having this exact problem until I changed a setting in my template mxd. When i checked 'on' the "Only display layers that are checked on in the Table Of Contents" in the legend properties this issue seemed to go away.[ATTACH=CONFIG]19640[/ATTACH]
0 Kudos