@octostar/map-component 0.2.13 → 0.2.15

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.
Files changed (34) hide show
  1. package/dist/index.cjs +1127 -271
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.mjs +1130 -274
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/styles.css +4 -0
  6. package/dist/types/components/cluster-pie-chart.d.ts.map +1 -1
  7. package/dist/types/components/ingest-progress-overlay.d.ts +12 -0
  8. package/dist/types/components/ingest-progress-overlay.d.ts.map +1 -0
  9. package/dist/types/components/layers-panel.d.ts +30 -4
  10. package/dist/types/components/layers-panel.d.ts.map +1 -1
  11. package/dist/types/components/map-editor-canvas.d.ts.map +1 -1
  12. package/dist/types/index.d.ts +2 -1
  13. package/dist/types/index.d.ts.map +1 -1
  14. package/dist/types/lib/cluster-count.d.ts +43 -0
  15. package/dist/types/lib/cluster-count.d.ts.map +1 -0
  16. package/dist/types/lib/cluster-gradient.d.ts +37 -0
  17. package/dist/types/lib/cluster-gradient.d.ts.map +1 -0
  18. package/dist/types/lib/color-utils.d.ts +67 -0
  19. package/dist/types/lib/color-utils.d.ts.map +1 -1
  20. package/dist/types/lib/ingest-client.d.ts +22 -4
  21. package/dist/types/lib/ingest-client.d.ts.map +1 -1
  22. package/dist/types/lib/ingest-pipeline.d.ts +52 -1
  23. package/dist/types/lib/ingest-pipeline.d.ts.map +1 -1
  24. package/dist/types/lib/ingest-progress.d.ts +21 -0
  25. package/dist/types/lib/ingest-progress.d.ts.map +1 -0
  26. package/dist/types/lib/ingest-stream.d.ts +50 -0
  27. package/dist/types/lib/ingest-stream.d.ts.map +1 -0
  28. package/dist/types/lib/label-pinning.d.ts +31 -0
  29. package/dist/types/lib/label-pinning.d.ts.map +1 -0
  30. package/dist/types/lib/map-editor-api.d.ts +13 -0
  31. package/dist/types/lib/map-editor-api.d.ts.map +1 -1
  32. package/dist/types/lib/property-utils.d.ts +7 -0
  33. package/dist/types/lib/property-utils.d.ts.map +1 -1
  34. 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 y(e){let n=e.crs?.properties?.name,t=null;if(n){let r=n.match(/EPSG::?(\\d+)/i);r&&(t=`EPSG:${r[1]}`)}if(!t&&e.features.length>0){let r=D(e.features[0].geometry);if(r){let[o,u]=r;if(Math.abs(o)<=180&&Math.abs(u)<=90)return{sourceCRS:"EPSG:4326",needsReprojection:!1}}return{sourceCRS:null,needsReprojection:!1}}return{sourceCRS:t,needsReprojection:t!==null&&t!=="EPSG:4326"}}function D(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 b(e){return e.geometry?.type==="LineString"?e.geometry.coordinates.some(t=>t.length>=3&&t[2]!==0):e.geometry?.type==="MultiLineString"?e.geometry.coordinates.some(t=>t.some(r=>r.length>=3&&r[2]!==0)):!1}function a(e){if(!e)return null;if(e instanceof Date)return e;if(typeof e=="string"||typeof e=="number"){let n=new Date(e);return isNaN(n.getTime())?null:n}return null}function p(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 S(e){let n=a(e.startDate)||a(e.startdate)||a(e.start_date)||a(e.start_time)||a(e.date)||a(e.timestamp)||a(e.flightDate)||a(e.time)||a(e.datetime),t=a(e.endDate)||a(e.enddate)||a(e.end_date)||a(e.end_time);return n&&t&&t<n&&([n,t]=[t,n]),{startDate:n,endDate:t}}function x(){let e=globalThis.crypto?.randomUUID?.bind(globalThis.crypto);return e?e():`f-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function G(e,n,t){switch(t.idStrategy){case"preserve":return e.id;case"layer-index":return e.id!==void 0&&e.id!==null?String(e.id):`${t.layerId}-f${n}`;case"uuid-fallback":return e.id?String(e.id):x()}}function I(e,n){if(Array.isArray(e)){if(typeof e[0]=="number"){let t=e[0],r=e[1];n[0]=Math.min(n[0],t),n[1]=Math.min(n[1],r),n[2]=Math.max(n[2],t),n[3]=Math.max(n[3],r);return}for(let t of e)I(t,n)}}function h(e,n){if(e){if(e.type==="GeometryCollection"){for(let t of e.geometries)h(t,n);return}I(e.coordinates,n)}}function O(e){let n=[1/0,1/0,-1/0,-1/0];for(let t of e)h(t.geometry,n);return n.every(t=>isFinite(t))?n:null}function k(e,n){let t;if(e.type==="text")try{t=JSON.parse(e.text)}catch(s){return{kind:"error",code:"parse-error",message:s instanceof Error?s.message:"Invalid file"}}else t=e.data;if(t&&t.type==="Feature"&&(t={type:"FeatureCollection",features:[t]}),!t||t.type!=="FeatureCollection"||!Array.isArray(t.features))return{kind:"error",code:"invalid-format",message:"Invalid GeoJSON format"};if(n.emptyIsError&&t.features.length===0)return{kind:"error",code:"empty",message:"The file contains no features"};if(t["octostar:map"])return{kind:"enriched",data:t};let{sourceCRS:r,needsReprojection:o}=y(t),u=!1,l=!1,i=[];t.features.forEach((s,C)=>{let m=G(s,C,n);!l&&b(s)&&(l=!0);let d=s.properties||{};if(!p(d)){i.push(n.idStrategy==="preserve"?s:{...s,id:m});return}let{startDate:f,endDate:g}=S(d);(f||g)&&(u=!0),i.push({...s,id:m,properties:{...d,startDate:f?.toISOString()||null,endDate:g?.toISOString()||null}})});let c=t.properties?.layerMetadata;return{kind:"features",features:i,featureCount:i.length,bbox:O(i),hasTemporal:u,hasAltitude:l,reprojected:!1,sourceCRS:r,...o&&{needsReprojection:o},...c&&{layerMetadata:c}}}var R=e=>self.postMessage(e);self.onmessage=async e=>{let{id:n,source:t,options:r}=e.data;try{let o=t.type==="blob"?{type:"text",text:await t.blob.text()}:t;R({id:n,ok:!0,result:k(o,r)})}catch(o){R({id:n,ok:!1,error:o instanceof Error?o.message:String(o)})}};})();\n';
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 INGEST_TIMEOUT_MS = 12e4;
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
- port.onMessage((msg) => {
398
- const request = pending.get(msg.id);
399
- if (!request) return;
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 timeout = setTimeout(() => {
440
- console.warn(
441
- `[map-component] Ingest worker unresponsive for "${label}" after ${INGEST_TIMEOUT_MS}ms; it will be respawned on next use.`
442
- );
443
- abandonPort("Ingest worker unresponsive — the file could not be parsed");
444
- }, INGEST_TIMEOUT_MS);
445
- pending.set(id, { resolve, reject, startedAt: performance.now(), label, timeout });
446
- activePort.post({
447
- id,
448
- source: typeof input === "string" ? { type: "text", text: input } : { type: "blob", blob: input },
449
- options
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" },
@@ -2113,6 +2337,85 @@ function hashStringToColor(str) {
2113
2337
  const light = 45 + (hash >>> 16) % 18;
2114
2338
  return hslToHex(hue, sat, light);
2115
2339
  }
2340
+ const GRADIENT_RAMP = [
2341
+ "#fee5d9",
2342
+ "#fcae91",
2343
+ "#fb6a4a",
2344
+ "#de2d26",
2345
+ "#a50f15"
2346
+ ];
2347
+ const GRADIENT_FALLBACK_COLOR = "#9ca3af";
2348
+ const NUMERIC_FIELD_RATIO_THRESHOLD = 0.8;
2349
+ const NUMERIC_FIELD_COVERAGE_FLOOR = 0.3;
2350
+ function coerceFiniteNumber(raw) {
2351
+ if (typeof raw === "number") return Number.isFinite(raw) ? raw : null;
2352
+ if (typeof raw === "string" && raw.trim() !== "") {
2353
+ const n = Number(raw);
2354
+ return Number.isFinite(n) ? n : null;
2355
+ }
2356
+ return null;
2357
+ }
2358
+ function parseHexColor(hex) {
2359
+ return [
2360
+ parseInt(hex.slice(1, 3), 16),
2361
+ parseInt(hex.slice(3, 5), 16),
2362
+ parseInt(hex.slice(5, 7), 16)
2363
+ ];
2364
+ }
2365
+ function gradientColor(t, ramp = GRADIENT_RAMP) {
2366
+ const clamped = Math.max(0, Math.min(1, Number.isFinite(t) ? t : 0.5));
2367
+ const scaled = clamped * (ramp.length - 1);
2368
+ const i = Math.min(Math.floor(scaled), ramp.length - 2);
2369
+ const frac = scaled - i;
2370
+ const [r1, g1, b1] = parseHexColor(ramp[i]);
2371
+ const [r2, g2, b2] = parseHexColor(ramp[i + 1]);
2372
+ const channel = (a, b) => Math.round(a + (b - a) * frac).toString(16).padStart(2, "0");
2373
+ return `#${channel(r1, r2)}${channel(g1, g2)}${channel(b1, b2)}`;
2374
+ }
2375
+ function defaultColorScaleForField(field) {
2376
+ if (!field) return "categorical";
2377
+ return (field.numericRatio ?? 0) >= NUMERIC_FIELD_RATIO_THRESHOLD && (field.coverage ?? 0) >= NUMERIC_FIELD_COVERAGE_FLOOR ? "gradient" : "categorical";
2378
+ }
2379
+ function computeNumericRange(featureIds, getProperties, fieldName) {
2380
+ var _a;
2381
+ let min = Infinity;
2382
+ let max = -Infinity;
2383
+ for (const id of featureIds) {
2384
+ const v = coerceFiniteNumber((_a = getProperties(id)) == null ? void 0 : _a[fieldName]);
2385
+ if (v === null) continue;
2386
+ if (v < min) min = v;
2387
+ if (v > max) max = v;
2388
+ }
2389
+ return isFinite(min) ? { min, max } : null;
2390
+ }
2391
+ function resolveFeatureColor(colorConfig, properties, fallback, gradientRange) {
2392
+ if (!colorConfig) return fallback;
2393
+ if (colorConfig.mode === "fixed" && colorConfig.fixedColor) return colorConfig.fixedColor;
2394
+ if (colorConfig.mode === "field" && colorConfig.fieldName) {
2395
+ if (colorConfig.scale === "gradient") {
2396
+ const value = coerceFiniteNumber(properties == null ? void 0 : properties[colorConfig.fieldName]);
2397
+ if (value === null || !gradientRange) return GRADIENT_FALLBACK_COLOR;
2398
+ const t = gradientRange.max > gradientRange.min ? (value - gradientRange.min) / (gradientRange.max - gradientRange.min) : 0.5;
2399
+ return gradientColor(t);
2400
+ }
2401
+ if (properties) {
2402
+ const key = categoricalKey(properties[colorConfig.fieldName]);
2403
+ if (key !== null) return hashStringToColor(key);
2404
+ }
2405
+ }
2406
+ return fallback;
2407
+ }
2408
+ function formatGradientStop(value) {
2409
+ if (!Number.isFinite(value)) return "";
2410
+ const abs = Math.abs(value);
2411
+ if (abs >= 1e4) {
2412
+ return new Intl.NumberFormat("en-US", { notation: "compact", maximumFractionDigits: 1 }).format(value);
2413
+ }
2414
+ if (abs > 0 && abs < 1) {
2415
+ return new Intl.NumberFormat("en-US", { maximumSignificantDigits: 3 }).format(value);
2416
+ }
2417
+ return new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 }).format(value);
2418
+ }
2116
2419
  const MAP_STYLES = [
2117
2420
  { id: "streets", name: "Streets", icon: lucideReact.Map },
2118
2421
  { id: "satellite", name: "Satellite", icon: lucideReact.Satellite },
@@ -2201,6 +2504,38 @@ function ColorByFieldLegend({
2201
2504
  }
2202
2505
  );
2203
2506
  }
