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

fillOpacity support for the markSymbolizer geostyler object #621

Merged
merged 10 commits into from
Dec 13, 2022
2 changes: 1 addition & 1 deletion src/OlStyleParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ describe('OlStyleParser implements StyleParser', () => {
expecSymb.rotate = expecSymb.rotate as number;
const expecRotation = expecSymb.rotate * Math.PI / 180;
// openlayers adds default font-style
const expecFont = `Normal ${expecSymb.size}px ${expecSymb.font?.join(', ')}`;
const expecFont = `normal normal ${expecSymb.size}px ${expecSymb.font?.join(', ')}`;

const style = styles[0] as OlStyle;
expect(style).toBeDefined();
Expand Down
12 changes: 9 additions & 3 deletions src/OlStyleParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export class OlStyleParser implements StyleParser<OlStyleLike> {
MarkSymbolizer: {
avoidEdges: 'none',
blur: 'none',
fillOpacity: 'none',
offsetAnchor: 'none',
pitchAlignment: 'none',
pitchScale: 'none',
Expand Down Expand Up @@ -943,8 +942,15 @@ export class OlStyleParser implements StyleParser<OlStyleLike> {
}

const fill = new this.OlStyleFillConstructor({
color: (markSymbolizer.color && markSymbolizer.opacity !== undefined) ?
OlStyleUtil.getRgbaColor(markSymbolizer.color, markSymbolizer.opacity) : markSymbolizer.color
color:
markSymbolizer.color &&
(markSymbolizer.opacity !== undefined ||
markSymbolizer.fillOpacity !== undefined)
? OlStyleUtil.getRgbaColor(
markSymbolizer.color,
markSymbolizer.opacity ?? markSymbolizer.fillOpacity ?? 1
)
: markSymbolizer.color,
});

let olStyle: any;
Expand Down
2 changes: 1 addition & 1 deletion src/Util/OlStyleUtil.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('OlStyleUtil', () => {
offset: [0, 5]
};
const opac = OlStyleUtil.getTextFont(symb);
expect(opac).toEqual('Normal 12px Arial');
expect(opac).toEqual('normal normal 12px Arial');
});
});

Expand Down
8 changes: 5 additions & 3 deletions src/Util/OlStyleUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,15 @@ class OlStyleUtil {
* @param symbolizer The TextSymbolizer to derive the font string from
*/
public static getTextFont(symbolizer: TextSymbolizer) {
// since TextSymbolizer has no prop for font weight we use 'Normal' as default
const weight = 'Normal';
const fontWeight = symbolizer.fontWeight ?? 'normal';
const fontStyle = symbolizer.fontStyle ?? 'normal';

const size = symbolizer.size;
const font = symbolizer.font;
return weight + ' ' + size + 'px ' + font;
return fontWeight + ' ' + fontStyle + ' ' + size + 'px ' + font;
}


/**
* Returns true if the given mark symbolizer is based on a font glyph
* (i.e. has a well known name property starting with 'ttf://').
Expand Down