Skip to content

Commit

Permalink
fix: Test if opacity is realy undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
ger-benjamin committed Oct 4, 2024
1 parent ff7268b commit a615412
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/SldStyleParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -808,7 +812,7 @@ export class SldStyleParser implements StyleParser<string> {
}

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)) {
Expand Down Expand Up @@ -1181,7 +1185,7 @@ export class SldStyleParser implements StyleParser<string> {
}
const label = getAttribute(cm, 'label');
let opacity = getAttribute(cm, 'opacity');
if (opacity) {
if (!isNil(opacity)) {
opacity = numberExpression(opacity);
}
return {
Expand Down Expand Up @@ -1687,7 +1691,7 @@ export class SldStyleParser implements StyleParser<string> {
}]
}];

if (markSymbolizer.color || markSymbolizer.fillOpacity) {
if (markSymbolizer.color || !isNil(markSymbolizer.fillOpacity)) {
const fillCssParamaters = [];
if (markSymbolizer.color) {
if (isGeoStylerFunction(markSymbolizer.color)) {
Expand All @@ -1709,7 +1713,7 @@ export class SldStyleParser implements StyleParser<string> {
});
}
}
if (markSymbolizer.fillOpacity) {
if (!isNil(markSymbolizer.fillOpacity)) {
if (isGeoStylerFunction(markSymbolizer.fillOpacity)) {
const children = geoStylerFunctionToSldFunction(markSymbolizer.fillOpacity);
fillCssParamaters.push({
Expand Down Expand Up @@ -1779,7 +1783,7 @@ export class SldStyleParser implements StyleParser<string> {
});
}
}
if (markSymbolizer.strokeOpacity) {
if (!isNil(markSymbolizer.strokeOpacity)) {
if (isGeoStylerFunction(markSymbolizer.strokeOpacity)) {
const children = geoStylerFunctionToSldFunction(markSymbolizer.strokeOpacity);
strokeCssParameters.push({
Expand Down Expand Up @@ -1808,10 +1812,10 @@ export class SldStyleParser implements StyleParser<string> {
[Mark]: mark
}];

if (markSymbolizer.opacity) {
if (!isNil(markSymbolizer.opacity)) {
graphic.push({
[Opacity]: [{
'#text': markSymbolizer.opacity.toString()
'#text': markSymbolizer.opacity!.toString()
}]
});
}
Expand Down Expand Up @@ -1907,7 +1911,7 @@ export class SldStyleParser implements StyleParser<string> {
}
}

if (iconSymbolizer.opacity) {
if (!isNil(iconSymbolizer.opacity)) {
graphic.push({
[Opacity]: [{
'#text': iconSymbolizer.opacity
Expand Down

0 comments on commit a615412

Please sign in to comment.