Hi,
in my Arc JS App I use the legend widget.
private _legendWidget?: Legend;
@ViewChild('legendDiv', { static: false }) private _legendDiv?: ElementRef;
async ngAfterViewInit(): Promise<void> {
const view = await this._mvp.getMapViewAsync();
this._legendWidget = new Legend({ view, container: this._legendDiv?.nativeElement });
}
When I add a WMS Layer with sublayers I recognize that these are not shown in the legend widget.
E.G. from the following WMS I try using the sublayer with name "dwd:Ewam_reg025_fd_sl_SHTS"
https://maps.dwd.de/geoserver/ows?service=WMS&version=1.3.0&request=GetCapabilities
There I can see
<Style>
<Name>ewam_reg025_fd_sl_shts</Name>
<Title>Wellenhöhe</Title>
<Abstract>style for wind waves and sewll isoflaechen</Abstract>
<LegendURL width="91" height="252">
<Format>image/png</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="https://maps.dwd.de/geoserver/ows?service=WMS&version=1.3.0&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=dwd%3AEwam_reg025_fd_sl_SHTS"/>
</LegendURL>
</Style>
So it seems all necessary information are in place but somehow the legend url is not taken by arcgis.
When debugging I can see at the layer object that legendEnabled is set to true while legendUrl is null.
When I manually insert the legend URL into the property of the layer, the legend widget does show the legend correctly.
This is how we load the layer:
private getWmsLayerProperties(wmsLayerConfig: WmsLayerConfig) {
const properties: __esri.WMSSublayerProperties = {};
properties.name = "dwd:Ewam_reg025_fd_sl_SHTS";
return {
id: wmsLayerConfig.id,
url: wmsLayerConfig.url,
title: wmsLayerConfig.title,
opacity: wmsLayerConfig.opacity,
refreshInterval: wmsLayerConfig.refreshInterval,
sublayers: [properties],
visible: wmsLayerConfig.visible ?? false
}
}
private loadLayer() {
const layer = new WMSLayer(this.getWmsLayerProperties(config));
layer.load();
}
From my understanding the layer.load does some magic including to load the defined sublayers.
But unfortunately by this the legendUrl is not taken and keeps beeing null.
Of course I could add the legendUrl by hand but we are talking about much layers and those the user may indiviudally add to the map. So I need to find a way to either get ArcGIS do that job for me or else to dynamically load/find the legend url of the given sub layer.
Obviously I would prefer the first. Thanks.