if (optionalLayer.visible) { legendLayer = new esri.tasks.LegendLayer(); legendLayer.layerId = optionalLayer.id; legendLayer.subLayerIds = optionalLayer.visibleLayers; options.legendLayers.push(legendLayer); }
I had the same problem only to realize when using Portrait the legend is present. Meaning my legend had so many items that it did not show. I'm not sure why Malcolm Williamson's is not working. Or maybe this post is long due and a solution was found?
Format PDF Layout_Template A3 Landscape Web_Map_as_JSON {"mapOptions":{"showAttribution":true,"extent":{"xmin":-10884089.275607755,"ymin":4039507.1494186064,"xmax":-9710016.521147506,"ymax":4407627.877639997,"spatialReference":{"wkid":102100}},"spatialReference":{"wkid":102100},"scale":2311162.217155},"operationalLayers":[{"id":"layer0","title":"layer0","opacity":1,"minScale":591657527.591555,"maxScale":2256.994353,"type":"OpenStreetMap","url":"http://a.tile.openstreetmap.org"},{"id":"Districts","title":"Districts","opacity":0.7,"minScale":0,"maxScale":0,"url":"http://165.29.23.149/arcgis/rest/services/DistrictReports_FY22/MapServer","visibleLayers":[32],"layers":[{"id":32,"layerDefinition":{"id":32,"source":{"type":"mapLayer","mapLayerId":32},"drawingInfo":{"renderer":{"type":"classBreaks","field":"Two_or_More_Races_Total_Pie","minValue":0,"classBreakInfos":[{"classMaxValue":161,"label":"0 - 161","description":"","symbol":{"color":[255,255,204,255],"outline":{"color":[0,0,0,255],"width":0.75,"type":"esriSLS","style":"esriSLSSolid"},"type":"esriSFS","style":"esriSFSSolid"}},{"classMaxValue":322,"label":"162 - 322","description":"","symbol":{"color":[218,196,131,255],"outline":{"color":[0,0,0,255],"width":0.75,"type":"esriSLS","style":"esriSLSSolid"},"type":"esriSFS","style":"esriSFSSolid"}},{"classMaxValue":483,"label":"323 - 483","description":"","symbol":{"color":[181,127,72,255],"outline":{"color":[0,0,0,255],"width":0.75,"type":"esriSLS","style":"esriSLSSolid"},"type":"esriSFS","style":"esriSFSSolid"}},{"classMaxValue":644,"label":"484 - 644","description":"","symbol":{"color":[144,58,29,255],"outline":{"color":[0,0,0,255],"width":0.75,"type":"esriSLS","style":"esriSLSSolid"},"type":"esriSFS","style":"esriSFSSolid"}},{"classMaxValue":805,"label":"645 - 805","description":"","symbol":{"color":[107,0,0,255],"outline":{"color":[0,0,0,255],"width":0.75,"type":"esriSLS","style":"esriSLSSolid"},"type":"esriSFS","style":"esriSFSSolid"}}],"classificationMethod":"esriClassifyEqualInterval"}},"minScale":0,"maxScale":0}}]},{"id":"map_graphics","minScale":0,"maxScale":0,"featureCollection":{"layers":[]}}],"exportOptions":{"outputSize":[800,1100],"dpi":96},"layoutOptions":{"titleText":"Two or More Races Total","authorText":"Made by: Arkansas Department of Education","copyrightText":"<copyright info here>","scaleBarOptions":{"metricUnit":"Kilometers","metricLabel":"km","nonMetricUnit":"Miles","nonMetricLabel":"mi"},"legendOptions":{"operationalLayers":[{"id":"Districts","subLayerIds":[32]}]}}} f json
I think the problem here are the default print templates.
The legend is placed in the bottom of the page leaving very small room for the legend info. If a layer has too many symbols it will simply not be displayed in the legend. To check this, load just one or two layers in your app rendered with a simple renderer. You should see the layers info in the bottom left side of the page.
The solution is simple. Edit the default print templates and place the legend elment somewhere else leaving more space for the layer info. And also check that "Shrink contents to fit frame" option to make the layer info fit the legend element (you'll find it in the Fitting strategy section inside the legend properties, here).
Hope this helps.
hmmm, everything in the request looks ok and it even looks like all the rendering info is being passed in.
Would you be able to put up a sample in JSFiddle if its not too much that I could look it.
I was looking for some code samples on my mac and I realized on one of the apps, we have a custom image service layer and that we had to do a sort of trick to get a legend to appear where we put a dummy layer in a map service with a mock legend to represent the image service layer. All other apps I have built and are using print are using default symbology except for one which is showing full page map only with no legend, I know we have one or two at work built by some of my colleagues that have print functionality with custom renderers so I will check on them when I get in tomorrow to see if they are showing legends or if I can tweak the one I have to add a legend to it.
I don't think this is impossible, if I recall correctly we have done it at our office in one of our apps but I will have to get back to you on that, been in school all day so my mind is not on GIS at the moment, maybe someone from Esri in the meantime can comment on this to maybe point out something I'm forgetting or point us to a sample.
Has anyone found a solution to the problem? I am facing something similar and would really appreciate any suggestions to get this to work.
Thanks,
Alexei