Select to view content in your preferred language

Expose layer legend utils

342
4
02-26-2026 10:06 AM
Status: Already Offered
JonathanDawe_BAS
Frequent Contributor

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:

  • Add significant custom logic to process a renderer into HTML for display, or
  • For OGC services, make additional calls to external services to obtain legend information.

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. 

Screenshot 2026-02-26 at 18.06.14.png

4 Comments
Sage_Wall
Status changed to: Needs Clarification

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.

JonathanDawe_BAS

@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

JonathanDawe_BAS

@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 🙂 

Sage_Wall
Status changed to: Already Offered

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.