Skip to content

Commit

Permalink
feat(wms): Provide title to grouped layers (comma)
Browse files Browse the repository at this point in the history
* feat(wms) Provide title to grouped layers (comma)

* refactor(layer-legend) based on reviews

* refactor(layer-legend) based on reviews

* refactor(layer-legend) code cleanup

* refactor(layer-legend) based on reviews

* refactor(layer-legend) based on reviews
  • Loading branch information
pelord authored and cbourget committed Apr 24, 2019
1 parent 87de1d8 commit e8ddafa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -16,10 +17,18 @@ export interface WMSDataSourceOptions extends DataSourceOptions {
ratio?: number;
ol?: olSourceImageWMS;
refreshIntervalSec?: number;
_layerOptionsFromCapabilities?: WMSLayerOptionsFromCapabilities;
}

export interface WMSDataSourceOptionsParams {
layers: string;
version?: string;
time?: string;
}

export interface WMSLayerOptionsFromCapabilities {
title?: string;
minResolution?: number;
maxResolution?: string;
metadata?: MetadataOptions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[target]="legend"
[collapsed]="false">
</mat-icon>
<h4 matLine>{{item.title}}</h4>
<h4 matLine>{{computeItemTitle(item) | async}}</h4>
</mat-list-item>

<div #legend class="igo-layer-legend" [ngClass]="{'with-title': item.title}">
Expand Down
21 changes: 18 additions & 3 deletions packages/geo/src/lib/layer/layer-legend/layer-legend.component.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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
Expand Down Expand Up @@ -60,4 +61,18 @@ export class LayerLegendComponent implements OnInit, OnDestroy {
this.legendItems$.next(legendItems);
}

computeItemTitle(layerLegend): Observable<string> {
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;
}));
}
}

0 comments on commit e8ddafa

Please sign in to comment.