@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.cjs
CHANGED
|
@@ -117,7 +117,7 @@ function featureCollectionBlobParts(collection, options) {
|
|
|
117
117
|
if (pending.length > 0) parts.push(pending.join(""));
|
|
118
118
|
return parts;
|
|
119
119
|
}
|
|
120
|
-
const ingestWorkerSource = '"use strict";(()=>{function
|
|
120
|
+
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';
|
|
121
121
|
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");
|
|
122
122
|
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");
|
|
123
123
|
proj4.defs("EPSG:32630", "+proj=utm +zone=30 +datum=WGS84 +units=m +no_defs");
|
|
@@ -266,7 +266,11 @@ function runIngestPipeline(source, options) {
|
|
|
266
266
|
if (startDate || endDate) hasTemporal = true;
|
|
267
267
|
features.push({
|
|
268
268
|
...f,
|
|
269
|
-
id
|
|
269
|
+
// Omit the key rather than set `id: undefined` ('preserve' + id-less
|
|
270
|
+
// feature): an own undefined key survives structured clone but is
|
|
271
|
+
// dropped by JSON chunks, so it would make the transfer encoding
|
|
272
|
+
// observable. Never undefined for the other strategies.
|
|
273
|
+
...id !== void 0 && { id },
|
|
270
274
|
properties: {
|
|
271
275
|
...props,
|
|
272
276
|
startDate: (startDate == null ? void 0 : startDate.toISOString()) || null,
|
|
@@ -288,6 +292,9 @@ function runIngestPipeline(source, options) {
|
|
|
288
292
|
...layerMetadata && { layerMetadata }
|
|
289
293
|
};
|
|
290
294
|
}
|
|
295
|
+
function decodeChunkPayload(payload) {
|
|
296
|
+
return typeof payload === "string" ? JSON.parse(payload) : payload;
|
|
297
|
+
}
|
|
291
298
|
const fromStorage = (() => {
|
|
292
299
|
var _a;
|
|
293
300
|
try {
|
|
@@ -365,7 +372,10 @@ function createWorkerPort() {
|
|
|
365
372
|
return null;
|
|
366
373
|
}
|
|
367
374
|
}
|
|
368
|
-
const
|
|
375
|
+
const INGEST_STALL_TIMEOUT_MS = 12e4;
|
|
376
|
+
function assembleStreamResult(stream) {
|
|
377
|
+
return finalizeReprojection({ kind: "features", ...stream.summary, features: stream.features });
|
|
378
|
+
}
|
|
369
379
|
function createIngestClient(portFactory = createWorkerPort) {
|
|
370
380
|
let port = null;
|
|
371
381
|
let portUnavailable = false;
|
|
@@ -383,6 +393,138 @@ function createIngestClient(portFactory = createWorkerPort) {
|
|
|
383
393
|
port == null ? void 0 : port.terminate();
|
|
384
394
|
port = null;
|
|
385
395
|
};
|
|
396
|
+
const armWatchdog = (request) => {
|
|
397
|
+
clearTimeout(request.timeout);
|
|
398
|
+
request.timeout = setTimeout(() => {
|
|
399
|
+
console.warn(
|
|
400
|
+
`[map-component] Ingest worker unresponsive for "${request.label}" after ${INGEST_STALL_TIMEOUT_MS}ms; it will be respawned on next use.`
|
|
401
|
+
);
|
|
402
|
+
abandonPort("Ingest worker unresponsive — the file could not be parsed");
|
|
403
|
+
}, INGEST_STALL_TIMEOUT_MS);
|
|
404
|
+
};
|
|
405
|
+
const callHook = (request, invoke) => {
|
|
406
|
+
if (!request.hooks) return;
|
|
407
|
+
try {
|
|
408
|
+
invoke(request.hooks);
|
|
409
|
+
} catch (err) {
|
|
410
|
+
console.warn("[map-component] Ingest stream hook threw; progress reporting disabled for this request.", err);
|
|
411
|
+
request.hooks = void 0;
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
const settle = (id, request) => {
|
|
415
|
+
pending.delete(id);
|
|
416
|
+
clearTimeout(request.timeout);
|
|
417
|
+
};
|
|
418
|
+
const handleChunk = (activePort, request, msg) => {
|
|
419
|
+
const stream = request.stream;
|
|
420
|
+
if (!stream || msg.seq !== stream.nextSeq) {
|
|
421
|
+
abandonPort("Ingest worker sent an out-of-order chunk");
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
armWatchdog(request);
|
|
425
|
+
const features = decodeChunkPayload(msg.payload);
|
|
426
|
+
features.forEach((f) => stream.features.push(f));
|
|
427
|
+
stream.nextSeq += 1;
|
|
428
|
+
callHook(request, (hooks) => {
|
|
429
|
+
var _a;
|
|
430
|
+
return (_a = hooks.onProgress) == null ? void 0 : _a.call(hooks, stream.features.length, stream.summary.featureCount);
|
|
431
|
+
});
|
|
432
|
+
activePort.post({ kind: "ack", id: msg.id, seq: msg.seq });
|
|
433
|
+
};
|
|
434
|
+
const handleMessage = (activePort, msg) => {
|
|
435
|
+
const request = pending.get(msg.id);
|
|
436
|
+
if (!request) return;
|
|
437
|
+
switch (msg.kind) {
|
|
438
|
+
case "result": {
|
|
439
|
+
if (request.stream) {
|
|
440
|
+
abandonPort("Ingest worker sent a single-shot result mid-stream");
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (!msg.ok) {
|
|
444
|
+
settle(msg.id, request);
|
|
445
|
+
mapPerfLog("ingest", `worker request "${request.label}" finished`, {
|
|
446
|
+
ms: Math.round(performance.now() - request.startedAt),
|
|
447
|
+
ok: false
|
|
448
|
+
});
|
|
449
|
+
request.reject(new Error(msg.error));
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
let finalized;
|
|
453
|
+
try {
|
|
454
|
+
finalized = finalizeReprojection(msg.result);
|
|
455
|
+
} catch (err) {
|
|
456
|
+
settle(msg.id, request);
|
|
457
|
+
request.reject(err instanceof Error ? err : new Error(String(err)));
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
settle(msg.id, request);
|
|
461
|
+
mapPerfLog("ingest", `worker request "${request.label}" finished`, {
|
|
462
|
+
ms: Math.round(performance.now() - request.startedAt),
|
|
463
|
+
ok: true
|
|
464
|
+
});
|
|
465
|
+
request.resolve(finalized);
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
case "head":
|
|
469
|
+
if (request.stream) {
|
|
470
|
+
abandonPort("Ingest worker restarted a stream mid-request");
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
armWatchdog(request);
|
|
474
|
+
request.stream = {
|
|
475
|
+
summary: msg.summary,
|
|
476
|
+
features: [],
|
|
477
|
+
nextSeq: 0
|
|
478
|
+
};
|
|
479
|
+
callHook(request, (hooks) => {
|
|
480
|
+
var _a;
|
|
481
|
+
return (_a = hooks.onHead) == null ? void 0 : _a.call(hooks, msg.summary);
|
|
482
|
+
});
|
|
483
|
+
return;
|
|
484
|
+
case "chunk":
|
|
485
|
+
try {
|
|
486
|
+
handleChunk(activePort, request, msg);
|
|
487
|
+
} catch (err) {
|
|
488
|
+
console.warn("[map-component] Ingest chunk could not be processed; abandoning the worker.", err);
|
|
489
|
+
abandonPort("Ingest worker sent an unreadable chunk");
|
|
490
|
+
}
|
|
491
|
+
return;
|
|
492
|
+
case "done": {
|
|
493
|
+
const stream = request.stream;
|
|
494
|
+
if (!stream) {
|
|
495
|
+
abandonPort("Ingest worker completed a stream that never started");
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
if (msg.chunkCount !== stream.nextSeq) {
|
|
499
|
+
abandonPort("Ingest worker stream ended with missing chunks");
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
let assembled;
|
|
503
|
+
try {
|
|
504
|
+
assembled = assembleStreamResult(stream);
|
|
505
|
+
} catch (err) {
|
|
506
|
+
settle(msg.id, request);
|
|
507
|
+
request.reject(err instanceof Error ? err : new Error(String(err)));
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
settle(msg.id, request);
|
|
511
|
+
mapPerfLog("ingest", `worker request "${request.label}" streamed`, {
|
|
512
|
+
ms: Math.round(performance.now() - request.startedAt),
|
|
513
|
+
features: stream.features.length,
|
|
514
|
+
chunks: msg.chunkCount
|
|
515
|
+
});
|
|
516
|
+
request.resolve(assembled);
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
case "error":
|
|
520
|
+
settle(msg.id, request);
|
|
521
|
+
mapPerfLog("ingest", `worker request "${request.label}" failed mid-stream`, {
|
|
522
|
+
ms: Math.round(performance.now() - request.startedAt)
|
|
523
|
+
});
|
|
524
|
+
request.reject(new Error(msg.message));
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
};
|
|
386
528
|
const ensurePort = () => {
|
|
387
529
|
if (portUnavailable || port) return port;
|
|
388
530
|
try {
|
|
@@ -394,22 +536,9 @@ function createIngestClient(portFactory = createWorkerPort) {
|
|
|
394
536
|
portUnavailable = true;
|
|
395
537
|
return null;
|
|
396
538
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
pending.delete(msg.id);
|
|
401
|
-
clearTimeout(request.timeout);
|
|
402
|
-
mapPerfLog("ingest", `worker request "${request.label}" finished`, {
|
|
403
|
-
ms: Math.round(performance.now() - request.startedAt),
|
|
404
|
-
ok: msg.ok
|
|
405
|
-
});
|
|
406
|
-
if (msg.ok) {
|
|
407
|
-
request.resolve(finalizeReprojection(msg.result));
|
|
408
|
-
} else {
|
|
409
|
-
request.reject(new Error(msg.error));
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
port.onError((err) => {
|
|
539
|
+
const activePort = port;
|
|
540
|
+
activePort.onMessage((msg) => handleMessage(activePort, msg));
|
|
541
|
+
activePort.onError((err) => {
|
|
413
542
|
console.warn("[map-component] Ingest worker crashed; it will be respawned on next use.", err);
|
|
414
543
|
abandonPort("Ingest worker crashed");
|
|
415
544
|
});
|
|
@@ -425,7 +554,7 @@ function createIngestClient(portFactory = createWorkerPort) {
|
|
|
425
554
|
return result;
|
|
426
555
|
};
|
|
427
556
|
return {
|
|
428
|
-
ingest(input, options) {
|
|
557
|
+
ingest(input, options, stream, tuning) {
|
|
429
558
|
if (typeof input === "object" && !(input instanceof Blob)) {
|
|
430
559
|
return Promise.resolve().then(
|
|
431
560
|
() => finalizeReprojection(runIngestPipeline({ type: "parsed", data: input }, options))
|
|
@@ -436,18 +565,26 @@ function createIngestClient(portFactory = createWorkerPort) {
|
|
|
436
565
|
const id = nextId++;
|
|
437
566
|
const label = input instanceof File ? input.name : typeof input === "string" ? "text" : "blob";
|
|
438
567
|
return new Promise((resolve, reject) => {
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
)
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
568
|
+
const request = {
|
|
569
|
+
resolve,
|
|
570
|
+
reject,
|
|
571
|
+
startedAt: performance.now(),
|
|
572
|
+
label,
|
|
573
|
+
hooks: stream
|
|
574
|
+
};
|
|
575
|
+
armWatchdog(request);
|
|
576
|
+
pending.set(id, request);
|
|
577
|
+
try {
|
|
578
|
+
activePort.post({
|
|
579
|
+
id,
|
|
580
|
+
source: typeof input === "string" ? { type: "text", text: input } : { type: "blob", blob: input },
|
|
581
|
+
options,
|
|
582
|
+
...tuning && { tuning }
|
|
583
|
+
});
|
|
584
|
+
} catch (err) {
|
|
585
|
+
settle(id, request);
|
|
586
|
+
throw err;
|
|
587
|
+
}
|
|
451
588
|
});
|
|
452
589
|
},
|
|
453
590
|
dispose() {
|
|
@@ -461,6 +598,54 @@ function getSharedIngestClient() {
|
|
|
461
598
|
if (!sharedClient) sharedClient = createIngestClient();
|
|
462
599
|
return sharedClient;
|
|
463
600
|
}
|
|
601
|
+
function createIngestProgressStore() {
|
|
602
|
+
const entries = /* @__PURE__ */ new Map();
|
|
603
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
604
|
+
let nextId = 0;
|
|
605
|
+
let snapshot = [];
|
|
606
|
+
let dirty = false;
|
|
607
|
+
const notify = () => {
|
|
608
|
+
dirty = true;
|
|
609
|
+
listeners.forEach((listener) => listener());
|
|
610
|
+
};
|
|
611
|
+
return {
|
|
612
|
+
begin(label) {
|
|
613
|
+
const id = nextId++;
|
|
614
|
+
entries.set(id, { label, received: 0, total: null });
|
|
615
|
+
notify();
|
|
616
|
+
return {
|
|
617
|
+
setTotal(total) {
|
|
618
|
+
const entry = entries.get(id);
|
|
619
|
+
if (!entry || entry.total === total) return;
|
|
620
|
+
entry.total = total;
|
|
621
|
+
notify();
|
|
622
|
+
},
|
|
623
|
+
update(received) {
|
|
624
|
+
const entry = entries.get(id);
|
|
625
|
+
if (!entry || entry.received === received) return;
|
|
626
|
+
entry.received = received;
|
|
627
|
+
notify();
|
|
628
|
+
},
|
|
629
|
+
end() {
|
|
630
|
+
if (entries.delete(id)) notify();
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
},
|
|
634
|
+
subscribe(listener) {
|
|
635
|
+
listeners.add(listener);
|
|
636
|
+
return () => listeners.delete(listener);
|
|
637
|
+
},
|
|
638
|
+
getSnapshot() {
|
|
639
|
+
if (dirty) {
|
|
640
|
+
const next = [];
|
|
641
|
+
entries.forEach((entry, id) => next.push({ id, ...entry }));
|
|
642
|
+
snapshot = next;
|
|
643
|
+
dirty = false;
|
|
644
|
+
}
|
|
645
|
+
return snapshot;
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
}
|
|
464
649
|
function CursorCoordinatesOverlay({ map }) {
|
|
465
650
|
const [coords, setCoords] = react.useState(null);
|
|
466
651
|
react.useEffect(() => {
|
|
@@ -502,6 +687,45 @@ function CursorCoordinatesOverlay({ map }) {
|
|
|
502
687
|
}
|
|
503
688
|
);
|
|
504
689
|
}
|
|
690
|
+
const NO_IMPORTS = Object.freeze([]);
|
|
691
|
+
const getServerSnapshot = () => NO_IMPORTS;
|
|
692
|
+
function IngestProgressOverlay({
|
|
693
|
+
store,
|
|
694
|
+
bottomPx
|
|
695
|
+
}) {
|
|
696
|
+
const entries = react.useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot);
|
|
697
|
+
if (entries.length === 0) return null;
|
|
698
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
699
|
+
"div",
|
|
700
|
+
{
|
|
701
|
+
className: "absolute left-1/2 z-10 flex -translate-x-1/2 flex-col gap-1 pointer-events-none",
|
|
702
|
+
style: { bottom: bottomPx },
|
|
703
|
+
"data-testid": "ingest-progress",
|
|
704
|
+
children: entries.map((entry) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
705
|
+
"div",
|
|
706
|
+
{
|
|
707
|
+
className: "rounded-md border bg-background/90 px-3 py-1.5 text-xs text-muted-foreground shadow-md",
|
|
708
|
+
children: [
|
|
709
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
710
|
+
"Importing ",
|
|
711
|
+
entry.label,
|
|
712
|
+
"…",
|
|
713
|
+
entry.total !== null ? ` ${entry.received.toLocaleString()} / ${entry.total.toLocaleString()} features` : ""
|
|
714
|
+
] }),
|
|
715
|
+
entry.total !== null && entry.total > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 h-1 w-48 overflow-hidden rounded bg-muted", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
716
|
+
"div",
|
|
717
|
+
{
|
|
718
|
+
className: "h-full bg-primary",
|
|
719
|
+
style: { width: `${Math.min(100, entry.received / entry.total * 100)}%` }
|
|
720
|
+
}
|
|
721
|
+
) })
|
|
722
|
+
]
|
|
723
|
+
},
|
|
724
|
+
entry.id
|
|
725
|
+
))
|
|
726
|
+
}
|
|
727
|
+
);
|
|
728
|
+
}
|
|
505
729
|
const ICONS = [
|
|
506
730
|
// Location & Places
|
|
507
731
|
{ id: "map-pin", emoji: "📍", name: "Map Pin", category: "places" },
|
|
@@ -9650,6 +9874,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
9650
9874
|
map.current.flyTo({ center: center.geometry.coordinates });
|
|
9651
9875
|
},
|
|
9652
9876
|
listLayers: () => [...layersRef.current],
|
|
9877
|
+
// Worker parse + streamed transfer + the canvas progress overlay, with
|
|
9878
|
+
// layer creation left to the host (see MapEditorHandle docs).
|
|
9879
|
+
parseGeoJSONText: (label, text) => ingestWithProgress(label, text, { idStrategy: "preserve" }),
|
|
9653
9880
|
addLayer: (name, geojson, options) => {
|
|
9654
9881
|
if (!isMapLoadedRef.current) return "";
|
|
9655
9882
|
if (options == null ? void 0 : options.recordHistory) saveStateForUndo(`add layer "${name}"`);
|
|
@@ -12787,10 +13014,22 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
12787
13014
|
duration: 1e3
|
|
12788
13015
|
});
|
|
12789
13016
|
}, [layers, toast]);
|
|
13017
|
+
const [ingestProgressStore] = react.useState(createIngestProgressStore);
|
|
13018
|
+
const ingestWithProgress = react.useCallback(async (label, input, options) => {
|
|
13019
|
+
const progress = ingestProgressStore.begin(label);
|
|
13020
|
+
try {
|
|
13021
|
+
return await getSharedIngestClient().ingest(input, options, {
|
|
13022
|
+
onHead: (summary) => progress.setTotal(summary.featureCount),
|
|
13023
|
+
onProgress: (received) => progress.update(received)
|
|
13024
|
+
});
|
|
13025
|
+
} finally {
|
|
13026
|
+
progress.end();
|
|
13027
|
+
}
|
|
13028
|
+
}, [ingestProgressStore]);
|
|
12790
13029
|
const loadGeoJSONFile = react.useCallback(async (file, requestedTargetLayerId, createNewLayer) => {
|
|
12791
13030
|
let result;
|
|
12792
13031
|
try {
|
|
12793
|
-
result = await
|
|
13032
|
+
result = await ingestWithProgress(file.name, file, {
|
|
12794
13033
|
idStrategy: "uuid-fallback",
|
|
12795
13034
|
emptyIsError: true
|
|
12796
13035
|
});
|
|
@@ -12929,7 +13168,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
12929
13168
|
title: "GeoJSON loaded",
|
|
12930
13169
|
description: `Added ${normalizedFeatures.length} features${reprojectMsg}${!(targetLayer == null ? void 0 : targetLayer.visible) ? " (layer hidden)" : ""}`
|
|
12931
13170
|
});
|
|
12932
|
-
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad]);
|
|
13171
|
+
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad, ingestWithProgress]);
|
|
12933
13172
|
const handleFileChange = react.useCallback((e) => {
|
|
12934
13173
|
var _a;
|
|
12935
13174
|
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
@@ -12946,7 +13185,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
12946
13185
|
const startedAt = performance.now();
|
|
12947
13186
|
let result;
|
|
12948
13187
|
try {
|
|
12949
|
-
result = await
|
|
13188
|
+
result = await ingestWithProgress(name, input, { idStrategy: "layer-index", layerId });
|
|
12950
13189
|
} catch (error) {
|
|
12951
13190
|
toast({
|
|
12952
13191
|
title: "Failed to load GeoJSON",
|
|
@@ -13013,7 +13252,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13013
13252
|
title: "Layer added",
|
|
13014
13253
|
description: `Created "${newLayer.name}" with ${addedIds.length} features${reprojectMsg} (high-performance)`
|
|
13015
13254
|
});
|
|
13016
|
-
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad]);
|
|
13255
|
+
}, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad, ingestWithProgress]);
|
|
13017
13256
|
const handleDropGeoJSON = react.useCallback((name, data) => {
|
|
13018
13257
|
void ingestDroppedLayer(name, data);
|
|
13019
13258
|
}, [ingestDroppedLayer]);
|
|
@@ -13034,7 +13273,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13034
13273
|
prevTimelineEnabledRef.current = isNowEnabled;
|
|
13035
13274
|
if (!isNowEnabled || !timelineStore.hasTemporalData) {
|
|
13036
13275
|
timelineVisibleIdsRef.current = null;
|
|
13037
|
-
scheduleSync();
|
|
13276
|
+
scheduleSync("timeline");
|
|
13038
13277
|
} else if (!wasEnabled && isNowEnabled) {
|
|
13039
13278
|
updateTimelineStore();
|
|
13040
13279
|
}
|
|
@@ -13889,6 +14128,13 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
13889
14128
|
}
|
|
13890
14129
|
),
|
|
13891
14130
|
/* @__PURE__ */ jsxRuntime.jsx(CursorCoordinatesOverlay, { map: isMapLoaded ? map.current : null }),
|
|
14131
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
14132
|
+
IngestProgressOverlay,
|
|
14133
|
+
{
|
|
14134
|
+
store: ingestProgressStore,
|
|
14135
|
+
bottomPx: timelineStore.isEnabled ? TIMEBAR_HEIGHT + TIMEBAR_BOTTOM_OFFSET + 8 : 32
|
|
14136
|
+
}
|
|
14137
|
+
),
|
|
13892
14138
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
13893
14139
|
"input",
|
|
13894
14140
|
{
|