geostyler / geostyler-mapbox-parser

GeoStyler-Style-Parser implementation for Mapbox
BSD 2-Clause "Simplified" License
14 stars 9 forks source link

Filters for integers don't work #96

Closed MangoChris closed 3 months ago

MangoChris commented 2 years ago

Bug

The filter value for number comparisons (=/</>/<=/>=) is being stored as a string rather than an integer in the mbtiles output. This causes the expressions to fail when loading in Mapbox GL.

To Reproduce Steps to reproduce the behavior:

  1. Create a style that uses a numerical expression
  2. Pass it to MapboxParser.writeStyle

Expected filter output

[ ">=", "Median income", 56390.333333333321207 ], **Actual filter output:

[ ">=", "Median income", "56390.333333333321207" ],

jansule commented 2 years ago

Thanks for the info @MangoChris and sorry for the late response.

Unfortunately, I cannot reproduce the error on my local setup.

How did you create the style in step 1? Is the value in the filter input numerical?

On my setup, following GeoStyler style

{
  name: 'Small populated New Yorks',
  rules: [{
    filter: ['&&',
      ['==', 'NAME', 'New York'],
      ['==', 'TEST_BOOL', 'true'],
      ['==', 'TEST', null],
      ['*=', 'TEST2', '*York*'],
      ['*=', 'TEST1', '*New*'],
      ['!', ['>', 'POPULATION', '100000']],
      ['||',
        ['==', 'TEST2', '1'], // <----------------- string input
        ['>=', 'TEST2', 2] // <------------------- numeric input
      ]
    ],
    name: 'Small populated New Yorks',
    symbolizers: [{
      kind: 'Line',
      color: '#FF0000',
      width: 3
    }]
  }]
}

creates the following mapbox style:

{
  version: 8,
  name: "Small populated New Yorks",
  layers: [{
    id: "Small populated New Yorks",
    type: "line",
    filter: ["all",
      ["==", "NAME", "New York"],
      ["==", "TEST_BOOL", "true"],
      ["==", "TEST", null],
      ["*=", "TEST2", "*York*"],
      ["*=", "TEST1", "*New*"],
      ["!", [">", "POPULATION", "100000"]],
      ["any",
        ["==", "TEST2", "1"], // <---------------- string input
        [">=", "TEST2", 2] // <------------------- numeric input
      ]
    ],
    paint: {
      "line-color": "#FF0000",
      "line-width": 3
    }
  }]
}
jansule commented 3 months ago

Closed due to inactivity. Feel free to reopen issue, if it is still relevant.