@octostar/map-component 0.2.13 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +283 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +285 -39
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +4 -0
- package/dist/types/components/ingest-progress-overlay.d.ts +12 -0
- package/dist/types/components/ingest-progress-overlay.d.ts.map +1 -0
- package/dist/types/components/map-editor-canvas.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/ingest-client.d.ts +22 -4
- package/dist/types/lib/ingest-client.d.ts.map +1 -1
- package/dist/types/lib/ingest-pipeline.d.ts +52 -1
- package/dist/types/lib/ingest-pipeline.d.ts.map +1 -1
- package/dist/types/lib/ingest-progress.d.ts +21 -0
- package/dist/types/lib/ingest-progress.d.ts.map +1 -0
- package/dist/types/lib/ingest-stream.d.ts +50 -0
- package/dist/types/lib/ingest-stream.d.ts.map +1 -0
- package/dist/types/lib/map-editor-api.d.ts +13 -0
- package/dist/types/lib/map-editor-api.d.ts.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsxs,
|
|
2
|
-
import { useState, useEffect, useCallback, useMemo, createContext, useContext, useRef, forwardRef, useImperativeHandle } from "react";
|
|
1
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect, useSyncExternalStore, useCallback, useMemo, createContext, useContext, useRef, forwardRef, useImperativeHandle } from "react";
|
|
3
3
|
import maplibregl from "maplibre-gl";
|
|
4
4
|
import MapboxDraw from "@mapbox/mapbox-gl-draw";
|
|
5
5
|
import * as turf from "@turf/turf";
|
|
@@ -96,7 +96,7 @@ function featureCollectionBlobParts(collection, options) {
|
|
|
96
96
|
if (pending.length > 0) parts.push(pending.join(""));
|
|
97
97
|
return parts;
|
|
98
98
|
}
|
|
99
|
-
const ingestWorkerSource = '"use strict";(()=>{function
|
|
99
|
+
const ingestWorkerSource = '"use strict";(()=>{function p(e){let t=e.crs?.properties?.name,n=null;if(t){let r=t.match(/EPSG::?(\\d+)/i);r&&(n=`EPSG:${r[1]}`)}if(!n&&e.features.length>0){let r=w(e.features[0].geometry);if(r){let[s,a]=r;if(Math.abs(s)<=180&&Math.abs(a)<=90)return{sourceCRS:"EPSG:4326",needsReprojection:!1}}return{sourceCRS:null,needsReprojection:!1}}return{sourceCRS:n,needsReprojection:n!==null&&n!=="EPSG:4326"}}function w(e){if(!e)return null;switch(e.type){case"Point":return e.coordinates;case"MultiPoint":case"LineString":return e.coordinates[0];case"MultiLineString":case"Polygon":return e.coordinates[0]?.[0];case"MultiPolygon":return e.coordinates[0]?.[0]?.[0];default:return null}}function S(e){return e.geometry?.type==="LineString"?e.geometry.coordinates.some(n=>n.length>=3&&n[2]!==0):e.geometry?.type==="MultiLineString"?e.geometry.coordinates.some(n=>n.some(r=>r.length>=3&&r[2]!==0)):!1}function i(e){if(!e)return null;if(e instanceof Date)return e;if(typeof e=="string"||typeof e=="number"){let t=new Date(e);return isNaN(t.getTime())?null:t}return null}function b(e){return!!(e.startDate||e.startdate||e.start_date||e.start_time||e.date||e.timestamp||e.flightDate||e.time||e.datetime||e.endDate||e.enddate||e.end_date||e.end_time)}function I(e){let t=i(e.startDate)||i(e.startdate)||i(e.start_date)||i(e.start_time)||i(e.date)||i(e.timestamp)||i(e.flightDate)||i(e.time)||i(e.datetime),n=i(e.endDate)||i(e.enddate)||i(e.end_date)||i(e.end_time);return t&&n&&n<t&&([t,n]=[n,t]),{startDate:t,endDate:n}}function h(e){return"kind"in e&&e.kind==="ack"}function J(){let e=globalThis.crypto?.randomUUID?.bind(globalThis.crypto);return e?e():`f-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function D(e,t,n){switch(n.idStrategy){case"preserve":return e.id;case"layer-index":return e.id!==void 0&&e.id!==null?String(e.id):`${n.layerId}-f${t}`;case"uuid-fallback":return e.id?String(e.id):J()}}function C(e,t){if(Array.isArray(e)){if(typeof e[0]=="number"){let n=e[0],r=e[1];t[0]=Math.min(t[0],n),t[1]=Math.min(t[1],r),t[2]=Math.max(t[2],n),t[3]=Math.max(t[3],r);return}for(let n of e)C(n,t)}}function R(e,t){if(e){if(e.type==="GeometryCollection"){for(let n of e.geometries)R(n,t);return}C(e.coordinates,t)}}function M(e){let t=[1/0,1/0,-1/0,-1/0];for(let n of e)R(n.geometry,t);return t.every(n=>isFinite(n))?t:null}function x(e,t){let n;if(e.type==="text")try{n=JSON.parse(e.text)}catch(d){return{kind:"error",code:"parse-error",message:d instanceof Error?d.message:"Invalid file"}}else n=e.data;if(n&&n.type==="Feature"&&(n={type:"FeatureCollection",features:[n]}),!n||n.type!=="FeatureCollection"||!Array.isArray(n.features))return{kind:"error",code:"invalid-format",message:"Invalid GeoJSON format"};if(t.emptyIsError&&n.features.length===0)return{kind:"error",code:"empty",message:"The file contains no features"};if(n["octostar:map"])return{kind:"enriched",data:n};let{sourceCRS:r,needsReprojection:s}=p(n),a=!1,o=!1,u=[];n.features.forEach((d,G)=>{let m=D(d,G,t);!o&&S(d)&&(o=!0);let g=d.properties||{};if(!b(g)){u.push(t.idStrategy==="preserve"?d:{...d,id:m});return}let{startDate:y,endDate:k}=I(g);(y||k)&&(a=!0),u.push({...d,...m!==void 0&&{id:m},properties:{...g,startDate:y?.toISOString()||null,endDate:k?.toISOString()||null}})});let c=n.properties?.layerMetadata;return{kind:"features",features:u,featureCount:u.length,bbox:M(u),hasTemporal:a,hasAltitude:o,reprojected:!1,sourceCRS:r,...s&&{needsReprojection:s},...c&&{layerMetadata:c}}}var O=5e3;function P(e,t){let n=Number.isNaN(t)?O:Math.max(1,Math.floor(t)),r=[];for(let s=0;s<e.length;s+=n)r.push(e.slice(s,s+n));return r}function f(e){if(e===void 0)return!1;if(typeof e=="number")return Number.isFinite(e)&&!Object.is(e,-0);if(e===null||typeof e!="object")return!0;if(Array.isArray(e)){for(let t=0;t<e.length;t++)if(!f(e[t]))return!1;return!0}for(let t in e)if(!f(e[t]))return!1;return!0}function A(e){for(let t=0;t<e.length;t++)if(!f(e[t]))return e;try{return JSON.stringify(e)}catch{return e}}function E(e){let{kind:t,features:n,...r}=e;return r}async function N(e,t,n,r){let s;try{s=x(t,n)}catch(a){r.post({kind:"result",id:e,ok:!1,error:a instanceof Error?a.message:String(a)});return}if(s.kind!=="features"){r.post({kind:"result",id:e,ok:!0,result:s});return}try{let a=r.encode??A,o=P(s.features,r.chunkSize??O);r.post({kind:"head",id:e,summary:E(s)});let u=o.length>0?a(o[0]):null;for(let c=0;c<o.length;c++){let d=r.waitAck(c);r.post({kind:"chunk",id:e,seq:c,payload:u}),u=c+1<o.length?a(o[c+1]):null,await d}r.post({kind:"done",id:e,chunkCount:o.length})}catch(a){r.post({kind:"error",id:e,message:a instanceof Error?a.message:String(a)})}}var F=e=>self.postMessage(e),l=new Map;self.onmessage=async e=>{let t=e.data;if(h(t)){let o=`${t.id}:${t.seq}`,u=l.get(o);l.delete(o),u?.();return}let{id:n,source:r,options:s,tuning:a}=t;try{let o=r.type==="blob"?{type:"text",text:await r.blob.text()}:r;await N(n,o,s,{post:F,waitAck:u=>new Promise(c=>{l.set(`${n}:${u}`,c)}),...a?.chunkSize!==void 0&&{chunkSize:a.chunkSize},...a?.featureArrayChunks&&{encode:u=>u}})}catch(o){F({kind:"result",id:n,ok:!1,error:o instanceof Error?o.message:String(o)})}finally{l.forEach((o,u)=>{u.startsWith(`${n}:`)&&l.delete(u)})}};})();\n';
|
|
100
100
|
proj4.defs("EPSG:27700", "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs");
|
|
101
101
|
proj4.defs("EPSG:3857", "+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs");
|
|
102
102
|
proj4.defs("EPSG:32630", "+proj=utm +zone=30 +datum=WGS84 +units=m +no_defs");
|
|
@@ -245,7 +245,11 @@ function runIngestPipeline(source, options) {
|
|
|
245
245
|
if (startDate || endDate) hasTemporal = true;
|
|
246
246
|
features.push({
|
|
247
247
|
...f,
|
|
248
|
-
id
|
|
248
|
+
// Omit the key rather than set `id: undefined` ('preserve' + id-less
|
|
249
|
+
// feature): an own undefined key survives structured clone but is
|
|
250
|
+
// dropped by JSON chunks, so it would make the transfer encoding
|
|
251
|
+
// observable. Never undefined for the other strategies.
|
|
252
|
+
...id !== void 0 && { id },
|
|
249
253
|
properties: {
|
|
250
254
|
...props,
|
|
251
255
|
startDate: (startDate == null ? void 0 : startDate.toISOString()) || null,
|
|
@@ -267,6 +271,9 @@ function runIngestPipeline(source, options) {
|
|
|
267
271
|
...layerMetadata && { layerMetadata }
|
|
268
272
|
};
|
|
269
273
|
}
|
|
274
|
+
function decodeChunkPayload(payload) {
|
|
275
|
+
return typeof payload === "string" ? JSON.parse(payload) : payload;
|
|
276
|
+
}
|
|
270
277
|
const fromStorage = (() => {
|
|
271
278
|
var _a;
|
|
272
279
|
try {
|
|
@@ -344,7 +351,10 @@ function createWorkerPort() {
|
|
|
344
351
|
return null;
|
|
345
352
|
}
|
|
346
353
|
}
|
|
347
|
-
const
|
|
354
|
+
const INGEST_STALL_TIMEOUT_MS = 12e4;
|
|
355
|
+
function assembleStreamResult(stream) {
|
|
356
|
+
return finalizeReprojection({ kind: "features", ...stream.summary, features: stream.features });
|
|
357
|
+
}
|
|
348
358
|
function createIngestClient(portFactory = createWorkerPort) {
|
|
349
359
|
let port = null;
|
|
350
360
|
let portUnavailable = false;
|
|
@@ -362,6 +372,138 @@ function createIngestClient(portFactory = createWorkerPort) {
|
|
|
362
372
|
port == null ? void 0 : port.terminate();
|
|
363
373
|
port = null;
|
|
364
374
|
};
|
|
375
|
+
const armWatchdog = (request) => {
|
|
376
|
+
clearTimeout(request.timeout);
|
|
377
|
+
request.timeout = setTimeout(() => {
|
|
378
|
+
console.warn(
|
|
379
|
+
`[map-component] Ingest worker unresponsive for "${request.label}" after ${INGEST_STALL_TIMEOUT_MS}ms; it will be respawned on next use.`
|
|
380
|
+
);
|
|
381
|
+
abandonPort("Ingest worker unresponsive — the file could not be parsed");
|
|
382
|
+
}, INGEST_STALL_TIMEOUT_MS);
|
|
383
|
+
};
|
|
384
|
+
const callHook = (request, invoke) => {
|
|
385
|
+
if (!request.hooks) return;
|
|
386
|
+
try {
|
|
387
|
+
invoke(request.hooks);
|
|
388
|
+
} catch (err) {
|
|
389
|
+
console.warn("[map-component] Ingest stream hook threw; progress reporting disabled for this request.", err);
|
|
390
|
+
request.hooks = void 0;
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
const settle = (id, request) => {
|
|
394
|
+
pending.delete(id);
|
|
395
|
+
clearTimeout(request.timeout);
|
|
396
|
+
};
|
|
397
|
+
const handleChunk = (activePort, request, msg) => {
|
|
398
|
+
const stream = request.stream;
|
|
399
|
+
if (!stream || msg.seq !== stream.nextSeq) {
|
|
400
|
+
abandonPort("Ingest worker sent an out-of-order chunk");
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
armWatchdog(request);
|
|
404
|
+
const features = decodeChunkPayload(msg.payload);
|
|
405
|
+
features.forEach((f) => stream.features.push(f));
|
|
406
|
+
stream.nextSeq += 1;
|
|
407
|
+
callHook(request, (hooks) => {
|
|
408
|
+
var _a;
|
|
409
|
+
return (_a = hooks.onProgress) == null ? void 0 : _a.call(hooks, stream.features.length, stream.summary.featureCount);
|
|
410
|
+
});
|
|
411
|
+
activePort.post({ kind: "ack", id: msg.id, seq: msg.seq });
|
|
412
|
+
};
|
|
413
|
+
const handleMessage = (activePort, msg) => {
|
|
414
|
+
const request = pending.get(msg.id);
|
|
415
|
+
if (!request) return;
|
|
416
|
+
switch (msg.kind) {
|
|
417
|
+
case "result": {
|
|
418
|
+
if (request.stream) {
|
|
419
|
+
abandonPort("Ingest worker sent a single-shot result mid-stream");
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
if (!msg.ok) {
|
|
423
|
+
settle(msg.id, request);
|
|
424
|
+
mapPerfLog("ingest", `worker request "${request.label}" finished`, {
|
|
425
|
+
ms: Math.round(performance.now() - request.startedAt),
|
|
426
|
+
ok: false
|
|
427
|
+
});
|
|
428
|
+
request.reject(new Error(msg.error));
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
let finalized;
|
|
432
|
+
try {
|
|
433
|
+
finalized = finalizeReprojection(msg.result);
|
|
434
|
+
} catch (err) {
|
|
435
|
+
settle(msg.id, request);
|
|
436
|
+
request.reject(err instanceof Error ? err : new Error(String(err)));
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
settle(msg.id, request);
|
|
440
|
+
mapPerfLog("ingest", `worker request "${request.label}" finished`, {
|
|
441
|
+
ms: Math.round(performance.now() - request.startedAt),
|
|
442
|
+
ok: true
|
|
443
|
+
});
|
|
444
|
+
request.resolve(finalized);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
case "head":
|
|
448
|
+
if (request.stream) {
|
|
449
|
+
abandonPort("Ingest worker restarted a stream mid-request");
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
armWatchdog(request);
|
|
453
|
+
request.stream = {
|
|
454
|
+
summary: msg.summary,
|
|
455
|
+
features: [],
|
|
456
|
+
nextSeq: 0
|
|
457
|
+
};
|
|
458
|
+
callHook(request, (hooks) => {
|
|
459
|
+
var _a;
|
|
460
|
+
return (_a = hooks.onHead) == null ? void 0 : _a.call(hooks, msg.summary);
|
|
461
|
+
});
|
|
462
|
+
return;
|
|
463
|
+
case "chunk":
|
|
464
|
+
try {
|
|
465
|
+
handleChunk(activePort, request, msg);
|
|
466
|
+
} catch (err) {
|
|
467
|
+
console.warn("[map-component] Ingest chunk could not be processed; abandoning the worker.", err);
|
|
468
|
+
abandonPort("Ingest worker sent an unreadable chunk");
|
|
469
|
+
}
|
|
470
|
+
return;
|
|
471
|
+
case "done": {
|
|
472
|
+
const stream = request.stream;
|
|
473
|
+
if (!stream) {
|
|
474
|
+
abandonPort("Ingest worker completed a stream that never started");
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
if (msg.chunkCount !== stream.nextSeq) {
|
|
478
|
+
abandonPort("Ingest worker stream ended with missing chunks");
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
let assembled;
|
|
482
|
+
try {
|
|
483
|
+
assembled = assembleStreamResult(stream);
|
|
484
|
+
} catch (err) {
|
|
485
|
+
settle(msg.id, request);
|
|
486
|
+
request.reject(err instanceof Error ? err : new Error(String(err)));
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
settle(msg.id, request);
|
|
490
|
+
mapPerfLog("ingest", `worker request "${request.label}" streamed`, {
|
|
491
|
+
ms: Math.round(performance.now() - request.startedAt),
|
|
492
|
+
features: stream.features.length,
|
|
493
|
+
chunks: msg.chunkCount
|
|
494
|
+
});
|
|
495
|
+
request.resolve(assembled);
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
case "error":
|
|
499
|
+
settle(msg.id, request);
|
|
500
|
+
mapPerfLog("ingest", `worker request "${request.label}" failed mid-stream`, {
|
|
501
|
+
ms: Math.round(performance.now() - request.startedAt)
|
|
502
|
+
});
|
|
503
|
+
request.reject(new Error(msg.message));
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
};
|
|
365
507
|
const ensurePort = () => {
|
|
366
508
|
if (portUnavailable || port) return port;
|
|
367
509
|
try {
|
|
@@ -373,22 +515,9 @@ function createIngestClient(portFactory = createWorkerPort) {
|
|
|
373
515
|
portUnavailable = true;
|
|
374
516
|
return null;
|
|
375
517
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
pending.delete(msg.id);
|
|
380
|
-
clearTimeout(request.timeout);
|
|
381
|
-
mapPerfLog("ingest", `worker request "${request.label}" finished`, {
|
|
382
|
-
ms: Math.round(performance.now() - request.startedAt),
|
|
383
|
-
ok: msg.ok
|
|
384
|
-
});
|
|
385
|
-
if (msg.ok) {
|
|
386
|
-
request.resolve(finalizeReprojection(msg.result));
|
|
387
|
-
} else {
|
|
388
|
-
request.reject(new Error(msg.error));
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
port.onError((err) => {
|
|
518
|
+
const activePort = port;
|
|
519
|
+
activePort.onMessage((msg) => handleMessage(activePort, msg));
|
|
520
|
+
activePort.onError((err) => {
|
|
392
521
|
console.warn("[map-component] Ingest worker crashed; it will be respawned on next use.", err);
|
|
393
522
|
abandonPort("Ingest worker crashed");
|
|
394
523
|
});
|
|
@@ -404,7 +533,7 @@ function createIngestClient(portFactory = createWorkerPort) {
|
|
|
404
533
|
return result;
|
|
405
534
|
};
|
|
406
535
|
return {
|
|
407
|
-
ingest(input, options) {
|
|
536
|
+
ingest(input, options, stream, tuning) {
|
|
408
537
|
if (typeof input === "object" && !(input instanceof Blob)) {
|
|
409
538
|
return Promise.resolve().then(
|
|
410
539
|
() => finalizeReprojection(runIngestPipeline({ type: "parsed", data: input }, options))
|
|
@@ -415,18 +544,26 @@ function createIngestClient(portFactory = createWorkerPort) {
|
|
|
415
544
|
const id = nextId++;
|
|
416
545
|
const label = input instanceof File ? input.name : typeof input === "string" ? "text" : "blob";
|
|
417
546
|
return new Promise((resolve, reject) => {
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
)
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
547
|
+
const request = {
|
|
548
|
+
resolve,
|
|
549
|
+
reject,
|
|
550
|
+
startedAt: performance.now(),
|
|
551
|
+
label,
|
|
552
|
+
hooks: stream
|
|
553
|
+
};
|
|
554
|
+
armWatchdog(request);
|
|
555
|
+
pending.set(id, request);
|
|
556
|
+
try {
|
|
557
|
+
activePort.post({
|
|
558
|
+
id,
|
|
559
|
+
source: typeof input === "string" ? { type: "text", text: input } : { type: "blob", blob: input },
|
|
560
|
+
options,
|
|
561
|
+
...tuning && { tuning }
|
|
562
|
+
});
|
|
563
|
+
} catch (err) {
|
|
564
|
+
settle(id, request);
|
|
565
|
+
throw err;
|
|
566
|
+
}
|
|
430
567
|
});
|
|
431
568
|
},
|
|
432
569
|
dispose() {
|
|
@@ -440,6 +577,54 @@ function getSharedIngestClient() {
|
|
|
440
577
|
if (!sharedClient) sharedClient = createIngestClient();
|
|
441
578
|
return sharedClient;
|
|
442
579
|
}
|
|
580
|
+
function createIngestProgressStore() {
|
|
581
|
+
const entries = /* @__PURE__ */ new Map();
|
|
582
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
583
|
+
let nextId = 0;
|
|
584
|
+
let snapshot = [];
|
|
585
|
+
let dirty = false;
|
|
586
|
+
const notify = () => {
|
|
587
|
+
dirty = true;
|
|
588
|
+
listeners.forEach((listener) => listener());
|
|
589
|
+
};
|
|
590
|
+
return {
|
|
591
|
+
begin(label) {
|
|
592
|
+
const id = nextId++;
|
|
593
|
+
entries.set(id, { label, received: 0, total: null });
|
|
594
|
+
notify();
|
|
595
|
+
return {
|
|
596
|
+
setTotal(total) {
|
|
597
|
+
const entry = entries.get(id);
|
|
598
|
+
if (!entry || entry.total === total) return;
|
|
599
|
+
entry.total = total;
|
|
600
|
+
notify();
|
|
601
|
+
},
|
|
602
|
+
update(received) {
|
|
603
|
+
const entry = entries.get(id);
|
|
604
|
+
if (!entry || entry.received === received) return;
|
|
605
|
+
entry.received = received;
|
|
606
|
+
notify();
|
|
607
|
+
},
|
|
608
|
+
end() {
|
|
609
|
+
if (entries.delete(id)) notify();
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
},
|
|
613
|
+
subscribe(listener) {
|
|
614
|
+
listeners.add(listener);
|
|
615
|
+
return () => listeners.delete(listener);
|
|
616
|
+
},
|
|
617
|
+
getSnapshot() {
|
|
618
|
+
if (dirty) {
|
|
619
|
+
const next = [];
|
|
620
|
+
entries.forEach((entry, id) => next.push({ id, ...entry }));
|
|
621
|
+
snapshot = next;
|
|
622
|
+
dirty = false;
|
|
623
|
+
}
|
|
624
|
+
return snapshot;
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
}
|
|
443
628
|
function CursorCoordinatesOverlay({ map }) {
|
|
444
629
|
const [coords, setCoords] = useState(null);
|
|
445
630
|
useEffect(() => {
|
|
@@ -481,6 +666,45 @@ function CursorCoordinatesOverlay({ map }) {
|
|
|
481
666
|
}
|
|
482
667
|
);
|
|
483
668
|
}
|
|
669
|
+
const NO_IMPORTS = Object.freeze([]);
|
|
670
|
+
const getServerSnapshot = () => NO_IMPORTS;
|
|
671
|
+
function IngestProgressOverlay({
|
|
672
|
+
store,
|
|
673
|
+
bottomPx
|
|
674
|
+
}) {
|
|
675
|
+
const entries = useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot);
|
|
676
|
+
if (entries.length === 0) return null;
|
|
677
|
+
return /* @__PURE__ */ jsx(
|
|
678
|
+
"div",
|
|
679
|
+
{
|
|
680
|
+
className: "absolute left-1/2 z-10 flex -translate-x-1/2 flex-col gap-1 pointer-events-none",
|
|
681
|
+
style: { bottom: bottomPx },
|
|
682
|
+
"data-testid": "ingest-progress",
|
|
683
|
+
children: entries.map((entry) => /* @__PURE__ */ jsxs(
|
|
684
|
+
"div",
|
|
685
|
+
{
|
|
686
|
+
className: "rounded-md border bg-background/90 px-3 py-1.5 text-xs text-muted-foreground shadow-md",
|
|
687
|
+
children: [
|
|
688
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
689
|
+
"Importing ",
|
|
690
|
+
entry.label,
|
|
691
|
+
"…",
|
|
692
|
+
entry.total !== null ? ` ${entry.received.toLocaleString()} / ${entry.total.toLocaleString()} features` : ""
|
|
693
|
+
] }),
|
|
694
|
+
entry.total !== null && entry.total > 0 && /* @__PURE__ */ jsx("div", { className: "mt-1 h-1 w-48 overflow-hidden rounded bg-muted", children: /* @__PURE__ */ jsx(
|
|
695
|
+
"div",
|
|
696
|
+
{
|
|
697
|
+
className: "h-full bg-primary",
|
|
698
|
+
style: { width: `${Math.min(100, entry.received / entry.total * 100)}%` }
|
|
699
|
+
}
|
|
700
|
+
) })
|
|
701
|
+
]
|
|
702
|
+
},
|
|
703
|
+
entry.id
|
|
704
|
+
))
|
|
705
|
+
}
|
|
706
|
+
);
|
|
707
|
+
}
|
|
484
708
|
const ICONS = [
|
|
485
709
|
// Location & Places
|
|
486
710
|
{ id: "map-pin", emoji: "📍", name: "Map Pin", category: "places" },
|
|
@@ -9629,6 +9853,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9629
9853
|
map.current.flyTo({ center: center.geometry.coordinates });
|
|
9630
9854
|
},
|
|
9631
9855
|
listLayers: () => [...layersRef.current],
|
|
9856
|
+
// Worker parse + streamed transfer + the canvas progress overlay, with
|
|
9857
|
+
// layer creation left to the host (see MapEditorHandle docs).
|
|
9858
|
+
parseGeoJSONText: (label, text) => ingestWithProgress(label, text, { idStrategy: "preserve" }),
|
|
9632
9859
|
addLayer: (name, geojson, options) => {
|
|
9633
9860
|
if (!isMapLoadedRef.current) return "";
|
|
9634
9861
|
if (options == null ? void 0 : options.recordHistory) saveStateForUndo(`add layer "${name}"`);
|
|
@@ -12766,10 +12993,22 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
12766
12993
|
duration: 1e3
|
|
12767
12994
|
});
|
|
12768
12995
|
}, [layers, toast]);
|
|
12996
|
+
const [ingestProgressStore] = useState(createIngestProgressStore);
|
|
12997
|
+
const ingestWithProgress = useCallback(async (label, input, options) => {
|
|
12998
|
+
const progress = ingestProgressStore.begin(label);
|
|
12999
|
+
try {
|
|
13000
|
+
return await getSharedIngestClient().ingest(input, options, {
|
|
13001
|
+
onHead: (summary) => progress.setTotal(summary.featureCount),
|
|
13002
|
+
onProgress: (received) => progress.update(received)
|
|
13003
|
+
});
|
|
13004
|
+
} finally {
|
|
13005
|
+
progress.end();
|
|
13006
|
+
}
|
|
13007
|
+
}, [ingestProgressStore]);
|
|
12769
13008
|
const loadGeoJSONFile = useCallback(async (file, requestedTargetLayerId, createNewLayer) => {
|
|
12770
13009
|
let result;
|
|
12771
13010
|
try {
|
|
12772
|
-
result = await
|
|
13011
|
+
result = await ingestWithProgress(file.name, file, {
|
|
12773
13012
|
idStrategy: "uuid-fallback",
|
|
12774
13013
|
emptyIsError: true
|
|
12775
13014
|
});
|
|
@@ -12908,7 +13147,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
12908
13147
|
title: "GeoJSON loaded",
|
|
12909
13148
|
description: `Added ${normalizedFeatures.length} features${reprojectMsg}${!(targetLayer == null ? void 0 : targetLayer.visible) ? " (layer hidden)" : ""}`
|
|
12910
13149
|
});
|
|
12911
|
-
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad]);
|
|
13150
|
+
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad, ingestWithProgress]);
|
|
12912
13151
|
const handleFileChange = useCallback((e) => {
|
|
12913
13152
|
var _a;
|
|
12914
13153
|
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
@@ -12925,7 +13164,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
12925
13164
|
const startedAt = performance.now();
|
|
12926
13165
|
let result;
|
|
12927
13166
|
try {
|
|
12928
|
-
result = await
|
|
13167
|
+
result = await ingestWithProgress(name, input, { idStrategy: "layer-index", layerId });
|
|
12929
13168
|
} catch (error) {
|
|
12930
13169
|
toast({
|
|
12931
13170
|
title: "Failed to load GeoJSON",
|
|
@@ -12992,7 +13231,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
12992
13231
|
title: "Layer added",
|
|
12993
13232
|
description: `Created "${newLayer.name}" with ${addedIds.length} features${reprojectMsg} (high-performance)`
|
|
12994
13233
|
});
|
|
12995
|
-
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad]);
|
|
13234
|
+
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad, ingestWithProgress]);
|
|
12996
13235
|
const handleDropGeoJSON = useCallback((name, data) => {
|
|
12997
13236
|
void ingestDroppedLayer(name, data);
|
|
12998
13237
|
}, [ingestDroppedLayer]);
|
|
@@ -13013,7 +13252,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
13013
13252
|
prevTimelineEnabledRef.current = isNowEnabled;
|
|
13014
13253
|
if (!isNowEnabled || !timelineStore.hasTemporalData) {
|
|
13015
13254
|
timelineVisibleIdsRef.current = null;
|
|
13016
|
-
scheduleSync();
|
|
13255
|
+
scheduleSync("timeline");
|
|
13017
13256
|
} else if (!wasEnabled && isNowEnabled) {
|
|
13018
13257
|
updateTimelineStore();
|
|
13019
13258
|
}
|
|
@@ -13868,6 +14107,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
13868
14107
|
}
|
|
13869
14108
|
),
|
|
13870
14109
|
/* @__PURE__ */ jsx(CursorCoordinatesOverlay, { map: isMapLoaded ? map.current : null }),
|
|
14110
|
+
/* @__PURE__ */ jsx(
|
|
14111
|
+
IngestProgressOverlay,
|
|
14112
|
+
{
|
|
14113
|
+
store: ingestProgressStore,
|
|
14114
|
+
bottomPx: timelineStore.isEnabled ? TIMEBAR_HEIGHT + TIMEBAR_BOTTOM_OFFSET + 8 : 32
|
|
14115
|
+
}
|
|
14116
|
+
),
|
|
13871
14117
|
/* @__PURE__ */ jsx(
|
|
13872
14118
|
"input",
|
|
13873
14119
|
{
|