Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
weskamm committed Mar 24, 2023
1 parent 4a948dc commit b6bdd70
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
4 changes: 1 addition & 3 deletions data/styles/point_styledLabel_static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ const pointStyledLabel: Style = {
offset: [0, 5],
haloColor: '#000000',
haloWidth: 5,
rotate: 45,
fontStyle: 'normal',
fontWeight: 'normal'
rotate: 45
}]
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/OlStyleParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ describe('OlStyleParser implements StyleParser', () => {
const fontFamily = [
['arial', 'sans-serif'],
['Georgia', 'serif'],
['Neue Helvetica', 'Helvetica', 'sans-serif']
['"Neue Helvetica"', 'Helvetica', 'sans-serif']
];
const font1 = `bold 5px ${fontFamily[0].join(', ')}`;
const font2 = `italic bold 12px/30px ${fontFamily[1].join(', ')}`;
Expand Down
15 changes: 8 additions & 7 deletions src/OlStyleParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,22 +407,23 @@ export class OlStyleParser implements StyleParser<OlStyleLike> {
const label = Array.isArray(text) ? text[0] : text;
let fontSize: number = Infinity;
let fontFamily: string[]|undefined = undefined;
let fontWeight: 'normal' | 'bold' = 'normal';
let fontStyle: 'normal' | 'italic' | 'oblique' = 'normal';
let fontWeight: 'normal' | 'bold' | undefined = undefined;
let fontStyle: 'normal' | 'italic' | 'oblique' | undefined = undefined;

if (font) {
const fontObj = parseFont(font);
if (fontObj['font-weight']) {
fontWeight = fontObj['font-weight'] as 'normal' | 'bold';
fontWeight = fontObj['font-weight'];
}
if (fontObj['font-size']) {
fontSize = parseInt(fontObj['font-size'], 10);
}
if (fontObj['font-family']) {
fontFamily = fontObj['font-family'];
const fontFamilies = fontObj['font-family'];
fontFamily = fontFamilies?.map((f: string) => f.includes(' ') ? '"' + f + '"' : f);
}
if (fontObj['font-style']) {
fontStyle = fontObj['font-style'] as 'normal' | 'italic' | 'oblique';
fontStyle = fontObj['font-style'];
}
}

Expand All @@ -433,8 +434,8 @@ export class OlStyleParser implements StyleParser<OlStyleLike> {
color: olFillStyle ? OlStyleUtil.getHexColor(olFillStyle.getColor() as string) : undefined,
size: isFinite(fontSize) ? fontSize : undefined,
font: fontFamily,
fontWeight,
fontStyle,
fontWeight: fontWeight || undefined,
fontStyle: fontStyle || undefined,
offset: (offsetX !== undefined) && (offsetY !== undefined) ? [offsetX, offsetY] : [0, 0],
haloColor: olStrokeStyle && olStrokeStyle.getColor() ?
OlStyleUtil.getHexColor(olStrokeStyle.getColor() as string) : undefined,
Expand Down

0 comments on commit b6bdd70

Please sign in to comment.