diff --git a/CHANGELOG.md b/CHANGELOG.md index eb87c2a2..017949ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - _...Add new stuff here..._ ### 🐞 Bug fixes +- Fix issue with `geomtry-type` filter ([#924](https://github.com/maplibre/maplibre-style-spec/pull/924)) - _...Add new stuff here..._ ## 22.0.0 diff --git a/src/feature_filter/feature_filter.test.ts b/src/feature_filter/feature_filter.test.ts index 743b16fc..4b54c784 100644 --- a/src/feature_filter/feature_filter.test.ts +++ b/src/feature_filter/feature_filter.test.ts @@ -171,6 +171,30 @@ describe('filter', () => { expect(withinFilter.filter({zoom: 3}, featureInTile, canonical)).toBe(false); }); + test('expression, geomtery-type point', () => { + const withinFilter = featureFilter(['==', ['geometry-type'], 'Point']); + expect(withinFilter.needGeometry).toBe(true); + const canonical = {z: 3, x: 3, y: 3} as ICanonicalTileID; + const featureInTile = { + type: 1, + geometry: [[{x: 0, y: 0}]], + properties: {} + } as Feature; + expect(withinFilter.filter({zoom: 3}, featureInTile, canonical)).toBe(true); + }); + + test('expression, geomtery-type multipoint', () => { + const withinFilter = featureFilter(['==', ['geometry-type'], 'MultiPoint']); + expect(withinFilter.needGeometry).toBe(true); + const canonical = {z: 3, x: 3, y: 3} as ICanonicalTileID; + const featureInTile = { + type: 1, + geometry: [[{x: 0, y: 0}], [{x: 1, y: 1}]], + properties: {} + } as Feature; + expect(withinFilter.filter({zoom: 3}, featureInTile, canonical)).toBe(true); + }); + legacyFilterTests(featureFilter); }); diff --git a/src/feature_filter/index.ts b/src/feature_filter/index.ts index 2a652e14..5b8dd135 100644 --- a/src/feature_filter/index.ts +++ b/src/feature_filter/index.ts @@ -103,7 +103,7 @@ function compare(a, b) { function geometryNeeded(filter) { if (!Array.isArray(filter)) return false; - if (filter[0] === 'within' || filter[0] === 'distance') return true; + if (filter[0] === 'within' || filter[0] === 'distance' || filter[0] === 'geometry-type') return true; for (let index = 1; index < filter.length; index++) { if (geometryNeeded(filter[index])) return true; }