1

Is there an API to retrieve a Legend for a FeatureServer?

I was looking for something like /FeatureServer/2/legend.

I believe /MapServer/2/legend works OK.

For example,

https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/Florida_Annual_Average_Daily_Traffic/FeatureServer/0

https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/Florida_Annual_Average_Daily_Traffic/FeatureServer/0/legend

If there is not a direct way of retrieving a Legend is there a way in the response to parse out the symbology so that a legend can be constructed manually using JavaScript?

zakariah1
  • 362
  • 1
  • 11

1 Answers1

2

If you're using the ESRI JS 4.x API, you can achieve this by widget 'esri/widgets/Legend'

Once all the layer are added into Map, you can initialize the widget as below and legends will be displayed in a custom DIV.

        var legend = new Legend({
            view: mapView,
            container: document.createElement("div")
        });
vivek shukla
  • 56
  • 1
  • 4