Skip to content

Commit 43d706a

Browse files
authored
Add test for undefined GeoJSON properties (#6873)
* Add test for undefined properties * FIx lint * Review comments * Update changelog
1 parent 6aeafd7 commit 43d706a

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Fix `LngLatBounds#intersects` returning `false` for bounds spanning 360° or more ([#6863](https://github.com/maplibre/maplibre-gl-js/pull/6863)) (by [@lucaswoj](https://github.com/lucaswoj))
99
- Fix getting the right zoom for getElevationForLngLat ([#6825](https://github.com/maplibre/maplibre-gl-js/pull/6825)) (by [@HarelM](https://github.com/HarelM))
1010
- Fix stale transform state being applied after changing `minZoom` or `maxZoom` due to old copies from `transformCameraUpdate` taking precedence. `transformCameraUpdate` is now called from `setMinZoom` and `setMaxZoom` to allow user to control subsequent changes to `zoom` [#6766](https://github.com/maplibre/maplibre-gl-js/issues/6766) (by [@Auspicus](https://github.com/Auspicus))
11+
- Fix GeoJSON source throwing with undefined properties [#6730](https://github.com/maplibre/maplibre-gl-js/issues/6730) (by [@wayofthefuture](https://github.com/wayofthefuture))
1112
- _...Add new stuff here..._
1213

1314
## 5.14.0

src/source/geojson_worker_source.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {type Actor} from '../util/actor';
88
import {type WorkerTileParameters} from './worker_source';
99
import {setPerformance, sleep} from '../util/test/util';
1010
import {type FakeServer, fakeServer} from 'nise';
11+
import {GEOJSON_TILE_LAYER_NAME} from '@maplibre/vt-pbf';
1112

1213
const actor = {send: () => {}} as any as Actor;
1314

@@ -66,6 +67,49 @@ describe('reloadTile', () => {
6667
expect(spy).toHaveBeenCalledTimes(2);
6768
});
6869

70+
test('handles null and undefined properties during tile serialization', async () => {
71+
const layers = [
72+
{
73+
id: 'mylayer',
74+
source: 'sourceId',
75+
type: 'symbol',
76+
}
77+
] as LayerSpecification[];
78+
const layerIndex = new StyleLayerIndex(layers);
79+
const source = new GeoJSONWorkerSource(actor, layerIndex, []);
80+
const geoJson = {
81+
'type': 'Feature',
82+
'geometry': {
83+
'type': 'Point',
84+
'coordinates': [0, 0]
85+
},
86+
'properties': {
87+
'nullProperty': null,
88+
'undefinedProperty': undefined,
89+
'stringProperty': 'string'
90+
}
91+
};
92+
const tileParams = {
93+
source: 'sourceId',
94+
uid: 0,
95+
tileID: new OverscaledTileID(0, 0, 0, 0, 0),
96+
maxZoom: 10
97+
};
98+
99+
await source.loadData({type: 'geojson', source: 'sourceId', data: geoJson} as LoadGeoJSONParameters);
100+
101+
// load vector data from geojson, passing through the tile serialization step
102+
const data = await source.reloadTile(tileParams as any as WorkerTileParameters);
103+
expect(data.featureIndex).toBeDefined();
104+
105+
// deserialize tile layers in the feature index
106+
data.featureIndex.rawTileData = data.rawTileData;
107+
const featureLayers = data.featureIndex.loadVTLayers();
108+
expect(Object.keys(featureLayers)).toHaveLength(1);
109+
110+
// validate supported features are present in the index
111+
expect(featureLayers[GEOJSON_TILE_LAYER_NAME].feature(0).properties['stringProperty']).toBeDefined();
112+
});
69113
});
70114

71115
describe('resourceTiming', () => {

0 commit comments

Comments
 (0)