2507
+ function ColorGradientLegend({
2508
+ layerId,
2509
+ min,
2510
+ max,
2511
+ sampled
2512
+ }) {
2513
+ const degenerate = min === max;
2514
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2515
+ "div",
2516
+ {
2517
+ className: "mt-1 rounded border border-border/50 bg-background/40 p-1.5",
2518
+ "data-testid": `legend-gradient-${layerId}`,
2519
+ children: [
2520
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-[10px] uppercase tracking-wide text-muted-foreground mb-1", children: [
2521
+ "Legend",
2522
+ sampled ? " (sampled)" : ""
2523
+ ] }),
2524
+ /* @__PURE__ */ jsxRuntime.jsx(
2525
+ "div",
2526
+ {
2527
+ className: "h-2.5 rounded-sm border border-black/10",
2528
+ style: { background: degenerate ? gradientColor(0.5) : `linear-gradient(to right, ${GRADIENT_RAMP.join(", ")})` }
2529
+ }
2530
+ ),
2531
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-between text-[11px] text-muted-foreground tabular-nums mt-0.5", children: degenerate ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mx-auto", children: formatGradientStop(min) }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2532
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: formatGradientStop(min) }),
2533
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: formatGradientStop(max) })
2534
+ ] }) })
2535
+ ]
2536
+ }
2537
+ );
2538
+ }
2204
2539
  function LayersPanel({
2205
2540
  layers,
2206
2541
  onAddLayer,
@@ -2339,7 +2674,7 @@ function LayersPanel({
2339
2674
  });
2340
2675
  }, [onRemoveLayer]);
