Currently it is difficult to generate a custom implementation of a legend for a map layer without relying directly on the Legend map component/widget. To build a bespoke legend UI, an application developer typically has to:
At the same time, there is clearly existing logic in the Legend view model for producing HTML (or DOM structure) for different layer types, but this logic is not programmatically exposed for reuse.
Proposed solution
Introduce a set of reusable utilities (similar in spirit to existing symbolUtils) to generate legend content for a given layer. For example a function that, given a Layer (or renderer), returns a structured or HTML representation of its legend items.
The utility would be similar to the renderPreviewHTML function.
Hi @JonathanDawe_BAS , Thanks for submitting this idea. I'm hoping to get a little more information about the HTML structure desired. Recently with the 5.0 release we have documented a lot more of the legend view model. Could you possible take a look at the view models activeLayerInfos and the newly documented ActiveLayerInfo legendElements they might provide the functionality you are looking for.
https://developers.arcgis.com/javascript/latest/references/core/widgets/types/#LegendElement
If not, this sounds like a good idea if you offer a bit more detail on what you would like to see implemented and what's currently missing.
@Sage_Wall - I had completely missed this subtle addition! The new Legend Elements is most likely exactly what I was looking for - I composed this idea based on feedback pre 5.0
I'll go away and do some testing and see whether this meets the requirements we have!
Thanks for your help
@Sage_Wall - After some testing this works perfectly and provides exactly the api I was hoping for! A huge thanks to the whole Esri Development team!
Genuinely delighted 🙂
Awesome, I'm so glad this helped. I'll go ahead and close down this idea for now, but I'm really happy the new public api will work for your needs. Also very interested in seeing what you are creating if it happens to be a publicly available application or if your attending the Developers summit next week.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.