import { csvParse } from 'd3-dsv'; import { Feature, FeatureCollection, Point } from 'geojson'; function snooze(ms: number): Promise { return new Promise((resolve) => setTimeout(resolve, ms)); } addEventListener('message', async (event: MessageEvent) => { const { payload, sleep } = event.data.message; await snooze(sleep); const data = csvParse(payload); const geojson = await transformGeoJSON(data); postMessage(geojson); }); async function transformGeoJSON(payload: any): Promise { const geojson: FeatureCollection = { type: 'FeatureCollection', features: [], } as FeatureCollection; for await (const t of payload) { geojson.features.push({ type: 'Feature', properties: { userId: t?.userId || null, userName: t?.userName || null, }, geometry: { type: 'Point', coordinates: [ parseFloat(t?.longitude) || 0, parseFloat(t?.latitude) || 0, ], }, } as Feature); } return geojson; }