diff --git a/packages/geo/src/lib/datasource/shared/datasources/wms-datasource.interface.ts b/packages/geo/src/lib/datasource/shared/datasources/wms-datasource.interface.ts index 7f6678045d..0cbd6dd7d9 100644 --- a/packages/geo/src/lib/datasource/shared/datasources/wms-datasource.interface.ts +++ b/packages/geo/src/lib/datasource/shared/datasources/wms-datasource.interface.ts @@ -2,6 +2,7 @@ import olSourceImageWMS from 'ol/source/ImageWMS'; import { DataSourceOptions } from './datasource.interface'; import { WFSDataSourceOptionsParams } from './wfs-datasource.interface'; +import { MetadataOptions } from '../../../metadata/shared/metadata.interface'; export interface WMSDataSourceOptions extends DataSourceOptions { // type?: 'wms'; @@ -16,6 +17,7 @@ export interface WMSDataSourceOptions extends DataSourceOptions { ratio?: number; ol?: olSourceImageWMS; refreshIntervalSec?: number; + _layerOptionsFromCapabilities?: WMSLayerOptionsFromCapabilities; } export interface WMSDataSourceOptionsParams { @@ -23,3 +25,10 @@ export interface WMSDataSourceOptionsParams { version?: string; time?: string; } + +export interface WMSLayerOptionsFromCapabilities { + title?: string; + minResolution?: number; + maxResolution?: string; + metadata?: MetadataOptions; +} diff --git a/packages/geo/src/lib/layer/layer-legend/layer-legend.component.html b/packages/geo/src/lib/layer/layer-legend/layer-legend.component.html index 6469098d6e..c609b54854 100644 --- a/packages/geo/src/lib/layer/layer-legend/layer-legend.component.html +++ b/packages/geo/src/lib/layer/layer-legend/layer-legend.component.html @@ -10,7 +10,7 @@ [target]="legend" [collapsed]="false"> -

{{item.title}}

+

{{computeItemTitle(item) | async}}

diff --git a/packages/geo/src/lib/layer/layer-legend/layer-legend.component.ts b/packages/geo/src/lib/layer/layer-legend/layer-legend.component.ts index eb2c77f61b..9f925ff0e9 100644 --- a/packages/geo/src/lib/layer/layer-legend/layer-legend.component.ts +++ b/packages/geo/src/lib/layer/layer-legend/layer-legend.component.ts @@ -1,9 +1,11 @@ import { Component, Input, OnInit, OnDestroy, ChangeDetectionStrategy } from '@angular/core'; -import { Subscription, BehaviorSubject } from 'rxjs'; +import { Subscription, BehaviorSubject, of, Observable } from 'rxjs'; import { DataSourceLegendOptions } from '../../datasource/shared/datasources/datasource.interface'; import { Layer } from '../shared/layers'; +import { CapabilitiesService } from '../../datasource/shared/capabilities.service'; +import { map } from 'rxjs/operators'; @Component({ selector: 'igo-layer-legend', @@ -22,13 +24,12 @@ export class LayerLegendComponent implements OnInit, OnDestroy { * Subscription to the map's resolution */ private resolution$$: Subscription; - /** * Layer */ @Input() layer: Layer; - constructor() {} + constructor(private capabilitiesService: CapabilitiesService) {} /** * On init, subscribe to the map's resolution and update the legend accordingly @@ -60,4 +61,18 @@ export class LayerLegendComponent implements OnInit, OnDestroy { this.legendItems$.next(legendItems); } + computeItemTitle(layerLegend): Observable { + const layerOptions = this.layer.dataSource.options as any; + if (layerOptions.type !== 'wms') { + return of(layerLegend.title); + } + const layers = layerOptions.params.layers.split(','); + const localLayerOptions = JSON.parse(JSON.stringify(layerOptions)); // to avoid to alter the original options. + localLayerOptions.params.layers = layers.find(layer => layer === layerLegend.title); + return this.capabilitiesService + .getWMSOptions(localLayerOptions) + .pipe(map(wmsDataSourceOptions => { + return wmsDataSourceOptions._layerOptionsFromCapabilities.title; + })); + } }