Skip to content

Commit

Permalink
Merge pull request #246 from KaiVolland/geostyler-style-v7
Browse files Browse the repository at this point in the history
Update to geostyler-style v7
  • Loading branch information
KaiVolland committed Apr 26, 2023
2 parents 6358abe + 79df827 commit 17c74e1
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on-pull-request.yml
Expand Up @@ -12,7 +12,7 @@ jobs:

steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/on-push-master.yml
Expand Up @@ -15,7 +15,7 @@ jobs:

steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
Expand Down
2 changes: 1 addition & 1 deletion data/mapfiles/point_simple_point.map
Expand Up @@ -5,7 +5,7 @@ LAYER
EXTENT -180 -90 180 90
METADATA
"wms_title" "point_simple_point"
"wms_srs" "EPSG:4326"
"wms_srs" "EPSG:4326"
END
CLASS
STYLE
Expand Down
8 changes: 7 additions & 1 deletion data/styles/point_st_sample_style_tags_single_filter_list.ts
Expand Up @@ -4,7 +4,13 @@ const pointStyle: Style = {
name: 'point_st_sample_style_tags_single_filter_list',
rules: [{
filter: [
'*=', ['FN_strMatches', 'name', '/(bus|bank)/'], true
'==', {
name: 'strMatches',
args: [{
name: 'property',
args: ['name']
}, '/(bus|bank)/']
}, true
],
name: 'Test point',
symbolizers: [{
Expand Down
Expand Up @@ -4,7 +4,13 @@ const pointStyle: Style = {
name: 'point_st_sample_style_tags_single_filter_regex',
rules: [{
filter: [
'*=', ['FN_strMatches', 'name', '/bus/'], true
'==', {
name: 'strMatches',
args: [{
name: 'property',
args: ['name']
}, '/bus/']
}, true
],
name: 'Test point',
symbolizers: [{
Expand Down
66 changes: 7 additions & 59 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
Expand Up @@ -39,7 +39,7 @@
},
"dependencies": {
"@terrestris/base-util": "^1.0.1",
"geostyler-style": "^5.0.0",
"geostyler-style": "^7.2.0",
"ts-jest": "^27.0.5"
},
"devDependencies": {
Expand Down
87 changes: 61 additions & 26 deletions src/MapfileStyleParser.ts
Expand Up @@ -52,7 +52,7 @@ export type ConstructorParams = Record<string, unknown>;
* @class MapfileStyleParser
* @implements StyleParser
*/
export class MapfileStyleParser implements StyleParser {
export class MapfileStyleParser implements StyleParser<string> {
/**
* The name of the Mapfile Style Parser.
*/
Expand All @@ -62,6 +62,22 @@ export class MapfileStyleParser implements StyleParser {

symbolsPath = `${process.cwd()}/symbols.sym`;

unsupportedProperties: UnsupportedProperties = {
Symbolizer: {
support: 'partial',
info: 'Read only'
},
Filter: {
support: 'partial',
info: 'Read only'
},
Function: 'none',
ScaleDenominator: {
support: 'partial',
info: 'Read only'
}
};

constructor(opts?: ConstructorParams) {
Object.assign(this, opts);
}
Expand Down Expand Up @@ -95,17 +111,27 @@ export class MapfileStyleParser implements StyleParser {
case '"':
return ['==' as ComparisonOperator, mapfileClassItem, expression.substring(1, expression.length - 1)];
case '/':
return ['*=', ['FN_strMatches', mapfileClassItem, expression as unknown as RegExp], true];
return ['==', {
name: 'strMatches',
args: [
{
name: 'property',
args: [mapfileClassItem]
},
expression
]
}, true];
case '{':
return [
'*=',
[
'FN_strMatches',
mapfileClassItem,
`/(${expression.substring(1, expression.length - 1).replace(/,/g, '|')})/` as unknown as RegExp
],
true,
];
return ['==', {
name: 'strMatches',
args: [
{
name: 'property',
args: [mapfileClassItem]
},
`/(${expression.substring(1, expression.length - 1).replace(/,/g, '|')})/`
]
}, true];
default:
logger.error(`Unable to get Filter from CLASSITEM: ${mapfileClass}`);
}
Expand All @@ -131,27 +157,36 @@ export class MapfileStyleParser implements StyleParser {
.replace('le', '<=')
.replace('ge', '>=');

// TODO: assert there are no qotes in strings, either of!
// TODO: assert there are no quotes in strings, either of!

switch (operator) {
case '~': {
const valueOrNumber: string | number = /^[-\d]/.test(value) ? parseFloat(value) : value;
return ['*=', ['FN_strMatches', attribute, valueOrNumber as any], true];
return ['==', {
name: 'strMatches',
args: [{
name: 'property',
args: [attribute]
}, value]
}, true];
}
case '~*':
return ['*=', ['FN_strMatches', attribute, `${value}i` as any], true];
return ['==', {
name: 'strMatches',
args: [{
name: 'property',
args: [attribute]
}, value + 'i']
}, true];
case 'IN':
return [
'*=',
[
'FN_strMatches',
attribute,
(`/${value
.substring(1, value.length - 1)
.replace(',', '|')}/` as unknown) as RegExp
],
true,
];
return [ '==', {
name: 'in',
args: [{
name: 'property',
args: [attribute]
},
...value.split(',')
]
}, true];
case '==':
case '!=':
case '<':
Expand Down

0 comments on commit 17c74e1

Please sign in to comment.