How to filter layers in a legend: understanding PrintTemplate.layoutOptions.legendLayers

2737
10
Jump to solution
11-29-2016 02:34 PM
PitersonPaulgek
New Contributor III

Hi,

I try to define the list of layers to be included in a legend in print task. It (marked with red color) has no impact on output printed image. It always only one layer - "address_points" (I tried ["address_points,streets,lakes"] or ["streets,"] or ["lakes"]). I see in debug mode that "map" object contains layerIds ("address_points,streets,lakes").

I tried to use PrintTemplate.layoutOptions.legendLayers

template2.layoutOptions = {
"titleText": title,
"authorText": author,
"copyrightText": "<Copyright info here>",
"legendLayers": ["address_points,streets,lakes"],
"scalebarUnit": "Miles",
};

Please explain how to make it working.

I also noticed the question (see the link below), but cannot understand it.

Javascript API print task legend with dynamically rendered layer 

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Piterson,

   Here is the quote from the docs:

legendLayers: an array of LegendLayer containing the id's of the layers that will be included in the legend. If legendLayers is not specified, all operational layers (non-tiled layers) will be present in the legend. To specify that no layers will be included in the legend set legendLayer to an empty array.

So I am not sure what you are trying to do but you are confined to what API allows.

View solution in original post

0 Kudos
10 Replies
RobertScheitlin__GISP
MVP Emeritus

Piterson,

   The printTemplates.layoutOptions.legendLayers is expecting an array of 

esri/tasks/LegendLayer

objects not just strings.

LegendLayer | API Reference | ArcGIS API for JavaScript 3.18 

PitersonPaulgek
New Contributor III

Robert,

Thank you for the response.

It works, thank you.  

But it shows now number of layers I define plus one layer ("address_points" - that was before).

Example: I ask to include 3 layers "address_points,streets,lakes" - it includes 4 layers - "address_points,streets,lakes" + "address_points". How to remove it?

Additional question: How to include in a legend only symbols that actually on current extent?

 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Piterson,

   Why not just not add the address_points then? In ArcMap there is an option to limit the legend for a mxd but the only way (untested) that I can think of to have this happen in the print layout is to edit the ArcGIS Server default print layouts to enable that option (I don't have much more advice on this though as I have never attempted).

0 Kudos
PitersonPaulgek
New Contributor III

Just for information - 

we use custom map layouts/templates.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Piterson,

   That should make it easy as you know where the templates are located on the file system and to make sure the mxd has the option checked to limit the legend then.

0 Kudos
PitersonPaulgek
New Contributor III

Currently, it works partly:

1) We created mxd with all layers 

and set "Legend properties"->"General" check box on "Only display layers that are checked on in Table Of Contents" - 

and set "Items" Only show classes visible in current extent

2) the code is now

template2.layoutOptions = {
"titleText": title,
"authorText": author,
"copyrightText": "Any copyright",
"legendLayers": [],
"scalebarUnit": "Miles",
};

it works partly:

1) OK - when change "display layers that are checked on in Table Of Contents" - it changes legend layers accordingly.

2) OK - it shows only visible (current extent) features symbology in the legend

3) NOT OK -  it does not change visible sublayers: example:

"address_points" has 3 sublayers (the same source but different symbology):

- "show by population"

- "show by year"

- "show by update_time"
We expect when user change sublayer it will show in the legend (printed map) accordingly.

But it only takes first every time.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Piterson,

   If you want to change visible sub layer then you need to follow the documentation on LegendLayer and set the subLayerIds property of the LegendLayer.

Don't forget to mark this question as answered by clicking on the "Correct Answer" link on the reply that answered your question.

0 Kudos
PitersonPaulgek
New Contributor III

Robert,

Please see that we do not use LegendLayer object in the current code

template2.layoutOptions = {
"titleText": title,
"authorText": author,
"copyrightText": "Any copyright",
"legendLayers": [],
"scalebarUnit": "Miles",
};

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Piterson,

   Here is the quote from the docs:

legendLayers: an array of LegendLayer containing the id's of the layers that will be included in the legend. If legendLayers is not specified, all operational layers (non-tiled layers) will be present in the legend. To specify that no layers will be included in the legend set legendLayer to an empty array.

So I am not sure what you are trying to do but you are confined to what API allows.

0 Kudos