Hello.
I am using v 3.11 of the Javascript API and executing the PrintTask to generate a printable pdf. The map has a couple of Dynamic Map Service Layers that are dynamically rendered, i.e. the user can control the layer symbology based on various inputs.
When I execute the PrintTask, the dynamically rendered layers do appear on the printed map. But, I can't get a legend for those dynamic layers to appear on the printed map. I have tried a couple different approaches:
1) I have excluded the legendLayer array from the 'layoutOptions' object. I was hoping that would automatically generate a legend for all layers on the map, as suggested by the documentation. A legend does appear with he non-dynamic operational layers present, but not the dynamically rendered layers
2) I have created a legendLayer object specific to the dynamically rendered layers, like the code below, but still the layer doesn't appear in the legend.
var printTemplate = new PrintTemplate();
var legendLayers = [];
var legendLayer = new LegendLayer();
legendLayer.layerId = "dynLayer_0";
legendLayer.subLayerIds = [0];
legendLayers.push(legendLayer);
printTemplate.layoutOptions = { "titleText": title, "scalebarUnit": this._localMap.getAppConfig().printing.scalebarUnit, "legendLayers": legendLayers};
Any suggestions on how i can get my dynamically rendered layers to appear in the map legend?
Thank you.
Solved! Go to Solution.
Hi Thomas, I did end up getting a solution from ESRI technical support. Apparently a string value works for setVisibleLayers, however this does not pass properly into the printTask. In my situation I needed to convert the string value to an integer. I'm not sure how you've gone about yours but mine was looping through a bunch of checkboxes and updating an array based on which ones were checked, then using that array in setVisibleLayers.
Here's my code:
for (var i = 0; i < inputsAgreementsCount; i++) { if (inputsAgreements.checked) { visibleAgreementsLayerIds.push(parseInt(inputsAgreements.value)); } } layerAgreements.setVisibleLayers(visibleAgreementsLayerIds);
Where 'inputsAgreementsCount' holds the length of the array, 'inputsAgreements' is the checkbox, and 'visibleAgreementsLayerIds' is the array containing the layerId of each layer that should be visible. Previously I didn't have parseInt in the loop to convert the layerId to an integer. As soon as I added that, everything worked!
Hopefully this is some help to you too.
Thomas, did you ever figure this out? I'm running into the same issue.
Hi Laura.
Nope. Sorry to say that i never got it figured it. At the 2015 dev summit i chatted with one of the Esri devs and we never got it figured out then either. It 'should' work but doesn't. Not sure if any of the updates since 3.11 helped or not.....
Wow, that's disappointing to hear! I'm using 3.15 and the issue still seems to be present. I posted a new question here on geonet but no replies so far. Thanks for your quick response.
Good luck. Please post back here if you get an answer to your other thread. Thank you.
Thanks, I certainly will!
Hi Thomas, I did end up getting a solution from ESRI technical support. Apparently a string value works for setVisibleLayers, however this does not pass properly into the printTask. In my situation I needed to convert the string value to an integer. I'm not sure how you've gone about yours but mine was looping through a bunch of checkboxes and updating an array based on which ones were checked, then using that array in setVisibleLayers.
Here's my code:
for (var i = 0; i < inputsAgreementsCount; i++) { if (inputsAgreements.checked) { visibleAgreementsLayerIds.push(parseInt(inputsAgreements.value)); } } layerAgreements.setVisibleLayers(visibleAgreementsLayerIds);
Where 'inputsAgreementsCount' holds the length of the array, 'inputsAgreements' is the checkbox, and 'visibleAgreementsLayerIds' is the array containing the layerId of each layer that should be visible. Previously I didn't have parseInt in the loop to convert the layerId to an integer. As soon as I added that, everything worked!
Hopefully this is some help to you too.
I should clarify - 'inputsAgreementsCount' holds the length of a separate array, which contains all the checkboxes.
Hey Laura.
That is awesome! Thank you for your undaunted quest for the answer. I am going to have to brush off an old project and see if we can finally get the printing to work.
Thanks again,
Tom