2341
2676
  const renderLayerItem = (layer) => {
2342
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba;
2677
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da;
2343
2678
  const customCount = featureCountProvider == null ? void 0 : featureCountProvider(layer.id);
2344
2679
  const featureCount = customCount != null ? customCount : getFeatureCount(layer.id);
2345
2680
  const isExpanded = expandedLayers.has(layer.id);
@@ -2452,6 +2787,41 @@ function LayersPanel({
2452
2787
  label: "Save GeoJSON to desktop",
2453
2788
  onClick: () => onSaveLayerGeoJSON(layer.id)
2454
2789
  },
2790
+ ...onUpdateVisualConfig ? [
2791
+ { type: "divider" },
2792
+ {
2793
+ key: "never-hide-labels",
2794
+ label: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-1.5 py-1", onClick: (e) => e.stopPropagation(), children: [
2795
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
2796
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
2797
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Type, { className: "w-[18px] h-[18px]" }),
2798
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm", children: "Never hide labels" })
2799
+ ] }),
2800
+ /* @__PURE__ */ jsxRuntime.jsx(
2801
+ antd.Switch,
2802
+ {
2803
+ size: "small",
2804
+ disabled: (_b = (_a = layer.visualConfig) == null ? void 0 : _a.label) == null ? void 0 : _b.hidden,
2805
+ checked: !!((_d = (_c = layer.visualConfig) == null ? void 0 : _c.label) == null ? void 0 : _d.neverHide),
2806
+ onChange: (checked) => {
2807
+ var _a2, _b2, _c2;
2808
+ return onUpdateVisualConfig(layer.id, {
2809
+ ...layer.visualConfig,
2810
+ label: {
2811
+ ...(_a2 = layer.visualConfig) == null ? void 0 : _a2.label,
2812
+ mode: ((_c2 = (_b2 = layer.visualConfig) == null ? void 0 : _b2.label) == null ? void 0 : _c2.mode) ?? "standard",
2813
+ neverHide: checked
2814
+ }
2815
+ });
2816
+ },
2817
+ "data-testid": `switch-never-hide-labels-${layer.id}`
2818
+ }
2819
+ )
2820
+ ] }),
2821
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-muted-foreground mt-1", children: ((_f = (_e = layer.visualConfig) == null ? void 0 : _e.label) == null ? void 0 : _f.hidden) ? "Labels are turned off for this layer" : "Show every label even when the map is crowded" })
2822
+ ] })
2823
+ }
2824
+ ] : [],
2455
2825
  ...onFitToLayerFeatures && (typeof featureCount === "string" ? featureCount.length > 0 : featureCount > 0) ? [
2456
2826
  { type: "divider" },
2457
2827
  {
@@ -2504,14 +2874,14 @@ function LayersPanel({
2504
2874
  ]
2505
2875
  }
2506
2876
  ),
2507
- (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_a = layer.metadata) == null ? void 0 : _a.hidePointFeatures) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1 p-1.5 bg-muted/30 rounded-md", children: [
2877
+ (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_g = layer.metadata) == null ? void 0 : _g.hidePointFeatures) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1 p-1.5 bg-muted/30 rounded-md", children: [
2508
2878
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-1.5 text-xs font-medium", children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: "Point Features" }) }),
2509
2879
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
2510
2880
  /* @__PURE__ */ jsxRuntime.jsx(
2511
2881
  antd.Switch,
2512
2882
  {
2513
2883
  size: "small",
2514
- checked: ((_b = layer.traceConfig) == null ? void 0 : _b.enabled) ?? false,
2884
+ checked: ((_h = layer.traceConfig) == null ? void 0 : _h.enabled) ?? false,
2515
2885
  onChange: (checked) => {
2516
2886
  var _a2;
2517
2887
  return onUpdateTraceConfig(layer.id, {
@@ -2524,7 +2894,7 @@ function LayersPanel({
2524
2894
  ),
2525
2895
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs", children: "Trace Lines" })
2526
2896
  ] }),
2527
- ((_c = layer.traceConfig) == null ? void 0 : _c.enabled) && /* @__PURE__ */ jsxRuntime.jsx(
2897
+ ((_i = layer.traceConfig) == null ? void 0 : _i.enabled) && /* @__PURE__ */ jsxRuntime.jsx(
2528
2898
  antd.Select,
2529
2899
  {
2530
2900
  size: "small",
@@ -2550,7 +2920,7 @@ function LayersPanel({
2550
2920
  antd.Switch,
2551
2921
  {
2552
2922
  size: "small",
2553
- checked: ((_d = layer.heatmapConfig) == null ? void 0 : _d.enabled) ?? false,
2923
+ checked: ((_j = layer.heatmapConfig) == null ? void 0 : _j.enabled) ?? false,
2554
2924
  onChange: (checked) => {
2555
2925
  var _a2, _b2;
2556
2926
  return onUpdateHeatmapConfig(layer.id, {
@@ -2564,7 +2934,7 @@ function LayersPanel({
2564
2934
  ),
2565
2935
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs", children: "Heatmap" })
2566
2936
  ] }),
2567
- ((_e = layer.heatmapConfig) == null ? void 0 : _e.enabled) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1 pl-4", children: [
2937
+ ((_k = layer.heatmapConfig) == null ? void 0 : _k.enabled) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1 pl-4", children: [
2568
2938
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1", children: [
2569
2939
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[10px] w-12", children: "Intensity" }),
2570
2940
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -2608,10 +2978,11 @@ function LayersPanel({
2608
2978
  antd.Switch,
2609
2979
  {
2610
2980
  size: "small",
2611
- checked: ((_f = layer.clusterConfig) == null ? void 0 : _f.enabled) ?? false,
2981
+ checked: ((_l = layer.clusterConfig) == null ? void 0 : _l.enabled) ?? false,
2612
2982
  onChange: (checked) => {
2613
2983
  var _a2, _b2;
2614
2984
  return onUpdateClusterConfig(layer.id, {
2985
+ ...layer.clusterConfig,
2615
2986
  enabled: checked,
2616
2987
  groupByField: ((_a2 = layer.clusterConfig) == null ? void 0 : _a2.groupByField) ?? null,
2617
2988
  showPointDots: ((_b2 = layer.clusterConfig) == null ? void 0 : _b2.showPointDots) ?? false
@@ -2622,7 +2993,7 @@ function LayersPanel({
2622
2993
  ),
2623
2994
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs", children: "Clustering" })
2624
2995
  ] }),
2625
- ((_g = layer.clusterConfig) == null ? void 0 : _g.enabled) && getLayerFields && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1 pl-4", children: [
2996
+ ((_m = layer.clusterConfig) == null ? void 0 : _m.enabled) && getLayerFields && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1 pl-4", children: [
2626
2997
  /* @__PURE__ */ jsxRuntime.jsx(
2627
2998
  antd.Select,
2628
2999
  {
@@ -2655,6 +3026,53 @@ function LayersPanel({
2655
3026
  }
2656
3027
  ),
2657
3028
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[10px]", children: "Show point dots" })
3029
+ ] }),
3030
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
3031
+ /* @__PURE__ */ jsxRuntime.jsx(
3032
+ antd.Switch,
3033
+ {
3034
+ size: "small",
3035
+ checked: layer.clusterConfig.countByFieldEnabled ?? false,
3036
+ onChange: (checked) => onUpdateClusterConfig(layer.id, {
3037
+ ...layer.clusterConfig,
3038
+ countByFieldEnabled: checked
3039
+ }),
3040
+ "data-testid": `switch-cluster-count-by-${layer.id}`
3041
+ }
3042
+ ),
3043
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[10px]", children: "Count by field" })
3044
+ ] }),
3045
+ layer.clusterConfig.countByFieldEnabled && /* @__PURE__ */ jsxRuntime.jsx(
3046
+ antd.Select,
3047
+ {
3048
+ size: "small",
3049
+ value: layer.clusterConfig.countByField ?? void 0,
3050
+ onChange: (val) => onUpdateClusterConfig(layer.id, {
3051
+ ...layer.clusterConfig,
3052
+ countByField: val
3053
+ }),
3054
+ className: "w-full text-xs",
3055
+ placeholder: "Select numeric field...",
3056
+ showSearch: true,
3057
+ optionFilterProp: "label",
3058
+ options: getLayerFields(layer.id).filter((f) => f.isNumeric).map((f) => ({ value: f.name, label: f.name })),
3059
+ "data-testid": `select-cluster-count-field-${layer.id}`
3060
+ }
3061
+ ),
3062
+ !layer.clusterConfig.groupByField && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
3063
+ /* @__PURE__ */ jsxRuntime.jsx(
3064
+ antd.Switch,
3065
+ {
3066
+ size: "small",
3067
+ checked: layer.clusterConfig.bubbleGradient ?? false,
3068
+ onChange: (checked) => onUpdateClusterConfig(layer.id, {
3069
+ ...layer.clusterConfig,
3070
+ bubbleGradient: checked
3071
+ }),
3072
+ "data-testid": `switch-cluster-gradient-${layer.id}`
3073
+ }
3074
+ ),
3075
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[10px]", children: "Color bubbles by value" })
2658
3076
  ] })
2659
3077
  ] })
2660
3078
  ] })
@@ -2691,7 +3109,7 @@ function LayersPanel({
2691
3109
  antd.Switch,
2692
3110
  {
2693
3111
  size: "small",
2694
- checked: !((_i = (_h = layer.visualConfig) == null ? void 0 : _h.label) == null ? void 0 : _i.hidden),
3112
+ checked: !((_o = (_n = layer.visualConfig) == null ? void 0 : _n.label) == null ? void 0 : _o.hidden),
2695
3113
  onChange: (checked) => {
2696
3114
  var _a2, _b2, _c2;
2697
3115
  return onUpdateVisualConfig(layer.id, {
@@ -2707,8 +3125,8 @@ function LayersPanel({
2707
3125
  antd.Select,
2708
3126
  {
2709
3127
  size: "small",
2710
- disabled: (_k = (_j = layer.visualConfig) == null ? void 0 : _j.label) == null ? void 0 : _k.hidden,
2711
- value: ((_m = (_l = layer.visualConfig) == null ? void 0 : _l.label) == null ? void 0 : _m.mode) ?? "standard",
3128
+ disabled: (_q = (_p = layer.visualConfig) == null ? void 0 : _p.label) == null ? void 0 : _q.hidden,
3129
+ value: ((_s = (_r = layer.visualConfig) == null ? void 0 : _r.label) == null ? void 0 : _s.mode) ?? "standard",
2712
3130
  onChange: (val) => {
2713
3131
  var _a2;
2714
3132
  return onUpdateVisualConfig(layer.id, {
@@ -2725,15 +3143,18 @@ function LayersPanel({
2725
3143
  "data-testid": `select-label-mode-${layer.id}`
2726
3144
  }
2727
3145
  ),
2728
- ((_o = (_n = layer.visualConfig) == null ? void 0 : _n.label) == null ? void 0 : _o.mode) === "field" && /* @__PURE__ */ jsxRuntime.jsx(
3146
+ ((_u = (_t = layer.visualConfig) == null ? void 0 : _t.label) == null ? void 0 : _u.mode) === "field" && /* @__PURE__ */ jsxRuntime.jsx(
2729
3147
  antd.Select,
2730
3148
  {
2731
3149
  size: "small",
2732
- value: ((_q = (_p = layer.visualConfig) == null ? void 0 : _p.label) == null ? void 0 : _q.fieldName) ?? "",
2733
- onChange: (val) => onUpdateVisualConfig(layer.id, {
2734
- ...layer.visualConfig,
2735
- label: { mode: "field", fieldName: val }
2736
- }),
3150
+ value: ((_w = (_v = layer.visualConfig) == null ? void 0 : _v.label) == null ? void 0 : _w.fieldName) ?? "",
3151
+ onChange: (val) => {
3152
+ var _a2;
3153
+ return onUpdateVisualConfig(layer.id, {
3154
+ ...layer.visualConfig,
3155
+ label: { ...(_a2 = layer.visualConfig) == null ? void 0 : _a2.label, mode: "field", fieldName: val }
3156
+ });
3157
+ },
2737
3158
  className: "w-full text-sm",
2738
3159
  placeholder: "Select field...",
2739
3160
  showSearch: true,
@@ -2742,15 +3163,18 @@ function LayersPanel({
2742
3163
  "data-testid": `select-label-field-${layer.id}`
2743
3164
  }
2744
3165
  ),
2745
- ((_s = (_r = layer.visualConfig) == null ? void 0 : _r.label) == null ? void 0 : _s.mode) === "fixed" && /* @__PURE__ */ jsxRuntime.jsx(
3166
+ ((_y = (_x = layer.visualConfig) == null ? void 0 : _x.label) == null ? void 0 : _y.mode) === "fixed" && /* @__PURE__ */ jsxRuntime.jsx(
2746
3167
  antd.Input,
2747
3168
  {
2748
3169
  size: "small",
2749
- value: ((_u = (_t = layer.visualConfig) == null ? void 0 : _t.label) == null ? void 0 : _u.fixedText) ?? "",
2750
- onChange: (e) => onUpdateVisualConfig(layer.id, {
2751
- ...layer.visualConfig,
2752
- label: { mode: "fixed", fixedText: e.target.value }
2753
- }),
3170
+ value: ((_A = (_z = layer.visualConfig) == null ? void 0 : _z.label) == null ? void 0 : _A.fixedText) ?? "",
3171
+ onChange: (e) => {
3172
+ var _a2;
3173
+ return onUpdateVisualConfig(layer.id, {
3174
+ ...layer.visualConfig,
3175
+ label: { ...(_a2 = layer.visualConfig) == null ? void 0 : _a2.label, mode: "fixed", fixedText: e.target.value }
3176
+ });
3177
+ },
2754
3178
  placeholder: "Enter label text...",
2755
3179
  className: "text-sm",
2756
3180
  "data-testid": `input-label-text-${layer.id}`
@@ -2764,7 +3188,7 @@ function LayersPanel({
2764
3188
  antd.Select,
2765
3189
  {
2766
3190
  size: "small",
2767
- value: ((_w = (_v = layer.visualConfig) == null ? void 0 : _v.size) == null ? void 0 : _w.mode) ?? "standard",
3191
+ value: ((_C = (_B = layer.visualConfig) == null ? void 0 : _B.size) == null ? void 0 : _C.mode) ?? "standard",
2768
3192
  onChange: (val) => onUpdateVisualConfig(layer.id, {
2769
3193
  ...layer.visualConfig,
2770
3194
  size: { mode: val }
@@ -2778,11 +3202,11 @@ function LayersPanel({
2778
3202
  "data-testid": `select-size-mode-${layer.id}`
2779
3203
  }
2780
3204
  ),
2781
- ((_y = (_x = layer.visualConfig) == null ? void 0 : _x.size) == null ? void 0 : _y.mode) === "field" && /* @__PURE__ */ jsxRuntime.jsx(
3205
+ ((_E = (_D = layer.visualConfig) == null ? void 0 : _D.size) == null ? void 0 : _E.mode) === "field" && /* @__PURE__ */ jsxRuntime.jsx(
2782
3206
  antd.Select,
2783
3207
  {
2784
3208
  size: "small",
2785
- value: ((_A = (_z = layer.visualConfig) == null ? void 0 : _z.size) == null ? void 0 : _A.fieldName) ?? "",
3209
+ value: ((_G = (_F = layer.visualConfig) == null ? void 0 : _F.size) == null ? void 0 : _G.fieldName) ?? "",
2786
3210
  onChange: (val) => onUpdateVisualConfig(layer.id, {
2787
3211
  ...layer.visualConfig,
2788
3212
  size: { mode: "field", fieldName: val }
@@ -2795,11 +3219,11 @@ function LayersPanel({
2795
3219
  "data-testid": `select-size-field-${layer.id}`
2796
3220
  }
2797
3221
  ),
2798
- ((_C = (_B = layer.visualConfig) == null ? void 0 : _B.size) == null ? void 0 : _C.mode) === "override" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1", children: [
3222
+ ((_I = (_H = layer.visualConfig) == null ? void 0 : _H.size) == null ? void 0 : _I.mode) === "override" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1", children: [
2799
3223
  /* @__PURE__ */ jsxRuntime.jsx(
2800
3224
  antd.Slider,
2801
3225
  {
2802
- value: ((_E = (_D = layer.visualConfig) == null ? void 0 : _D.size) == null ? void 0 : _E.overrideValue) ?? 5,
3226
+ value: ((_K = (_J = layer.visualConfig) == null ? void 0 : _J.size) == null ? void 0 : _K.overrideValue) ?? 5,
2803
3227
  min: 1,
2804
3228
  max: 10,
2805
3229
  step: 1,
@@ -2810,7 +3234,7 @@ function LayersPanel({
2810
3234
  })
2811
3235
  }
2812
3236
  ),
2813
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm w-4 text-right", children: ((_G = (_F = layer.visualConfig) == null ? void 0 : _F.size) == null ? void 0 : _G.overrideValue) ?? 5 })
3237
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm w-4 text-right", children: ((_M = (_L = layer.visualConfig) == null ? void 0 : _L.size) == null ? void 0 : _M.overrideValue) ?? 5 })
2814
3238
  ] }),
2815
3239
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1 text-sm text-muted-foreground pt-0.5", children: [
2816
3240
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "w-3.5 h-3.5 rounded-full bg-current" }),
@@ -2820,7 +3244,7 @@ function LayersPanel({
2820
3244
  antd.Select,
2821
3245
  {
2822
3246
  size: "small",
2823
- value: ((_I = (_H = layer.visualConfig) == null ? void 0 : _H.color) == null ? void 0 : _I.mode) ?? "standard",
3247
+ value: ((_O = (_N = layer.visualConfig) == null ? void 0 : _N.color) == null ? void 0 : _O.mode) ?? "standard",
2824
3248
  onChange: (val) => onUpdateVisualConfig(layer.id, {
2825
3249
  ...layer.visualConfig,
2826
3250
  color: { mode: val }
@@ -2834,37 +3258,77 @@ function LayersPanel({
2834
3258
  "data-testid": `select-color-mode-${layer.id}`
2835
3259
  }
2836
3260
  ),
2837
- ((_K = (_J = layer.visualConfig) == null ? void 0 : _J.color) == null ? void 0 : _K.mode) === "field" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2838
- /* @__PURE__ */ jsxRuntime.jsx(
2839
- antd.Select,
2840
- {
2841
- size: "small",
2842
- value: ((_M = (_L = layer.visualConfig) == null ? void 0 : _L.color) == null ? void 0 : _M.fieldName) ?? "",
2843
- onChange: (val) => onUpdateVisualConfig(layer.id, {
2844
- ...layer.visualConfig,
2845
- color: { mode: "field", fieldName: val }
2846
- }),
2847
- className: "w-full text-sm",
2848
- placeholder: "Select field...",
2849
- showSearch: true,
2850
- optionFilterProp: "label",
2851
- options: getLayerFields(layer.id).map((f) => ({ value: f.name, label: f.name })),
2852
- "data-testid": `select-color-field-${layer.id}`
2853
- }
2854
- ),
2855
- ((_O = (_N = layer.visualConfig) == null ? void 0 : _N.color) == null ? void 0 : _O.fieldName) && getFieldValueDistribution && /* @__PURE__ */ jsxRuntime.jsx(
2856
- ColorByFieldLegend,
2857
- {
2858
- layerId: layer.id,
2859
- fieldName: layer.visualConfig.color.fieldName,
2860
- getFieldValueDistribution
2861
- }
2862
- )
2863
- ] }),
2864
- ((_Q = (_P = layer.visualConfig) == null ? void 0 : _P.color) == null ? void 0 : _Q.mode) === "fixed" && /* @__PURE__ */ jsxRuntime.jsx(
3261
+ ((_Q = (_P = layer.visualConfig) == null ? void 0 : _P.color) == null ? void 0 : _Q.mode) === "field" && (() => {
3262
+ var _a2, _b2, _c2, _d2;
3263
+ const fields = getLayerFields(layer.id);
3264
+ const colorField = (_b2 = (_a2 = layer.visualConfig) == null ? void 0 : _a2.color) == null ? void 0 : _b2.fieldName;
3265
+ const fieldStats = colorField ? fields.find((f) => f.name === colorField) : void 0;
3266
+ const fieldHasNumeric = (fieldStats == null ? void 0 : fieldStats.min) !== void 0;
3267
+ const scale = ((_d2 = (_c2 = layer.visualConfig) == null ? void 0 : _c2.color) == null ? void 0 : _d2.scale) ?? "categorical";
3268
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3269
+ /* @__PURE__ */ jsxRuntime.jsx(
3270
+ antd.Select,
3271
+ {
3272
+ size: "small",
3273
+ value: colorField ?? "",
3274
+ onChange: (val) => onUpdateVisualConfig(layer.id, {
3275
+ ...layer.visualConfig,
3276
+ // The scale default is decided once, at pick time, and
3277
+ // stored — never re-inferred at render, so data drifting
3278
+ // later can't silently flip a user's choice.
3279
+ color: { mode: "field", fieldName: val, scale: defaultColorScaleForField(fields.find((f) => f.name === val)) }
3280
+ }),
3281
+ className: "w-full text-sm",
3282
+ placeholder: "Select field...",
3283
+ showSearch: true,
3284
+ optionFilterProp: "label",
3285
+ options: fields.map((f) => ({ value: f.name, label: f.name })),
3286
+ "data-testid": `select-color-field-${layer.id}`
3287
+ }
3288
+ ),
3289
+ colorField && /* @__PURE__ */ jsxRuntime.jsx(
3290
+ antd.Segmented,
3291
+ {
3292
+ size: "small",
3293
+ block: true,
3294
+ value: scale,
3295
+ onChange: (val) => {
3296
+ var _a3;
3297
+ return onUpdateVisualConfig(layer.id, {
3298
+ ...layer.visualConfig,
3299
+ color: { ...(_a3 = layer.visualConfig) == null ? void 0 : _a3.color, mode: "field", scale: val }
3300
+ });
3301
+ },
3302
+ options: [
3303
+ { label: "Categories", value: "categorical" },
3304
+ { label: "Gradient", value: "gradient", disabled: !fieldHasNumeric && scale !== "gradient" }
3305
+ ],
3306
+ "data-testid": `segmented-color-scale-${layer.id}`
3307
+ }
3308
+ ),
3309
+ colorField && scale === "gradient" && fieldStats && fieldStats.min !== void 0 && fieldStats.max !== void 0 && /* @__PURE__ */ jsxRuntime.jsx(
3310
+ ColorGradientLegend,
3311
+ {
3312
+ layerId: layer.id,
3313
+ min: fieldStats.min,
3314
+ max: fieldStats.max,
3315
+ sampled: fieldStats.sampled
3316
+ }
3317
+ ),
3318
+ colorField && scale !== "gradient" && getFieldValueDistribution && /* @__PURE__ */ jsxRuntime.jsx(
3319
+ ColorByFieldLegend,
3320
+ {
3321
+ layerId: layer.id,
3322
+ fieldName: colorField,
3323
+ getFieldValueDistribution
3324
+ }
3325
+ )
3326
+ ] });
3327
+ })(),
3328
+ ((_S = (_R = layer.visualConfig) == null ? void 0 : _R.color) == null ? void 0 : _S.mode) === "fixed" && /* @__PURE__ */ jsxRuntime.jsx(
2865
3329
  ColorPickerPopover,
2866
3330
  {
2867
- value: ((_S = (_R = layer.visualConfig) == null ? void 0 : _R.color) == null ? void 0 : _S.fixedColor) ?? "#3b82f6",
3331
+ value: ((_U = (_T = layer.visualConfig) == null ? void 0 : _T.color) == null ? void 0 : _U.fixedColor) ?? "#3b82f6",
2868
3332
  onChange: (color) => {
2869
3333
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
2870
3334
  ...layer.visualConfig,
@@ -2877,7 +3341,7 @@ function LayersPanel({
2877
3341
  testId: `color-fixed-${layer.id}`
2878
3342
  }
2879
3343
  ),
2880
- (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_T = layer.metadata) == null ? void 0 : _T.hidePointFeatures) && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3344
+ (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_V = layer.metadata) == null ? void 0 : _V.hidePointFeatures) && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2881
3345
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1 text-sm text-muted-foreground pt-0.5", children: [
2882
3346
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Smile, { className: "w-3.5 h-3.5" }),
2883
3347
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: "Point Icon" })
@@ -2887,7 +3351,7 @@ function LayersPanel({
2887
3351
  antd.Switch,
2888
3352
  {
2889
3353
  size: "small",
2890
- checked: ((_V = (_U = layer.visualConfig) == null ? void 0 : _U.icon) == null ? void 0 : _V.enabled) ?? false,
3354
+ checked: ((_X = (_W = layer.visualConfig) == null ? void 0 : _W.icon) == null ? void 0 : _X.enabled) ?? false,
2891
3355
  onChange: (checked) => {
2892
3356
  var _a2, _b2, _c2, _d2;
2893
3357
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
@@ -2902,11 +3366,11 @@ function LayersPanel({
2902
3366
  "data-testid": `switch-icon-${layer.id}`
2903
3367
  }
2904
3368
  ),
2905
- ((_X = (_W = layer.visualConfig) == null ? void 0 : _W.icon) == null ? void 0 : _X.enabled) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1 flex-1", children: [
3369
+ ((_Z = (_Y = layer.visualConfig) == null ? void 0 : _Y.icon) == null ? void 0 : _Z.enabled) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1 flex-1", children: [
2906
3370
  /* @__PURE__ */ jsxRuntime.jsx(
2907
3371
  IconPicker,
2908
3372
  {
2909
- value: ((_Z = (_Y = layer.visualConfig) == null ? void 0 : _Y.icon) == null ? void 0 : _Z.icon) ?? "📍",
3373
+ value: ((_$ = (__ = layer.visualConfig) == null ? void 0 : __.icon) == null ? void 0 : _$.icon) ?? "📍",
2910
3374
  onChange: (icon) => {
2911
3375
  var _a2, _b2;
2912
3376
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
@@ -2923,7 +3387,7 @@ function LayersPanel({
2923
3387
  /* @__PURE__ */ jsxRuntime.jsx(
2924
3388
  antd.Slider,
2925
3389
  {
2926
- value: ((_$ = (__ = layer.visualConfig) == null ? void 0 : __.icon) == null ? void 0 : _$.size) ?? 24,
3390
+ value: ((_ba = (_aa = layer.visualConfig) == null ? void 0 : _aa.icon) == null ? void 0 : _ba.size) ?? 24,
2927
3391
  min: 12,
2928
3392
  max: 48,
2929
3393
  step: 2,
@@ -2941,7 +3405,7 @@ function LayersPanel({
2941
3405
  }
2942
3406
  }
2943
3407
  ),
2944
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm w-6 text-right", children: ((_ba = (_aa = layer.visualConfig) == null ? void 0 : _aa.icon) == null ? void 0 : _ba.size) ?? 24 })
3408
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm w-6 text-right", children: ((_da = (_ca = layer.visualConfig) == null ? void 0 : _ca.icon) == null ? void 0 : _da.size) ?? 24 })
2945
3409
  ] })
2946
3410
  ] })
2947
3411
  ] })
@@ -6274,13 +6738,282 @@ function hitTestSelection(featureGroups, selectionPolygon, options) {
6274
6738
  mapPerfLog("hit-test", "selection gesture", { visited, total, selected: selectedIds.length });
6275
6739
  return selectedIds;
6276
6740
  }
6741
+ const CLUSTER_COUNT_VALUE_PROP = "__cluster_count_value";
6742
+ const CLUSTER_SUM_PROP = "value_sum";
6743
+ const CLUSTER_MEMBER_ID_PROP = "__cluster_fid";
6744
+ function clusterCountValue(raw) {
6745
+ if (typeof raw === "number") return Number.isFinite(raw) ? raw : 1;
6746
+ if (typeof raw === "string" && raw.trim() !== "") {
6747
+ const n = Number(raw);
6748
+ if (Number.isFinite(n)) return n;
6749
+ }
6750
+ return 1;
6751
+ }
6752
+ function injectClusterCountValues(features, fieldName) {
6753
+ return features.map((f) => {
6754
+ var _a;
6755
+ return {
6756
+ ...f,
6757
+ properties: {
6758
+ ...f.properties,
6759
+ [CLUSTER_COUNT_VALUE_PROP]: clusterCountValue((_a = f.properties) == null ? void 0 : _a[fieldName]),
6760
+ ...f.id != null ? { [CLUSTER_MEMBER_ID_PROP]: String(f.id) } : {}
6761
+ }
6762
+ };
6763
+ });
6764
+ }
6765
+ function roundHalfAwayFromZero1(n) {
6766
+ return Math.sign(n) * Math.round(Math.abs(n) * 10) / 10;
6767
+ }
6768
+ function formatClusterBadge(value) {
6769
+ if (value >= 1e6) return `${roundHalfAwayFromZero1(value / 1e6)}M`;
6770
+ if (value >= 1e3) return `${roundHalfAwayFromZero1(value / 1e3)}k`;
6771
+ return String(roundHalfAwayFromZero1(value));
6772
+ }
6773
+ function clusterBadgeTextField(prop) {
6774
+ const value = ["get", prop];
6775
+ const round1 = (expr) => ["/", ["round", ["*", expr, 10]], 10];
6776
+ return [
6777
+ "step",
6778
+ value,
6779
+ ["to-string", round1(value)],
6780
+ 1e3,
6781
+ ["concat", ["to-string", round1(["/", value, 1e3])], "k"],
6782
+ 1e6,
6783
+ ["concat", ["to-string", round1(["/", value, 1e6])], "M"]
6784
+ ];
6785
+ }
6786
+ const INTERNAL_PROPERTY_KEYS = /* @__PURE__ */ new Set([
6787
+ "fill",
6788
+ "fill-opacity",
6789
+ "pointRadius",
6790
+ "pointIcon",
6791
+ "pointIconSize",
6792
+ "circleCenter",
6793
+ "circleRadius",
6794
+ "icon",
6795
+ "iconSize",
6796
+ "fontSize",
6797
+ "fontColor",
6798
+ "fontWeight",
6799
+ "arrowSize",
6800
+ "label",
6801
+ "entityType",
6802
+ "kind",
6803
+ "meta:type",
6804
+ "stroke",
6805
+ "stroke-width",
6806
+ "stroke-opacity",
6807
+ CLUSTER_COUNT_VALUE_PROP,
6808
+ CLUSTER_MEMBER_ID_PROP
6809
+ ]);
6810
+ const STYLING_PROPERTY_KEYS = [
6811
+ "stroke",
6812
+ "stroke-width",
6813
+ "stroke-opacity",
6814
+ "fill",
6815
+ "fill-opacity",
6816
+ "pointRadius",
6817
+ "pointIcon",
6818
+ "pointIconSize",
6819
+ "icon",
6820
+ "iconSize",
6821
+ "circleCenter",
6822
+ "circleRadius",
6823
+ "fontSize",
6824
+ "fontColor",
6825
+ "fontWeight",
6826
+ "arrowSize"
6827
+ ];
6828
+ const INTERNAL_PROPERTY_PREFIXES = [
6829
+ "IsHiddenBy",
6830
+ "isHidden",
6831
+ "isSelected",
6832
+ "isTrace",
6833
+ "isTimeline",
6834
+ "trace"
6835
+ ];
6836
+ function isInternalProperty(key) {
6837
+ if (INTERNAL_PROPERTY_KEYS.has(key)) return true;
6838
+ return INTERNAL_PROPERTY_PREFIXES.some((prefix) => key.startsWith(prefix));
6839
+ }
6840
+ function computeBubbleDomain(values) {
6841
+ let min = Infinity;
6842
+ let max = -Infinity;
6843
+ for (const v of values) {
6844
+ if (!Number.isFinite(v)) continue;
6845
+ if (v < min) min = v;
6846
+ if (v > max) max = v;
6847
+ }
6848
+ return isFinite(min) ? { min, max } : null;
6849
+ }
6850
+ function bubbleGradientColorExpression(prop, min, max) {
6851
+ if (!(max > min)) return gradientColor(0.5);
6852
+ const expr = ["interpolate", ["linear"], ["get", prop]];
6853
+ const span = max - min;
6854
+ GRADIENT_RAMP.forEach((color, i) => {
6855
+ expr.push(min + span * i / (GRADIENT_RAMP.length - 1), color);
6856
+ });
6857
+ return expr;
6858
+ }
6859
+ function createClusterGradientManager(map, sourceId, options) {
6860
+ const clusterProp = options.valueProp ?? "point_count";
6861
+ let scheduled = false;
6862
+ let lastDomainKey = "";
6863
+ let reportedFailure = false;
6864
+ function reportFailure(stage, error) {
6865
+ if (reportedFailure) return;
6866
+ reportedFailure = true;
6867
+ console.error(`[map-component] cluster gradient ${stage} failed; bubbles keep their current colors:`, error);
6868
+ }
6869
+ function apply() {
6870
+ scheduled = false;
6871
+ let values;
6872
+ try {
6873
+ if (!map.getSource(sourceId)) return;
6874
+ values = map.querySourceFeatures(sourceId, { filter: ["has", "point_count"] }).map((f) => {
6875
+ var _a;
6876
+ return Number((_a = f.properties) == null ? void 0 : _a[clusterProp]);
6877
+ });
6878
+ if (options.singleLayerId) {
6879
+ const singles = map.querySourceFeatures(sourceId, {
6880
+ filter: ["all", ["!", ["has", "point_count"]], [">", ["get", CLUSTER_COUNT_VALUE_PROP], 1]]
6881
+ });
6882
+ values.push(...singles.map((f) => {
6883
+ var _a;
6884
+ return Number((_a = f.properties) == null ? void 0 : _a[CLUSTER_COUNT_VALUE_PROP]);
6885
+ }));
6886
+ }
6887
+ } catch (error) {
6888
+ reportFailure("domain query", error);
6889
+ return;
6890
+ }
6891
+ const domain = computeBubbleDomain(values);
6892
+ if (!domain) return;
6893
+ const key = `${domain.min}|${domain.max}`;
6894
+ if (key === lastDomainKey) return;
6895
+ lastDomainKey = key;
6896
+ try {
6897
+ if (map.getLayer(options.clustersLayerId)) {
6898
+ map.setPaintProperty(
6899
+ options.clustersLayerId,
6900
+ "circle-color",
6901
+ bubbleGradientColorExpression(clusterProp, domain.min, domain.max)
6902
+ );
6903
+ }
6904
+ if (options.singleLayerId && map.getLayer(options.singleLayerId)) {
6905
+ map.setPaintProperty(
6906
+ options.singleLayerId,
6907
+ "circle-color",
6908
+ bubbleGradientColorExpression(CLUSTER_COUNT_VALUE_PROP, domain.min, domain.max)
6909
+ );
6910
+ }
6911
+ } catch (error) {
6912
+ reportFailure("paint update", error);
6913
+ lastDomainKey = "";
6914
+ }
6915
+ }
6916
+ function schedule() {
6917
+ if (scheduled) return;
6918
+ scheduled = true;
6919
+ requestAnimationFrame(apply);
6920
+ }
6921
+ function onData(e) {
6922
+ if (e.sourceId === sourceId) schedule();
6923
+ }
6924
+ map.on("moveend", schedule);
6925
+ map.on("data", onData);
6926
+ schedule();
6927
+ return {
6928
+ destroy: () => {
6929
+ map.off("moveend", schedule);
6930
+ map.off("data", onData);
6931
+ }
6932
+ };
6933
+ }
6934
+ const LABEL_NEVER_HIDE_PROP = "_labelNeverHide";
6935
+ const PINNED_LABEL_FILTER = ["==", ["get", LABEL_NEVER_HIDE_PROP], 1];
6936
+ const UNPINNED_LABEL_FILTER = ["!=", ["get", LABEL_NEVER_HIDE_PROP], 1];
6937
+ function computeLabelNeverHide(label) {
6938
+ return (label == null ? void 0 : label.neverHide) && !label.hidden ? 1 : 0;
6939
+ }
6940
+ function buildCustomLabelLayout() {
6941
+ return {
6942
+ // Hide labels for trace points (except last point which has isTraceLabel),
6943
+ // arrows handled by the custom-arrow-labels layer. Features blanked by
6944
+ // heatmap/cluster/trace modes stay blank in BOTH layers: "never hide"
6945
+ // exempts labels from collision and density culling, it does not resurrect
6946
+ // labels other mode choices explicitly blank.
6947
+ "text-field": [
6948
+ "case",
6949
+ ["==", ["get", "isHiddenByTrace"], true],
6950
+ "",
6951
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6952
+ "",
6953
+ ["==", ["get", "isHiddenByCluster"], 1],
6954
+ "",
6955
+ ["==", ["get", "kind"], "arrow"],
6956
+ "",
6957
+ // Trace points: only show label if isTraceLabel is true (last point in group)
6958
+ ["all", ["==", ["get", "isTracePoint"], true], ["!=", ["get", "isTraceLabel"], true]],
6959
+ "",
6960
+ ["==", ["get", "kind"], "text"],
6961
+ ["coalesce", ["get", "label"], ["get", "text"], "New Label"],
6962
+ ["coalesce", ["get", "name"], ""]
6963
+ ],
6964
+ // Text features use their fontSize property; trace labels 14px; others 12px
6965
+ "text-size": [
6966
+ "case",
6967
+ ["==", ["get", "kind"], "text"],
6968
+ ["coalesce", ["get", "fontSize"], 14],
6969
+ ["==", ["get", "isTraceLabel"], true],
6970
+ 14,
6971
+ 12
6972
+ ],
6973
+ // Text features: center anchor; others: top anchor
6974
+ "text-anchor": ["case", ["==", ["get", "kind"], "text"], "center", "top"],
6975
+ "text-offset": ["case", ["==", ["get", "kind"], "text"], ["literal", [0, 0]], ["literal", [0, 0.8]]],
6976
+ "text-padding": 2,
6977
+ // Bold font for text features with fontWeight=bold, trace labels, others regular
6978
+ "text-font": [
6979
+ "case",
6980
+ ["all", ["==", ["get", "kind"], "text"], ["==", ["get", "fontWeight"], "bold"]],
6981
+ ["literal", ["Montserrat SemiBold", "Noto Sans Regular"]],
6982
+ ["==", ["get", "isTraceLabel"], true],
6983
+ ["literal", ["Montserrat Medium", "Noto Sans Regular"]],
6984
+ ["literal", ["Montserrat Regular", "Noto Sans Regular"]]
6985
+ ]
6986
+ };
6987
+ }
6988
+ function buildCustomLabelPaint() {
6989
+ return {
6990
+ // Text features use fontColor; others use default
6991
+ "text-color": [
6992
+ "case",
6993
+ ["==", ["get", "kind"], "text"],
6994
+ ["coalesce", ["get", "fontColor"], "#000000"],
6995
+ "#1f2937"
6996
+ ],
6997
+ "text-halo-color": "#ffffff",
6998
+ // Thicker halo for trace labels and text features
6999
+ "text-halo-width": [
7000
+ "case",
7001
+ ["==", ["get", "kind"], "text"],
7002
+ 2,
7003
+ ["==", ["get", "isTraceLabel"], true],
7004
+ 2,
7005
+ 1.5
7006
+ ],
7007
+ "text-opacity": ["*", 0.9, ["get", "stroke-opacity"]]
7008
+ };
7009
+ }
6277
7010
  const OTHER_BUCKET_KEY = "__other__";
6278
7011
  const OTHER_BUCKET_LABEL = "Other";
6279
7012
  const OTHER_BUCKET_COLOR = "#9ca3af";
6280
7013
  function toDisplayName(name) {
6281
7014
  return name === OTHER_BUCKET_KEY ? OTHER_BUCKET_LABEL : name;
6282
7015
  }
6283
- function createPieSVG(categories, total, size = 44, onSliceHover) {
7016
+ function createPieSVG(categories, total, size = 44, onSliceHover, badgeValue) {
6284
7017
  const container = document.createElement("div");
6285
7018
  container.style.width = `${size}px`;
6286
7019
  container.style.height = `${size}px`;
@@ -6378,16 +7111,17 @@ function createPieSVG(categories, total, size = 44, onSliceHover) {
6378
7111
  centerCircle.setAttribute("r", String(innerRadius - 2));
6379
7112
  centerCircle.setAttribute("fill", "#1f2937");
6380
7113
  svg.appendChild(centerCircle);
7114
+ const badgeText = formatClusterBadge(badgeValue ?? total);
6381
7115
  const text = document.createElementNS("http://www.w3.org/2000/svg", "text");
6382
7116
  text.setAttribute("x", String(radius));
6383
7117
  text.setAttribute("y", String(radius));
6384
7118
  text.setAttribute("text-anchor", "middle");
6385
7119
  text.setAttribute("dominant-baseline", "central");
6386
7120
  text.setAttribute("fill", "white");
6387
- text.setAttribute("font-size", total >= 1e3 ? "9" : total >= 100 ? "10" : "11");
7121
+ text.setAttribute("font-size", badgeText.length >= 6 ? "8" : badgeText.length >= 4 ? "9" : badgeText.length >= 3 ? "10" : "11");
6388
7122
  text.setAttribute("font-weight", "bold");
6389
7123
  text.setAttribute("font-family", "system-ui, sans-serif");
6390
- text.textContent = total >= 1e3 ? `${(total / 1e3).toFixed(1)}k` : String(total);
7124
+ text.textContent = badgeText;
6391
7125
  svg.appendChild(text);
6392
7126
  container.appendChild(svg);
6393
7127
  return container;
@@ -6434,17 +7168,17 @@ function hideTooltip() {
6434
7168
  tooltipEl.style.display = "none";
6435
7169
  }
6436
7170
  }
6437
- function fingerprintCluster(pointCount, counts, size) {
6438
- return `${size}|${pointCount}|${counts.join(",")}`;
7171
+ function fingerprintCluster(pointCount, counts, size, badgeValue) {
7172
+ return `${size}|${pointCount}|${badgeValue ?? ""}|${counts.join(",")}`;
6439
7173
  }
6440
- function buildPieElement(categories, pointCount, size, source, clusterId, map, coords) {
7174
+ function buildPieElement(categories, pointCount, size, source, clusterId, map, coords, badgeValue) {
6441
7175
  const el = createPieSVG(categories, pointCount, size, (cat, event) => {
6442
7176
  if (cat) {
6443
7177
  showTooltip(cat, event.clientX, event.clientY);
6444
7178
  } else {
6445
7179
  hideTooltip();
6446
7180
  }
6447
- });
7181
+ }, badgeValue);
6448
7182
  el.addEventListener("click", () => {
6449
7183
  source.getClusterExpansionZoom(clusterId).then((zoom) => {
6450
7184
  if (typeof zoom === "number") {
@@ -6463,13 +7197,16 @@ function renderClusterPies(map, sourceId, categoryValues, categoryColorMap, mark
6463
7197
  });
6464
7198
  const visibleClusterIds = /* @__PURE__ */ new Set();
6465
7199
  clusters.forEach((feature) => {
6466
- var _a, _b;
7200
+ var _a, _b, _c;
6467
7201
  const clusterId = (_a = feature.properties) == null ? void 0 : _a.cluster_id;
6468
7202
  if (clusterId === void 0) return;
6469
7203
  const clusterKey = `${clusterId}`;
6470
7204
  visibleClusterIds.add(clusterKey);
6471
7205
  const coords = feature.geometry.coordinates;
6472
7206
  const pointCount = ((_b = feature.properties) == null ? void 0 : _b.point_count) || 0;
7207
+ const sumRaw = (_c = feature.properties) == null ? void 0 : _c[CLUSTER_SUM_PROP];
7208
+ const sumNum = typeof sumRaw === "number" ? sumRaw : sumRaw != null ? Number(sumRaw) : NaN;
7209
+ const badgeValue = Number.isFinite(sumNum) ? sumNum : void 0;
6473
7210
  const allCounts = categoryValues.map((_, i) => {
6474
7211
  var _a2;
6475
7212
  return Number(((_a2 = feature.properties) == null ? void 0 : _a2[`cat_${i}`]) || 0);
@@ -6481,13 +7218,13 @@ function renderClusterPies(map, sourceId, categoryValues, categoryColorMap, mark
6481
7218
  color: categoryColorMap[cat] || "#3b82f6"
6482
7219
  })).filter((c) => c.count > 0);
6483
7220
  const size = pointCount < 100 ? 40 : pointCount < 750 ? 50 : 60;
6484
- const fingerprint = fingerprintCluster(pointCount, allCounts, size);
7221
+ const fingerprint = fingerprintCluster(pointCount, allCounts, size, badgeValue);
6485
7222
  const existing = markers.get(clusterKey);
6486
7223
  if (existing && existing.fingerprint === fingerprint) {
6487
7224
  existing.marker.setLngLat(coords);
6488
7225
  return;
6489
7226
  }
6490
- const el = buildPieElement(categories, pointCount, size, source, clusterId, map, coords);
7227
+ const el = buildPieElement(categories, pointCount, size, source, clusterId, map, coords, badgeValue);
6491
7228
  if (existing) {
6492
7229
  existing.marker.remove();
6493
7230
  }
@@ -6928,6 +7665,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
6928
7665
  const loadingBasemaps = react.useRef(/* @__PURE__ */ new Set());
6929
7666
  const customBasemapRegistry = react.useRef(/* @__PURE__ */ new Map());
6930
7667
  const clusterPieManagers = react.useRef(/* @__PURE__ */ new Map());
7668
+ const clusterGradientManagers = react.useRef(/* @__PURE__ */ new Map());
7669
+ const clusterLayerHandlers = react.useRef(/* @__PURE__ */ new Map());
6931
7670
  const handleMapStyleChangeRef = react.useRef(null);
6932
7671
  const flightPath3DLayerId = react.useRef(null);
6933
7672
  const update3DFlightPathsRef = react.useRef(null);
@@ -6942,6 +7681,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
6942
7681
  const [selectedFeatureIds, setSelectedFeatureIds] = react.useState([]);
6943
7682
  const [featureCount, setFeatureCount] = react.useState(0);
6944
7683
  const [featureUpdateCounter, setFeatureUpdateCounter] = react.useState(0);
7684
+ const [clusterDataVersion, setClusterDataVersion] = react.useState(0);
6945
7685
  const [showProperties, setShowProperties] = react.useState(false);
6946
7686
  const [autoFocusLabel, setAutoFocusLabel] = react.useState(false);
6947
7687
  const [showLayers, setShowLayers] = react.useState(false);
@@ -7273,6 +8013,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7273
8013
  });
7274
8014
  });
7275
8015
  });
8016
+ const layerGradientRanges = /* @__PURE__ */ new Map();
7276
8017
  selectedFeatureIds.forEach((fid) => {
7277
8018
  var _a;
7278
8019
  const feature = featById.get(fid);
@@ -7282,22 +8023,29 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7282
8023
  colorMap.set(fid, tracePointColors.get(fid));
7283
8024
  return;
7284
8025
  }
7285
- let color = ((_a = feature == null ? void 0 : feature.properties) == null ? void 0 : _a.stroke) || "#3b82f6";
8026
+ const fallback = ((_a = feature == null ? void 0 : feature.properties) == null ? void 0 : _a.stroke) || "#3b82f6";
8027
+ let color = fallback;
7286
8028
  const colorConfig = visualConfig == null ? void 0 : visualConfig.color;
7287
8029
  if (colorConfig && feature) {
7288
- if (colorConfig.mode === "fixed" && colorConfig.fixedColor) {
7289
- color = colorConfig.fixedColor;
7290
- } else if (colorConfig.mode === "field" && colorConfig.fieldName && feature.properties) {
7291
- const key = categoricalKey(feature.properties[colorConfig.fieldName]);
7292
- if (key !== null) {
7293
- color = hashStringToColor$1(key);
8030
+ let range;
8031
+ if (layer && colorConfig.mode === "field" && colorConfig.scale === "gradient" && colorConfig.fieldName) {
8032
+ const cached = layerGradientRanges.get(layer.id);
8033
+ if (cached === void 0) {
8034
+ range = computeNumericRange(layer.featureIds, (id) => {
8035
+ var _a2;
8036
+ return (_a2 = featById.get(id)) == null ? void 0 : _a2.properties;
8037
+ }, colorConfig.fieldName);
8038
+ layerGradientRanges.set(layer.id, range);
8039
+ } else {
8040
+ range = cached;
7294
8041
  }
7295
8042
  }
8043
+ color = resolveFeatureColor(colorConfig, feature.properties, fallback, range);
7296
8044
  }
7297
8045
  colorMap.set(fid, color);
7298
8046
  });
7299
8047
  return colorMap;
7300
- }, [selectedFeatureIds, layers, getAllFeatures, hashStringToColor$1]);
8048
+ }, [selectedFeatureIds, layers, getAllFeatures]);
7301
8049
  const countVisibleFeatures = react.useCallback((threshold) => {
7302
8050
  const m = map.current;
7303
8051
  if (!m) return 0;
@@ -7448,27 +8196,38 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7448
8196
  layer.featureIds.forEach((fid) => featureToLayer.set(fid, layer));
7449
8197
  });
7450
8198
  const sizeFieldRanges = /* @__PURE__ */ new Map();
8199
+ const colorFieldRanges = /* @__PURE__ */ new Map();
7451
8200
  currentLayers.forEach((layer) => {
7452
- var _a;
8201
+ var _a, _b;
7453
8202
  if (!layer.visible) return;
7454
8203
  const sizeConfig = (_a = layer.visualConfig) == null ? void 0 : _a.size;
7455
- if ((sizeConfig == null ? void 0 : sizeConfig.mode) === "field" && sizeConfig.fieldName) {
7456
- let min = Infinity, max = -Infinity;
7457
- layer.featureIds.forEach((fid) => {
7458
- const feature = featureById.get(fid);
7459
- if (feature == null ? void 0 : feature.properties) {
7460
- const rawVal = feature.properties[sizeConfig.fieldName];
7461
- const val = typeof rawVal === "number" ? rawVal : typeof rawVal === "string" && rawVal.trim() !== "" ? Number(rawVal) : NaN;
7462
- if (isFinite(val)) {
7463
- min = Math.min(min, val);
7464
- max = Math.max(max, val);
7465
- }
8204
+ const colorConfig = (_b = layer.visualConfig) == null ? void 0 : _b.color;
8205
+ const sizeField = (sizeConfig == null ? void 0 : sizeConfig.mode) === "field" && sizeConfig.fieldName ? sizeConfig.fieldName : null;
8206
+ const colorField = (colorConfig == null ? void 0 : colorConfig.mode) === "field" && colorConfig.scale === "gradient" && colorConfig.fieldName ? colorConfig.fieldName : null;
8207
+ if (!sizeField && !colorField) return;
8208
+ let sMin = Infinity, sMax = -Infinity;
8209
+ let cMin = Infinity, cMax = -Infinity;
8210
+ layer.featureIds.forEach((fid) => {
8211
+ var _a2;
8212
+ const props = (_a2 = featureById.get(fid)) == null ? void 0 : _a2.properties;
8213
+ if (!props) return;
8214
+ if (sizeField) {
8215
+ const v = coerceFiniteNumber(props[sizeField]);
8216
+ if (v !== null) {
8217
+ if (v < sMin) sMin = v;
8218
+ if (v > sMax) sMax = v;
7466
8219
  }
7467
- });
7468
- if (isFinite(min) && isFinite(max)) {
7469
- sizeFieldRanges.set(layer.id, { min, max });
7470
8220
  }
7471
- }
8221
+ if (colorField) {
8222
+ const v = coerceFiniteNumber(props[colorField]);
8223
+ if (v !== null) {
8224
+ if (v < cMin) cMin = v;
8225
+ if (v > cMax) cMax = v;
8226
+ }
8227
+ }
8228
+ });
8229
+ if (sizeField && isFinite(sMin)) sizeFieldRanges.set(layer.id, { min: sMin, max: sMax });
8230
+ if (colorField && isFinite(cMin)) colorFieldRanges.set(layer.id, { min: cMin, max: cMax });
7472
8231
  });
7473
8232
  const lastTracePointIds = /* @__PURE__ */ new Set();
7474
8233
  const tracePointColors = /* @__PURE__ */ new Map();
@@ -7533,7 +8292,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7533
8292
  const sourceData = {
7534
8293
  type: "FeatureCollection",
7535
8294
  features: allFeatures.map((f) => {
7536
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
8295
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
7537
8296
  const featureId = String(f.id);
7538
8297
  const layer = featureToLayer.get(featureId);
7539
8298
  const visualConfig = layer == null ? void 0 : layer.visualConfig;
@@ -7542,14 +8301,12 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7542
8301
  let strokeColor = ((_b = f.properties) == null ? void 0 : _b.stroke) || "#3b82f6";
7543
8302
  const colorConfig = visualConfig == null ? void 0 : visualConfig.color;
7544
8303
  if (colorConfig) {
7545
- if (colorConfig.mode === "fixed" && colorConfig.fixedColor) {
7546
- strokeColor = colorConfig.fixedColor;
7547
- } else if (colorConfig.mode === "field" && colorConfig.fieldName && f.properties) {
7548
- const key = categoricalKey(f.properties[colorConfig.fieldName]);
7549
- if (key !== null) {
7550
- strokeColor = hashStringToColor$1(key);
7551
- }
7552
- }
8304
+ strokeColor = resolveFeatureColor(
8305
+ colorConfig,
8306
+ f.properties,
8307
+ strokeColor,
8308
+ layer ? colorFieldRanges.get(layer.id) : void 0
8309
+ );
7553
8310
  }
7554
8311
  let strokeWidth = ((_c = f.properties) == null ? void 0 : _c["stroke-width"]) || 2;
7555
8312
  let pointRadius = Math.round(3 + strokeWidth);
@@ -7677,7 +8434,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7677
8434
  pointRadius,
7678
8435
  isHiddenFor3DOnly: hideFlatFor3DOnly ? 1 : 0,
7679
8436
  isTimelineHidden: isTimelineVisible ? 0 : 1,
7680
- _labelPriority: labelPriority
8437
+ _labelPriority: labelPriority,
8438
+ [LABEL_NEVER_HIDE_PROP]: computeLabelNeverHide((_o = layer == null ? void 0 : layer.visualConfig) == null ? void 0 : _o.label)
7681
8439
  }
7682
8440
  };
7683
8441
  })
@@ -7991,6 +8749,15 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7991
8749
  clusterPieManagers.current.delete(layerId);
7992
8750
  }
7993
8751
  });
8752
+ clusterGradientManagers.current.forEach((mgr, layerId) => {
8753
+ if (!liveLayerIds.has(layerId)) {
8754
+ try {
8755
+ mgr.destroy();
8756
+ } catch {
8757
+ }
8758
+ clusterGradientManagers.current.delete(layerId);
8759
+ }
8760
+ });
7994
8761
  const m = map.current;
7995
8762
  if (!m) return;
7996
8763
  let style;
@@ -7999,7 +8766,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7999
8766
  } catch {
8000
8767
  return;
8001
8768
  }
8002
- const layerPrefixes = ["heatmap-layer-", "cluster-count-", "clusters-", "unclustered-point-"];
8769
+ const layerPrefixes = ["heatmap-layer-", "cluster-count-", "cluster-single-count-", "cluster-single-", "clusters-", "unclustered-point-"];
8003
8770
  const sourcePrefixes = ["heatmap-source-", "cluster-source-"];
8004
8771
  ((style == null ? void 0 : style.layers) ?? []).forEach((sl) => {
8005
8772
  const prefix = layerPrefixes.find((p) => sl.id.startsWith(p));
@@ -8449,39 +9216,10 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
8449
9216
  id: "custom-labels",
8450
9217
  type: "symbol",
8451
9218
  source: "custom-features",
9219
+ filter: UNPINNED_LABEL_FILTER,
8452
9220
  layout: {
9221
+ ...buildCustomLabelLayout(),
8453
9222
  "visibility": "none",
8454
- // Hide labels for trace points (except last point which has isTraceLabel), arrows handled separately
8455
- "text-field": [
8456
- "case",
8457
- ["==", ["get", "isHiddenByTrace"], true],
8458
- "",
8459
- ["==", ["get", "isHiddenByHeatmap"], 1],
8460
- "",
8461
- ["==", ["get", "isHiddenByCluster"], 1],
8462
- "",
8463
- ["==", ["get", "kind"], "arrow"],
8464
- "",
8465
- // Arrows use custom-arrow-labels layer
8466
- // Trace points: only show label if isTraceLabel is true (last point in group)
8467
- ["all", ["==", ["get", "isTracePoint"], true], ["!=", ["get", "isTraceLabel"], true]],
8468
- "",
8469
- ["==", ["get", "kind"], "text"],
8470
- ["coalesce", ["get", "label"], ["get", "text"], "New Label"],
8471
- ["coalesce", ["get", "name"], ""]
8472
- ],
8473
- // Text features use their fontSize property; trace labels 14px; others 12px
8474
- "text-size": [
8475
- "case",
8476
- ["==", ["get", "kind"], "text"],
8477
- ["coalesce", ["get", "fontSize"], 14],
8478
- ["==", ["get", "isTraceLabel"], true],
8479
- 14,
8480
- 12
8481
- ],
8482
- // Text features: center anchor; others: top anchor
8483
- "text-anchor": ["case", ["==", ["get", "kind"], "text"], "center", "top"],
8484
- "text-offset": ["case", ["==", ["get", "kind"], "text"], ["literal", [0, 0]], ["literal", [0, 0.8]]],
8485
9223
  // Native collision-based de-overlap.
8486
9224
  //
8487
9225
  // History: a prior PR turned collision off (`text-allow-overlap: true`)
@@ -8508,40 +9246,28 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
8508
9246
  "text-allow-overlap": false,
8509
9247
  "text-ignore-placement": false,
8510
9248
  "text-optional": true,
8511
- "text-padding": 2,
8512
9249
  // Lower value = higher collision priority (placed first).
8513
9250
  // Computed per-feature in syncFeaturesToCustomLayers.
8514
- "symbol-sort-key": ["coalesce", ["get", "_labelPriority"], 100],
8515
- // Bold font for text features with fontWeight=bold, trace labels, others regular
8516
- "text-font": [
8517
- "case",
8518
- ["all", ["==", ["get", "kind"], "text"], ["==", ["get", "fontWeight"], "bold"]],
8519
- ["literal", ["Montserrat SemiBold", "Noto Sans Regular"]],
8520
- ["==", ["get", "isTraceLabel"], true],
8521
- ["literal", ["Montserrat Medium", "Noto Sans Regular"]],
8522
- ["literal", ["Montserrat Regular", "Noto Sans Regular"]]
8523
- ]
9251
+ "symbol-sort-key": ["coalesce", ["get", "_labelPriority"], 100]
8524
9252
  },
8525
- paint: {
8526
- // Text features use fontColor; others use default
8527
- "text-color": [
8528
- "case",
8529
- ["==", ["get", "kind"], "text"],
8530
- ["coalesce", ["get", "fontColor"], "#000000"],
8531
- "#1f2937"
8532
- ],
8533
- "text-halo-color": "#ffffff",
8534
- // Thicker halo for trace labels and text features
8535
- "text-halo-width": [
8536
- "case",
8537
- ["==", ["get", "kind"], "text"],
8538
- 2,
8539
- ["==", ["get", "isTraceLabel"], true],
8540
- 2,
8541
- 1.5
8542
- ],
8543
- "text-opacity": ["*", 0.9, ["get", "stroke-opacity"]]
8544
- }
9253
+ paint: buildCustomLabelPaint()
9254
+ });
9255
+ mapInstance.addLayer({
9256
+ id: "custom-labels-pinned",
9257
+ type: "symbol",
9258
+ source: "custom-features",
9259
+ filter: PINNED_LABEL_FILTER,
9260
+ layout: {
9261
+ ...buildCustomLabelLayout(),
9262
+ "visibility": "visible",
9263
+ "text-allow-overlap": true,
9264
+ "text-ignore-placement": true,
9265
+ // With allow-overlap the collision pass is gone and the key only
9266
+ // orders painting, where HIGHER paints on top — negate so important
9267
+ // (low-priority-value) labels draw over their neighbours' halos.
9268
+ "symbol-sort-key": ["*", -1, ["coalesce", ["get", "_labelPriority"], 100]]
9269
+ },
9270
+ paint: buildCustomLabelPaint()
8545
9271
  });
8546
9272
  mapInstance.addSource("arrow-heads", {
8547
9273
  type: "geojson",
@@ -9367,7 +10093,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9367
10093
  scheduleSync();
9368
10094
  });
9369
10095
  mapInstance.on("click", (e) => {
9370
- var _a;
10096
+ var _a, _b;
9371
10097
  if (!enableSelectionRef.current) return;
9372
10098
  if (e.originalEvent.button !== 0) return;
9373
10099
  if (contextMenuFiredRef.current) return;
@@ -9376,14 +10102,24 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9376
10102
  const features = mapInstance.queryRenderedFeatures(e.point, {
9377
10103
  layers: ["custom-polygon-fill", "custom-line", "custom-point"]
9378
10104
  });
10105
+ let clusteredFeatureId = null;
9379
10106
  if (features.length === 0) {
9380
- if (selectedFeatureIdsRef.current.length > 0 && !isModifierKey) {
9381
- applySelectionState([]);
10107
+ const clusterOverlayIds = layersRef.current.filter((l) => {
10108
+ var _a2;
10109
+ return (_a2 = l.clusterConfig) == null ? void 0 : _a2.enabled;
10110
+ }).flatMap((l) => [`clusters-${l.id}`, `cluster-single-${l.id}`, `cluster-single-count-${l.id}`, `unclustered-point-${l.id}`]).filter((id) => mapInstance.getLayer(id));
10111
+ const clusterHit = clusterOverlayIds.length > 0 ? mapInstance.queryRenderedFeatures(e.point, { layers: clusterOverlayIds })[0] : void 0;
10112
+ if (!clusterHit) {
10113
+ if (selectedFeatureIdsRef.current.length > 0 && !isModifierKey) {
10114
+ applySelectionState([]);
10115
+ }
10116
+ return;
9382
10117
  }
9383
- return;
10118
+ const memberId = (_a = clusterHit.properties) == null ? void 0 : _a[CLUSTER_MEMBER_ID_PROP];
10119
+ if (memberId == null || memberId === "") return;
10120
+ clusteredFeatureId = String(memberId);
9384
10121
  }
9385
- const hitFeature = features[0];
9386
- const featureId = (_a = hitFeature.properties) == null ? void 0 : _a.id;
10122
+ const featureId = clusteredFeatureId ?? ((_b = features[0].properties) == null ? void 0 : _b.id);
9387
10123
  if (!featureId) return;
9388
10124
  let isReadOnly = false;
9389
10125
  readOnlyFeatures.current.forEach((layerFeatures) => {
@@ -9650,6 +10386,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9650
10386
  map.current.flyTo({ center: center.geometry.coordinates });
9651
10387
  },
9652
10388
  listLayers: () => [...layersRef.current],
10389
+ // Worker parse + streamed transfer + the canvas progress overlay, with
10390
+ // layer creation left to the host (see MapEditorHandle docs).
10391
+ parseGeoJSONText: (label, text) => ingestWithProgress(label, text, { idStrategy: "preserve" }),
9653
10392
  addLayer: (name, geojson, options) => {
9654
10393
  if (!isMapLoadedRef.current) return "";
9655
10394
  if (options == null ? void 0 : options.recordHistory) saveStateForUndo(`add layer "${name}"`);
@@ -10681,10 +11420,17 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10681
11420
  scheduleSync();
10682
11421
  scheduleTimelineUpdate();
10683
11422
  setFeatureUpdateCounter((c) => c + 1);
11423
+ if (hasRealChange && !(options == null ? void 0 : options.fromRefresh) && layersRef.current.some((l) => {
11424
+ var _a2;
11425
+ return (_a2 = l.clusterConfig) == null ? void 0 : _a2.enabled;
11426
+ })) {
11427
+ setClusterDataVersion((c) => c + 1);
11428
+ }
10684
11429
  const updated = draw.current.get(featureId);
10685
11430
  if (updated) onFeatureUpdate == null ? void 0 : onFeatureUpdate(updated);
10686
11431
  } else {
10687
11432
  let updatedFeature;
11433
+ let anyRealChange = false;
10688
11434
  readOnlyFeatures.current.forEach((features, layerId) => {
10689
11435
  var _a2;
10690
11436
  const idx = features.findIndex((f) => String(f.id) === featureId);
@@ -10696,6 +11442,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10696
11442
  const oldVal = (_a3 = f.properties) == null ? void 0 : _a3[key];
10697
11443
  if (JSON.stringify(oldVal) !== JSON.stringify(value)) hasRealChange = true;
10698
11444
  });
11445
+ if (hasRealChange) anyRealChange = true;
10699
11446
  const currentUnsaved = (_a2 = f.properties) == null ? void 0 : _a2._unsaved;
10700
11447
  const nextProperties = { ...f.properties, ...normalizedProperties };
10701
11448
  if (!externalPersistence && hasRealChange && currentUnsaved !== false && !(options == null ? void 0 : options.fromRefresh)) {
@@ -10716,6 +11463,12 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10716
11463
  scheduleSync();
10717
11464
  scheduleTimelineUpdate();
10718
11465
  setFeatureUpdateCounter((c) => c + 1);
11466
+ if (anyRealChange && !(options == null ? void 0 : options.fromRefresh) && layersRef.current.some((l) => {
11467
+ var _a2;
11468
+ return (_a2 = l.clusterConfig) == null ? void 0 : _a2.enabled;
11469
+ })) {
11470
+ setClusterDataVersion((c) => c + 1);
11471
+ }
10719
11472
  onFeatureUpdate == null ? void 0 : onFeatureUpdate(updatedFeature);
10720
11473
  }
10721
11474
  }
@@ -10743,6 +11496,12 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10743
11496
  draw.current.changeMode("simple_select", { featureIds: [featureId] });
10744
11497
  scheduleSync();
10745
11498
  setFeatureUpdateCounter((c) => c + 1);
11499
+ if (layersRef.current.some((l) => {
11500
+ var _a;
11501
+ return (_a = l.clusterConfig) == null ? void 0 : _a.enabled;
11502
+ })) {
11503
+ setClusterDataVersion((c) => c + 1);
11504
+ }
10746
11505
  const updated = draw.current.get(featureId);
10747
11506
  if (updated) {
10748
11507
  onFeatureUpdate == null ? void 0 : onFeatureUpdate(updated);
@@ -11097,11 +11856,17 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11097
11856
  try {
11098
11857
  if (firstVisibleBasemapSymbol) {
11099
11858
  m.moveLayer("custom-labels", firstVisibleBasemapSymbol.id);
11859
+ if (m.getLayer("custom-labels-pinned")) {
11860
+ m.moveLayer("custom-labels-pinned", firstVisibleBasemapSymbol.id);
11861
+ }
11100
11862
  if (m.getLayer("custom-arrow-labels")) {
11101
11863
  m.moveLayer("custom-arrow-labels", firstVisibleBasemapSymbol.id);
11102
11864
  }
11103
11865
  } else {
11104
11866
  m.moveLayer("custom-labels");
11867
+ if (m.getLayer("custom-labels-pinned")) {
11868
+ m.moveLayer("custom-labels-pinned");
11869
+ }
11105
11870
  if (m.getLayer("custom-arrow-labels")) {
11106
11871
  m.moveLayer("custom-arrow-labels");
11107
11872
  }
@@ -11406,7 +12171,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11406
12171
  const layer = layers.find((l) => l.id === layerId);
11407
12172
  if (!layer) return [];
11408
12173
  const fieldsMap = /* @__PURE__ */ new Map();
11409
- const excludedFields = /* @__PURE__ */ new Set(["name", "startDate", "endDate", "opacity"]);
12174
+ const excludedFields = /* @__PURE__ */ new Set(["name", "startDate", "endDate", "opacity", ...STYLING_PROPERTY_KEYS]);
11410
12175
  const MAX_SAMPLES = 1e4;
11411
12176
  let features = [];
11412
12177
  if (layer.readOnly) {
@@ -11416,22 +12181,41 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11416
12181
  } else {
11417
12182
  features = hiddenFeatures.current.get(layerId) || [];
11418
12183
  }
11419
- const sampleFeatures = features.slice(0, MAX_SAMPLES);
12184
+ const sampled = !layer.readOnly && features.length > MAX_SAMPLES;
12185
+ const sampleFeatures = layer.readOnly ? features : features.slice(0, MAX_SAMPLES);
11420
12186
  sampleFeatures.forEach((f) => {
11421
12187
  if (f && f.properties) {
11422
12188
  Object.entries(f.properties).forEach(([key, value]) => {
11423
- if (!excludedFields.has(key)) {
11424
- const isNumeric = typeof value === "number" || typeof value === "string" && value.trim() !== "" && !isNaN(Number(value));
11425
- if (!fieldsMap.has(key)) {
11426
- fieldsMap.set(key, isNumeric);
11427
- } else if (isNumeric && !fieldsMap.get(key)) {
11428
- fieldsMap.set(key, true);
11429
- }
12189
+ if (excludedFields.has(key)) return;
12190
+ let acc = fieldsMap.get(key);
12191
+ if (!acc) {
12192
+ acc = { isNumeric: false, numericCount: 0, nonEmptyCount: 0, min: Infinity, max: -Infinity };
12193
+ fieldsMap.set(key, acc);
12194
+ }
12195
+ if (typeof value === "number" || typeof value === "string" && value.trim() !== "" && !isNaN(Number(value))) {
12196
+ acc.isNumeric = true;
12197
+ }
12198
+ if (!(value == null || typeof value === "string" && value.trim() === "")) {
12199
+ acc.nonEmptyCount++;
12200
+ }
12201
+ const num = coerceFiniteNumber(value);
12202
+ if (num !== null) {
12203
+ acc.numericCount++;
12204
+ if (num < acc.min) acc.min = num;
12205
+ if (num > acc.max) acc.max = num;
11430
12206
  }
11431
12207
  });
11432
12208
  }
11433
12209
  });
11434
- return Array.from(fieldsMap.entries()).map(([name, isNumeric]) => ({ name, isNumeric })).sort((a, b) => a.name.localeCompare(b.name));
12210
+ const sampledFeatureCount = sampleFeatures.length;
12211
+ return Array.from(fieldsMap.entries()).map(([name, acc]) => ({
12212
+ name,
12213
+ isNumeric: acc.isNumeric,
12214
+ numericRatio: acc.nonEmptyCount > 0 ? acc.numericCount / acc.nonEmptyCount : 0,
12215
+ coverage: sampledFeatureCount > 0 ? acc.nonEmptyCount / sampledFeatureCount : 0,
12216
+ sampled,
12217
+ ...acc.numericCount > 0 ? { min: acc.min, max: acc.max } : {}
12218
+ })).sort((a, b) => a.name.localeCompare(b.name));
11435
12219
  }, [layers]);
11436
12220
  const getFieldValueDistribution = react.useCallback(
11437
12221
  (layerId, fieldName, maxValues = 50) => {
@@ -12787,10 +13571,22 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
12787
13571
  duration: 1e3
12788
13572
  });
12789
13573
  }, [layers, toast]);
13574
+ const [ingestProgressStore] = react.useState(createIngestProgressStore);
13575
+ const ingestWithProgress = react.useCallback(async (label, input, options) => {
13576
+ const progress = ingestProgressStore.begin(label);
13577
+ try {
13578
+ return await getSharedIngestClient().ingest(input, options, {
13579
+ onHead: (summary) => progress.setTotal(summary.featureCount),
13580
+ onProgress: (received) => progress.update(received)
13581
+ });
13582
+ } finally {
13583
+ progress.end();
13584
+ }
13585
+ }, [ingestProgressStore]);
12790
13586
  const loadGeoJSONFile = react.useCallback(async (file, requestedTargetLayerId, createNewLayer) => {
12791
13587
  let result;
12792
13588
  try {
12793
- result = await getSharedIngestClient().ingest(file, {
13589
+ result = await ingestWithProgress(file.name, file, {
12794
13590
  idStrategy: "uuid-fallback",
12795
13591
  emptyIsError: true
12796
13592
  });
@@ -12929,7 +13725,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
12929
13725
  title: "GeoJSON loaded",
12930
13726
  description: `Added ${normalizedFeatures.length} features${reprojectMsg}${!(targetLayer == null ? void 0 : targetLayer.visible) ? " (layer hidden)" : ""}`
12931
13727
  });
12932
- }, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad]);
13728
+ }, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad, ingestWithProgress]);
12933
13729
  const handleFileChange = react.useCallback((e) => {
12934
13730
  var _a;
12935
13731
  const file = (_a = e.target.files) == null ? void 0 : _a[0];
@@ -12946,7 +13742,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
12946
13742
  const startedAt = performance.now();
12947
13743
  let result;
12948
13744
  try {
12949
- result = await getSharedIngestClient().ingest(input, { idStrategy: "layer-index", layerId });
13745
+ result = await ingestWithProgress(name, input, { idStrategy: "layer-index", layerId });
12950
13746
  } catch (error) {
12951
13747
  toast({
12952
13748
  title: "Failed to load GeoJSON",
@@ -13013,7 +13809,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13013
13809
  title: "Layer added",
13014
13810
  description: `Created "${newLayer.name}" with ${addedIds.length} features${reprojectMsg} (high-performance)`
13015
13811
  });
13016
- }, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad]);
13812
+ }, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad, ingestWithProgress]);
13017
13813
  const handleDropGeoJSON = react.useCallback((name, data) => {
13018
13814
  void ingestDroppedLayer(name, data);
13019
13815
  }, [ingestDroppedLayer]);
@@ -13034,7 +13830,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13034
13830
  prevTimelineEnabledRef.current = isNowEnabled;
13035
13831
  if (!isNowEnabled || !timelineStore.hasTemporalData) {
13036
13832
  timelineVisibleIdsRef.current = null;
13037
- scheduleSync();
13833
+ scheduleSync("timeline");
13038
13834
  } else if (!wasEnabled && isNowEnabled) {
13039
13835
  updateTimelineStore();
13040
13836
  }
@@ -13167,16 +13963,33 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13167
13963
  mapInstance.once("idle", rebuildClusters);
13168
13964
  return;
13169
13965
  }
13966
+ clusterLayerHandlers.current.forEach((handlers, layerId) => {
13967
+ const clustersLayerId = `clusters-${layerId}`;
13968
+ try {
13969
+ mapInstance.off("click", clustersLayerId, handlers.click);
13970
+ mapInstance.off("mouseenter", clustersLayerId, handlers.enter);
13971
+ mapInstance.off("mouseleave", clustersLayerId, handlers.leave);
13972
+ } catch {
13973
+ }
13974
+ });
13975
+ clusterLayerHandlers.current.clear();
13170
13976
  layers.forEach((layer) => {
13171
13977
  const sourceId = `cluster-source-${layer.id}`;
13172
13978
  const clustersLayerId = `clusters-${layer.id}`;
13173
13979
  const clusterCountLayerId = `cluster-count-${layer.id}`;
13174
13980
  const unclusteredLayerId = `unclustered-point-${layer.id}`;
13981
+ const singleValueLayerId = `cluster-single-${layer.id}`;
13982
+ const singleValueCountLayerId = `cluster-single-count-${layer.id}`;
13175
13983
  const existingPieManager = clusterPieManagers.current.get(layer.id);
13176
13984
  if (existingPieManager) {
13177
13985
  existingPieManager.destroy();
13178
13986
  clusterPieManagers.current.delete(layer.id);
13179
13987
  }
13988
+ const existingGradientManager = clusterGradientManagers.current.get(layer.id);
13989
+ if (existingGradientManager) {
13990
+ existingGradientManager.destroy();
13991
+ clusterGradientManagers.current.delete(layer.id);
13992
+ }
13180
13993
  try {
13181
13994
  if (mapInstance.getLayer(clusterCountLayerId)) {
13182
13995
  mapInstance.removeLayer(clusterCountLayerId);
@@ -13184,6 +13997,12 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13184
13997
  if (mapInstance.getLayer(clustersLayerId)) {
13185
13998
  mapInstance.removeLayer(clustersLayerId);
13186
13999
  }
14000
+ if (mapInstance.getLayer(singleValueCountLayerId)) {
14001
+ mapInstance.removeLayer(singleValueCountLayerId);
14002
+ }
14003
+ if (mapInstance.getLayer(singleValueLayerId)) {
14004
+ mapInstance.removeLayer(singleValueLayerId);
14005
+ }
13187
14006
  if (mapInstance.getLayer(unclusteredLayerId)) {
13188
14007
  mapInstance.removeLayer(unclusteredLayerId);
13189
14008
  }
@@ -13194,12 +14013,14 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13194
14013
  }
13195
14014
  });
13196
14015
  layers.forEach((layer) => {
13197
- var _a, _b, _c, _d;
14016
+ var _a, _b, _c, _d, _e, _f, _g;
13198
14017
  if (!((_a = layer.clusterConfig) == null ? void 0 : _a.enabled) || !layer.visible) return;
13199
14018
  const sourceId = `cluster-source-${layer.id}`;
13200
14019
  const clustersLayerId = `clusters-${layer.id}`;
13201
14020
  const clusterCountLayerId = `cluster-count-${layer.id}`;
13202
14021
  const unclusteredLayerId = `unclustered-point-${layer.id}`;
14022
+ const singleValueLayerId = `cluster-single-${layer.id}`;
14023
+ const singleValueCountLayerId = `cluster-single-count-${layer.id}`;
13203
14024
  let pointFeatures = [];
13204
14025
  if (layer.visible) {
13205
14026
  if (layer.readOnly) {
@@ -13226,10 +14047,12 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13226
14047
  }
13227
14048
  if (pointFeatures.length === 0) return;
13228
14049
  const groupByField = (_b = layer.clusterConfig) == null ? void 0 : _b.groupByField;
14050
+ const countByField = ((_c = layer.clusterConfig) == null ? void 0 : _c.countByFieldEnabled) && ((_d = layer.clusterConfig) == null ? void 0 : _d.countByField) || null;
14051
+ const bubbleGradient = !!((_e = layer.clusterConfig) == null ? void 0 : _e.bubbleGradient) && !groupByField;
13229
14052
  const OTHER_COLOR = OTHER_BUCKET_COLOR;
13230
14053
  const MAX_CATEGORIES = 15;
13231
14054
  try {
13232
- const layerColor = ((_d = (_c = layer.visualConfig) == null ? void 0 : _c.color) == null ? void 0 : _d.fixedColor) || "#3b82f6";
14055
+ const layerColor = ((_g = (_f = layer.visualConfig) == null ? void 0 : _f.color) == null ? void 0 : _g.fixedColor) || "#3b82f6";
13233
14056
  let clusterProperties = {};
13234
14057
  let categoryValues = [];
13235
14058
  let categoryColorMap = {};
@@ -13259,12 +14082,16 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13259
14082
  const otherExpr = topKeys.length === 0 ? 1 : ["match", fieldAsString, topKeys, 0, 1];
13260
14083
  clusterProperties[`cat_${categoryValues.length - 1}`] = ["+", otherExpr];
13261
14084
  }
14085
+ if (countByField) {
14086
+ clusterProperties[CLUSTER_SUM_PROP] = ["+", ["get", CLUSTER_COUNT_VALUE_PROP]];
14087
+ }
14088
+ const sourceFeatures = countByField ? injectClusterCountValues(pointFeatures, countByField) : pointFeatures;
13262
14089
  const mapStyleMaxZoom = typeof mapInstance.getMaxZoom === "function" ? mapInstance.getMaxZoom() : 24;
13263
14090
  const clusterMaxZoom = Math.min(24, Math.max(1, mapStyleMaxZoom - 1));
13264
14091
  const geojsonSourceMaxZoom = Math.min(24, Math.max(clusterMaxZoom + 1, mapStyleMaxZoom));
13265
14092
  mapInstance.addSource(sourceId, {
13266
14093
  type: "geojson",
13267
- data: { type: "FeatureCollection", features: pointFeatures },
14094
+ data: { type: "FeatureCollection", features: sourceFeatures },
13268
14095
  maxzoom: geojsonSourceMaxZoom,
13269
14096
  cluster: true,
13270
14097
  clusterMaxZoom,
@@ -13322,12 +14149,15 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13322
14149
  source: sourceId,
13323
14150
  filter: ["has", "point_count"],
13324
14151
  layout: {
13325
- "text-field": ["get", "point_count_abbreviated"],
14152
+ "text-field": countByField ? clusterBadgeTextField(CLUSTER_SUM_PROP) : ["get", "point_count_abbreviated"],
13326
14153
  "text-font": ["Open Sans Bold", "Arial Unicode MS Bold"],
13327
14154
  "text-size": 12
13328
14155
  },
13329
14156
  paint: {
13330
- "text-color": "#ffffff"
14157
+ "text-color": "#ffffff",
14158
+ // The gradient's pale end needs a dark halo for the white
14159
+ // badge text to stay readable at every ramp stop.
14160
+ ...bubbleGradient ? { "text-halo-color": "#111827", "text-halo-width": 1.1 } : {}
13331
14161
  }
13332
14162
  });
13333
14163
  }
@@ -13342,7 +14172,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13342
14172
  id: unclusteredLayerId,
13343
14173
  type: "circle",
13344
14174
  source: sourceId,
13345
- filter: ["!", ["has", "point_count"]],
14175
+ // With count-by-field on, points whose value exceeds 1 render as
14176
+ // value bubbles below instead of plain dots.
14177
+ filter: countByField ? ["all", ["!", ["has", "point_count"]], ["<=", ["get", CLUSTER_COUNT_VALUE_PROP], 1]] : ["!", ["has", "point_count"]],
13346
14178
  paint: {
13347
14179
  "circle-color": unclusteredColor,
13348
14180
  "circle-radius": 6,
@@ -13350,7 +14182,50 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13350
14182
  "circle-stroke-color": "#ffffff"
13351
14183
  }
13352
14184
  });
13353
- mapInstance.on("click", clustersLayerId, async (e) => {
14185
+ if (countByField) {
14186
+ const singleValueFilter = ["all", ["!", ["has", "point_count"]], [">", ["get", CLUSTER_COUNT_VALUE_PROP], 1]];
14187
+ mapInstance.addLayer({
14188
+ id: singleValueLayerId,
14189
+ type: "circle",
14190
+ source: sourceId,
14191
+ filter: singleValueFilter,
14192
+ paint: {
14193
+ "circle-color": unclusteredColor,
14194
+ "circle-radius": 14,
14195
+ "circle-stroke-width": 2,
14196
+ "circle-stroke-color": "#ffffff"
14197
+ }
14198
+ });
14199
+ mapInstance.addLayer({
14200
+ id: singleValueCountLayerId,
14201
+ type: "symbol",
14202
+ source: sourceId,
14203
+ filter: singleValueFilter,
14204
+ layout: {
14205
+ "text-field": clusterBadgeTextField(CLUSTER_COUNT_VALUE_PROP),
14206
+ "text-font": ["Open Sans Bold", "Arial Unicode MS Bold"],
14207
+ "text-size": 11,
14208
+ // A bubble without its number reads as broken - never cull.
14209
+ "text-allow-overlap": true,
14210
+ "text-ignore-placement": true
14211
+ },
14212
+ paint: {
14213
+ "text-color": "#ffffff",
14214
+ ...bubbleGradient ? { "text-halo-color": "#111827", "text-halo-width": 1.1 } : {}
14215
+ }
14216
+ });
14217
+ }
14218
+ if (bubbleGradient) {
14219
+ clusterGradientManagers.current.set(
14220
+ layer.id,
14221
+ createClusterGradientManager(mapInstance, sourceId, {
14222
+ clustersLayerId,
14223
+ valueProp: countByField ? CLUSTER_SUM_PROP : null,
14224
+ ...countByField ? { singleLayerId: singleValueLayerId } : {}
14225
+ })
14226
+ );
14227
+ }
14228
+ const handleClusterClick = async (e) => {
13354
14229
  var _a2;
13355
14230
  const features = mapInstance.queryRenderedFeatures(e.point, {
13356
14231
  layers: [clustersLayerId]
@@ -13369,12 +14244,20 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13369
14244
  }
13370
14245
  } catch {
13371
14246
  }
13372
- });
13373
- mapInstance.on("mouseenter", clustersLayerId, () => {
14247
+ };
14248
+ const handleClusterMouseEnter = () => {
13374
14249
  mapInstance.getCanvas().style.cursor = "pointer";
13375
- });
13376
- mapInstance.on("mouseleave", clustersLayerId, () => {
14250
+ };
14251
+ const handleClusterMouseLeave = () => {
13377
14252
  mapInstance.getCanvas().style.cursor = "";
14253
+ };
14254
+ mapInstance.on("click", clustersLayerId, handleClusterClick);
14255
+ mapInstance.on("mouseenter", clustersLayerId, handleClusterMouseEnter);
14256
+ mapInstance.on("mouseleave", clustersLayerId, handleClusterMouseLeave);
14257
+ clusterLayerHandlers.current.set(layer.id, {
14258
+ click: handleClusterClick,
14259
+ enter: handleClusterMouseEnter,
14260
+ leave: handleClusterMouseLeave
13378
14261
  });
13379
14262
  } catch (e) {
13380
14263
  console.warn("Error creating cluster layer:", e);
@@ -13392,7 +14275,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13392
14275
  } catch {
13393
14276
  }
13394
14277
  };
13395
- }, [isMapLoaded, layers, currentMapStyle, hashStringToColor$1]);
14278
+ }, [isMapLoaded, layers, currentMapStyle, hashStringToColor$1, clusterDataVersion]);
13396
14279
  if (mapError) {
13397
14280
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: `flex items-center justify-center h-full bg-muted/30 ${className || ""}`, "data-testid": "map-error", children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Card, { className: "max-w-md", children: [
13398
14281
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4 border-b border-border", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
@@ -13889,6 +14772,13 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13889
14772
  }
13890
14773
  ),
13891
14774
  /* @__PURE__ */ jsxRuntime.jsx(CursorCoordinatesOverlay, { map: isMapLoaded ? map.current : null }),
14775
+ /* @__PURE__ */ jsxRuntime.jsx(
14776
+ IngestProgressOverlay,
14777
+ {
14778
+ store: ingestProgressStore,
14779
+ bottomPx: timelineStore.isEnabled ? TIMEBAR_HEIGHT + TIMEBAR_BOTTOM_OFFSET + 8 : 32
14780
+ }
14781
+ ),
13892
14782
  /* @__PURE__ */ jsxRuntime.jsx(
13893
14783
  "input",
13894
14784
  {
@@ -14905,40 +15795,6 @@ function DebugSidebar({ onAddRandomPoints, onImportKML, onAddDomMarkers, onRemov
14905
15795
  }
14906
15796
  );
14907
15797
  }
14908
- const INTERNAL_PROPERTY_KEYS = /* @__PURE__ */ new Set([
14909
- "fill",
14910
- "fill-opacity",
14911
- "pointRadius",
14912
- "pointIcon",
14913
- "pointIconSize",
14914
- "circleCenter",
14915
- "circleRadius",
14916
- "icon",
14917
- "iconSize",
14918
- "fontSize",
14919
- "fontColor",
14920
- "fontWeight",
14921
- "arrowSize",
14922
- "label",
14923
- "entityType",
14924
- "kind",
14925
- "meta:type",
14926
- "stroke",
14927
- "stroke-width",
14928
- "stroke-opacity"
14929
- ]);
14930
- const INTERNAL_PROPERTY_PREFIXES = [
14931
- "IsHiddenBy",
14932
- "isHidden",
14933
- "isSelected",
14934
- "isTrace",
14935
- "isTimeline",
14936
- "trace"
14937
- ];
14938
- function isInternalProperty(key) {
14939
- if (INTERNAL_PROPERTY_KEYS.has(key)) return true;
14940
- return INTERNAL_PROPERTY_PREFIXES.some((prefix) => key.startsWith(prefix));
14941
- }
14942
15798
  exports.ActionPanel = ActionPanel;
14943
15799
  exports.ClusterPieManager = ClusterPieManager;
14944
15800
  exports.ColorPickerPopover = ColorPickerPopover;