From 5d11f435c2289db2d5765c11f2c5f688badf23b9 Mon Sep 17 00:00:00 2001 From: Benjamin Gerber Date: Fri, 4 Oct 2024 10:16:14 +0200 Subject: [PATCH 1/2] fix: test if opacity is realy undefined --- src/SldStyleParser.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/SldStyleParser.ts b/src/SldStyleParser.ts index da35352e..005c2957 100644 --- a/src/SldStyleParser.ts +++ b/src/SldStyleParser.ts @@ -162,7 +162,11 @@ export const defaultTranslations: SldStyleParserTranslations = { }, } as const; -const isNil = (val: unknown) => val === undefined || val === null; + +/** + * @returns true if the provided value is null or undefined. Returns false otherwise. + */ +const isNil = (val: unknown): boolean => val === undefined || val === null; /** * This parser can be used with the GeoStyler. @@ -808,7 +812,7 @@ export class SldStyleParser implements StyleParser { } textSymbolizer.color = color ? color : '#000000'; - textSymbolizer.opacity = opacity ? numberExpression(opacity) : 1; + textSymbolizer.opacity = isNil(opacity) ? 1 : numberExpression(opacity); const haloRadius = get(sldSymbolizer, 'Halo.Radius.#text'); if (!isNil(haloRadius)) { @@ -1181,7 +1185,7 @@ export class SldStyleParser implements StyleParser { } const label = getAttribute(cm, 'label'); let opacity = getAttribute(cm, 'opacity'); - if (opacity) { + if (!isNil(opacity)) { opacity = numberExpression(opacity); } return { @@ -1687,7 +1691,7 @@ export class SldStyleParser implements StyleParser { }] }]; - if (markSymbolizer.color || markSymbolizer.fillOpacity) { + if (markSymbolizer.color || !isNil(markSymbolizer.fillOpacity)) { const fillCssParamaters = []; if (markSymbolizer.color) { if (isGeoStylerFunction(markSymbolizer.color)) { @@ -1709,7 +1713,7 @@ export class SldStyleParser implements StyleParser { }); } } - if (markSymbolizer.fillOpacity) { + if (!isNil(markSymbolizer.fillOpacity)) { if (isGeoStylerFunction(markSymbolizer.fillOpacity)) { const children = geoStylerFunctionToSldFunction(markSymbolizer.fillOpacity); fillCssParamaters.push({ @@ -1779,7 +1783,7 @@ export class SldStyleParser implements StyleParser { }); } } - if (markSymbolizer.strokeOpacity) { + if (!isNil(markSymbolizer.strokeOpacity)) { if (isGeoStylerFunction(markSymbolizer.strokeOpacity)) { const children = geoStylerFunctionToSldFunction(markSymbolizer.strokeOpacity); strokeCssParameters.push({ @@ -1808,10 +1812,10 @@ export class SldStyleParser implements StyleParser { [Mark]: mark }]; - if (markSymbolizer.opacity) { + if (!isNil(markSymbolizer.opacity)) { graphic.push({ [Opacity]: [{ - '#text': markSymbolizer.opacity.toString() + '#text': markSymbolizer.opacity!.toString() }] }); } @@ -1907,7 +1911,7 @@ export class SldStyleParser implements StyleParser { } } - if (iconSymbolizer.opacity) { + if (!isNil(iconSymbolizer.opacity)) { graphic.push({ [Opacity]: [{ '#text': iconSymbolizer.opacity From 43fc38a541ecfaf22a450d8246677ed50a1325ab Mon Sep 17 00:00:00 2001 From: Benjamin Gerber Date: Tue, 8 Oct 2024 08:51:55 +0200 Subject: [PATCH 2/2] fix!: opacity is not longer forced on text symbolizer BREAKING CHANGE: opacity is not longer forced to be 1 on text symbolizer. --- data/styles/geoserver/poi.ts | 1 - data/styles/geoserver/poly_landmarks.ts | 1 - data/styles/geoserver/pophatch.ts | 1 - data/styles/geoserver/popshade.ts | 1 - data/styles/geoserver/tiger_roads.ts | 1 - data/styles/multi_simplelineLabel.ts | 1 - data/styles/point_simpleLabel.ts | 1 - .../point_styledLabel_literalPlaceholder.ts | 1 - data/styles/point_styledlabel.ts | 1 - data/styles/text_lineplacement.ts | 1 - data/styles/text_pointplacement.ts | 1 - src/SldStyleParser.ts | 23 +++++++++++-------- 12 files changed, 14 insertions(+), 20 deletions(-) diff --git a/data/styles/geoserver/poi.ts b/data/styles/geoserver/poi.ts index 67b44de2..ba41324a 100644 --- a/data/styles/geoserver/poi.ts +++ b/data/styles/geoserver/poi.ts @@ -32,7 +32,6 @@ const style: Style = { kind: 'Text', label: '{{NAME}}', color: '#000000', - opacity: 1, haloWidth: 2, haloColor: '#FFFFFF', offset: [ diff --git a/data/styles/geoserver/poly_landmarks.ts b/data/styles/geoserver/poly_landmarks.ts index d71464a0..3e1b8e4b 100644 --- a/data/styles/geoserver/poly_landmarks.ts +++ b/data/styles/geoserver/poly_landmarks.ts @@ -146,7 +146,6 @@ const style: Style = { kind: 'Text', label: '{{LANAME}}', color: '#000000', - opacity: 1, haloWidth: 2, haloColor: '#FDE5A5', haloOpacity: 0.75, diff --git a/data/styles/geoserver/pophatch.ts b/data/styles/geoserver/pophatch.ts index 6143c973..f4d5da56 100644 --- a/data/styles/geoserver/pophatch.ts +++ b/data/styles/geoserver/pophatch.ts @@ -71,7 +71,6 @@ const style: Style = { kind: 'Text', label: '{{STATE_ABBR}}', color: '#000000', - opacity: 1, haloWidth: 2, haloColor: '#FFFFFF', font: [ diff --git a/data/styles/geoserver/popshade.ts b/data/styles/geoserver/popshade.ts index c5749c22..69203fc2 100644 --- a/data/styles/geoserver/popshade.ts +++ b/data/styles/geoserver/popshade.ts @@ -60,7 +60,6 @@ const style: Style = { kind: 'Text', label: '{{STATE_ABBR}}', color: '#000000', - opacity: 1, font: [ 'Times New Roman' ], diff --git a/data/styles/geoserver/tiger_roads.ts b/data/styles/geoserver/tiger_roads.ts index 74af2ee5..73d15f0c 100644 --- a/data/styles/geoserver/tiger_roads.ts +++ b/data/styles/geoserver/tiger_roads.ts @@ -52,7 +52,6 @@ const style: Style = { kind: 'Text', label: '{{NAME}}', color: '#000000', - opacity: 1, haloWidth: 2, haloColor: '#FFFFFF', haloOpacity: 0.85, diff --git a/data/styles/multi_simplelineLabel.ts b/data/styles/multi_simplelineLabel.ts index ea73c967..a2b8d25d 100644 --- a/data/styles/multi_simplelineLabel.ts +++ b/data/styles/multi_simplelineLabel.ts @@ -12,7 +12,6 @@ const multiSimplelineLabel: Style = { }, { kind: 'Text', color: '#000000', - opacity: 1, label: '{{name}}', font: ['Arial'], size: 12, diff --git a/data/styles/point_simpleLabel.ts b/data/styles/point_simpleLabel.ts index 479524e0..a8adee8b 100644 --- a/data/styles/point_simpleLabel.ts +++ b/data/styles/point_simpleLabel.ts @@ -6,7 +6,6 @@ const pointStyledLabel: Style = { name: '', symbolizers: [{ color: '#000000', - opacity: 1, kind: 'Text', label: 'myText' }] diff --git a/data/styles/point_styledLabel_literalPlaceholder.ts b/data/styles/point_styledLabel_literalPlaceholder.ts index c409e68f..c6c23ee5 100644 --- a/data/styles/point_styledLabel_literalPlaceholder.ts +++ b/data/styles/point_styledLabel_literalPlaceholder.ts @@ -14,7 +14,6 @@ const pointStyledLabel: Style = { haloColor: '#000000', haloWidth: 5, haloOpacity: 1, - opacity: 1, rotate: 45, fontStyle: 'normal', fontWeight: 'bold', diff --git a/data/styles/point_styledlabel.ts b/data/styles/point_styledlabel.ts index 5ed122b0..545a06c9 100644 --- a/data/styles/point_styledlabel.ts +++ b/data/styles/point_styledlabel.ts @@ -7,7 +7,6 @@ const pointStyledLabel: Style = { symbolizers: [{ kind: 'Text', color: '#000000', - opacity: 1, label: '{{name}}', font: ['Arial'], size: 12, diff --git a/data/styles/text_lineplacement.ts b/data/styles/text_lineplacement.ts index f1223fee..515c0b8c 100644 --- a/data/styles/text_lineplacement.ts +++ b/data/styles/text_lineplacement.ts @@ -6,7 +6,6 @@ const pointStyledLabel: Style = { name: '', symbolizers: [{ color: '#000000', - opacity: 1, kind: 'Text', label: 'myText', placement: 'line' diff --git a/data/styles/text_pointplacement.ts b/data/styles/text_pointplacement.ts index 4de02e32..efc6ce92 100644 --- a/data/styles/text_pointplacement.ts +++ b/data/styles/text_pointplacement.ts @@ -6,7 +6,6 @@ const pointStyledLabel: Style = { name: '', symbolizers: [{ color: '#000000', - opacity: 1, kind: 'Text', label: 'myText', placement: 'point' diff --git a/src/SldStyleParser.ts b/src/SldStyleParser.ts index 005c2957..9ede263e 100644 --- a/src/SldStyleParser.ts +++ b/src/SldStyleParser.ts @@ -812,7 +812,10 @@ export class SldStyleParser implements StyleParser { } textSymbolizer.color = color ? color : '#000000'; - textSymbolizer.opacity = isNil(opacity) ? 1 : numberExpression(opacity); + + if (!isNil(opacity)) { + textSymbolizer.opacity = numberExpression(opacity); + } const haloRadius = get(sldSymbolizer, 'Halo.Radius.#text'); if (!isNil(haloRadius)) { @@ -2099,15 +2102,17 @@ export class SldStyleParser implements StyleParser { ':@': { '@_name': 'fill' } - }, - { - [CssParameter]: [{ - '#text': Number.isFinite(textSymbolizer.opacity) ? textSymbolizer.opacity : '1', - }], - ':@': { - '@_name': 'fill-opacity' - } }]; + if (Number.isFinite(textSymbolizer.opacity)) { + fill.push({ + [CssParameter]: [{ + '#text': `${textSymbolizer.opacity}`, + }], + ':@': { + '@_name': 'fill-opacity' + }, + }); + } sldTextSymbolizer.push({ [Fill]: fill });