I have a custom widget that allows the user to enter a query string and select a field to symbolize the selection set by unique value. I want to pass the unique field values/symbolization to the legend of a custom print layout template. The attached image represents an example of a selected field, unique values and their symbolization (This is what I'd like the legend to look like). This is what I would like to pass to a Legend element I have in my custom print layout template. I can pass text elements with no problem, just can't figure out how to pass a legend item. I'm using the print dijit and set the "templates" param to a variable that contains info pertaining to that specific layout. I see there is a "legendLayers": , param within the layoutOptions; however, I can't seem to get this to work. As I mentioned, I'd like the legend to look like the attached image. Does anyone know if this is possible? Any help/suggestions would be greatly appreciated.
The LegendLayer in Print Template is normally used for specific feature layer that you already define with the renderer. For instance, in your scenario, when user select the dropdown to define the renderer. You should give that featurelayer an id, then attach the renderer to that layer.
Then add the layer to map.
Later, you need to define a new legend as LegendLayer, and follow this doc to define the legendLayer id match with the featurelayer that you previous assign with the renderer.
var stateLegend = new LegendLayer(); stateLegend.layerId = "FL";
Then add this line into layoutOptions:
For a similar sample about using legendLayer, you can take a look about this sample: developer-support/ModifyPrintLegend_preCallback.html at master · Esri/developer-support · GitHub
Hope this can help!
Yue, thanks for the reply. I've looked at the API reference and the sample you provided; however, my rendering is not on an entire feature layer. I'm creating a selection set and rendering the results as a graphics layer. Is there a way to set the legend layer to a graphics layer instead of a feature layer?
I do check our API documentation and previous thread on Geonet,
Unfortunately, the legend dijit only supports tiled, dynamic, kml and feature layers.
However, the workaround is create a feature layer from a feature collection and you'll be able to use that with the legend dijit. According to the old thread: Legend for Graphics Layer
Try this: http://jsfiddle.net/6R3T8