Skip to content

Commit 2ed393e

Browse files
authored
Fixes geometry type filter (#924)
* Fixes geometry type filter * Fix lint, add changelog
1 parent e1a098c commit 2ed393e

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- _...Add new stuff here..._
55

66
### 🐞 Bug fixes
7+
- Fix issue with `geomtry-type` filter ([#924](https://github.com/maplibre/maplibre-style-spec/pull/924))
78
- _...Add new stuff here..._
89

910
## 22.0.0

src/feature_filter/feature_filter.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,30 @@ describe('filter', () => {
171171
expect(withinFilter.filter({zoom: 3}, featureInTile, canonical)).toBe(false);
172172
});
173173

174+
test('expression, geomtery-type point', () => {
175+
const withinFilter = featureFilter(['==', ['geometry-type'], 'Point']);
176+
expect(withinFilter.needGeometry).toBe(true);
177+
const canonical = {z: 3, x: 3, y: 3} as ICanonicalTileID;
178+
const featureInTile = {
179+
type: 1,
180+
geometry: [[{x: 0, y: 0}]],
181+
properties: {}
182+
} as Feature;
183+
expect(withinFilter.filter({zoom: 3}, featureInTile, canonical)).toBe(true);
184+
});
185+
186+
test('expression, geomtery-type multipoint', () => {
187+
const withinFilter = featureFilter(['==', ['geometry-type'], 'MultiPoint']);
188+
expect(withinFilter.needGeometry).toBe(true);
189+
const canonical = {z: 3, x: 3, y: 3} as ICanonicalTileID;
190+
const featureInTile = {
191+
type: 1,
192+
geometry: [[{x: 0, y: 0}], [{x: 1, y: 1}]],
193+
properties: {}
194+
} as Feature;
195+
expect(withinFilter.filter({zoom: 3}, featureInTile, canonical)).toBe(true);
196+
});
197+
174198
legacyFilterTests(featureFilter);
175199

176200
});

src/feature_filter/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function compare(a, b) {
103103

104104
function geometryNeeded(filter) {
105105
if (!Array.isArray(filter)) return false;
106-
if (filter[0] === 'within' || filter[0] === 'distance') return true;
106+
if (filter[0] === 'within' || filter[0] === 'distance' || filter[0] === 'geometry-type') return true;
107107
for (let index = 1; index < filter.length; index++) {
108108
if (geometryNeeded(filter[index])) return true;
109109
}

0 commit comments

Comments
 (0)