From ea651542fb0d9c294f492c6a36907f735064b2e8 Mon Sep 17 00:00:00 2001 From: Filip Leitner Date: Thu, 18 Jan 2024 09:15:58 +0100 Subject: [PATCH] feat: Option to add WMS layers as one group or separate layers --- .../common/url/details/details.component.html | 37 +++++++++++++------ .../common/url/details/details.component.ts | 10 +++++ .../add-data/url/wms/wms.component.html | 5 +-- .../shared/add-data/common.service.ts | 11 ++++-- .../shared/add-data/url/wms.service.ts | 16 ++++---- projects/hslayers/src/assets/locales/cs.json | 5 ++- projects/hslayers/src/assets/locales/en.json | 5 ++- projects/hslayers/src/assets/locales/sk.json | 5 ++- .../types/add-data/data-object.type.ts | 5 +++ 9 files changed, 70 insertions(+), 29 deletions(-) diff --git a/projects/hslayers/components/add-data/common/url/details/details.component.html b/projects/hslayers/components/add-data/common/url/details/details.component.html index 2be987a381..c9929e013f 100644 --- a/projects/hslayers/components/add-data/common/url/details/details.component.html +++ b/projects/hslayers/components/add-data/common/url/details/details.component.html @@ -1,23 +1,36 @@
-
{{'COMMON.title' | translateHs }}
-
- {{'COMMON.addAs' | translateHs }} -
- - +
+ {{'COMMON.addAs' | translateHs }} +
+
+ + +
+
+ + +
+
diff --git a/projects/hslayers/components/add-data/common/url/details/details.component.ts b/projects/hslayers/components/add-data/common/url/details/details.component.ts index 442f44a683..1ae0afa49c 100644 --- a/projects/hslayers/components/add-data/common/url/details/details.component.ts +++ b/projects/hslayers/components/add-data/common/url/details/details.component.ts @@ -7,6 +7,11 @@ import {HsUrlTypeServiceModel} from 'hslayers-ng/types'; @Component({ selector: 'hs-url-details', templateUrl: './details.component.html', + styles: ` + .hs-add-url-wms-addas button{ + min-width: 5rem + } + `, }) export class HsUrlDetailsComponent implements AfterContentInit { @Input() injectedService: HsUrlTypeServiceModel; @@ -26,4 +31,9 @@ export class HsUrlDetailsComponent implements AfterContentInit { this.data.srs, ); } + + setBase(state: boolean) { + this.data.base = state; + this.data.group = state || this.data.group; + } } diff --git a/projects/hslayers/components/add-data/url/wms/wms.component.html b/projects/hslayers/components/add-data/url/wms/wms.component.html index f3383c5c46..781da9851e 100644 --- a/projects/hslayers/components/add-data/url/wms/wms.component.html +++ b/projects/hslayers/components/add-data/url/wms/wms.component.html @@ -1,7 +1,6 @@
- + -
+ \ No newline at end of file diff --git a/projects/hslayers/shared/add-data/common.service.ts b/projects/hslayers/shared/add-data/common.service.ts index aa80bc600a..04ff34d5dc 100644 --- a/projects/hslayers/shared/add-data/common.service.ts +++ b/projects/hslayers/shared/add-data/common.service.ts @@ -124,20 +124,23 @@ export class HsAddDataCommonService { } /** - * Constructs body of LAYER parameter for getMap request + * Constructs body of LAYER parameter for getMap request for grouped layer e.g. + * for a basemap or thematic layer with property group set to true * @param layerOrLayers - layer object or layers received from capabilities. If no layer is provided * merge all checked layer ids into one string * @param property - layer property - * @returns */ - createBasemapName(layerOrLayers: any | Array, property: string): string { + getGroupedLayerNames( + layerOrLayers: any | Array, + property: string, + ): string { const baseNameParts = []; if (Array.isArray(layerOrLayers)) { for (const layer of layerOrLayers) { if (layer.checked) { baseNameParts.push(layer[property]); } else if (layer.Layer) { - const nested = this.createBasemapName(layer.Layer, property); + const nested = this.getGroupedLayerNames(layer.Layer, property); nested.length > 0 ? baseNameParts.push(nested) : null; } } diff --git a/projects/hslayers/shared/add-data/url/wms.service.ts b/projects/hslayers/shared/add-data/url/wms.service.ts index a7c3c655e4..537f2987cf 100644 --- a/projects/hslayers/shared/add-data/url/wms.service.ts +++ b/projects/hslayers/shared/add-data/url/wms.service.ts @@ -70,6 +70,7 @@ export class HsUrlWmsService implements HsUrlTypeServiceModel { trackBy: 'Name', nameProperty: 'Title', }, + group: true, }; } @@ -359,7 +360,7 @@ export class HsUrlWmsService implements HsUrlTypeServiceModel { this.data.visible = checkedOnly ? this.data.layers.filter((l) => l.checked === true).length <= 10 : false; - if (this.data.base) { + if (this.data.base || this.data.group) { const newLayer = this.getLayer( {}, { @@ -428,12 +429,13 @@ export class HsUrlWmsService implements HsUrlTypeServiceModel { attributions, projection: this.data.srs, params: { - LAYERS: this.data.base - ? this.hsAddDataCommonService.createBasemapName( - this.data.layers, - 'Name', - ) - : layer.Name, + LAYERS: + this.data.base || this.data.group + ? this.hsAddDataCommonService.getGroupedLayerNames( + this.data.layers, + 'Name', + ) + : layer.Name, INFO_FORMAT: layer.queryable ? options.queryFormat : undefined, FORMAT: options.imageFormat, VERSION: this.data.version, diff --git a/projects/hslayers/src/assets/locales/cs.json b/projects/hslayers/src/assets/locales/cs.json index 46fbaaa90e..b27697e8d2 100644 --- a/projects/hslayers/src/assets/locales/cs.json +++ b/projects/hslayers/src/assets/locales/cs.json @@ -314,7 +314,10 @@ "on": "zapnuto", "off": "vypnuto", "Tile": "Dlaždice", - "done": "Hotovo" + "done": "Hotovo", + "group": "skupina", + "single": "singl", + "separateLayers": "samostatné vrstvy" }, "COMPOSITIONS": { "addByAddress": "Přidat kompozici z adresy", diff --git a/projects/hslayers/src/assets/locales/en.json b/projects/hslayers/src/assets/locales/en.json index 4641614600..1cc27cb523 100644 --- a/projects/hslayers/src/assets/locales/en.json +++ b/projects/hslayers/src/assets/locales/en.json @@ -314,7 +314,10 @@ "on": "on", "off": "off", "Tile": "Tile", - "done": "Done" + "done": "Done", + "group": "group", + "single": "single", + "separateLayers": "separate layers" }, "COMPOSITIONS": { "addByAddress": "Add composition by address", diff --git a/projects/hslayers/src/assets/locales/sk.json b/projects/hslayers/src/assets/locales/sk.json index ba92dfd479..efe4492033 100644 --- a/projects/hslayers/src/assets/locales/sk.json +++ b/projects/hslayers/src/assets/locales/sk.json @@ -314,7 +314,10 @@ "on": "zapnuté", "off": "vypnuté", "Tile": "Dlaždica", - "done": "Hotovo" + "done": "Hotovo", + "group": "skupina", + "single": "slobodný", + "separateLayers": "samostatné vrstvy" }, "COMPOSITIONS": { "addByAddress": "Pridať kompozíciu z adresy", diff --git a/projects/hslayers/types/add-data/data-object.type.ts b/projects/hslayers/types/add-data/data-object.type.ts index dab2c376d3..51cabd2c6e 100644 --- a/projects/hslayers/types/add-data/data-object.type.ts +++ b/projects/hslayers/types/add-data/data-object.type.ts @@ -5,6 +5,11 @@ export type UrlDataObject = { add_all?: boolean; add_under?: Layer; base?: boolean; + /** + * Used with WMS to control whether each checked layer should be added as a separate layer + * or only one layer grouping all the checked + */ + group?: boolean; bbox?: string; caps?: any; description?: string;