Skip to content

Commit

Permalink
Merge pull request #794 from miccoh1994/master
Browse files Browse the repository at this point in the history
fix: parsing of property functions in filter args
  • Loading branch information
jansule authored Jan 2, 2024
2 parents df88272 + 484bb8c commit 0688ab4
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 1 deletion.
80 changes: 80 additions & 0 deletions data/styles/filter_comparison_propertyFunction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {Fproperty, Style} from "geostyler-style";

const value: Fproperty = {
name: "property",
args: [
"value"
]
};

const min: Fproperty = {
name: "property",
args: [
"min"
]
}

const max: Fproperty = {
name: "property",
args: [
"max"
]
}

const filterComparisonPropertyFunction: Style = {
name: 'OL Style',
rules: [
{
name: "between min and max",
filter: [
"&&",
[
">=",
value, min

],
[
"<=",
value,
max
]
],
symbolizers: [
{
kind: "Text",
label: "between min and max",
}
]
},
{
name: 'above max',
filter: [
">",
value,
max
],
symbolizers: [
{
kind: "Text",
label: "above max"
}
]
},
{
name: "below min",
filter: [
"<",
value,
min
],
symbolizers: [
{
kind: "Text",
label: "below min",
}
]
}
]
}

export default filterComparisonPropertyFunction;
36 changes: 36 additions & 0 deletions src/OlStyleParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import function_case from '../data/styles/function_case';
import text_placement_point from '../data/styles/text_placement_point';
import text_placement_line from '../data/styles/text_placement_line';
import text_placement_line_center from '../data/styles/text_palcement_line_center';
import filter_comparison_propertyFunction from "../data/styles/filter_comparison_propertyFunction";

import ol_function_marksymbolizer from '../data/olStyles/function_markSymbolizer';
import ol_function_nested_fillsymbolizer from '../data/olStyles/function_nested_fillSymbolizer';
Expand Down Expand Up @@ -1267,6 +1268,41 @@ describe('OlStyleParser implements StyleParser', () => {
expect(targetStyle2[0]).toEqual(ol_function_boolean_fillsymbolizer2);
});

it('can write a comparison filter where the first and second arguments are property functions', async () => {
let { output: geoStylerStyle } = await styleParser.writeStyle(filter_comparison_propertyFunction);
expect(geoStylerStyle).toBeDefined();
expect(typeof geoStylerStyle === 'function').toBe(true);
geoStylerStyle = geoStylerStyle as OlParserStyleFct;
const inBetweenLabel = (filter_comparison_propertyFunction.rules[0].symbolizers[0] as TextSymbolizer).label;
const aboveLabel = (filter_comparison_propertyFunction.rules[1].symbolizers[0] as TextSymbolizer).label;
const belowLabel = (filter_comparison_propertyFunction.rules[2].symbolizers[0] as TextSymbolizer).label;

const inBetweenFeat = new OlFeature({
value: 0.8,
max: 1,
min: 0.5
});
const aboveFeat = new OlFeature({
value: 2,
max: 1,
min: 0.5
});
const belowFeat = new OlFeature({
value: 0.2,
max: 1,
min: 0.5
});

const inBetweenOLStyle = geoStylerStyle(inBetweenFeat);
const aboveOLStyle = geoStylerStyle(aboveFeat);
const belowOLStyle = geoStylerStyle(belowFeat);

expect(inBetweenOLStyle[0].getText().getText()).toBe(inBetweenLabel);
expect(aboveOLStyle[0].getText().getText()).toBe(aboveLabel);
expect(belowOLStyle[0].getText().getText()).toBe(belowLabel);

});

it('adds unsupportedProperties to the write output', async () => {
let {
output: olStyle,
Expand Down
2 changes: 1 addition & 1 deletion src/OlStyleParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ export class OlStyleParser implements StyleParser<OlStyleLike> {
}
let arg2: any;
if (isGeoStylerFunction(filter[2])) {
arg2 = feature.get(OlStyleUtil.evaluateFunction(filter[2], feature));
arg2 = OlStyleUtil.evaluateFunction(filter[2], feature);
} else {
arg2 = filter[2];
}
Expand Down

0 comments on commit 0688ab4

Please sign in to comment.