Skip to content

Commit 7c170cb

Browse files
committed
fix(addlayers): wfs style loading
1 parent 890e779 commit 7c170cb

File tree

8 files changed

+58
-27
lines changed

8 files changed

+58
-27
lines changed

projects/hslayers/services/add-data/catalogue/catalogue.service.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
HsAddDataMickaLayerDescriptor,
2121
HsEndpoint,
2222
WhatToAddDescriptor,
23+
OwsConnection,
2324
} from 'hslayers-ng/types';
2425
import {HsAddDataCatalogueMapService} from './catalogue-map.service';
2526
import {HsAddDataOwsService} from '../url/add-data-ows.service';
@@ -548,7 +549,6 @@ export class HsAddDataCatalogueService extends HsAddDataCatalogueParams {
548549
whatToAdd.abstract,
549550
whatToAdd.projection,
550551
{
551-
extractStyles: whatToAdd.extractStyles,
552552
workspace: whatToAdd.workspace,
553553
style: whatToAdd.style,
554554
saveToLayman: true,
@@ -558,17 +558,25 @@ export class HsAddDataCatalogueService extends HsAddDataCatalogueParams {
558558
this.datasetSelect('catalogue');
559559
} else {
560560
// Layman layers without write access
561-
await this.hsAddDataOwsService.connectToOWS({
561+
const params: OwsConnection = {
562562
type: 'wfs',
563563
uri: whatToAdd.link,
564564
layer: whatToAdd.layer, // basically not used in this case
565-
layerOptions: {
566-
style: whatToAdd.style,
567-
},
565+
layerOptions: {},
568566
connectOptions: {
569567
laymanLayer: whatToAdd,
570568
},
571-
});
569+
};
570+
//Set property sld/qml based on the type - conent is fetched style string
571+
if (whatToAdd.styleType) {
572+
params.layerOptions[whatToAdd.styleType] = whatToAdd.style;
573+
}
574+
//Unexpected as layman whatToAdd is expected to have styleType
575+
//keeping for backwards compatibility and as fallback
576+
else {
577+
params.layerOptions.style = whatToAdd.style;
578+
}
579+
await this.hsAddDataOwsService.connectToOWS(params);
572580
}
573581
}
574582

projects/hslayers/services/add-data/catalogue/layman.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ export class HsLaymanBrowserService {
292292
dsType: ds.type,
293293
extent: bounding_box,
294294
style,
295+
styleType: lyr.style?.type,
295296
name,
296297
title,
297298
editable,

projects/hslayers/services/add-data/url/add-data-ows.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ export class HsAddDataOwsService {
109109
? this.hsAddDataWmsLaymanService
110110
: this.hsAddDataWfsLaymanService;
111111
const {laymanLayer, ...rest} = options.connectOptions;
112-
response = await service.getLayer(laymanLayer, rest);
112+
response = await service.getLayer(laymanLayer, {
113+
...rest,
114+
...options?.layerOptions,
115+
});
113116
this.typeService.finalizeLayerRetrieval(response, options?.layerOptions);
114117
} else {
115118
/**

projects/hslayers/services/add-data/vector/vector.service.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {Feature} from 'ol';
44
import {Layer, Vector as VectorLayer} from 'ol/layer';
55
import {Source, Vector as VectorSource} from 'ol/source';
66
import {get as getProjection} from 'ol/proj';
7+
import {createDefaultStyle} from 'ol/style/Style';
78

89
import {HsAddDataCommonFileService} from '../common-file.service';
910
import {HsAddDataService} from '../add-data.service';
@@ -16,7 +17,7 @@ import {
1617
} from 'hslayers-ng/common/layman';
1718
import {HsLaymanService} from 'hslayers-ng/services/save-map';
1819
import {HsMapService} from 'hslayers-ng/services/map';
19-
import {HsStylerService} from 'hslayers-ng/services/styler';
20+
import {defaultStyle, HsStylerService} from 'hslayers-ng/services/styler';
2021
import {
2122
OverwriteResponse,
2223
UpsertLayerObject,
@@ -166,12 +167,26 @@ export class HsAddDataVectorService {
166167
? new sourceDescriptor.sourceClass(sourceDescriptor.sourceParams)
167168
: new sourceDescriptor.sourceClass(sourceDescriptor);
168169
descriptor.layerParams.source = src;
169-
Object.assign(
170-
descriptor.layerParams,
171-
await this.hsStylerService.parseStyle(
172-
(options.sld || options.qml) ?? options.style,
173-
),
174-
);
170+
171+
/**
172+
* Same as with parseStyle but we want to prevent
173+
* passing SLD/QML with already parsed style to not interfere with initLayerStyle
174+
* and to not parse it twice
175+
*/
176+
const style = (options.sld || options.qml) ?? options.style;
177+
const styleType = this.hsStylerService.guessStyleFormat(style);
178+
179+
if (style) {
180+
if (typeof styleType == 'string') {
181+
descriptor.layerParams[styleType] = style as string;
182+
descriptor.layerParams.style = undefined;
183+
} else {
184+
descriptor.layerParams.style = {style};
185+
}
186+
} else {
187+
descriptor.layerParams.style = createDefaultStyle;
188+
descriptor.layerParams.sld = defaultStyle;
189+
}
175190
return new VectorLayer(descriptor.layerParams);
176191
}
177192

projects/hslayers/services/compositions/layer-parser.service.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,25 @@ export class HsCompositionsLayerParserService {
5555
: {name: lyr_def.name, workspace: lyr_def.workspace};
5656

5757
const style = (lyr_def.sld || lyr_def.qml) ?? lyr_def.style;
58+
const styleType = this.hsStylerService.guessStyleFormat(style);
59+
60+
const layerOptions = {
61+
path: lyr_def.path,
62+
fromComposition: true,
63+
minResolution: lyr_def.minResolution || 0,
64+
maxResolution: lyr_def.maxResolution || Infinity,
65+
opacity: parseFloat(lyr_def.opacity) ?? 1,
66+
};
67+
layerOptions[styleType] = style;
68+
5869
const uri = lyr_def.protocol.url.split('?')[0];
5970
const newLayer = await this.hsAddDataOwsService.connectToOWS({
6071
type: 'wfs',
6172
uri,
6273
layer: lyr_def.name,
6374
owrCache: false,
6475
getOnly: true,
65-
layerOptions: {
66-
style: style,
67-
path: lyr_def.path,
68-
fromComposition: true,
69-
minResolution: lyr_def.minResolution || 0,
70-
maxResolution: lyr_def.maxResolution || Infinity,
71-
opacity: parseFloat(lyr_def.opacity) ?? 1,
72-
},
76+
layerOptions,
7377
connectOptions: {
7478
laymanLayer: this.hsCommonLaymanService.isLaymanUrl(
7579
uri,
@@ -455,9 +459,7 @@ export class HsCompositionsLayerParserService {
455459
}
456460
}
457461
// Parse the style definition (SLD, QML, or standard style object)
458-
const styleType = await this.hsStylerService.guessStyleFormat(
459-
lyr_def.style,
460-
);
462+
const styleType = this.hsStylerService.guessStyleFormat(lyr_def.style);
461463
// Assign the appropriate style property to options
462464
if (styleType == 'sld') {
463465
options.sld = lyr_def.style;

projects/hslayers/services/styler/styler.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ export class HsStylerService {
338338
return {style};
339339
}
340340

341-
guessStyleFormat(style: any): 'qml' | 'sld' {
341+
guessStyleFormat(style: any): 'qml' | 'sld' | undefined {
342342
if (typeof style == 'string') {
343343
if ((style as string).includes('StyledLayerDescriptor')) {
344344
return 'sld';
@@ -347,6 +347,7 @@ export class HsStylerService {
347347
return 'qml';
348348
}
349349
}
350+
return undefined;
350351
}
351352

352353
/**

projects/hslayers/types/add-data/whatToAddDescriptor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type WhatToAddDescriptorBase = {
1010
editable?: boolean;
1111
workspace?: string;
1212
style?: string;
13+
styleType?: 'sld' | 'qml';
1314
recordType?: string;
1415
//Layman layer descriptor only
1516
extent?: number[];

projects/hslayers/types/layman/layman-layer-descriptor.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export interface HsLaymanLayerDescriptor extends HsLaymanLayerBase {
7070
};
7171
style?: {
7272
url?: string;
73-
type?: string;
73+
type?: 'sld' | 'qml';
7474
status?: StatusStateType;
7575
error?: any;
7676
};

0 commit comments

Comments
 (0)