Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/source/geojson_source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,20 @@ describe('GeoJSONSource.update', () => {
expect(transformSpy).toHaveBeenCalledTimes(1);
expect(transformSpy.mock.calls[0][0]).toBe('https://example.com/data.geojson');
});

test('updates _data.geojson when worker returns data from URL load', async () => {
const source = new GeoJSONSource('id', {data: 'https://example.com/data.geojson'} as GeoJSONSourceOptions, wrapDispatcher({
sendAsync() { return Promise.resolve({data: hawkHill}); }
}), undefined);
source.map = {_requestManager: {transformRequest: (url) => ({url})}} as any;

const promise = waitForEvent(source, 'data', (e: MapSourceDataEvent) => e.sourceDataType === 'metadata');
source.load();
await promise;

expect((source as any)._data.geojson).toStrictEqual(hawkHill);
});

test('fires event when metadata loads', async () => {
const mockDispatcher = wrapDispatcher({
sendAsync(_message: ActorMessage<MessageType>) {
Expand Down
3 changes: 2 additions & 1 deletion src/source/geojson_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ export class GeoJSONSource extends Evented implements Source {
return;
}

if (diff) this._applyDiff(diff);
if (result.data) this._data.geojson = result.data;
else if (diff) this._applyDiff(diff);

let resourceTiming: PerformanceResourceTiming[] = null;
if (result.resourceTiming && result.resourceTiming[this.id]) {
Expand Down
10 changes: 7 additions & 3 deletions src/source/geojson_worker_source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ describe('resourceTiming', () => {

const result = await source.loadData({source: 'testSource', data: geoJson} as LoadGeoJSONParameters);
expect(result.resourceTiming).toBeUndefined();
expect(result.data).toBeUndefined();
});

});
Expand Down Expand Up @@ -296,7 +297,8 @@ describe('loadData', () => {
const load1Promise = worker.loadData({source: 'source1', request: {url: ''}} as LoadGeoJSONParameters);
server.respond();

await load1Promise;
const result = await load1Promise;
expect(result.data).toStrictEqual(updateableGeoJson);
await expect(worker.loadData({source: 'source1', dataDiff: {removeAll: true}} as LoadGeoJSONParameters)).resolves.toBeDefined();
});

Expand All @@ -320,14 +322,16 @@ describe('loadData', () => {
const worker = new GeoJSONWorkerSource(actor, layerIndex, []);

await worker.loadData({source: 'source1', data: updateableGeoJson} as LoadGeoJSONParameters);
await expect(worker.loadData({source: 'source1', dataDiff: {
const result = await worker.loadData({source: 'source1', dataDiff: {
add: [{
type: 'Feature',
id: 'update_point',
geometry: {type: 'Point', coordinates: [0, 0]},
properties: {}
}]
}} as LoadGeoJSONParameters)).resolves.toBeDefined();
}} as LoadGeoJSONParameters);
expect(result).toBeDefined();
expect(result.data).toBeUndefined();
});

test('loadData should reject as first call with no data', async () => {
Expand Down
6 changes: 6 additions & 0 deletions src/source/geojson_worker_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ export class GeoJSONWorkerSource extends VectorTileWorkerSource {

const result: GeoJSONWorkerSourceLoadDataResult = {};

// Sending a large GeoJSON payload from the worker thread to the main thread
// is SLOW so we only do it if absolutely nescessary.
// The main thread already has a copy of this data UNLESS it was loaded
// from a URL.
if (params.request) result.data = data;

this._finishPerformance(perf, params, result);
return result;
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions src/util/actor_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type GetClusterLeavesParams = ClusterIDAndSource & { limit: number; offse
export type GeoJSONWorkerSourceLoadDataResult = {
resourceTiming?: {[_: string]: Array<PerformanceResourceTiming>};
abandoned?: boolean;
data?: GeoJSON.GeoJSON;
};

/**
Expand Down
Loading