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
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion data/styles/geoserver/poi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const style: Style = {
kind: 'Text',
label: '{{NAME}}',
color: '#000000',
opacity: 1,
haloWidth: 2,
haloColor: '#FFFFFF',
offset: [
Expand Down
1 change: 0 additions & 1 deletion data/styles/geoserver/poly_landmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ const style: Style = {
kind: 'Text',
label: '{{LANAME}}',
color: '#000000',
opacity: 1,
haloWidth: 2,
haloColor: '#FDE5A5',
haloOpacity: 0.75,
Expand Down
1 change: 0 additions & 1 deletion data/styles/geoserver/pophatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const style: Style = {
kind: 'Text',
label: '{{STATE_ABBR}}',
color: '#000000',
opacity: 1,
haloWidth: 2,
haloColor: '#FFFFFF',
font: [
Expand Down
1 change: 0 additions & 1 deletion data/styles/geoserver/popshade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ const style: Style = {
kind: 'Text',
label: '{{STATE_ABBR}}',
color: '#000000',
opacity: 1,
font: [
'Times New Roman'
],
Expand Down
1 change: 0 additions & 1 deletion data/styles/geoserver/tiger_roads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const style: Style = {
kind: 'Text',
label: '{{NAME}}',
color: '#000000',
opacity: 1,
haloWidth: 2,
haloColor: '#FFFFFF',
haloOpacity: 0.85,
Expand Down
1 change: 0 additions & 1 deletion data/styles/multi_simplelineLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const multiSimplelineLabel: Style = {
}, {
kind: 'Text',
color: '#000000',
opacity: 1,
label: '{{name}}',
font: ['Arial'],
size: 12,
Expand Down
1 change: 0 additions & 1 deletion data/styles/point_simpleLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const pointStyledLabel: Style = {
name: '',
symbolizers: [{
color: '#000000',
opacity: 1,
kind: 'Text',
label: 'myText'
}]
Expand Down
1 change: 0 additions & 1 deletion data/styles/point_styledLabel_literalPlaceholder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const pointStyledLabel: Style = {
haloColor: '#000000',
haloWidth: 5,
haloOpacity: 1,
opacity: 1,
rotate: 45,
fontStyle: 'normal',
fontWeight: 'bold',
Expand Down
1 change: 0 additions & 1 deletion data/styles/point_styledlabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const pointStyledLabel: Style = {
symbolizers: [{
kind: 'Text',
color: '#000000',
opacity: 1,
label: '{{name}}',
font: ['Arial'],
size: 12,
Expand Down
1 change: 0 additions & 1 deletion data/styles/text_lineplacement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const pointStyledLabel: Style = {
name: '',
symbolizers: [{
color: '#000000',
opacity: 1,
kind: 'Text',
label: 'myText',
placement: 'line'
Expand Down
1 change: 0 additions & 1 deletion data/styles/text_pointplacement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const pointStyledLabel: Style = {
name: '',
symbolizers: [{
color: '#000000',
opacity: 1,
kind: 'Text',
label: 'myText',
placement: 'point'
Expand Down
43 changes: 26 additions & 17 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,10 @@ export class SldStyleParser implements StyleParser<string> {
}

textSymbolizer.color = color ? color : '#000000';
textSymbolizer.opacity = opacity ? numberExpression(opacity) : 1;

if (!isNil(opacity)) {
textSymbolizer.opacity = numberExpression(opacity);
}

const haloRadius = get(sldSymbolizer, 'Halo.Radius.#text');
if (!isNil(haloRadius)) {
Expand Down Expand Up @@ -1181,7 +1188,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 +1694,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 +1716,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 +1786,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 +1815,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 +1914,7 @@ export class SldStyleParser implements StyleParser<string> {
}
}

if (iconSymbolizer.opacity) {
if (!isNil(iconSymbolizer.opacity)) {
graphic.push({
[Opacity]: [{
'#text': iconSymbolizer.opacity
Expand Down Expand Up @@ -2095,15 +2102,17 @@ export class SldStyleParser implements StyleParser<string> {
':@': {
'@_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
});
Expand Down
Loading