[GIS] How to call Legend end points of multiple layers published from Geoserver

geoservergetlegendgraphiclegendscale-factor

I have map services published from ArcGIS server being called from Angular- Leaflet app and we are displaying the legend (controlled through map controls) from
https://pxxxx.com/arcgis/rest/services/aaa/aaa/MapServer/Legend?f=pjson&token=ddddd.&callback=angular.callbacks._0

and receiving the Json as below based on layerID
angular.callbacks._0({
"layers": [
{
"layerId": 1,
"layerName": "abc",
"layerType": "Feature Layer",
"minScale": 0,
"maxScale": 0,
"legend": [
{
"label": "",
"url": "76d5be60e5691543860aa46358f5dcf8",
"imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAF9JREFUOI1jYaAyYIExzFcw/EeXPBnBwEisPIaBlACYZScjGBjhBmKzjZBrsAGquBDDQGQnU8VAagKqGIjss8HpQgwDKY0MrOmQWmA0HZIH6J8OKSkbqZIOCbqQkrIRAPKcIWF3tuu1AAAAAElFTkSuQmCC",
"contentType": "image/png",
"height": 20,
"width": 20
}
]
},
{
"layerId": 3,
"layerName": "xyz",
"layerType": "Feature Layer",
"minScale": 750000,
"maxScale": 0,
"legend": [
{
"label": "",
"url": "0c13bfd1080ed2b63ddc93e033c6739e",
"imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAElJREFUOI3t1DEKACAMA8AIfi+vzQPrVEFwqpmkmTpdM2XCnAkAkuIVIjk26IikIDkOML9UsLxtDRtssMGPQccu2hoeA1vdwVsWVeQROSDODxUAAAAASUVORK5CYII=",
"contentType": "image/png",
"height": 20,
"width": 20
}
]
},

The most complex map service consists of 53 layers and there are some more services. We are planning to switch to geoserver. Geoserver's getlegendgrahics works only for one layer at one time. So almost feels like there has to be 53 + calls just to gather legend info (unless I am missing something). Also legend in current application are being displayed based on the max and min scale through map controls- which in case of geoserver are stored in SLDs- is there any workflow similar in geoserver e.g. what will be the end point to use SLD info? (it may sound as 2 questions but both are from same context and very much related.)

Best Answer

According to this blog, the GetLegendGraphic call will render a legend for Layer Groups. However, I wasn't able to confirm that in Geoserver documentation--perhaps because it's implicit that it should work? And unfortunately our Geoserver instance predates the blog (11.02.2013) so I wasn't able to test it against one of our layer groups, either. :/

If you're loading your layers individually for toggling display on/off, you might try making a layer group with a few layers just to see if you can call GetLegendGraphic on the group layer. Then if it works, just create a group layer with all of your layers in it for the sake of grabbing a huge legend graphic.