Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Test if opacity is realy undefined #968

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
ger-benjamin marked this conversation as resolved.
Show resolved Hide resolved

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
Loading