Skip to content

Commit 9d41404

Browse files
mournergithub-actions[bot]
authored andcommitted
Fix an error when querying multipolygons in dynamic mode
GitOrigin-RevId: 725a5501699c06356b07a79538697df8fd67d5b9
1 parent f3a6643 commit 9d41404

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/source/geojson_rt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ function transformAndClipPolygon(input: number[], z2: number, tx: number, ty: nu
333333
Math.round(EXTENT * (clipped[i] * z2 - tx)),
334334
Math.round(EXTENT * (clipped[i + 1] * z2 - ty))
335335
]);
336-
out.push(ring);
336+
if (ring.length) out.push(ring);
337337
}
338338

339339
// rewind a polygon ring to a given winding order (clockwise or anti-clockwise)

src/source/vector_tile_to_pbf.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ function writeGeometry(feature: Feature, pbf: Pbf) {
113113

114114
} else {
115115
for (const ring of geometry) {
116+
if (ring.length === 0) continue;
116117
pbf.writeVarint(command(1, 1));
117118
const lineCount = ring.length - (type === 3 ? 1 : 0); // do not write polygon closing path as lineto
118119
for (let i = 0; i < lineCount; i++) {

test/unit/source/vector_tile_to_pbf.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {test, expect} from '../../util/vitest';
22
import writePbf from '../../../src/source/vector_tile_to_pbf';
3+
import Pbf from 'pbf';
4+
import {VectorTile} from '@mapbox/vector-tile';
35

46
import type {Feature} from '../../../src/source/geojson_wrapper';
57

@@ -25,3 +27,18 @@ test('loadData does not error on non-numeric feature IDs', () => {
2527
writePbf({test: features});
2628
}).not.toThrowError();
2729
});
30+
31+
test('does not encode empty rings', () => {
32+
const features: Feature[] = [{
33+
id: 1,
34+
type: 2,
35+
tags: {},
36+
geometry: [[[0, 0]], []]
37+
}];
38+
39+
expect(() => {
40+
const buf = writePbf({test: features});
41+
const tile = new VectorTile(new Pbf(buf));
42+
tile.layers.test.feature(0).loadGeometry();
43+
}).not.toThrowError();
44+
});

0 commit comments

Comments
 (0)