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

Update to geostyler-style 6.0.0 #582

Merged
merged 2 commits into from
Aug 5, 2022
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
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"dependencies": {
"color-name": "^1.1.4",
"geostyler-style": "^5.0.2",
"geostyler-style": "^6.0.0",
"lodash": "^4.17.21"
},
"peerDependencies": {
Expand Down
14 changes: 7 additions & 7 deletions src/OlStyleParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ export class OlStyleParser implements StyleParser<OlStyleLike> {
return symbolizer.kind === 'Text';
});
const hasDynamicIconSymbolizer = rules[0].symbolizers.some((symbolizer: Symbolizer) => {
return symbolizer.kind === 'Icon' && symbolizer.image?.includes('{{');
return symbolizer.kind === 'Icon' && typeof(symbolizer.image) === 'string' && symbolizer.image.includes('{{');
});
if (!hasFilter && !hasScaleDenominator && !hasTextSymbolizer && !hasDynamicIconSymbolizer) {
if (nrSymbolizers === 1) {
Expand Down Expand Up @@ -906,10 +906,10 @@ export class OlStyleParser implements StyleParser<OlStyleLike> {
fill: fill,
// @ts-ignore
opacity: markSymbolizer.opacity || 1,
radius: markSymbolizer.radius || 5,
rotation: markSymbolizer.rotate ? markSymbolizer.rotate * Math.PI / 180 : undefined,
radius: markSymbolizer.radius as number || 5,
rotation: typeof(markSymbolizer.rotate) === 'number' ? markSymbolizer.rotate * Math.PI / 180 : undefined,
stroke: stroke,
displacement: markSymbolizer.offset
displacement: typeof(markSymbolizer.offset) === 'number' ? markSymbolizer.offset : undefined
};

switch (markSymbolizer.wellKnownName) {
Expand Down Expand Up @@ -1072,14 +1072,14 @@ export class OlStyleParser implements StyleParser<OlStyleLike> {
opacity: symbolizer.opacity,
scale: symbolizer.size || 1,
// Rotation in openlayers is radians while we use degree
rotation: symbolizer.rotate ? symbolizer.rotate * Math.PI / 180 : undefined,
rotation: typeof(symbolizer.rotate) === 'number' ? symbolizer.rotate * Math.PI / 180 : undefined,
displacement: symbolizer.offset
};
// check if IconSymbolizer.image contains a placeholder
const prefix = '\\{\\{';
const suffix = '\\}\\}';
const regExp = new RegExp(prefix + '.*?' + suffix, 'g');
const regExpRes = symbolizer.image ? symbolizer.image.match(regExp) : null;
const regExpRes = typeof(symbolizer.image) === 'string' ? symbolizer.image.match(regExp) : null;
if (regExpRes) {
// if it contains a placeholder
// return olStyleFunction
Expand Down Expand Up @@ -1258,7 +1258,7 @@ export class OlStyleParser implements StyleParser<OlStyleLike> {
overflow: symbolizer.allowOverlap,
offsetX: symbolizer.offset ? symbolizer.offset[0] : 0,
offsetY: symbolizer.offset ? symbolizer.offset[1] : 0,
rotation: symbolizer.rotate ? symbolizer.rotate * Math.PI / 180 : undefined
rotation: typeof(symbolizer.rotate) === 'number' ? symbolizer.rotate * Math.PI / 180 : undefined
// TODO check why props match
// textAlign: symbolizer.pitchAlignment,
// textBaseline: symbolizer.anchor
Expand Down
7 changes: 5 additions & 2 deletions src/Util/OlStyleUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MarkSymbolizer, TextSymbolizer } from 'geostyler-style';
import { Expression, MarkSymbolizer, TextSymbolizer } from 'geostyler-style';
import colors from 'color-name';

const WELLKNOWNNAME_TTF_REGEXP = /^ttf:\/\/(.+)#(.+)$/;
Expand All @@ -16,7 +16,10 @@ class OlStyleUtil {
* @param {number} opacity Opacity (Betweeen 0 and 1)
* @return {string} the RGB(A) value of the input color
*/
public static getRgbaColor(colorString: string, opacity: number) {
public static getRgbaColor(colorString: Expression | string, opacity: number | Expression) {
if (typeof(colorString) !== 'string') {
return;
}
if (colorString.startsWith('rgba(')) {
return colorString;
}
Expand Down