I am using some stock print templates like the 2 in this sample. The problem is that the legend doesn't show up at all. I found a few forum questions showing problems with the legend but none of them involved having no legend at all. My code looks like this ...
var legendLayer = new LegendLayer();
legendLayer.layerId = "Parcels_and_Zoning";
legendLayer.subLayerIds = [4, 10];
The LegendLayer is included in the require section "esri/tasks/LegendLayer" and using typeof(legendLayer), it is an object. None of the samples that I have found show where to include space for the legend so maybe that is where things are going wrong. This next bit of my code is almost directly from the sample that I linked above ...
var layouts = [{
name: "Letter ANSI A Landscape",
label: "Landscape (PDF)",
format: "pdf",
options: {
legendLayers: [legendLayer], // empty array means no legend
scalebarUnit: "Miles",
titleText: printTitle + ", Landscape PDF"
}
}, {
name: "Letter ANSI A Portrait",
label: "Portrait (Image)",
format: "jpg", // ETC. ETC.
Note the comment saying "// empty array means no legend". I took the legendLayers option out entirely and STILL get no legend. Does anyone have any idea what I am doing wrong? I considered that I may need to add a legend in the html but I only need it for printing (I have not fully explored this). Do I need to create a legend in some way other than the code I've provided (the samples don't indicate this at all and all seem to avoid having a legend)? Is it possibly a problem with the service I have created ? The screenshot shows the result with no legend and sublayer 10 is the pink and amber colored polygon layer that I was hoping to get in the legend.