Hi all, I am using Chris Sergent's print used in his simple map somewhat successfully, however not all of my layers are getting sent to the legend - only the one layer that is visible when the map is loaded is turning up in the legend. I have several checkboxes where the user can turn on and off other layers, and if this is done, these layers are not being sent to the legend. They do end up in the printed map, with the exception of the layer that was visible by default on map load. For some reason turning on/off any other layers causes this one layer to be removed from the final print. Is there some sort of refresh of the print tool that can be done?
I've discovered from reading other threads (here and elsewhere) that this seems to be an issue between the Print Task and ArcGISDynamicMapServiceLayer's setVisibleLayers method. Once you use setVisibleLayers (triggered when a user checks a layer on or off in my map), it wipes out the legend in the Print Task for unknown reasons. I can change all my hundreds of layers to feature layers, but this seems like a really cumbersome workaround. Turning on and off dynamic layers and having the resulting layers show up in a printout seems like a very basic function that should work.
In case anyone comes across this, I ended up getting a solution from ESRI tech support.
I had an array containing the layerId of the layers to be updated using setVisibleLayers. This worked fine, but did not translate to the print task - the array contained text values when the print task requires integers. So the fix was to add parseInt() to convert each layerId before pushing it to the array:
for (var i = 0; i < inputsAgreementsCount; i++) { if (inputsAgreements.checked) { visibleAgreementsLayerIds.push(parseInt(inputsAgreements.value)); } } layerAgreements.setVisibleLayers(visibleAgreementsLayerIds);
Each checkbox in my map has a value that corresponds to its layerId, so the above loop takes inventory of all the values of the checked checkboxes, puts them into an array, the uses that array to update the layer visibility.