geostyler / geostyler-openlayers-parser

GeoStyler Style Parser implementation for OpenLayers styles
BSD 2-Clause "Simplified" License
38 stars 28 forks source link

Incorrect parsing of property function in geoStylerFilterToOlParserFilter #791

Closed miccoh1994 closed 8 months ago

miccoh1994 commented 10 months ago

Surely this:

https://github.com/geostyler/geostyler-openlayers-parser/blob/59944a7c0acc3dee40eb8924b7c0ae464a9c0d74/src/OlStyleParser.ts#L901

should be:

 arg2 = OlStyleUtil.evaluateFunction(filter[2], feature)

or at least (if original line is intended):

if (filter[2].name === 'property') {
   arg2 = OlStyleUtil.evaluateFunction(filter[2], feature)
} else {
   arg2 = feature.get(OlStyleUtil.evaluateFunction(filter[2], feature));
}

example rule:

{
    "name": "below min",
    "filter": [
        "<",
        {
            "name": "property",
            "args": [
                "P_value"
            ]
        },
        {
            "name": "property",
            "args": [
                "P_min"
            ]
        }
    ],
    "symbolizers": [
        {
            "kind": "Text",
            "label": "{{P_value}}",
            "size": 12,
            "fontWeight": "bold",
            "font": [
                "Arial"
            ],
            "offset": [
                0,
                -15
            ],
            "color": "#FF0200",
            "haloColor": "#333333",
            "haloWidth": 10,
            "haloOpacity": 1,
            "opacity": 1,
            "maxAngle": 0,
            "allowOverlap": true,
            "avoidEdges": false,
            "anchor": "center"
        }
    ]
}
miccoh1994 commented 10 months ago

current workaround is to add property for each key in the feature being used e.g. feature:

{
    "id": 115979,
    "type": "Feature",
    "geometry": {
        "type": "Point",
        "coordinates": [
            20.6419111,
            -28.79971792
        ]
    },
    "properties": {
        "P_value": 0.11,
        "P_max": 0.16,
        "P_min": 0.12,
        "P_max_key": "P_max", // added
        "P_min_key": "P_min", // added
        "S_value": 0.23,
        "S_max": 0.3,
        "S_min": 0.2,
        "S_max_key": "S_max", // added
        "S_min_key": "S_min", // added
    }
}

rule

{
    "name": "below min",
    "filter": [
        "<",
        {
            "name": "property",
            "args": [
                "P_value"
            ]
        },
        {
            "name": "property",
            "args": [
                "P_min_key"
            ]
        }
    ],
    "symbolizers": [
        {
            "kind": "Text",
            "label": "{{P_value}}",
            "size": 12,
            "fontWeight": "bold",
            "font": [
                "Arial"
            ],
            "offset": [
                0,
                -15
            ],
            "color": "#FF0200",
            "haloColor": "#333333",
            "haloWidth": 10,
            "haloOpacity": 1,
            "opacity": 1,
            "maxAngle": 0,
            "allowOverlap": true,
            "avoidEdges": false,
            "anchor": "center"
        }
    ]
}

P_max_key and use a property function to return the key to use :zany_face:

jansule commented 10 months ago

Nice catch @miccoh1994. Are you planning on providing a PR for this?

miccoh1994 commented 10 months ago

Nice catch @miccoh1994. Are you planning on providing a PR for this?

I will submit a PR with tests sometime this week