@octostar/map-component 0.3.3 → 0.3.4

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 (46) hide show
  1. package/dist/index.cjs +898 -475
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.mjs +898 -475
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/types/components/layers-panel.d.ts +3 -1
  6. package/dist/types/components/layers-panel.d.ts.map +1 -1
  7. package/dist/types/components/map-editor-canvas.d.ts.map +1 -1
  8. package/dist/types/components/timebar.d.ts +7 -1
  9. package/dist/types/components/timebar.d.ts.map +1 -1
  10. package/dist/types/lib/custom-layer-stack.d.ts +2 -1
  11. package/dist/types/lib/custom-layer-stack.d.ts.map +1 -1
  12. package/dist/types/lib/label-pinning.d.ts +4 -1
  13. package/dist/types/lib/label-pinning.d.ts.map +1 -1
  14. package/dist/types/lib/paint-feature.d.ts +9 -27
  15. package/dist/types/lib/paint-feature.d.ts.map +1 -1
  16. package/dist/types/lib/selection-diff.d.ts +0 -51
  17. package/dist/types/lib/selection-diff.d.ts.map +1 -1
  18. package/dist/types/lib/selection-overlay.d.ts +0 -8
  19. package/dist/types/lib/selection-overlay.d.ts.map +1 -1
  20. package/dist/types/lib/selection-paint.d.ts +9 -1
  21. package/dist/types/lib/selection-paint.d.ts.map +1 -1
  22. package/dist/types/lib/selection-state.d.ts +2 -2
  23. package/dist/types/lib/selection-state.d.ts.map +1 -1
  24. package/dist/types/lib/shard-locator.d.ts +2 -0
  25. package/dist/types/lib/shard-locator.d.ts.map +1 -1
  26. package/dist/types/lib/shard-pipeline.d.ts +4 -5
  27. package/dist/types/lib/shard-pipeline.d.ts.map +1 -1
  28. package/dist/types/lib/shard-registry.d.ts +0 -28
  29. package/dist/types/lib/shard-registry.d.ts.map +1 -1
  30. package/dist/types/lib/timeline-index.d.ts +56 -0
  31. package/dist/types/lib/timeline-index.d.ts.map +1 -0
  32. package/dist/types/lib/timeline-state.d.ts +64 -0
  33. package/dist/types/lib/timeline-state.d.ts.map +1 -0
  34. package/dist/types/lib/timeline-window.d.ts +19 -0
  35. package/dist/types/lib/timeline-window.d.ts.map +1 -0
  36. package/dist/types/lib/trace-group-suggestion.d.ts +17 -0
  37. package/dist/types/lib/trace-group-suggestion.d.ts.map +1 -0
  38. package/dist/types/lib/trace-groups.d.ts +6 -5
  39. package/dist/types/lib/trace-groups.d.ts.map +1 -1
  40. package/dist/types/lib/trace-timeline.d.ts +56 -49
  41. package/dist/types/lib/trace-timeline.d.ts.map +1 -1
  42. package/dist/types/lib/visible-feature-count.d.ts +18 -4
  43. package/dist/types/lib/visible-feature-count.d.ts.map +1 -1
  44. package/package.json +1 -1
  45. package/dist/types/lib/timeline-diff.d.ts +0 -43
  46. package/dist/types/lib/timeline-diff.d.ts.map +0 -1
package/dist/index.cjs CHANGED
@@ -772,6 +772,10 @@ const SELECTED_STATE_KEY = "selected";
772
772
  const SELECTED = ["boolean", ["feature-state", SELECTED_STATE_KEY], false];
773
773
  const SELECTED_STATE = Object.freeze({ [SELECTED_STATE_KEY]: true });
774
774
  const SELECTION_COLOR = "#06b6d4";
775
+ const TIMELINE_HIDDEN_KEY = "timelineHidden";
776
+ const TIMELINE_HIDDEN = ["boolean", ["feature-state", TIMELINE_HIDDEN_KEY], false];
777
+ const TRACE_ENDPOINT_KEY = "traceEndpoint";
778
+ const TRACE_ENDPOINT = ["boolean", ["feature-state", TRACE_ENDPOINT_KEY], false];
775
779
  const LABEL_NEVER_HIDE_PROP = "_labelNeverHide";
776
780
  const PINNED_LABEL_FILTER = ["==", ["get", LABEL_NEVER_HIDE_PROP], 1];
777
781
  const UNPINNED_LABEL_FILTER = ["!=", ["get", LABEL_NEVER_HIDE_PROP], 1];
@@ -780,8 +784,8 @@ function computeLabelNeverHide(label) {
780
784
  }
781
785
  function buildCustomLabelLayout() {
782
786
  return {
783
- // Hide labels for trace points (except last point which has isTraceLabel),
784
- // arrows handled by the custom-arrow-labels layer. Features blanked by
787
+ // Hide labels for trace points (a group's endpoint label is the trace
788
+ // source's, trace-timeline.ts), arrows handled by the custom-arrow-labels layer.Features blanked by
785
789
  // heatmap/cluster modes stay blank in BOTH layers: "never hide"
786
790
  // exempts labels from collision and density culling, it does not resurrect
787
791
  // labels other mode choices explicitly blank.
@@ -793,33 +797,28 @@ function buildCustomLabelLayout() {
793
797
  "",
794
798
  ["==", ["get", "kind"], "arrow"],
795
799
  "",
796
- // Trace points: only show label if isTraceLabel is true (last point in group)
797
- ["all", ["==", ["get", "isTracePoint"], true], ["!=", ["get", "isTraceLabel"], true]],
800
+ ["==", ["get", "isTracePoint"], true],
798
801
  "",
799
802
  ["==", ["get", "kind"], "text"],
800
803
  ["coalesce", ["get", "label"], ["get", "text"], "New Label"],
801
804
  ["coalesce", ["get", "name"], ""]
802
805
  ],
803
- // Text features use their fontSize property; trace labels 14px; others 12px
806
+ // Text features use their fontSize property; others 12px
804
807
  "text-size": [
805
808
  "case",
806
809
  ["==", ["get", "kind"], "text"],
807
810
  ["coalesce", ["get", "fontSize"], 14],
808
- ["==", ["get", "isTraceLabel"], true],
809
- 14,
810
811
  12
811
812
  ],
812
813
  // Text features: center anchor; others: top anchor
813
814
  "text-anchor": ["case", ["==", ["get", "kind"], "text"], "center", "top"],
814
815
  "text-offset": ["case", ["==", ["get", "kind"], "text"], ["literal", [0, 0]], ["literal", [0, 0.8]]],
815
816
  "text-padding": 2,
816
- // Bold font for text features with fontWeight=bold, trace labels, others regular
817
+ // Bold font for text features with fontWeight=bold, others regular
817
818
  "text-font": [
818
819
  "case",
819
820
  ["all", ["==", ["get", "kind"], "text"], ["==", ["get", "fontWeight"], "bold"]],
820
821
  ["literal", ["Montserrat SemiBold", "Noto Sans Regular"]],
821
- ["==", ["get", "isTraceLabel"], true],
822
- ["literal", ["Montserrat Medium", "Noto Sans Regular"]],
823
822
  ["literal", ["Montserrat Regular", "Noto Sans Regular"]]
824
823
  ]
825
824
  };
@@ -835,16 +834,14 @@ function buildCustomLabelPaint(opts) {
835
834
  "#1f2937"
836
835
  ],
837
836
  "text-halo-color": "#ffffff",
838
- // Thicker halo for trace labels and text features
837
+ // Thicker halo for text features
839
838
  "text-halo-width": [
840
839
  "case",
841
840
  ["==", ["get", "kind"], "text"],
842
841
  2,
843
- ["==", ["get", "isTraceLabel"], true],
844
- 2,
845
842
  1.5
846
843
  ],
847
- "text-opacity": (opts == null ? void 0 : opts.hideSelected) ? ["case", SELECTED, 0, visibleOpacity] : visibleOpacity
844
+ "text-opacity": (opts == null ? void 0 : opts.hideSelected) ? ["case", TIMELINE_HIDDEN, 0, SELECTED, 0, visibleOpacity] : visibleOpacity
848
845
  };
849
846
  }
850
847
  const CUSTOM_LAYER_ROLES = [
@@ -914,6 +911,10 @@ function shardInsertAnchor(role) {
914
911
  return "custom-arrow-heads";
915
912
  }
916
913
  }
914
+ const POINT_RADIUS = ["case", TRACE_ENDPOINT, ["get", "_endpointRadius"], ["coalesce", ["get", "pointRadius"], 5]];
915
+ function unlessTimelineHidden(value) {
916
+ return ["case", TIMELINE_HIDDEN, 0, value];
917
+ }
917
918
  function buildLayer(role, sourceId, opts) {
918
919
  const id = customLayerId(role, sourceId);
919
920
  switch (role) {
@@ -926,7 +927,7 @@ function buildLayer(role, sourceId, opts) {
926
927
  filter: ["==", "$type", "Polygon"],
927
928
  paint: {
928
929
  "fill-color": ["get", "fill"],
929
- "fill-opacity": ["get", "fill-opacity"]
930
+ "fill-opacity": unlessTimelineHidden(["get", "fill-opacity"])
930
931
  }
931
932
  };
932
933
  case "polygon-stroke":
@@ -938,7 +939,7 @@ function buildLayer(role, sourceId, opts) {
938
939
  paint: {
939
940
  "line-color": ["get", "stroke"],
940
941
  "line-width": ["get", "stroke-width"],
941
- "line-opacity": ["get", "stroke-opacity"]
942
+ "line-opacity": unlessTimelineHidden(["get", "stroke-opacity"])
942
943
  }
943
944
  };
944
945
  // Custom line layer - preserves original styling
@@ -951,7 +952,7 @@ function buildLayer(role, sourceId, opts) {
951
952
  paint: {
952
953
  "line-color": ["get", "stroke"],
953
954
  "line-width": ["get", "stroke-width"],
954
- "line-opacity": ["get", "stroke-opacity"]
955
+ "line-opacity": unlessTimelineHidden(["get", "stroke-opacity"])
955
956
  }
956
957
  };
957
958
  // Shadow layer rendered beneath points for depth (hidden when emoji icon is set)
@@ -965,7 +966,7 @@ function buildLayer(role, sourceId, opts) {
965
966
  "circle-color": "rgba(0, 0, 0, 0.2)",
966
967
  "circle-radius": [
967
968
  "case",
968
- ["==", ["get", "isTimelineHidden"], 1],
969
+ TIMELINE_HIDDEN,
969
970
  0,
970
971
  ["==", ["get", "isHiddenByCluster"], 1],
971
972
  0,
@@ -973,7 +974,7 @@ function buildLayer(role, sourceId, opts) {
973
974
  0,
974
975
  ["!=", ["get", "icon"], ""],
975
976
  0,
976
- ["+", ["coalesce", ["get", "pointRadius"], 5], 1.5]
977
+ ["+", POINT_RADIUS, 1.5]
977
978
  ],
978
979
  "circle-blur": 0.5,
979
980
  "circle-opacity": [
@@ -1001,7 +1002,7 @@ function buildLayer(role, sourceId, opts) {
1001
1002
  "circle-color": ["coalesce", ["get", "stroke"], "#3b82f6"],
1002
1003
  "circle-radius": [
1003
1004
  "case",
1004
- ["==", ["get", "isTimelineHidden"], 1],
1005
+ TIMELINE_HIDDEN,
1005
1006
  0,
1006
1007
  ["==", ["get", "isHiddenByCluster"], 1],
1007
1008
  0,
@@ -1009,7 +1010,7 @@ function buildLayer(role, sourceId, opts) {
1009
1010
  0,
1010
1011
  ["!=", ["get", "icon"], ""],
1011
1012
  0,
1012
- ["coalesce", ["get", "pointRadius"], 5]
1013
+ POINT_RADIUS
1013
1014
  ],
1014
1015
  "circle-opacity": [
1015
1016
  "case",
@@ -1024,7 +1025,7 @@ function buildLayer(role, sourceId, opts) {
1024
1025
  "circle-stroke-color": ["case", SELECTED, SELECTION_COLOR, "#555555"],
1025
1026
  "circle-stroke-width": [
1026
1027
  "case",
1027
- ["==", ["get", "isTimelineHidden"], 1],
1028
+ TIMELINE_HIDDEN,
1028
1029
  0,
1029
1030
  ["==", ["get", "isHiddenByCluster"], 1],
1030
1031
  0,
@@ -1064,6 +1065,8 @@ function buildLayer(role, sourceId, opts) {
1064
1065
  paint: {
1065
1066
  "icon-opacity": [
1066
1067
  "case",
1068
+ TIMELINE_HIDDEN,
1069
+ 0,
1067
1070
  ["==", ["get", "isHiddenByCluster"], 1],
1068
1071
  0,
1069
1072
  ["==", ["get", "isHiddenByHeatmap"], 1],
@@ -1073,7 +1076,7 @@ function buildLayer(role, sourceId, opts) {
1073
1076
  }
1074
1077
  };
1075
1078
  // Label layer for all features - shows 'name' property, or 'text' for text features
1076
- // Trace labels are slightly bigger and bolder, hidden points have no labels
1079
+ // Trace points have no label here: a group's label is the trace source's
1077
1080
  // Arrow labels are handled separately by the custom-arrow-labels layer.
1078
1081
  // Shared layout/paint live in label-pinning.ts so this layer and its
1079
1082
  // pinned twin below cannot drift.
@@ -1211,77 +1214,6 @@ function shardFingerprintsEqual(a, b) {
1211
1214
  if (!a || !b) return false;
1212
1215
  return Object.is(a.features, b.features) && Object.is(a.visualConfig, b.visualConfig) && Object.is(a.heatmapConfig, b.heatmapConfig) && Object.is(a.clusterConfig, b.clusterConfig) && Object.is(a.altitudeDisplayMode, b.altitudeDisplayMode) && Object.is(a.hasAltitudeData, b.hasAltitudeData) && Object.is(a.shardSize, b.shardSize);
1213
1216
  }
1214
- const DEFAULT_VISIBLE_STROKE_OPACITY = 1;
1215
- const DEFAULT_VISIBLE_FILL_OPACITY = 0.2;
1216
- function createSelectionPaintCache() {
1217
- return {
1218
- presentIds: /* @__PURE__ */ new Set(),
1219
- appliedHiddenIds: /* @__PURE__ */ new Set(),
1220
- visibleStrokeOpacityById: /* @__PURE__ */ new Map(),
1221
- visibleFillOpacityById: /* @__PURE__ */ new Map(),
1222
- updatable: true
1223
- };
1224
- }
1225
- function recordPaintedFeature(cache2, featureId, visibleStrokeOpacity, visibleFillOpacity, isTimelineHidden) {
1226
- if (cache2.presentIds.has(featureId)) {
1227
- cache2.updatable = false;
1228
- } else {
1229
- cache2.presentIds.add(featureId);
1230
- }
1231
- if (visibleStrokeOpacity !== DEFAULT_VISIBLE_STROKE_OPACITY) {
1232
- cache2.visibleStrokeOpacityById.set(featureId, visibleStrokeOpacity);
1233
- }
1234
- if (visibleFillOpacity !== DEFAULT_VISIBLE_FILL_OPACITY) {
1235
- cache2.visibleFillOpacityById.set(featureId, visibleFillOpacity);
1236
- }
1237
- if (isTimelineHidden) cache2.appliedHiddenIds.add(featureId);
1238
- }
1239
- function needsDrawSelectionUpdate(input) {
1240
- return input.editableSelectionCount > 0 || input.drawSelectedCount > 0 || input.currentMode !== input.targetMode;
1241
- }
1242
- function buildTimelineVisibilityDiff(cache2, nextVisibleSet) {
1243
- const update = [];
1244
- const nextHiddenIds = /* @__PURE__ */ new Set();
1245
- cache2.presentIds.forEach((id) => {
1246
- const nextHidden = nextVisibleSet !== null && !nextVisibleSet.has(id);
1247
- if (nextHidden) nextHiddenIds.add(id);
1248
- if (nextHidden === cache2.appliedHiddenIds.has(id)) return;
1249
- if (nextHidden) {
1250
- update.push({
1251
- id,
1252
- addOrUpdateProperties: [
1253
- { key: "stroke-opacity", value: 0 },
1254
- { key: "fill-opacity", value: 0 },
1255
- { key: "isTimelineHidden", value: 1 }
1256
- ]
1257
- });
1258
- } else {
1259
- update.push({
1260
- id,
1261
- addOrUpdateProperties: [
1262
- { key: "stroke-opacity", value: cache2.visibleStrokeOpacityById.get(id) ?? DEFAULT_VISIBLE_STROKE_OPACITY },
1263
- { key: "fill-opacity", value: cache2.visibleFillOpacityById.get(id) ?? DEFAULT_VISIBLE_FILL_OPACITY },
1264
- { key: "isTimelineHidden", value: 0 }
1265
- ]
1266
- });
1267
- }
1268
- });
1269
- return { diff: update.length > 0 ? { update } : null, nextHiddenIds };
1270
- }
1271
- function applyTimelineFastPath(cache2, nextVisibleSet, source) {
1272
- var _a;
1273
- if (!cache2 || !cache2.updatable || !source) return { applied: false, toggled: 0 };
1274
- const { diff, nextHiddenIds } = buildTimelineVisibilityDiff(cache2, nextVisibleSet);
1275
- if (diff) {
1276
- try {
1277
- source.updateData(diff);
1278
- } catch {
1279
- return { applied: false, toggled: 0 };
1280
- }
1281
- }
1282
- cache2.appliedHiddenIds = nextHiddenIds;
1283
- return { applied: true, toggled: ((_a = diff == null ? void 0 : diff.update) == null ? void 0 : _a.length) ?? 0 };
1284
- }
1285
1217
  const INTERACTIVE_ROLES = ["point", "line", "polygon-fill"];
1286
1218
  function createShardRegistry(host, hooks) {
1287
1219
  const states = /* @__PURE__ */ new Map();
@@ -1289,7 +1221,7 @@ function createShardRegistry(host, hooks) {
1289
1221
  const ensure = (layerId) => {
1290
1222
  let state = states.get(layerId);
1291
1223
  if (!state) {
1292
- state = { layerId, stacks: [], caches: [], fingerprint: null, inFlightFingerprint: null, generation: 0, visible: true, arrowLines: [] };
1224
+ state = { layerId, stacks: [], fingerprint: null, inFlightFingerprint: null, generation: 0, visible: true, arrowLines: [] };
1293
1225
  states.set(layerId, state);
1294
1226
  }
1295
1227
  return state;
@@ -1336,7 +1268,6 @@ function createShardRegistry(host, hooks) {
1336
1268
  removeStack(state.stacks[i]);
1337
1269
  }
1338
1270
  state.stacks.length = Math.min(state.stacks.length, index);
1339
- state.caches.length = state.stacks.length;
1340
1271
  };
1341
1272
  return {
1342
1273
  registerShared(layerIds) {
@@ -1431,50 +1362,9 @@ function createShardRegistry(host, hooks) {
1431
1362
  });
1432
1363
  });
1433
1364
  return ids;
1434
- },
1435
- sourceFor(layerId, index) {
1436
- var _a;
1437
- const stack = (_a = states.get(layerId)) == null ? void 0 : _a.stacks[index];
1438
- return stack ? host.getSource(stack.sourceId) : void 0;
1439
- },
1440
- sourceById(sourceId) {
1441
- return host.getSource(sourceId);
1442
- },
1443
- everyPaintedShard(visit) {
1444
- let ok = true;
1445
- states.forEach((state) => {
1446
- if (!ok) return;
1447
- state.stacks.forEach((stack, i) => {
1448
- if (!ok) return;
1449
- const cache2 = state.caches[i];
1450
- if (!cache2) return;
1451
- if (!visit(cache2, stack.sourceId)) ok = false;
1452
- });
1453
- });
1454
- return ok;
1455
1365
  }
1456
1366
  };
1457
1367
  }
1458
- function reconcileShardCaches(registry, layerId, expectedShards, visibleIds) {
1459
- const state = registry.state(layerId);
1460
- if (!state || state.stacks.length !== expectedShards) return false;
1461
- for (let i = 0; i < expectedShards; i++) {
1462
- const cache2 = state.caches[i];
1463
- if (!cache2) return false;
1464
- const source = registry.sourceFor(layerId, i);
1465
- if (!source) return false;
1466
- if (!applyTimelineFastPath(cache2, visibleIds, source).applied) return false;
1467
- }
1468
- return true;
1469
- }
1470
- function forEachShardCache(registry, apply) {
1471
- if (!registry) return true;
1472
- return registry.everyPaintedShard((cache2, sourceId) => {
1473
- const source = registry.sourceById(sourceId);
1474
- if (!source) return false;
1475
- return apply(cache2, source);
1476
- });
1477
- }
1478
1368
  function categoricalKey(raw) {
1479
1369
  if (raw == null) return null;
1480
1370
  if (typeof raw === "string") return raw === "" ? null : raw;
@@ -1593,6 +1483,158 @@ function formatGradientStop(value) {
1593
1483
  }
1594
1484
  return new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 }).format(value);
1595
1485
  }
1486
+ function windowFromRange(start, end) {
1487
+ if (!start || !end) return null;
1488
+ const t0 = start.getTime();
1489
+ const t1 = end.getTime();
1490
+ return Number.isFinite(t0) && Number.isFinite(t1) ? { t0, t1 } : null;
1491
+ }
1492
+ function sameWindow(a, b) {
1493
+ if (a === null || b === null) return a === b;
1494
+ return a.t0 === b.t0 && a.t1 === b.t1;
1495
+ }
1496
+ function isIntervalVisible(s, e, w) {
1497
+ if (w === null) return true;
1498
+ const noStart = Number.isNaN(s);
1499
+ const noEnd = Number.isNaN(e);
1500
+ if (noStart && noEnd) return true;
1501
+ return (noStart ? e : s) <= w.t1 && (noEnd ? s : e) >= w.t0;
1502
+ }
1503
+ const interval = { s: NaN, e: NaN };
1504
+ function readInterval(f) {
1505
+ interval.s = NaN;
1506
+ interval.e = NaN;
1507
+ const props = f.properties;
1508
+ if (!props || !hasAnyTemporalValue(props)) return;
1509
+ const { startDate, endDate } = normalizeTemporalProperties(props);
1510
+ const s = startDate ? startDate.getTime() : NaN;
1511
+ const e = endDate ? endDate.getTime() : NaN;
1512
+ interval.s = Number.isNaN(s) ? e : s;
1513
+ interval.e = Number.isNaN(e) ? s : e;
1514
+ }
1515
+ function featureInterval(f) {
1516
+ readInterval(f);
1517
+ return { s: interval.s, e: interval.e };
1518
+ }
1519
+ function isFeatureVisible(f, w) {
1520
+ if (w === null) return true;
1521
+ readInterval(f);
1522
+ return isIntervalVisible(interval.s, interval.e, w);
1523
+ }
1524
+ function collectRepeats(features) {
1525
+ const first = /* @__PURE__ */ new Map();
1526
+ const repeats = /* @__PURE__ */ new Map();
1527
+ for (let i = 0; i < features.length; i++) {
1528
+ const id = features[i].id;
1529
+ if (id === void 0 || id === null) continue;
1530
+ const key = String(id);
1531
+ const at = first.get(key);
1532
+ if (at === void 0) first.set(key, i);
1533
+ else {
1534
+ const more = repeats.get(key);
1535
+ if (more) more.push(i);
1536
+ else repeats.set(key, [at, i]);
1537
+ }
1538
+ }
1539
+ return repeats;
1540
+ }
1541
+ function buildIndex(features) {
1542
+ const size = features.length;
1543
+ const starts = new Float64Array(size);
1544
+ const ends = new Float64Array(size);
1545
+ let timed = 0;
1546
+ for (let i = 0; i < size; i++) {
1547
+ readInterval(features[i]);
1548
+ starts[i] = interval.s;
1549
+ ends[i] = interval.e;
1550
+ if (!Number.isNaN(interval.s)) timed++;
1551
+ }
1552
+ const byStart = new Uint32Array(timed);
1553
+ for (let i = 0, k = 0; i < size; i++) {
1554
+ if (!Number.isNaN(starts[i])) byStart[k++] = i;
1555
+ }
1556
+ const byEnd = byStart.slice();
1557
+ byStart.sort((a, b) => starts[a] - starts[b]);
1558
+ byEnd.sort((a, b) => ends[a] - ends[b]);
1559
+ return {
1560
+ size,
1561
+ starts,
1562
+ ends,
1563
+ byStart,
1564
+ sortedStarts: Float64Array.from(byStart, (p) => starts[p]),
1565
+ byEnd,
1566
+ sortedEnds: Float64Array.from(byEnd, (p) => ends[p]),
1567
+ untimedCount: size - timed,
1568
+ repeats: collectRepeats(features),
1569
+ mark: new Uint8Array(size)
1570
+ };
1571
+ }
1572
+ const cache$1 = /* @__PURE__ */ new WeakMap();
1573
+ function getTimelineIndex(features) {
1574
+ let index = cache$1.get(features);
1575
+ if (!index) {
1576
+ const started = performance.now();
1577
+ index = buildIndex(features);
1578
+ cache$1.set(features, index);
1579
+ mapPerfLog("timeline", "index built", { n: features.length, ms: Math.round(performance.now() - started) });
1580
+ }
1581
+ return index;
1582
+ }
1583
+ function isVisibleAt(index, position, w) {
1584
+ return isIntervalVisible(index.starts[position], index.ends[position], w);
1585
+ }
1586
+ function upperBound(keys, x) {
1587
+ let lo = 0;
1588
+ let hi = keys.length;
1589
+ while (lo < hi) {
1590
+ const mid = lo + hi >>> 1;
1591
+ if (keys[mid] <= x) lo = mid + 1;
1592
+ else hi = mid;
1593
+ }
1594
+ return lo;
1595
+ }
1596
+ function lowerBound(keys, x) {
1597
+ let lo = 0;
1598
+ let hi = keys.length;
1599
+ while (lo < hi) {
1600
+ const mid = lo + hi >>> 1;
1601
+ if (keys[mid] < x) lo = mid + 1;
1602
+ else hi = mid;
1603
+ }
1604
+ return lo;
1605
+ }
1606
+ const ALL = { t0: -Infinity, t1: Infinity };
1607
+ function flippedPositions(index, from, to, out) {
1608
+ const a = from ?? ALL;
1609
+ const b = to ?? ALL;
1610
+ const { starts, ends, byStart, byEnd, mark } = index;
1611
+ const flips = (p) => isIntervalVisible(starts[p], ends[p], a) !== isIntervalVisible(starts[p], ends[p], b);
1612
+ const s0 = upperBound(index.sortedStarts, Math.min(a.t1, b.t1));
1613
+ const s1 = upperBound(index.sortedStarts, Math.max(a.t1, b.t1));
1614
+ const e0 = lowerBound(index.sortedEnds, Math.min(a.t0, b.t0));
1615
+ const e1 = lowerBound(index.sortedEnds, Math.max(a.t0, b.t0));
1616
+ for (let k = s0; k < s1; k++) {
1617
+ const p = byStart[k];
1618
+ mark[p] = 1;
1619
+ if (flips(p)) out.push(p);
1620
+ }
1621
+ for (let k = e0; k < e1; k++) {
1622
+ const p = byEnd[k];
1623
+ if (mark[p] === 0 && flips(p)) out.push(p);
1624
+ }
1625
+ for (let k = s0; k < s1; k++) mark[byStart[k]] = 0;
1626
+ }
1627
+ function countVisible(index, w) {
1628
+ if (w === null) return index.size;
1629
+ if (w.t0 > w.t1) {
1630
+ let timed = 0;
1631
+ index.byStart.forEach((p) => {
1632
+ if (isVisibleAt(index, p, w)) timed++;
1633
+ });
1634
+ return timed + index.untimedCount;
1635
+ }
1636
+ return upperBound(index.sortedStarts, w.t1) - lowerBound(index.sortedEnds, w.t0) + index.untimedCount;
1637
+ }
1596
1638
  const TRACE_DEFAULT_COLOR = "#3b82f6";
1597
1639
  const TRACE_UNGROUPED_KEY = "__all__";
1598
1640
  const cache = /* @__PURE__ */ new WeakMap();
@@ -1624,16 +1666,17 @@ function compareStaged(a, b) {
1624
1666
  function buildTraceGroups(features, field) {
1625
1667
  var _a;
1626
1668
  const staged = /* @__PURE__ */ new Map();
1627
- for (const feature of features) {
1669
+ for (let position = 0; position < features.length; position++) {
1670
+ const feature = features[position];
1628
1671
  if (feature.id == null || feature.geometry.type !== "Point" || !((_a = feature.properties) == null ? void 0 : _a.startDate)) continue;
1629
1672
  const raw = field ? feature.properties[field] : void 0;
1630
- const key = field && raw ? String(raw) : TRACE_UNGROUPED_KEY;
1673
+ const key = field && raw != null && raw !== "" ? String(raw) : TRACE_UNGROUPED_KEY;
1631
1674
  let bucket = staged.get(key);
1632
1675
  if (!bucket) {
1633
1676
  bucket = [];
1634
1677
  staged.set(key, bucket);
1635
1678
  }
1636
- bucket.push({ feature, time: new Date(feature.properties.startDate).getTime() });
1679
+ bucket.push({ feature, time: new Date(feature.properties.startDate).getTime(), position });
1637
1680
  }
1638
1681
  const count = staged.size;
1639
1682
  const groups = [];
@@ -1644,6 +1687,7 @@ function buildTraceGroups(features, field) {
1644
1687
  points: bucket.map((p) => p.feature),
1645
1688
  ids: bucket.map((p) => String(p.feature.id)),
1646
1689
  times: bucket.map((p) => p.time),
1690
+ positions: bucket.map((p) => p.position),
1647
1691
  color: traceGroupColor(key, groups.length, count),
1648
1692
  label: field && key !== TRACE_UNGROUPED_KEY ? key : null,
1649
1693
  pairStats: /* @__PURE__ */ new Map()
@@ -1657,14 +1701,11 @@ function traceGroupColor(key, index, count) {
1657
1701
  }
1658
1702
  function visibleTraceIndices(group, isVisible) {
1659
1703
  const indices = [];
1660
- for (let i = 0; i < group.ids.length; i++) {
1661
- if (isVisible(group.ids[i])) indices.push(i);
1704
+ for (let i = 0; i < group.positions.length; i++) {
1705
+ if (isVisible(group.positions[i])) indices.push(i);
1662
1706
  }
1663
1707
  return indices;
1664
1708
  }
1665
- function timelineVisibility(visibleSet) {
1666
- return visibleSet === null ? () => true : (id) => visibleSet.has(id);
1667
- }
1668
1709
  function traceSegmentStats(group, fromIndex, toIndex) {
1669
1710
  const key = `${fromIndex}:${toIndex}`;
1670
1711
  const cached = group.pairStats.get(key);
@@ -1714,43 +1755,161 @@ function traceSegmentFeature(group, groupIndex, fromIndex, toIndex) {
1714
1755
  }
1715
1756
  };
1716
1757
  }
1717
- const TRACE_ENDPOINT_LABEL_PRIORITY = 5;
1718
1758
  const TRACE_POINT_RADIUS = 2;
1719
1759
  const TRACE_ENDPOINT_MIN_RADIUS = 8;
1720
- function buildTraceTimelineDiff(trace, paint, nextVisibleSet) {
1721
- const diff = { pointUpdates: [], segmentAdd: [], segmentRemove: [] };
1722
- const paintedVisible = (id) => !paint.appliedHiddenIds.has(id);
1723
- const nextVisible = timelineVisibility(nextVisibleSet);
1724
- trace.groups.forEach((group, groupIndex) => {
1725
- const prev = visibleTraceIndices(group, paintedVisible);
1726
- const next = visibleTraceIndices(group, nextVisible);
1727
- const prevEndpoint = prev.length > 0 ? prev[prev.length - 1] : -1;
1728
- const nextEndpoint = next.length > 0 ? next[next.length - 1] : -1;
1729
- if (prevEndpoint !== nextEndpoint) {
1730
- if (prevEndpoint >= 0) pushEndpointUpdate(diff, trace, group, group.ids[prevEndpoint], false);
1731
- if (nextEndpoint >= 0) pushEndpointUpdate(diff, trace, group, group.ids[nextEndpoint], true);
1760
+ const TRACE_SOURCE_ID = "trace-features";
1761
+ const TRACE_ENDPOINT_LABEL_LAYER_ID = "trace-endpoint-labels";
1762
+ const ENDPOINT_LABEL_KIND = "endpoint-label";
1763
+ const ENDPOINT_STATE = Object.freeze({ [TRACE_ENDPOINT_KEY]: true });
1764
+ function buildTraceEndpointLabelLayer() {
1765
+ return {
1766
+ id: TRACE_ENDPOINT_LABEL_LAYER_ID,
1767
+ type: "symbol",
1768
+ source: TRACE_SOURCE_ID,
1769
+ filter: ["==", ["get", "kind"], ENDPOINT_LABEL_KIND],
1770
+ layout: {
1771
+ "text-field": ["get", "name"],
1772
+ "text-size": 14,
1773
+ "text-font": ["Montserrat Medium", "Noto Sans Regular"],
1774
+ "text-anchor": "top",
1775
+ "text-offset": [0, 0.8],
1776
+ "text-padding": 2,
1777
+ "text-allow-overlap": false,
1778
+ "text-ignore-placement": false,
1779
+ "text-optional": true
1780
+ },
1781
+ paint: {
1782
+ "text-color": "#1f2937",
1783
+ "text-halo-color": "#ffffff",
1784
+ "text-halo-width": 2,
1785
+ "text-opacity": ["*", 0.9, ["coalesce", ["get", "stroke-opacity"], 1]]
1732
1786
  }
1787
+ };
1788
+ }
1789
+ function visibleGroupIndices(group, index, w) {
1790
+ return visibleTraceIndices(group, (position) => isVisibleAt(index, position, w));
1791
+ }
1792
+ const instantStarts = /* @__PURE__ */ new WeakMap();
1793
+ function instantsOf(group, index) {
1794
+ const cached = instantStarts.get(group);
1795
+ if (cached !== void 0) return cached;
1796
+ const starts = new Float64Array(group.positions.length);
1797
+ let instants = starts;
1798
+ for (let i = 0; i < starts.length; i++) {
1799
+ const p = group.positions[i];
1800
+ const s = index.starts[p];
1801
+ if (Number.isNaN(s) || s !== index.ends[p] || i > 0 && s < starts[i - 1]) {
1802
+ instants = null;
1803
+ break;
1804
+ }
1805
+ starts[i] = s;
1806
+ }
1807
+ instantStarts.set(group, instants);
1808
+ return instants;
1809
+ }
1810
+ function firstAbove(keys, x, inclusive) {
1811
+ let lo = 0;
1812
+ let hi = keys.length;
1813
+ while (lo < hi) {
1814
+ const mid = lo + hi >>> 1;
1815
+ if (keys[mid] < x || !inclusive && keys[mid] === x) lo = mid + 1;
1816
+ else hi = mid;
1817
+ }
1818
+ return lo;
1819
+ }
1820
+ function visibleRun(instants, w) {
1821
+ if (w === null) return { lo: 0, hi: instants.length };
1822
+ const lo = firstAbove(instants, w.t0, true);
1823
+ return { lo, hi: Math.max(lo, firstAbove(instants, w.t1, false)) };
1824
+ }
1825
+ function pairsOutside(a, b, visit) {
1826
+ const aEnd = a.hi - 1;
1827
+ const bEnd = b.hi - 1;
1828
+ if (bEnd <= b.lo) {
1829
+ for (let i = a.lo; i < aEnd; i++) visit(i);
1830
+ return;
1831
+ }
1832
+ for (let i = a.lo; i < Math.min(aEnd, b.lo); i++) visit(i);
1833
+ for (let i = Math.max(a.lo, bEnd); i < aEnd; i++) visit(i);
1834
+ }
1835
+ function traceEndpointLabelId(groupIndex) {
1836
+ return `label:${groupIndex}`;
1837
+ }
1838
+ function endpointLabel(group, groupIndex, pointIndex) {
1839
+ var _a;
1840
+ const point = group.points[pointIndex];
1841
+ const opacity = (_a = point.properties) == null ? void 0 : _a["stroke-opacity"];
1842
+ return {
1843
+ type: "Feature",
1844
+ id: traceEndpointLabelId(groupIndex),
1845
+ geometry: point.geometry,
1846
+ properties: {
1847
+ kind: ENDPOINT_LABEL_KIND,
1848
+ name: group.label,
1849
+ ...typeof opacity === "number" && { "stroke-opacity": opacity }
1850
+ }
1851
+ };
1852
+ }
1853
+ function diffGroup(diff, group, groupIndex, index, from, to) {
1854
+ let prevEndpoint;
1855
+ let nextEndpoint;
1856
+ const instants = instantsOf(group, index);
1857
+ if (instants) {
1858
+ const prev = visibleRun(instants, from);
1859
+ const next = visibleRun(instants, to);
1860
+ prevEndpoint = prev.hi > prev.lo ? prev.hi - 1 : -1;
1861
+ nextEndpoint = next.hi > next.lo ? next.hi - 1 : -1;
1862
+ pairsOutside(prev, next, (i) => diff.remove.push(traceSegmentId(groupIndex, i, i + 1)));
1863
+ pairsOutside(next, prev, (i) => diff.add.push(traceSegmentFeature(group, groupIndex, i, i + 1)));
1864
+ } else {
1865
+ const prev = visibleGroupIndices(group, index, from);
1866
+ const next = visibleGroupIndices(group, index, to);
1867
+ prevEndpoint = prev.length > 0 ? prev[prev.length - 1] : -1;
1868
+ nextEndpoint = next.length > 0 ? next[next.length - 1] : -1;
1733
1869
  diffConsecutivePairs(
1734
1870
  prev,
1735
1871
  next,
1736
- (from, to) => diff.segmentRemove.push(traceSegmentId(groupIndex, from, to)),
1737
- (from, to) => diff.segmentAdd.push(traceSegmentFeature(group, groupIndex, from, to))
1872
+ (a, b) => diff.remove.push(traceSegmentId(groupIndex, a, b)),
1873
+ (a, b) => diff.add.push(traceSegmentFeature(group, groupIndex, a, b))
1738
1874
  );
1875
+ }
1876
+ if (prevEndpoint === nextEndpoint) return;
1877
+ if (prevEndpoint >= 0) diff.endpointOff.push(group.ids[prevEndpoint]);
1878
+ if (nextEndpoint >= 0) diff.endpointOn.push(group.ids[nextEndpoint]);
1879
+ if (group.label === null) return;
1880
+ if (nextEndpoint >= 0) diff.add.push(endpointLabel(group, groupIndex, nextEndpoint));
1881
+ else diff.remove.push(traceEndpointLabelId(groupIndex));
1882
+ }
1883
+ function buildTraceTimelineDiff(trace, nextWindow) {
1884
+ const diff = { endpointOff: [], endpointOn: [], add: [], remove: [] };
1885
+ trace.groups.forEach((group, groupIndex) => {
1886
+ diffGroup(diff, group, groupIndex, trace.indexes[groupIndex], trace.window, nextWindow);
1739
1887
  });
1740
1888
  return diff;
1741
1889
  }
1742
- function pushEndpointUpdate(diff, trace, group, id, isEndpoint) {
1743
- const point = trace.pointPaint.get(id);
1744
- if (!point) return;
1745
- const labelled = isEndpoint && group.label !== null;
1746
- diff.pointUpdates.push({
1747
- id,
1748
- addOrUpdateProperties: [
1749
- { key: "pointRadius", value: isEndpoint ? point.endpointRadius : TRACE_POINT_RADIUS },
1750
- { key: "name", value: labelled ? group.label : point.name },
1751
- { key: "isTraceLabel", value: labelled },
1752
- { key: "_labelPriority", value: labelled ? TRACE_ENDPOINT_LABEL_PRIORITY : point.basePriority }
1753
- ]
1890
+ function paintTraceAt(groups, indexes, w) {
1891
+ const endpoints = [];
1892
+ const features = [];
1893
+ groups.forEach((group, groupIndex) => {
1894
+ const visible = visibleGroupIndices(group, indexes[groupIndex], w);
1895
+ if (visible.length === 0) return;
1896
+ const endpoint = visible[visible.length - 1];
1897
+ endpoints.push(group.ids[endpoint]);
1898
+ for (let k = 1; k < visible.length; k++) {
1899
+ features.push(traceSegmentFeature(group, groupIndex, visible[k - 1], visible[k]));
1900
+ }
1901
+ if (group.label !== null) features.push(endpointLabel(group, groupIndex, endpoint));
1902
+ });
1903
+ return { endpoints, features };
1904
+ }
1905
+ function setTraceEndpoints(host, applied, off, on) {
1906
+ off.forEach((id) => {
1907
+ if (applied.delete(id)) host.removeFeatureState(SHARED_SOURCE_ID, id, TRACE_ENDPOINT_KEY);
1908
+ });
1909
+ on.forEach((id) => {
1910
+ if (applied.has(id)) return;
1911
+ host.setFeatureState(SHARED_SOURCE_ID, id, ENDPOINT_STATE);
1912
+ applied.add(id);
1754
1913
  });
1755
1914
  }
1756
1915
  function diffConsecutivePairs(prev, next, onRemove, onAdd) {
@@ -1773,19 +1932,19 @@ function diffConsecutivePairs(prev, next, onRemove, onAdd) {
1773
1932
  }
1774
1933
  }
1775
1934
  }
1776
- function applyTraceTimelineDiff(diff, pointSource, segmentSource) {
1935
+ function applyTraceTimelineDiff(diff, traceSource, host, appliedEndpoints) {
1777
1936
  try {
1778
- if (diff.pointUpdates.length > 0) pointSource.updateData({ update: diff.pointUpdates });
1779
- if (diff.segmentAdd.length > 0 || diff.segmentRemove.length > 0) {
1780
- segmentSource.updateData({ add: diff.segmentAdd, remove: diff.segmentRemove });
1781
- }
1937
+ if (diff.add.length > 0 || diff.remove.length > 0) traceSource.updateData({ add: diff.add, remove: diff.remove });
1782
1938
  } catch (error) {
1783
1939
  console.error("Trace timeline fast path failed; falling back to the full sync:", error);
1784
1940
  return false;
1785
1941
  }
1942
+ setTraceEndpoints(host, appliedEndpoints, diff.endpointOff, diff.endpointOn);
1786
1943
  return true;
1787
1944
  }
1788
1945
  const DEFAULT_LABEL_PRIORITY = 100;
1946
+ const DEFAULT_VISIBLE_STROKE_OPACITY = 1;
1947
+ const DEFAULT_VISIBLE_FILL_OPACITY = 0.2;
1789
1948
  const RENDER_PASSTHROUGH_KEYS = ["_dvl_h3"];
1790
1949
  const ANNOTATION_PASSTHROUGH_KEYS = [
1791
1950
  "kind",
@@ -1802,11 +1961,21 @@ function sanitizeValue(value) {
1802
1961
  if (value instanceof Date) return value.toISOString();
1803
1962
  return String(value);
1804
1963
  }
1964
+ const heatmapHidesPoints = (layer) => {
1965
+ var _a;
1966
+ return ((_a = layer == null ? void 0 : layer.heatmapConfig) == null ? void 0 : _a.enabled) === true;
1967
+ };
1968
+ const clusterHidesPoints = (layer) => {
1969
+ var _a;
1970
+ return ((_a = layer == null ? void 0 : layer.clusterConfig) == null ? void 0 : _a.enabled) === true && !layer.clusterConfig.showPointDots;
1971
+ };
1972
+ function layerHidesPoints(layer) {
1973
+ return heatmapHidesPoints(layer) || clusterHidesPoints(layer);
1974
+ }
1805
1975
  function styleFeatureForPaint(f, layer, ctx, slim) {
1806
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1976
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1807
1977
  const featureId = String(f.id);
1808
1978
  const visualConfig = layer == null ? void 0 : layer.visualConfig;
1809
- const isTimelineVisible = ctx.timelineVisibleIds === null || ctx.timelineVisibleIds.has(featureId);
1810
1979
  const baseOpacity = ((_a = f.properties) == null ? void 0 : _a["stroke-opacity"]) ?? DEFAULT_VISIBLE_STROKE_OPACITY;
1811
1980
  let strokeColor = ((_b = f.properties) == null ? void 0 : _b.stroke) || "#3b82f6";
1812
1981
  const colorConfig = visualConfig == null ? void 0 : visualConfig.color;
@@ -1838,14 +2007,12 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
1838
2007
  }
1839
2008
  }
1840
2009
  }
1841
- const isTracePoint = ctx.tracePointIds.has(featureId);
1842
- const isLastTracePoint = ctx.lastTracePointIds.has(featureId);
1843
- const traceLabel = ctx.lastTracePointLabels.get(featureId);
1844
- let traceEndpointRadius = null;
1845
- if (isTracePoint && f.geometry.type === "Point") {
2010
+ const isTracePoint2 = ctx.tracePointIds.has(featureId);
2011
+ let endpointRadius = 0;
2012
+ if (isTracePoint2 && f.geometry.type === "Point") {
1846
2013
  strokeColor = ctx.tracePointColors.get(featureId) || strokeColor;
1847
- traceEndpointRadius = Math.max(pointRadius, TRACE_ENDPOINT_MIN_RADIUS);
1848
- pointRadius = isLastTracePoint ? traceEndpointRadius : TRACE_POINT_RADIUS;
2014
+ endpointRadius = Math.max(pointRadius, TRACE_ENDPOINT_MIN_RADIUS);
2015
+ pointRadius = TRACE_POINT_RADIUS;
1849
2016
  }
1850
2017
  let labelText = ((_d = f.properties) == null ? void 0 : _d.name) || "";
1851
2018
  const labelConfig = visualConfig == null ? void 0 : visualConfig.label;
@@ -1859,10 +2026,6 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
1859
2026
  labelText = fieldValue !== void 0 && fieldValue !== null ? String(fieldValue) : "";
1860
2027
  }
1861
2028
  }
1862
- const nonTraceLabelText = labelText;
1863
- if (traceLabel) {
1864
- labelText = traceLabel;
1865
- }
1866
2029
  let featureIcon = ((_e = f.properties) == null ? void 0 : _e.pointIcon) || ((_f = f.properties) == null ? void 0 : _f.icon);
1867
2030
  let featureIconSize = ((_g = f.properties) == null ? void 0 : _g.pointIconSize) || ((_h = f.properties) == null ? void 0 : _h.iconSize) || 24;
1868
2031
  const iconConfig = visualConfig == null ? void 0 : visualConfig.icon;
@@ -1871,8 +2034,8 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
1871
2034
  featureIconSize = iconConfig.size ?? 24;
1872
2035
  }
1873
2036
  const isPoint = f.geometry.type === "Point";
1874
- const hideByHeatmap = isPoint && ((_i = layer == null ? void 0 : layer.heatmapConfig) == null ? void 0 : _i.enabled) === true;
1875
- const hideByCluster = isPoint && ((_j = layer == null ? void 0 : layer.clusterConfig) == null ? void 0 : _j.enabled) === true && !((_k = layer == null ? void 0 : layer.clusterConfig) == null ? void 0 : _k.showPointDots);
2037
+ const hideByHeatmap = isPoint && heatmapHidesPoints(layer);
2038
+ const hideByCluster = isPoint && clusterHidesPoints(layer);
1876
2039
  const isLine = f.geometry.type === "LineString" || f.geometry.type === "MultiLineString";
1877
2040
  const hideFlatFor3DOnly = isLine && (layer == null ? void 0 : layer.hasAltitudeData) && (layer == null ? void 0 : layer.altitudeDisplayMode) === "3d";
1878
2041
  const sanitizedProps = {};
@@ -1893,9 +2056,9 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
1893
2056
  });
1894
2057
  }
1895
2058
  }
1896
- let nonTracePriority = DEFAULT_LABEL_PRIORITY;
1897
- if (((_l = f.properties) == null ? void 0 : _l.kind) === "text") {
1898
- nonTracePriority = ((_m = f.properties) == null ? void 0 : _m.fontWeight) === "bold" ? 8 : 10;
2059
+ let labelPriority = DEFAULT_LABEL_PRIORITY;
2060
+ if (((_i = f.properties) == null ? void 0 : _i.kind) === "text") {
2061
+ labelPriority = ((_j = f.properties) == null ? void 0 : _j.fontWeight) === "bold" ? 8 : 10;
1899
2062
  } else {
1900
2063
  const idStr = String(featureId);
1901
2064
  let h = 0;
@@ -1903,11 +2066,10 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
1903
2066
  h = (h << 5) - h + idStr.charCodeAt(i);
1904
2067
  h |= 0;
1905
2068
  }
1906
- nonTracePriority = DEFAULT_LABEL_PRIORITY + Math.abs(h) % 1e3;
2069
+ labelPriority = DEFAULT_LABEL_PRIORITY + Math.abs(h) % 1e3;
1907
2070
  }
1908
- const labelPriority = traceLabel ? TRACE_ENDPOINT_LABEL_PRIORITY : nonTracePriority;
1909
2071
  const visibleStrokeOpacity = hideFlatFor3DOnly ? 0 : baseOpacity;
1910
- const visibleFillOpacity = hideFlatFor3DOnly ? 0 : ((_n = f.properties) == null ? void 0 : _n["fill-opacity"]) ?? DEFAULT_VISIBLE_FILL_OPACITY;
2072
+ const visibleFillOpacity = hideFlatFor3DOnly ? 0 : ((_k = f.properties) == null ? void 0 : _k["fill-opacity"]) ?? DEFAULT_VISIBLE_FILL_OPACITY;
1911
2073
  return {
1912
2074
  feature: {
1913
2075
  type: "Feature",
@@ -1921,28 +2083,20 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
1921
2083
  name: labelText,
1922
2084
  isHiddenByHeatmap: hideByHeatmap ? 1 : 0,
1923
2085
  isHiddenByCluster: hideByCluster ? 1 : 0,
1924
- isTracePoint: isTracePoint ? true : false,
1925
- isTraceLabel: traceLabel ? true : false,
2086
+ isTracePoint: isTracePoint2 ? true : false,
2087
+ _endpointRadius: endpointRadius,
1926
2088
  icon: featureIcon || "",
1927
2089
  iconSize: featureIconSize,
1928
2090
  stroke: strokeColor,
1929
2091
  "stroke-width": strokeWidth,
1930
- "stroke-opacity": isTimelineVisible ? visibleStrokeOpacity : 0,
2092
+ "stroke-opacity": visibleStrokeOpacity,
1931
2093
  fill: strokeColor,
1932
- "fill-opacity": isTimelineVisible ? visibleFillOpacity : 0,
2094
+ "fill-opacity": visibleFillOpacity,
1933
2095
  pointRadius,
1934
- isTimelineHidden: isTimelineVisible ? 0 : 1,
1935
2096
  _labelPriority: labelPriority,
1936
- [LABEL_NEVER_HIDE_PROP]: computeLabelNeverHide((_o = layer == null ? void 0 : layer.visualConfig) == null ? void 0 : _o.label)
2097
+ [LABEL_NEVER_HIDE_PROP]: computeLabelNeverHide((_l = layer == null ? void 0 : layer.visualConfig) == null ? void 0 : _l.label)
1937
2098
  }
1938
- },
1939
- paint: {
1940
- featureId,
1941
- visibleStrokeOpacity,
1942
- visibleFillOpacity,
1943
- timelineHidden: !isTimelineVisible
1944
- },
1945
- tracePaint: traceEndpointRadius !== null ? { name: nonTraceLabelText, endpointRadius: traceEndpointRadius, basePriority: nonTracePriority } : null
2099
+ }
1946
2100
  };
1947
2101
  }
1948
2102
  function layerFieldRanges(visualConfig, forEachProperties) {
@@ -1979,37 +2133,32 @@ async function runShardPass(input) {
1979
2133
  var _a, _b;
1980
2134
  const { features, layer, shardSize, host } = input;
1981
2135
  const ranges = shardRanges(features.length, shardSize);
1982
- const caches = [];
1983
2136
  const arrowLines = [];
1984
2137
  for (let index = 0; index < ranges.length; index++) {
1985
2138
  const { start, end } = ranges[index];
1986
2139
  const slice = features.slice(start, end);
1987
2140
  const roles = rolesForGeometry(geometryClassesOf(slice));
1988
2141
  const ctx = input.contextForShard();
1989
- const cache2 = createSelectionPaintCache();
1990
2142
  const shardArrows = [];
1991
2143
  const painted = slice.map((f) => {
1992
2144
  var _a2;
1993
2145
  const styled = styleFeatureForPaint(f, layer, ctx, true);
1994
- const p = styled.paint;
1995
- recordPaintedFeature(cache2, p.featureId, p.visibleStrokeOpacity, p.visibleFillOpacity, p.timelineHidden);
1996
2146
  if (((_a2 = styled.feature.properties) == null ? void 0 : _a2.kind) === "arrow" && styled.feature.geometry.type === "LineString") {
1997
2147
  shardArrows.push(styled.feature);
1998
2148
  }
1999
2149
  return styled.feature;
2000
2150
  });
2001
2151
  host.paintShard(index, roles, { type: "FeatureCollection", features: painted });
2002
- caches[index] = cache2;
2003
2152
  if (shardArrows.length > 0) pushAll$1(arrowLines, shardArrows);
2004
- (_a = input.onShardPainted) == null ? void 0 : _a.call(input, index, cache2, shardArrows);
2153
+ (_a = input.onShardPainted) == null ? void 0 : _a.call(input, index, start, end);
2005
2154
  (_b = input.onProgress) == null ? void 0 : _b.call(input, end, features.length);
2006
2155
  await input.yieldFrame();
2007
2156
  if (!input.isCurrent()) {
2008
- return { completed: false, shardCount: index + 1, caches, arrowLines };
2157
+ return { completed: false, shardCount: index + 1, arrowLines };
2009
2158
  }
2010
2159
  }
2011
2160
  host.dropShardsFrom(ranges.length);
2012
- return { completed: true, shardCount: ranges.length, caches, arrowLines };
2161
+ return { completed: true, shardCount: ranges.length, arrowLines };
2013
2162
  }
2014
2163
  function pushAll$1(target, source) {
2015
2164
  for (let i = 0; i < source.length; i++) target.push(source[i]);
@@ -4035,6 +4184,7 @@ function LayersPanel({
4035
4184
  onMapStyleChange,
4036
4185
  onUpdateTraceConfig,
4037
4186
  getAvailableTraceFields,
4187
+ getSuggestedTraceField,
4038
4188
  getLayerFields,
4039
4189
  getFieldValueDistribution,
4040
4190
  onUpdateHeatmapConfig,
@@ -4358,13 +4508,12 @@ function LayersPanel({
4358
4508
  {
4359
4509
  size: "small",
4360
4510
  checked: ((_h = layer.traceConfig) == null ? void 0 : _h.enabled) ?? false,
4361
- onChange: (checked) => {
4362
- var _a2;
4363
- return onUpdateTraceConfig(layer.id, {
4364
- enabled: checked,
4365
- groupByField: ((_a2 = layer.traceConfig) == null ? void 0 : _a2.groupByField) ?? null
4366
- });
4367
- },
4511
+ onChange: (checked) => onUpdateTraceConfig(layer.id, {
4512
+ enabled: checked,
4513
+ // A layer that has never had trace settings starts grouped; a
4514
+ // choice made before, "Connect all points" included, is kept.
4515
+ groupByField: layer.traceConfig ? layer.traceConfig.groupByField ?? null : checked ? (getSuggestedTraceField == null ? void 0 : getSuggestedTraceField(layer.id)) ?? null : null
4516
+ }),
4368
4517
  "data-testid": `switch-trace-${layer.id}`
4369
4518
  }
4370
4519
  ),
@@ -7414,6 +7563,7 @@ function Timebar({
7414
7563
  const targetFps = 30;
7415
7564
  const frameInterval = 1e3 / targetFps;
7416
7565
  const applyFilter = react.useCallback(() => {
7566
+ if (!onFilterChange) return;
7417
7567
  const visibleIds = [];
7418
7568
  const hiddenIds = [];
7419
7569
  temporalFeatures.forEach((feature) => {
@@ -7835,30 +7985,138 @@ function buildReadOnlyFeatureIndex(store) {
7835
7985
  });
7836
7986
  return { sources: new Map(store), byId };
7837
7987
  }
7838
- function countFeaturesInBounds(featureGroups, bounds, options) {
7839
- var _a;
7840
- const { west, east, south, north } = bounds;
7841
- const { threshold, visibleSet } = options;
7988
+ function inViewTest({ west, east, south, north }) {
7842
7989
  const fullWidth = east - west >= 360;
7843
- const inView = (lng, lat) => {
7990
+ return (lng, lat) => {
7844
7991
  if (lat < south || lat > north) return false;
7845
7992
  if (fullWidth) return true;
7846
7993
  return lng >= west && lng <= east || lng + 360 >= west && lng + 360 <= east || lng - 360 >= west && lng - 360 <= east;
7847
7994
  };
7995
+ }
7996
+ function counts(group, p, inView) {
7997
+ var _a;
7998
+ if (group.isVisible && !group.isVisible(p)) return false;
7999
+ const f = group.features[p];
8000
+ if (((_a = f.geometry) == null ? void 0 : _a.type) !== "Point") return true;
8001
+ const [lng, lat] = f.geometry.coordinates;
8002
+ return inView(lng, lat);
8003
+ }
8004
+ function countLinear(group, inView, start, threshold) {
8005
+ let count = start;
8006
+ for (let p = 0; p < group.features.length; p++) {
8007
+ if (!counts(group, p, inView)) continue;
8008
+ count += 1;
8009
+ if (count > threshold) return count;
8010
+ }
8011
+ return count;
8012
+ }
8013
+ function countIndexed(group, { spatial, visibleTotal }, bounds, inView, start, threshold) {
8014
+ const tree = spatial.tree;
8015
+ if (!tree) return start;
8016
+ const { west, east, south, north } = bounds;
8017
+ const fullWidth = east - west >= 360;
8018
+ if ((fullWidth || west <= tree.minX && east >= tree.maxX) && south <= tree.minY && north >= tree.maxY) {
8019
+ return Math.min(start + visibleTotal, threshold + 1);
8020
+ }
8021
+ let count = start;
8022
+ const visit = (item) => {
8023
+ if (count <= threshold && counts(group, spatial.positions[item], inView)) count += 1;
8024
+ return false;
8025
+ };
8026
+ if (fullWidth) {
8027
+ tree.search(-Infinity, south, Infinity, north, visit);
8028
+ return count;
8029
+ }
8030
+ tree.search(west, south, east, north, visit);
8031
+ if (west < -180) tree.search(west + 360, south, Math.min(east + 360, 180), north, visit);
8032
+ if (east > 180) tree.search(Math.max(west - 360, -180), south, east - 360, north, visit);
8033
+ return count;
8034
+ }
8035
+ function countFeaturesInBounds(groups, bounds, options) {
8036
+ const inView = inViewTest(bounds);
7848
8037
  let count = 0;
7849
- for (const features of featureGroups) {
7850
- for (const f of features) {
7851
- if (visibleSet && f.id != null && !visibleSet.has(String(f.id))) continue;
7852
- if (((_a = f.geometry) == null ? void 0 : _a.type) === "Point") {
7853
- const [lng, lat] = f.geometry.coordinates;
7854
- if (!inView(lng, lat)) continue;
7855
- }
7856
- count += 1;
7857
- if (count > threshold) return count;
7858
- }
8038
+ for (const group of groups) {
8039
+ count = group.indexed ? countIndexed(group, group.indexed, bounds, inView, count, options.threshold) : countLinear(group, inView, count, options.threshold);
8040
+ if (count > options.threshold) return count;
7859
8041
  }
7860
8042
  return count;
7861
8043
  }
8044
+ function extendBounds(bounds, coords) {
8045
+ if (!Array.isArray(coords) || coords.length === 0) return;
8046
+ if (typeof coords[0] === "number") {
8047
+ const lng = coords[0];
8048
+ const lat = coords[1];
8049
+ if (lng < bounds.minLng) bounds.minLng = lng;
8050
+ if (lng > bounds.maxLng) bounds.maxLng = lng;
8051
+ if (lat < bounds.minLat) bounds.minLat = lat;
8052
+ if (lat > bounds.maxLat) bounds.maxLat = lat;
8053
+ return;
8054
+ }
8055
+ for (const nested of coords) extendBounds(bounds, nested);
8056
+ }
8057
+ function computeBounds(coords) {
8058
+ const bounds = { minLng: Infinity, minLat: Infinity, maxLng: -Infinity, maxLat: -Infinity };
8059
+ extendBounds(bounds, coords);
8060
+ return bounds;
8061
+ }
8062
+ function boundsDisjoint(a, b) {
8063
+ return a.maxLng < b.minLng || a.minLng > b.maxLng || a.maxLat < b.minLat || a.minLat > b.maxLat;
8064
+ }
8065
+ function pointInBounds(lng, lat, b) {
8066
+ return lng >= b.minLng && lng <= b.maxLng && lat >= b.minLat && lat <= b.maxLat;
8067
+ }
8068
+ function buildGroupSpatialIndex(features) {
8069
+ var _a;
8070
+ const boxes = [];
8071
+ const positions = [];
8072
+ for (let p = 0; p < features.length; p++) {
8073
+ const geom = (_a = features[p]) == null ? void 0 : _a.geometry;
8074
+ const b = computeBounds(geom == null ? void 0 : geom.coordinates);
8075
+ if (!isFinite(b.minLng) || !isFinite(b.minLat) || !isFinite(b.maxLng) || !isFinite(b.maxLat)) {
8076
+ continue;
8077
+ }
8078
+ boxes.push(b.minLng, b.minLat, b.maxLng, b.maxLat);
8079
+ positions.push(p);
8080
+ }
8081
+ if (positions.length === 0) {
8082
+ return { tree: null, positions, size: features.length };
8083
+ }
8084
+ const startedAt = performance.now();
8085
+ const tree = new Flatbush(positions.length);
8086
+ for (let i = 0; i < boxes.length; i += 4) {
8087
+ tree.add(boxes[i], boxes[i + 1], boxes[i + 2], boxes[i + 3]);
8088
+ }
8089
+ tree.finish();
8090
+ mapPerfLog("spatial-index", "built group index", {
8091
+ indexed: positions.length,
8092
+ of: features.length,
8093
+ ms: Math.round(performance.now() - startedAt)
8094
+ });
8095
+ return { tree, positions, size: features.length };
8096
+ }
8097
+ const indexCache = /* @__PURE__ */ new WeakMap();
8098
+ const failedBuilds = /* @__PURE__ */ new WeakSet();
8099
+ function getGroupSpatialIndex(features) {
8100
+ if (failedBuilds.has(features)) return void 0;
8101
+ let index = indexCache.get(features);
8102
+ if (!index) {
8103
+ try {
8104
+ index = buildGroupSpatialIndex(features);
8105
+ } catch {
8106
+ failedBuilds.add(features);
8107
+ return void 0;
8108
+ }
8109
+ indexCache.set(features, index);
8110
+ }
8111
+ return index;
8112
+ }
8113
+ function queryCandidatePositions(index, bounds) {
8114
+ if (!index.tree) return [];
8115
+ const items = index.tree.search(bounds.minLng, bounds.minLat, bounds.maxLng, bounds.maxLat);
8116
+ const positions = items.map((i) => index.positions[i]);
8117
+ positions.sort((a, b) => a - b);
8118
+ return positions;
8119
+ }
7862
8120
  const rafScheduler = {
7863
8121
  request: (cb) => requestAnimationFrame(() => cb()),
7864
8122
  cancel: (handle) => cancelAnimationFrame(handle)
@@ -7902,13 +8160,16 @@ function createRafCoalescer(run, scheduler = rafScheduler) {
7902
8160
  }
7903
8161
  };
7904
8162
  }
8163
+ function needsDrawSelectionUpdate(input) {
8164
+ return input.editableSelectionCount > 0 || input.drawSelectedCount > 0 || input.currentMode !== input.targetMode;
8165
+ }
7905
8166
  const EMPTY = /* @__PURE__ */ new Set();
7906
8167
  function isLive(host, entry) {
7907
8168
  return host.source(entry.sourceId) === entry.handle;
7908
8169
  }
7909
8170
  function remove(host, entry, id) {
7910
8171
  if (!isLive(host, entry)) return false;
7911
- host.removeFeatureState(entry.sourceId, id);
8172
+ host.removeFeatureState(entry.sourceId, id, SELECTED_STATE_KEY);
7912
8173
  return true;
7913
8174
  }
7914
8175
  function set(host, sourceId, id) {
@@ -8007,7 +8268,7 @@ function forEachIndex(index, id, visit) {
8007
8268
  function locateFeatureHolders(id, readOnly, cache2) {
8008
8269
  const holders = [];
8009
8270
  readOnly.forEach((features, layerId) => {
8010
- forEachIndex(indexOfIds(features, cache2), id, (at) => holders.push({ layerId, feature: features[at] }));
8271
+ forEachIndex(indexOfIds(features, cache2), id, (at) => holders.push({ layerId, feature: features[at], position: at }));
8011
8272
  });
8012
8273
  return holders;
8013
8274
  }
@@ -8025,6 +8286,210 @@ function locateFeatureSources(id, inputs, cache2) {
8025
8286
  if (sources.length === 0) add(SHARED_SOURCE_ID);
8026
8287
  return sources;
8027
8288
  }
8289
+ const HIDDEN_STATE = Object.freeze({ [TIMELINE_HIDDEN_KEY]: true });
8290
+ function sameSlices(a, b) {
8291
+ return a.length === b.length && a.every((s, i) => s.features === b[i].features && s.start === b[i].start && s.end === b[i].end);
8292
+ }
8293
+ function pushCopy(copies, id, copy, first) {
8294
+ const list = copies.get(id);
8295
+ if (list) list.push(copy);
8296
+ else copies.set(id, [first, copy]);
8297
+ }
8298
+ function collectCopies(slices) {
8299
+ const copies = /* @__PURE__ */ new Map();
8300
+ if (slices.length === 1) {
8301
+ const { features, start, end } = slices[0];
8302
+ const index = getTimelineIndex(features);
8303
+ index.repeats.forEach((positions, id) => {
8304
+ const inside = positions.filter((p) => p >= start && p < end);
8305
+ if (inside.length > 1) copies.set(id, inside.map((position) => ({ index, position })));
8306
+ });
8307
+ return copies;
8308
+ }
8309
+ const first = /* @__PURE__ */ new Map();
8310
+ slices.forEach(({ features, start, end }) => {
8311
+ const index = getTimelineIndex(features);
8312
+ for (let position = start; position < end; position++) {
8313
+ const raw = features[position].id;
8314
+ if (raw === void 0 || raw === null) continue;
8315
+ const id = String(raw);
8316
+ const copy = { index, position };
8317
+ const seen = first.get(id);
8318
+ if (seen) pushCopy(copies, id, copy, seen);
8319
+ else first.set(id, copy);
8320
+ }
8321
+ });
8322
+ return copies;
8323
+ }
8324
+ function copiesOf(record) {
8325
+ record.copies ?? (record.copies = collectCopies(record.slices));
8326
+ return record.copies;
8327
+ }
8328
+ function shouldHide(record, id, index, position, w) {
8329
+ if (isVisibleAt(index, position, w)) return false;
8330
+ const copies = copiesOf(record).get(id);
8331
+ return !copies || copies.every((c) => !isVisibleAt(c.index, c.position, w));
8332
+ }
8333
+ function setHidden(host, record, id, hide) {
8334
+ if (hide === record.hidden.has(id)) return false;
8335
+ if (hide) {
8336
+ host.setFeatureState(record.sourceId, id, HIDDEN_STATE);
8337
+ record.hidden.add(id);
8338
+ } else {
8339
+ host.removeFeatureState(record.sourceId, id, TIMELINE_HIDDEN_KEY);
8340
+ record.hidden.delete(id);
8341
+ }
8342
+ return true;
8343
+ }
8344
+ function idAt(features, position) {
8345
+ const raw = features[position].id;
8346
+ return raw === void 0 || raw === null ? null : String(raw);
8347
+ }
8348
+ function seedTimelineSource(host, applied, sourceId, slices, w) {
8349
+ const handle = host.source(sourceId);
8350
+ const old = applied.get(sourceId);
8351
+ if (!handle) {
8352
+ applied.delete(sourceId);
8353
+ return 0;
8354
+ }
8355
+ if (old && old.handle === handle && sameSlices(old.slices, slices)) return 0;
8356
+ const record = {
8357
+ sourceId,
8358
+ handle,
8359
+ slices,
8360
+ hidden: (old == null ? void 0 : old.handle) === handle ? old.hidden : /* @__PURE__ */ new Set(),
8361
+ copies: null,
8362
+ window: w
8363
+ };
8364
+ applied.set(sourceId, record);
8365
+ const hide = /* @__PURE__ */ new Set();
8366
+ if (w !== null) {
8367
+ slices.forEach(({ features, start, end }) => {
8368
+ const index = getTimelineIndex(features);
8369
+ for (let position = start; position < end; position++) {
8370
+ const id = idAt(features, position);
8371
+ if (id !== null && shouldHide(record, id, index, position, w)) hide.add(id);
8372
+ }
8373
+ });
8374
+ }
8375
+ let calls = 0;
8376
+ Array.from(record.hidden).forEach((id) => {
8377
+ if (!hide.has(id) && setHidden(host, record, id, false)) calls++;
8378
+ });
8379
+ hide.forEach((id) => {
8380
+ if (setHidden(host, record, id, true)) calls++;
8381
+ });
8382
+ return calls;
8383
+ }
8384
+ function isTimelineHiddenOn(applied, sourceId, id) {
8385
+ var _a;
8386
+ return ((_a = applied.get(sourceId)) == null ? void 0 : _a.hidden.has(id)) ?? false;
8387
+ }
8388
+ function ownerOf(owners, position) {
8389
+ let lo = 0;
8390
+ let hi = owners.length - 1;
8391
+ let found = null;
8392
+ while (lo <= hi) {
8393
+ const mid = lo + hi >>> 1;
8394
+ if (owners[mid].start <= position) {
8395
+ found = owners[mid];
8396
+ lo = mid + 1;
8397
+ } else {
8398
+ hi = mid - 1;
8399
+ }
8400
+ }
8401
+ return found && position < found.end ? found : null;
8402
+ }
8403
+ function groupBySliceArray(host, applied, next, isActive) {
8404
+ const groups = [];
8405
+ applied.forEach((record, sourceId) => {
8406
+ if (host.source(sourceId) !== record.handle) {
8407
+ applied.delete(sourceId);
8408
+ return;
8409
+ }
8410
+ if (!isActive(sourceId) || sameWindow(record.window, next)) return;
8411
+ record.slices.forEach(({ features, start, end }) => {
8412
+ let group = groups.find((g) => g.features === features && sameWindow(g.from, record.window));
8413
+ if (!group) {
8414
+ group = { features, from: record.window, owners: [] };
8415
+ groups.push(group);
8416
+ }
8417
+ group.owners.push({ record, start, end });
8418
+ });
8419
+ record.window = next;
8420
+ });
8421
+ return groups;
8422
+ }
8423
+ function applyTimelineWindow(host, applied, next, isActive = () => true) {
8424
+ const flipped = [];
8425
+ const positions = [];
8426
+ groupBySliceArray(host, applied, next, isActive).forEach(({ features, from, owners }) => {
8427
+ owners.sort((a, b) => a.start - b.start);
8428
+ const index = getTimelineIndex(features);
8429
+ positions.length = 0;
8430
+ flippedPositions(index, from, next, positions);
8431
+ positions.forEach((position) => {
8432
+ const owner = ownerOf(owners, position);
8433
+ const id = owner ? idAt(features, position) : null;
8434
+ if (!owner || id === null) return;
8435
+ if (setHidden(host, owner.record, id, shouldHide(owner.record, id, index, position, next))) flipped.push(id);
8436
+ });
8437
+ });
8438
+ return flipped;
8439
+ }
8440
+ const IDENTITY_PATTERNS = [
8441
+ /person|people|individual|subject|suspect/,
8442
+ /target/,
8443
+ /entity/,
8444
+ /device|imei|imsi|msisdn|phone/,
8445
+ /mmsi|vessel|ship/,
8446
+ /vehicle|plate|car_?id/,
8447
+ /callsign|flight|aircraft|icao/,
8448
+ /user|account|owner|driver/,
8449
+ /track|trajectory/,
8450
+ /(^|[^a-z])id$|_id$|^id_|uuid/
8451
+ ];
8452
+ const NOT_IDENTITY = /* @__PURE__ */ new Set(["id", "name", "startdate", "enddate", "opacity", "timestamp", "time", "date"]);
8453
+ const CATEGORY_SUFFIX = /(type|kind|category|class|status|model|role)$/;
8454
+ const MIN_COVERAGE = 0.9;
8455
+ const MAX_GROUPS = 500;
8456
+ const MIN_POINTS_PER_GROUP = 2;
8457
+ const MAX_SAMPLES = 1e4;
8458
+ function isTracePoint(f) {
8459
+ var _a, _b;
8460
+ return !!f && f.id != null && ((_a = f.geometry) == null ? void 0 : _a.type) === "Point" && !!((_b = f.properties) == null ? void 0 : _b.startDate);
8461
+ }
8462
+ function identityRank(field) {
8463
+ const name = field.toLowerCase();
8464
+ if (NOT_IDENTITY.has(name) || CATEGORY_SUFFIX.test(name)) return -1;
8465
+ return IDENTITY_PATTERNS.findIndex((pattern) => pattern.test(name));
8466
+ }
8467
+ function suggestTraceGroupField(features, fields) {
8468
+ var _a;
8469
+ const candidates = fields.map((field) => ({ field, rank: identityRank(field) })).filter((c) => c.rank >= 0).sort((a, b) => a.rank - b.rank || a.field.localeCompare(b.field));
8470
+ if (candidates.length === 0) return null;
8471
+ const step = Math.max(1, Math.ceil(features.length / MAX_SAMPLES));
8472
+ const points = [];
8473
+ for (let i = 0; i < features.length && points.length < MAX_SAMPLES; i += step) {
8474
+ const f = features[i];
8475
+ if (isTracePoint(f)) points.push(f);
8476
+ }
8477
+ if (points.length < 2) return null;
8478
+ const splitsIntoTracks = (field) => {
8479
+ var _a2;
8480
+ const values = /* @__PURE__ */ new Set();
8481
+ let present = 0;
8482
+ for (const f of points) {
8483
+ const raw = (_a2 = f.properties) == null ? void 0 : _a2[field];
8484
+ if (raw === null || raw === void 0 || raw === "") continue;
8485
+ present++;
8486
+ values.add(String(raw));
8487
+ if (values.size > MAX_GROUPS) return false;
8488
+ }
8489
+ return present >= points.length * MIN_COVERAGE && values.size >= 2 && present >= values.size * MIN_POINTS_PER_GROUP;
8490
+ };
8491
+ return ((_a = candidates.find((c) => splitsIntoTracks(c.field))) == null ? void 0 : _a.field) ?? null;
8492
+ }
8028
8493
  function deepClone(value) {
8029
8494
  try {
8030
8495
  return structuredClone(value);
@@ -8161,82 +8626,6 @@ function shouldDiffDrawRender({ mode, pointerDown, hasSelection }) {
8161
8626
  if (mode === "simple_select" || mode === "direct_select") return pointerDown && hasSelection;
8162
8627
  return true;
8163
8628
  }
8164
- function extendBounds(bounds, coords) {
8165
- if (!Array.isArray(coords) || coords.length === 0) return;
8166
- if (typeof coords[0] === "number") {
8167
- const lng = coords[0];
8168
- const lat = coords[1];
8169
- if (lng < bounds.minLng) bounds.minLng = lng;
8170
- if (lng > bounds.maxLng) bounds.maxLng = lng;
8171
- if (lat < bounds.minLat) bounds.minLat = lat;
8172
- if (lat > bounds.maxLat) bounds.maxLat = lat;
8173
- return;
8174
- }
8175
- for (const nested of coords) extendBounds(bounds, nested);
8176
- }
8177
- function computeBounds(coords) {
8178
- const bounds = { minLng: Infinity, minLat: Infinity, maxLng: -Infinity, maxLat: -Infinity };
8179
- extendBounds(bounds, coords);
8180
- return bounds;
8181
- }
8182
- function boundsDisjoint(a, b) {
8183
- return a.maxLng < b.minLng || a.minLng > b.maxLng || a.maxLat < b.minLat || a.minLat > b.maxLat;
8184
- }
8185
- function pointInBounds(lng, lat, b) {
8186
- return lng >= b.minLng && lng <= b.maxLng && lat >= b.minLat && lat <= b.maxLat;
8187
- }
8188
- function buildGroupSpatialIndex(features) {
8189
- var _a;
8190
- const boxes = [];
8191
- const positions = [];
8192
- for (let p = 0; p < features.length; p++) {
8193
- const geom = (_a = features[p]) == null ? void 0 : _a.geometry;
8194
- const b = computeBounds(geom == null ? void 0 : geom.coordinates);
8195
- if (!isFinite(b.minLng) || !isFinite(b.minLat) || !isFinite(b.maxLng) || !isFinite(b.maxLat)) {
8196
- continue;
8197
- }
8198
- boxes.push(b.minLng, b.minLat, b.maxLng, b.maxLat);
8199
- positions.push(p);
8200
- }
8201
- if (positions.length === 0) {
8202
- return { tree: null, positions, size: features.length };
8203
- }
8204
- const startedAt = performance.now();
8205
- const tree = new Flatbush(positions.length);
8206
- for (let i = 0; i < boxes.length; i += 4) {
8207
- tree.add(boxes[i], boxes[i + 1], boxes[i + 2], boxes[i + 3]);
8208
- }
8209
- tree.finish();
8210
- mapPerfLog("spatial-index", "built group index", {
8211
- indexed: positions.length,
8212
- of: features.length,
8213
- ms: Math.round(performance.now() - startedAt)
8214
- });
8215
- return { tree, positions, size: features.length };
8216
- }
8217
- const indexCache = /* @__PURE__ */ new WeakMap();
8218
- const failedBuilds = /* @__PURE__ */ new WeakSet();
8219
- function getGroupSpatialIndex(features) {
8220
- if (failedBuilds.has(features)) return void 0;
8221
- let index = indexCache.get(features);
8222
- if (!index) {
8223
- try {
8224
- index = buildGroupSpatialIndex(features);
8225
- } catch {
8226
- failedBuilds.add(features);
8227
- return void 0;
8228
- }
8229
- indexCache.set(features, index);
8230
- }
8231
- return index;
8232
- }
8233
- function queryCandidatePositions(index, bounds) {
8234
- if (!index.tree) return [];
8235
- const items = index.tree.search(bounds.minLng, bounds.minLat, bounds.maxLng, bounds.maxLat);
8236
- const positions = items.map((i) => index.positions[i]);
8237
- positions.sort((a, b) => a - b);
8238
- return positions;
8239
- }
8240
8629
  function collectVisibleFeatureGroups(drawFeatures, readOnlyByLayer, layers) {
8241
8630
  const groups = [];
8242
8631
  if (drawFeatures) groups.push({ features: drawFeatures });
@@ -8354,19 +8743,6 @@ function buildSelectionOverlayStack() {
8354
8743
  }
8355
8744
  ];
8356
8745
  }
8357
- function overlayTimelineInputs(ids, visible) {
8358
- const hidden = /* @__PURE__ */ new Set();
8359
- if (visible !== null) ids.forEach((id) => {
8360
- if (!visible.has(id)) hidden.add(id);
8361
- });
8362
- return { ids, hidden };
8363
- }
8364
- function sameIds(a, b) {
8365
- return a.size === b.size && Array.from(a).every((id) => b.has(id));
8366
- }
8367
- function sameOverlayTimelineInputs(a, b) {
8368
- return sameIds(a.ids, b.ids) && sameIds(a.hidden, b.hidden);
8369
- }
8370
8746
  function buildSelectionOverlayData(ids, styleFor) {
8371
8747
  const features = [];
8372
8748
  ids.forEach((id) => {
@@ -8753,8 +9129,8 @@ function hideTooltip() {
8753
9129
  tooltipEl.style.display = "none";
8754
9130
  }
8755
9131
  }
8756
- function fingerprintCluster(pointCount, counts, size, badgeValue) {
8757
- return `${size}|${pointCount}|${badgeValue ?? ""}|${counts.join(",")}`;
9132
+ function fingerprintCluster(pointCount, counts2, size, badgeValue) {
9133
+ return `${size}|${pointCount}|${badgeValue ?? ""}|${counts2.join(",")}`;
8758
9134
  }
8759
9135
  function buildPieElement(categories, pointCount, size, source, clusterId, map, coords, badgeValue) {
8760
9136
  const el = createPieSVG(categories, pointCount, size, (cat, event) => {
@@ -8906,6 +9282,8 @@ const EMPTY_ID_SET = /* @__PURE__ */ new Set();
8906
9282
  const EMPTY_SOURCES = [];
8907
9283
  const TOOLTIP_EXCLUDED_KEYS = ["stroke", "stroke-width", "stroke-opacity", "fill", "fill-opacity", "pointRadius", "kind", "meta:type", "circleCenter", "circleRadius", "icon", "iconSize", "pointIcon", "pointIconSize", "fontSize", "fontColor", "fontWeight", "arrowSize", "label", "entityType"];
8908
9284
  const EMPTY_LABEL_MAP = /* @__PURE__ */ new Map();
9285
+ const TICK_COUNT_SETTLE_MS = 300;
9286
+ const SPATIAL_COUNT_MIN_FEATURES = 5e3;
8909
9287
  function renderEmojiToCanvas(emoji, size = EMOJI_CANVAS_SIZE) {
8910
9288
  const ratio = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
8911
9289
  const canvas = document.createElement("canvas");
@@ -9113,7 +9491,7 @@ function basemapInsertAnchor(map) {
9113
9491
  function featureStateHostFor(m) {
9114
9492
  return {
9115
9493
  setFeatureState: (source, id, state) => m.setFeatureState({ source, id }, state),
9116
- removeFeatureState: (source, id) => m.removeFeatureState({ source, id }),
9494
+ removeFeatureState: (source, id, key) => m.removeFeatureState({ source, id }, key),
9117
9495
  source: (source) => m.getSource(source)
9118
9496
  };
9119
9497
  }
@@ -9296,6 +9674,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9296
9674
  const justCreatedFeatureRef = react.useRef(false);
9297
9675
  const [autoLabelConfig, setAutoLabelConfig] = react.useState({ enabled: true, threshold: 220 });
9298
9676
  const [visibleFeatureCount, setVisibleFeatureCount] = react.useState(Infinity);
9677
+ const visibleFeatureCountRef = react.useRef(visibleFeatureCount);
9678
+ visibleFeatureCountRef.current = visibleFeatureCount;
9679
+ const tickCountTimerRef = react.useRef(null);
9299
9680
  const lastLabelVisibility = react.useRef(false);
9300
9681
  const shardRegistryRef = react.useRef(null);
9301
9682
  const applyShardedLayersRef = react.useRef(null);
@@ -9303,9 +9684,12 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9303
9684
  const bindHoverHandlersRef = react.useRef(null);
9304
9685
  const unbindHoverHandlersRef = react.useRef(null);
9305
9686
  const [labelsSuppressed, setLabelsSuppressed] = react.useState(true);
9687
+ const labelsSuppressedRef = react.useRef(labelsSuppressed);
9688
+ labelsSuppressedRef.current = labelsSuppressed;
9306
9689
  const [contextMenu, setContextMenu] = react.useState(null);
9307
9690
  const [timelineStoreApi] = react.useState(createTimelineStore);
9308
- const timelineStore = zustand.useStore(timelineStoreApi);
9691
+ const timelineEnabled = zustand.useStore(timelineStoreApi, (s) => s.isEnabled);
9692
+ const timelineHasData = zustand.useStore(timelineStoreApi, (s) => s.hasTemporalData);
9309
9693
  const { toast: internalToast } = useToast();
9310
9694
  const toast = toastProvider ?? internalToast;
9311
9695
  const featureCap = react.useMemo(() => resolveFeatureCap(maxFeaturesPerLayer), [maxFeaturesPerLayer]);
@@ -9566,7 +9950,13 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9566
9950
  });
9567
9951
  setFeatureCount(drawFeatureCount + hiddenCount + readOnlyCount);
9568
9952
  }, []);
9569
- const timelineVisibleIdsRef = react.useRef(null);
9953
+ const timelineWindowRef = react.useRef(null);
9954
+ const appliedTimelineRef = react.useRef(/* @__PURE__ */ new Map());
9955
+ const isTimelineSourceActive = react.useCallback((sourceId) => {
9956
+ var _a;
9957
+ const shard = parseShardSourceId(sourceId);
9958
+ return !shard || ((_a = layersRef.current.find((l) => l.id === shard.layerId)) == null ? void 0 : _a.visible) === true;
9959
+ }, []);
9570
9960
  const syncRef = react.useRef(() => {
9571
9961
  });
9572
9962
  const trySelectionFastPathRef = react.useRef(null);
@@ -9598,6 +9988,19 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9598
9988
  }
9599
9989
  (_b = syncCoalescerRef.current) == null ? void 0 : _b.schedule(reason);
9600
9990
  }, []);
9991
+ react.useEffect(() => {
9992
+ const windowOf = (state) => state.isEnabled && state.hasTemporalData ? windowFromRange(state.rangeStart, state.rangeEnd) : null;
9993
+ const follow = (state) => {
9994
+ var _a;
9995
+ const next = windowOf(state);
9996
+ if (sameWindow(next, timelineWindowRef.current)) return;
9997
+ timelineWindowRef.current = next;
9998
+ scheduleSync("timeline");
9999
+ (_a = update3DFlightPathsRef.current) == null ? void 0 : _a.call(update3DFlightPathsRef);
10000
+ };
10001
+ follow(timelineStoreApi.getState());
10002
+ return timelineStoreApi.subscribe(follow);
10003
+ }, [timelineStoreApi, scheduleSync]);
9601
10004
  react.useEffect(() => {
9602
10005
  scheduleSync();
9603
10006
  }, [layers, scheduleSync]);
@@ -9661,21 +10064,33 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9661
10064
  const m = map.current;
9662
10065
  if (!m) return 0;
9663
10066
  const bounds = m.getBounds();
10067
+ const w = timelineWindowRef.current;
10068
+ const groupOf = (features) => {
10069
+ if (w === null) return { features };
10070
+ const index = getTimelineIndex(features);
10071
+ const group = { features, isVisible: (p) => isVisibleAt(index, p, w) };
10072
+ const spatial = features.length >= SPATIAL_COUNT_MIN_FEATURES ? getGroupSpatialIndex(features) : void 0;
10073
+ if (spatial) group.indexed = { spatial, visibleTotal: countVisible(index, w) };
10074
+ return group;
10075
+ };
9664
10076
  const groups = [];
9665
- if (draw.current) groups.push(draw.current.getAll().features);
10077
+ if (draw.current) {
10078
+ const features = draw.current.getAll().features;
10079
+ groups.push(w === null ? { features } : { features, isVisible: (p) => isFeatureVisible(features[p], w) });
10080
+ }
9666
10081
  readOnlyFeatures.current.forEach((features, layerId) => {
9667
10082
  const layer = layersRef.current.find((l) => l.id === layerId);
9668
- if (layer == null ? void 0 : layer.visible) groups.push(features);
10083
+ if (layer == null ? void 0 : layer.visible) groups.push(groupOf(features));
9669
10084
  });
9670
10085
  return countFeaturesInBounds(
9671
10086
  groups,
9672
10087
  { west: bounds.getWest(), east: bounds.getEast(), south: bounds.getSouth(), north: bounds.getNorth() },
9673
- { threshold, visibleSet: timelineVisibleIdsRef.current }
10088
+ { threshold }
9674
10089
  );
9675
10090
  }, []);
9676
10091
  const isSyncingRef = react.useRef(false);
9677
- const selectionPaintCacheRef = react.useRef(null);
9678
10092
  const tracePaintCacheRef = react.useRef(null);
10093
+ const traceEndpointsRef = react.useRef(/* @__PURE__ */ new Set());
9679
10094
  const paintedArrowLinesRef = react.useRef([]);
9680
10095
  const renderArrowOverlays = react.useCallback((arrowLines) => {
9681
10096
  const mapInstance = map.current;
@@ -9781,7 +10196,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9781
10196
  const source = map.current.getSource("custom-features");
9782
10197
  if (!source) return;
9783
10198
  const drawFeatures = draw.current ? draw.current.getAll() : { type: "FeatureCollection", features: [] };
9784
- const visibleSet = timelineVisibleIdsRef.current;
10199
+ const timelineWindow = timelineWindowRef.current;
9785
10200
  const currentLayers = layersRef.current;
9786
10201
  const isLayerVisible = (layer) => {
9787
10202
  return layer.visible;
@@ -9794,11 +10209,17 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9794
10209
  });
9795
10210
  shardedLayerIdsRef.current = shardedLayerIds;
9796
10211
  const allFeatures = [...drawFeatures.features];
10212
+ const sharedSlices = [];
10213
+ const addSlice = (features) => {
10214
+ if (features.length > 0) sharedSlices.push({ features, start: 0, end: features.length });
10215
+ };
10216
+ addSlice(drawFeatures.features);
9797
10217
  readOnlyFeatures.current.forEach((features, layerId) => {
9798
10218
  if (shardedLayerIds.has(layerId)) return;
9799
10219
  const layer = currentLayers.find((l) => l.id === layerId);
9800
10220
  if (layer && isLayerVisible(layer)) {
9801
10221
  pushAll(allFeatures, features);
10222
+ addSlice(features);
9802
10223
  }
9803
10224
  });
9804
10225
  const featureById = /* @__PURE__ */ new Map();
@@ -9846,71 +10267,69 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9846
10267
  if (sizeField && isFinite(sMin)) sizeFieldRanges.set(layer.id, { min: sMin, max: sMax });
9847
10268
  if (colorField && isFinite(cMin)) colorFieldRanges.set(layer.id, { min: cMin, max: cMax });
9848
10269
  });
9849
- const lastTracePointIds = /* @__PURE__ */ new Set();
9850
10270
  const tracePointColors = /* @__PURE__ */ new Map();
9851
- const lastTracePointLabels = /* @__PURE__ */ new Map();
9852
10271
  const tracePointIds = /* @__PURE__ */ new Set();
9853
10272
  const paintedTraceGroups = [];
9854
- const traceSegments = [];
9855
- const tracePointPaint = /* @__PURE__ */ new Map();
9856
- const isTimelineVisibleId = timelineVisibility(visibleSet);
10273
+ const traceIndexes = [];
9857
10274
  currentLayers.forEach((layer) => {
9858
10275
  var _a2;
9859
10276
  if (!((_a2 = layer.traceConfig) == null ? void 0 : _a2.enabled) || !layer.visible) return;
9860
- const groups = getTraceGroups(traceSourceFeatures(layer, featureById), layer.traceConfig.groupByField);
10277
+ const traceFeatures = traceSourceFeatures(layer, featureById);
10278
+ const traceIndex = getTimelineIndex(traceFeatures);
10279
+ const groups = getTraceGroups(traceFeatures, layer.traceConfig.groupByField);
10280
+ const pointsHidden = layerHidesPoints(layer);
9861
10281
  for (const group of groups) {
9862
- const groupIndex = paintedTraceGroups.push(group) - 1;
10282
+ paintedTraceGroups.push(pointsHidden && group.label !== null ? { ...group, label: null } : group);
10283
+ traceIndexes.push(traceIndex);
9863
10284
  for (const id of group.ids) {
9864
10285
  tracePointIds.add(id);
9865
10286
  tracePointColors.set(id, group.color);
9866
10287
  }
9867
- const visible = visibleTraceIndices(group, isTimelineVisibleId);
9868
- if (visible.length === 0) continue;
9869
- const endpointId = group.ids[visible[visible.length - 1]];
9870
- lastTracePointIds.add(endpointId);
9871
- if (group.label !== null) lastTracePointLabels.set(endpointId, group.label);
9872
- for (let k = 1; k < visible.length; k++) {
9873
- traceSegments.push(traceSegmentFeature(group, groupIndex, visible[k - 1], visible[k]));
9874
- }
9875
10288
  }
9876
10289
  });
9877
- const paintCache = createSelectionPaintCache();
9878
10290
  const paintContext = {
9879
- timelineVisibleIds: visibleSet,
9880
10291
  sizeFieldRanges,
9881
10292
  colorFieldRanges,
9882
10293
  tracePointIds,
9883
- lastTracePointIds,
9884
- lastTracePointLabels,
9885
10294
  tracePointColors
9886
10295
  };
9887
10296
  const drawFeatureCount = drawFeatures.features.length;
9888
10297
  const sourceData = {
9889
10298
  type: "FeatureCollection",
9890
10299
  features: allFeatures.map((f, i) => {
9891
- const styled = styleFeatureForPaint(f, featureToLayer.get(String(f.id)), paintContext, i >= drawFeatureCount);
9892
- const p = styled.paint;
9893
- recordPaintedFeature(paintCache, p.featureId, p.visibleStrokeOpacity, p.visibleFillOpacity, p.timelineHidden);
9894
- if (styled.tracePaint) tracePointPaint.set(p.featureId, styled.tracePaint);
9895
- return styled.feature;
10300
+ return styleFeatureForPaint(f, featureToLayer.get(String(f.id)), paintContext, i >= drawFeatureCount).feature;
9896
10301
  })
9897
10302
  };
9898
10303
  source.setData(sourceData);
9899
- selectionPaintCacheRef.current = paintCache;
9900
10304
  overlayPaintContextRef.current = paintContext;
10305
+ const stateHost = featureStateHostFor(map.current);
10306
+ seedTimelineSource(stateHost, appliedTimelineRef.current, SHARED_SOURCE_ID, sharedSlices, timelineWindow);
10307
+ applyTimelineWindow(stateHost, appliedTimelineRef.current, timelineWindow, isTimelineSourceActive);
9901
10308
  (_a = reconcileSelectionRef.current) == null ? void 0 : _a.call(reconcileSelectionRef);
9902
- const traceSource = map.current.getSource("trace-features");
9903
- if (traceSource) traceSource.setData({ type: "FeatureCollection", features: traceSegments });
9904
- tracePaintCacheRef.current = traceSource && paintedTraceGroups.length > 0 ? { groups: paintedTraceGroups, pointPaint: tracePointPaint } : null;
10309
+ const traceSource = map.current.getSource(TRACE_SOURCE_ID);
10310
+ const tracePaint = paintTraceAt(paintedTraceGroups, traceIndexes, timelineWindow);
10311
+ if (traceSource) traceSource.setData({ type: "FeatureCollection", features: tracePaint.features });
10312
+ const endpoints2 = new Set(tracePaint.endpoints);
10313
+ setTraceEndpoints(
10314
+ featureStateHostFor(map.current),
10315
+ traceEndpointsRef.current,
10316
+ Array.from(traceEndpointsRef.current).filter((id) => !endpoints2.has(id)),
10317
+ tracePaint.endpoints
10318
+ );
10319
+ tracePaintCacheRef.current = traceSource && paintedTraceGroups.length > 0 ? { groups: paintedTraceGroups, indexes: traceIndexes, window: timelineWindow } : null;
9905
10320
  {
9906
10321
  let sawArrowFeature = false;
9907
10322
  const arrowLines = [];
9908
- sourceData.features.forEach((f) => {
10323
+ const pushArrow = (styled, record) => {
10324
+ const { s, e } = record ? featureInterval(record) : { s: NaN, e: NaN };
10325
+ arrowLines.push(isIntervalVisible(s, e, timelineWindow) ? styled : { ...styled, properties: { ...styled.properties, "stroke-opacity": 0, "fill-opacity": 0 } });
10326
+ };
10327
+ sourceData.features.forEach((f, i) => {
9909
10328
  var _a2;
9910
10329
  const isArrow = ((_a2 = f.properties) == null ? void 0 : _a2.kind) === "arrow" || arrowFeatureIdsRef.current.has(String(f.id));
9911
10330
  if (!isArrow) return;
9912
10331
  sawArrowFeature = true;
9913
- if (f.geometry.type === "LineString") arrowLines.push(f);
10332
+ if (f.geometry.type === "LineString") pushArrow(f, allFeatures[i]);
9914
10333
  });
9915
10334
  const shardArrows = ((_b = shardRegistryRef.current) == null ? void 0 : _b.arrowLines((id) => {
9916
10335
  var _a2;
@@ -9918,7 +10337,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9918
10337
  })) ?? [];
9919
10338
  if (shardArrows.length > 0) {
9920
10339
  sawArrowFeature = true;
9921
- pushAll(arrowLines, shardArrows);
10340
+ shardArrows.forEach((f) => pushArrow(f, getReadOnlyFeatureById(String(f.id))));
9922
10341
  }
9923
10342
  hasArrowFeaturesRef.current = sawArrowFeature;
9924
10343
  paintedArrowLinesRef.current = arrowLines;
@@ -9948,7 +10367,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9948
10367
  } finally {
9949
10368
  isSyncingRef.current = false;
9950
10369
  }
9951
- }, [layers, hashStringToColor$1, autoLabelConfig, countVisibleFeatures, renderArrowOverlays]);
10370
+ }, [layers, hashStringToColor$1, autoLabelConfig, countVisibleFeatures, renderArrowOverlays, getReadOnlyFeatureById, isTimelineSourceActive]);
9952
10371
  const update3DFlightPaths = react.useCallback(() => {
9953
10372
  var _a;
9954
10373
  if (!map.current || !is3DTerrainEnabled) {
@@ -9962,11 +10381,11 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9962
10381
  return;
9963
10382
  }
9964
10383
  const mapInstance = map.current;
9965
- const visibleSet = timelineVisibleIdsRef.current;
9966
- const isFeatureVisibleInTimeline = (feature) => {
9967
- if (visibleSet === null) return true;
9968
- const featureId = String(feature.id);
9969
- return visibleSet.has(featureId);
10384
+ const timelineWindow = timelineWindowRef.current;
10385
+ const visibleIn = (features) => {
10386
+ if (timelineWindow === null) return [...features];
10387
+ const index = getTimelineIndex(features);
10388
+ return features.filter((_, p) => isVisibleAt(index, p, timelineWindow));
9970
10389
  };
9971
10390
  const allFeatures = [];
9972
10391
  const currentLayers = layersRef.current;
@@ -9976,9 +10395,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9976
10395
  if (((_a = l.traceConfig) == null ? void 0 : _a.enabled) !== true) continue;
9977
10396
  for (const featureId of l.featureIds) traceFeatureIds.add(featureId);
9978
10397
  }
9979
- const drawFeatures = draw.current.getAll().features.filter(
9980
- (feature) => isFeatureVisibleInTimeline(feature) && traceFeatureIds.has(feature.id)
9981
- );
10398
+ const drawFeatures = draw.current.getAll().features.filter((feature) => traceFeatureIds.has(feature.id) && isFeatureVisible(feature, timelineWindow));
9982
10399
  pushAll(allFeatures, drawFeatures);
9983
10400
  }
9984
10401
  readOnlyFeatures.current.forEach((features, layerId2) => {
@@ -9987,8 +10404,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9987
10404
  const altitudeMode = (layer2 == null ? void 0 : layer2.altitudeDisplayMode) ?? "both";
9988
10405
  const traceEnabled = ((_a2 = layer2 == null ? void 0 : layer2.traceConfig) == null ? void 0 : _a2.enabled) === true;
9989
10406
  if ((layer2 == null ? void 0 : layer2.visible) && traceEnabled && (altitudeMode === "3d" || altitudeMode === "both")) {
9990
- const visibleFeatures = features.filter(isFeatureVisibleInTimeline);
9991
- pushAll(allFeatures, visibleFeatures);
10407
+ pushAll(allFeatures, visibleIn(features));
9992
10408
  }
9993
10409
  });
9994
10410
  const flightPaths = extract3DFlightPaths(allFeatures);
@@ -10047,11 +10463,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10047
10463
  const fingerprint = buildShardFingerprint(layer, features, shardSize2);
10048
10464
  const expectedShards = shardRanges(features.length, shardSize2).length;
10049
10465
  if (shardFingerprintsEqual(state.fingerprint, fingerprint) && state.stacks.length === expectedShards) {
10050
- if (reconcileShardCaches(registry, state.layerId, expectedShards, timelineVisibleIdsRef.current)) {
10051
- setLayerImporting(layer.id, false);
10052
- mapPerfLog("shards", "pass skipped (fingerprint)", { layerId: layer.id, shards: expectedShards });
10053
- return;
10054
- }
10466
+ setLayerImporting(layer.id, false);
10467
+ mapPerfLog("shards", "pass skipped (fingerprint)", { layerId: layer.id, shards: expectedShards });
10468
+ return;
10055
10469
  }
10056
10470
  if (shardFingerprintsEqual(state.inFlightFingerprint, fingerprint)) {
10057
10471
  setLayerImporting(layer.id, true);
@@ -10082,19 +10496,22 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10082
10496
  isCurrent: () => map.current !== null && state.generation === generation,
10083
10497
  contextForShard: () => {
10084
10498
  return {
10085
- timelineVisibleIds: timelineVisibleIdsRef.current,
10086
10499
  sizeFieldRanges,
10087
10500
  colorFieldRanges,
10088
10501
  // Trace-enabled layers are never sharded, so these are empty by construction.
10089
10502
  tracePointIds: EMPTY_ID_SET,
10090
- lastTracePointIds: EMPTY_ID_SET,
10091
- lastTracePointLabels: EMPTY_LABEL_MAP,
10092
10503
  tracePointColors: EMPTY_LABEL_MAP
10093
10504
  };
10094
10505
  },
10095
- onShardPainted: (index, cache2) => {
10506
+ onShardPainted: (index, start, end) => {
10096
10507
  var _a2;
10097
- state.caches[index] = cache2;
10508
+ seedTimelineSource(
10509
+ featureStateHostFor(m),
10510
+ appliedTimelineRef.current,
10511
+ shardSourceId(layer.id, index),
10512
+ [{ features, start, end }],
10513
+ timelineWindowRef.current
10514
+ );
10098
10515
  (_a2 = reconcileSelectionRef.current) == null ? void 0 : _a2.call(reconcileSelectionRef, { overlay: !overlayRestyled });
10099
10516
  overlayRestyled = true;
10100
10517
  },
@@ -10128,7 +10545,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10128
10545
  }, [update3DFlightPaths]);
10129
10546
  react.useEffect(() => {
10130
10547
  update3DFlightPaths();
10131
- }, [update3DFlightPaths, layers, is3DTerrainEnabled, timelineStore.isEnabled, timelineStore.rangeStart, timelineStore.rangeEnd]);
10548
+ }, [update3DFlightPaths, layers, is3DTerrainEnabled]);
10132
10549
  react.useEffect(() => {
10133
10550
  if (map.current && is3DTerrainEnabled) {
10134
10551
  const timer = setTimeout(() => {
@@ -10621,7 +11038,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10621
11038
  "text-opacity": ["coalesce", ["get", "stroke-opacity"], 1]
10622
11039
  }
10623
11040
  });
10624
- mapInstance.addSource("trace-features", {
11041
+ mapInstance.addSource(TRACE_SOURCE_ID, {
10625
11042
  type: "geojson",
10626
11043
  data: { type: "FeatureCollection", features: [] },
10627
11044
  maxzoom: 22
@@ -10629,13 +11046,15 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10629
11046
  mapInstance.addLayer({
10630
11047
  id: "trace-lines",
10631
11048
  type: "line",
10632
- source: "trace-features",
11049
+ source: TRACE_SOURCE_ID,
11050
+ filter: ["==", "$type", "LineString"],
10633
11051
  paint: {
10634
11052
  "line-color": ["get", "color"],
10635
11053
  "line-width": 2,
10636
11054
  "line-opacity": 0.7
10637
11055
  }
10638
11056
  });
11057
+ mapInstance.addLayer(buildTraceEndpointLabelLayer());
10639
11058
  mapInstance.addSource(SELECTION_OVERLAY_SOURCE_ID, {
10640
11059
  type: "geojson",
10641
11060
  data: { type: "FeatureCollection", features: [] },
@@ -13293,8 +13712,10 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13293
13712
  if (!m.getLayer(id)) return;
13294
13713
  m.moveLayer(id, firstVisibleBasemapSymbol == null ? void 0 : firstVisibleBasemapSymbol.id);
13295
13714
  });
13296
- if (!firstVisibleBasemapSymbol && m.getLayer(SELECTION_OVERLAY_LAYER_IDS.label)) {
13297
- m.moveLayer(SELECTION_OVERLAY_LAYER_IDS.label);
13715
+ if (!firstVisibleBasemapSymbol) {
13716
+ [TRACE_ENDPOINT_LABEL_LAYER_ID, SELECTION_OVERLAY_LAYER_IDS.label].forEach((id) => {
13717
+ if (m.getLayer(id)) m.moveLayer(id);
13718
+ });
13298
13719
  }
13299
13720
  } catch (e) {
13300
13721
  console.warn("[map-component] moveLabelsBeforeBasemapSymbols failed:", (e == null ? void 0 : e.message) ?? e);
@@ -13612,7 +14033,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13612
14033
  if (!layer) return [];
13613
14034
  const fieldsMap = /* @__PURE__ */ new Map();
13614
14035
  const excludedFields = /* @__PURE__ */ new Set(["name", "startDate", "endDate", "opacity", ...STYLING_PROPERTY_KEYS]);
13615
- const MAX_SAMPLES = 1e4;
14036
+ const MAX_SAMPLES2 = 1e4;
13616
14037
  let features = [];
13617
14038
  if (layer.readOnly) {
13618
14039
  features = readOnlyFeatures.current.get(layerId) || [];
@@ -13621,8 +14042,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13621
14042
  } else {
13622
14043
  features = hiddenFeatures.current.get(layerId) || [];
13623
14044
  }
13624
- const sampled = !layer.readOnly && features.length > MAX_SAMPLES;
13625
- const sampleFeatures = layer.readOnly ? features : features.slice(0, MAX_SAMPLES);
14045
+ const sampled = !layer.readOnly && features.length > MAX_SAMPLES2;
14046
+ const sampleFeatures = layer.readOnly ? features : features.slice(0, MAX_SAMPLES2);
13626
14047
  sampleFeatures.forEach((f) => {
13627
14048
  if (f && f.properties) {
13628
14049
  Object.entries(f.properties).forEach(([key, value]) => {
@@ -13670,15 +14091,15 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13670
14091
  } else {
13671
14092
  features = hiddenFeatures.current.get(layerId) || [];
13672
14093
  }
13673
- const MAX_SAMPLES = 1e4;
13674
- const sample = features.slice(0, MAX_SAMPLES);
13675
- const counts = /* @__PURE__ */ new Map();
14094
+ const MAX_SAMPLES2 = 1e4;
14095
+ const sample = features.slice(0, MAX_SAMPLES2);
14096
+ const counts2 = /* @__PURE__ */ new Map();
13676
14097
  for (const f of sample) {
13677
14098
  const key = categoricalKey((_a = f == null ? void 0 : f.properties) == null ? void 0 : _a[fieldName]);
13678
14099
  if (key === null) continue;
13679
- counts.set(key, (counts.get(key) ?? 0) + 1);
14100
+ counts2.set(key, (counts2.get(key) ?? 0) + 1);
13680
14101
  }
13681
- return Array.from(counts.entries()).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, maxValues).map(([value, count]) => ({ value, count }));
14102
+ return Array.from(counts2.entries()).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, maxValues).map(([value, count]) => ({ value, count }));
13682
14103
  },
13683
14104
  [layers]
13684
14105
  );
@@ -13744,21 +14165,19 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13744
14165
  });
13745
14166
  }
13746
14167
  }, [layers]);
14168
+ const traceFieldSource = react.useCallback((layer) => {
14169
+ if (layer.readOnly) return readOnlyFeatures.current.get(layer.id) || [];
14170
+ if (layer.visible) return draw.current ? layer.featureIds.map((id) => draw.current.get(id)) : [];
14171
+ return hiddenFeatures.current.get(layer.id) || [];
14172
+ }, []);
13747
14173
  const getAvailableTraceFields = react.useCallback((layerId) => {
13748
14174
  const layer = layers.find((l) => l.id === layerId);
13749
14175
  if (!layer) return [];
13750
14176
  const fieldsSet = /* @__PURE__ */ new Set();
13751
14177
  const excludedFields = /* @__PURE__ */ new Set(["name", "startDate", "endDate", "opacity"]);
13752
- const MAX_SAMPLES = 1e4;
13753
- let features = [];
13754
- if (layer.readOnly) {
13755
- features = readOnlyFeatures.current.get(layerId) || [];
13756
- } else if (layer.visible) {
13757
- features = draw.current ? layer.featureIds.map((id) => draw.current.get(id)) : [];
13758
- } else {
13759
- features = hiddenFeatures.current.get(layerId) || [];
13760
- }
13761
- const sampleFeatures = features.slice(0, MAX_SAMPLES);
14178
+ const MAX_SAMPLES2 = 1e4;
14179
+ const features = traceFieldSource(layer);
14180
+ const sampleFeatures = features.slice(0, MAX_SAMPLES2);
13762
14181
  sampleFeatures.forEach((f) => {
13763
14182
  if (f && f.properties) {
13764
14183
  Object.entries(f.properties).forEach(([key, value]) => {
@@ -13769,7 +14188,11 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13769
14188
  }
13770
14189
  });
13771
14190
  return Array.from(fieldsSet).sort();
13772
- }, [layers]);
14191
+ }, [layers, traceFieldSource]);
14192
+ const getSuggestedTraceField = react.useCallback((layerId) => {
14193
+ const layer = layers.find((l) => l.id === layerId);
14194
+ return layer ? suggestTraceGroupField(traceFieldSource(layer), getAvailableTraceFields(layerId)) : null;
14195
+ }, [layers, traceFieldSource, getAvailableTraceFields]);
13773
14196
  const handleMeasureModeChange = react.useCallback((mode) => {
13774
14197
  setMeasureMode(mode);
13775
14198
  setMeasurePoints([]);
@@ -13859,18 +14282,24 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13859
14282
  if (ranges.size) sizeFieldRanges.set(layerId, ranges.size);
13860
14283
  if (ranges.color) colorFieldRanges.set(layerId, ranges.color);
13861
14284
  });
13862
- return { ...base, timelineVisibleIds: timelineVisibleIdsRef.current, sizeFieldRanges, colorFieldRanges };
14285
+ return { ...base, sizeFieldRanges, colorFieldRanges };
13863
14286
  }, []);
13864
14287
  const overlayFeatureCountRef = react.useRef(0);
13865
- const overlayTimelineInputsRef = react.useRef(overlayTimelineInputs(EMPTY_ID_SET, null));
13866
14288
  const refreshSelectionOverlay = react.useCallback((m, ids) => {
13867
- overlayTimelineInputsRef.current = overlayTimelineInputs(ids, timelineVisibleIdsRef.current);
13868
14289
  if (ids.size === 0 && overlayFeatureCountRef.current === 0) return;
13869
14290
  const overlay = m.getSource(SELECTION_OVERLAY_SOURCE_ID);
13870
14291
  if (!overlay) return;
13871
14292
  const ctx = ids.size > 0 ? overlayPaintContext() : null;
13872
14293
  const layers2 = layersRef.current;
13873
14294
  const layerById = new Map(layers2.map((l) => [l.id, l]));
14295
+ const styled = (feature, layer, paintCtx, sourceId) => {
14296
+ const out = styleFeatureForPaint(feature, layer, paintCtx, true).feature;
14297
+ if (isTimelineHiddenOn(appliedTimelineRef.current, sourceId, String(feature.id)) && out.properties) {
14298
+ out.properties["stroke-opacity"] = 0;
14299
+ out.properties["fill-opacity"] = 0;
14300
+ }
14301
+ return out;
14302
+ };
13874
14303
  const data = buildSelectionOverlayData(ids, (id) => {
13875
14304
  if (!ctx) return [];
13876
14305
  const holders = locateFeatureHolders(id, readOnlyFeatures.current, locatorCacheRef.current);
@@ -13878,12 +14307,12 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13878
14307
  return holders.filter((h) => {
13879
14308
  var _a;
13880
14309
  return ((_a = layerById.get(h.layerId)) == null ? void 0 : _a.visible) === true;
13881
- }).map((h) => styleFeatureForPaint(h.feature, layerById.get(h.layerId), ctx, true).feature);
14310
+ }).map((h) => styled(h.feature, layerById.get(h.layerId), ctx, shardedLayerIdsRef.current.has(h.layerId) ? shardSourceId(h.layerId, Math.floor(h.position / shardSizeRef.current)) : SHARED_SOURCE_ID));
13882
14311
  }
13883
14312
  const feature = getFeatureById(id);
13884
14313
  if (!feature) return [];
13885
14314
  const layer = layers2.find((l) => !l.readOnly && l.featureIds.includes(id));
13886
- return layer && !layer.visible ? [] : [styleFeatureForPaint(feature, layer, ctx, true).feature];
14315
+ return layer && !layer.visible ? [] : [styled(feature, layer, ctx, SHARED_SOURCE_ID)];
13887
14316
  });
13888
14317
  overlay.setData(data);
13889
14318
  overlayFeatureCountRef.current = data.features.length;
@@ -13939,35 +14368,42 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13939
14368
  const m = map.current;
13940
14369
  if (!m) return true;
13941
14370
  if (hasArrowFeaturesRef.current) return false;
13942
- const source = m.getSource("custom-features");
13943
- const paintCache = selectionPaintCacheRef.current;
13944
- const nextVisible = timelineVisibleIdsRef.current;
14371
+ const start = performance.now();
14372
+ const next = timelineWindowRef.current;
13945
14373
  const trace = tracePaintCacheRef.current;
13946
- const traceSource = trace ? m.getSource("trace-features") : void 0;
13947
- if (trace && !traceSource) return false;
13948
- const traceDiff = trace && paintCache ? buildTraceTimelineDiff(trace, paintCache, nextVisible) : null;
13949
- const { applied, toggled } = applyTimelineFastPath(paintCache, nextVisible, source);
13950
- if (!applied || !paintCache || !source) return false;
13951
- if (traceDiff && (!traceSource || !applyTraceTimelineDiff(traceDiff, source, traceSource))) return false;
13952
- if (!forEachShardCache(shardRegistryRef.current, (cache2, shardSource) => applyTimelineFastPath(cache2, nextVisible, shardSource).applied)) {
13953
- return false;
13954
- }
14374
+ let endpointsMoved = 0;
14375
+ if (trace) {
14376
+ const traceSource = m.getSource(TRACE_SOURCE_ID);
14377
+ if (!traceSource) return false;
14378
+ const traceDiff = buildTraceTimelineDiff(trace, next);
14379
+ if (!applyTraceTimelineDiff(traceDiff, traceSource, featureStateHostFor(m), traceEndpointsRef.current)) return false;
14380
+ trace.window = next;
14381
+ endpointsMoved = traceDiff.endpointOn.length;
14382
+ }
14383
+ const flipped = applyTimelineWindow(featureStateHostFor(m), appliedTimelineRef.current, next, isTimelineSourceActive);
13955
14384
  const threshold = autoLabelConfig.enabled ? autoLabelConfig.threshold : 220;
13956
- setVisibleFeatureCount(countVisibleFeatures(threshold));
13957
- setLabelsSuppressed(false);
14385
+ const count = countVisibleFeatures(threshold);
14386
+ if (tickCountTimerRef.current) clearTimeout(tickCountTimerRef.current);
14387
+ tickCountTimerRef.current = null;
14388
+ if (count < threshold !== visibleFeatureCountRef.current < threshold) setVisibleFeatureCount(count);
14389
+ else if (count !== visibleFeatureCountRef.current) {
14390
+ tickCountTimerRef.current = setTimeout(() => setVisibleFeatureCount(countVisibleFeatures(threshold)), TICK_COUNT_SETTLE_MS);
14391
+ }
14392
+ if (labelsSuppressedRef.current) setLabelsSuppressed(false);
13958
14393
  const selection = currentSelection() ?? EMPTY_ID_SET;
13959
- if (!sameOverlayTimelineInputs(overlayTimelineInputsRef.current, overlayTimelineInputs(selection, nextVisible))) {
13960
- refreshSelectionOverlay(m, selection);
13961
- }
13962
- mapPerfLog("timeline", "fast path applied", {
13963
- toggled,
13964
- endpointsMoved: (traceDiff == null ? void 0 : traceDiff.pointUpdates.length) ?? 0,
13965
- segmentsAdded: (traceDiff == null ? void 0 : traceDiff.segmentAdd.length) ?? 0,
13966
- segmentsRemoved: (traceDiff == null ? void 0 : traceDiff.segmentRemove.length) ?? 0
14394
+ if (selection.size > 0 && flipped.some((id) => selection.has(id))) refreshSelectionOverlay(m, selection);
14395
+ mapPerfLog("timeline", "applied", {
14396
+ flipped: flipped.length,
14397
+ sources: appliedTimelineRef.current.size,
14398
+ endpointsMoved,
14399
+ ms: Math.round(performance.now() - start)
13967
14400
  });
13968
14401
  return true;
13969
- }, [autoLabelConfig, countVisibleFeatures, currentSelection, refreshSelectionOverlay]);
14402
+ }, [autoLabelConfig, countVisibleFeatures, currentSelection, refreshSelectionOverlay, isTimelineSourceActive]);
13970
14403
  tryTimelineFastPathRef.current = tryTimelineFastPath;
14404
+ react.useEffect(() => () => {
14405
+ if (tickCountTimerRef.current) clearTimeout(tickCountTimerRef.current);
14406
+ }, []);
13971
14407
  const collectSelectionFeatureGroups = react.useCallback(() => {
13972
14408
  return collectVisibleFeatureGroups(
13973
14409
  draw.current ? draw.current.getAll().features : null,
@@ -15485,25 +15921,12 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
15485
15921
  const handleDropGeoJSONFile = react.useCallback((name, file) => {
15486
15922
  void ingestDroppedLayer(name, file);
15487
15923
  }, [ingestDroppedLayer]);
15488
- const handleTimelineFilterChange = react.useCallback((visibleIds, hiddenIds, untimedIds) => {
15489
- if (!draw.current || !map.current) return;
15490
- const nextVisible = new Set(visibleIds);
15491
- untimedIds.forEach((id) => nextVisible.add(id));
15492
- timelineVisibleIdsRef.current = nextVisible;
15493
- scheduleSync("timeline");
15494
- }, [scheduleSync]);
15495
- const prevTimelineEnabledRef = react.useRef(timelineStore.isEnabled);
15924
+ const prevTimelineEnabledRef = react.useRef(timelineEnabled);
15496
15925
  react.useEffect(() => {
15497
15926
  const wasEnabled = prevTimelineEnabledRef.current;
15498
- const isNowEnabled = timelineStore.isEnabled;
15499
- prevTimelineEnabledRef.current = isNowEnabled;
15500
- if (!isNowEnabled || !timelineStore.hasTemporalData) {
15501
- timelineVisibleIdsRef.current = null;
15502
- scheduleSync("timeline");
15503
- } else if (!wasEnabled && isNowEnabled) {
15504
- updateTimelineStore();
15505
- }
15506
- }, [timelineStore.isEnabled, timelineStore.hasTemporalData, scheduleSync, updateTimelineStore, scheduleTimelineUpdate]);
15927
+ prevTimelineEnabledRef.current = timelineEnabled;
15928
+ if (!wasEnabled && timelineEnabled && timelineHasData) updateTimelineStore();
15929
+ }, [timelineEnabled, timelineHasData, updateTimelineStore]);
15507
15930
  react.useEffect(() => {
15508
15931
  if (!map.current || !draw.current || !isMapLoaded) return;
15509
15932
  const mapInstance = map.current;
@@ -15727,14 +16150,14 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
15727
16150
  let categoryColorMap = {};
15728
16151
  let hasOtherBucket = false;
15729
16152
  if (groupByField) {
15730
- const counts = /* @__PURE__ */ new Map();
16153
+ const counts2 = /* @__PURE__ */ new Map();
15731
16154
  pointFeatures.forEach((f) => {
15732
16155
  var _a2;
15733
16156
  const key = categoricalKey((_a2 = f.properties) == null ? void 0 : _a2[groupByField]);
15734
16157
  if (key === null) return;
15735
- counts.set(key, (counts.get(key) ?? 0) + 1);
16158
+ counts2.set(key, (counts2.get(key) ?? 0) + 1);
15736
16159
  });
15737
- const sorted = Array.from(counts.entries()).sort((a, b) => b[1] - a[1]);
16160
+ const sorted = Array.from(counts2.entries()).sort((a, b) => b[1] - a[1]);
15738
16161
  const topKeys = sorted.slice(0, MAX_CATEGORIES).map(([k]) => k);
15739
16162
  categoryValues = [...topKeys];
15740
16163
  hasOtherBucket = true;
@@ -16255,21 +16678,21 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
16255
16678
  ] })
16256
16679
  }
16257
16680
  ),
16258
- enableTimeline && timelineStore.hasTemporalData && /* @__PURE__ */ jsxRuntime.jsx(
16681
+ enableTimeline && timelineHasData && /* @__PURE__ */ jsxRuntime.jsx(
16259
16682
  "div",
16260
16683
  {
16261
16684
  className: "absolute left-4 z-[200] transition-all",
16262
- style: { bottom: timelineStore.isEnabled ? TIMEBAR_HEIGHT + TIMEBAR_BOTTOM_OFFSET + 8 : 48 },
16685
+ style: { bottom: timelineEnabled ? TIMEBAR_HEIGHT + TIMEBAR_BOTTOM_OFFSET + 8 : 48 },
16263
16686
  children: /* @__PURE__ */ jsxRuntime.jsx(antd.Tooltip, { title: "Timeline", placement: "right", children: /* @__PURE__ */ jsxRuntime.jsx(
16264
16687
  antd.Button,
16265
16688
  {
16266
16689
  type: "default",
16267
16690
  icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Clock, { className: "w-5 h-5" }),
16268
- onClick: () => timelineStore.setEnabled(!timelineStore.isEnabled),
16691
+ onClick: () => timelineStoreApi.getState().setEnabled(!timelineEnabled),
16269
16692
  disabled: !isMapLoaded,
16270
- className: `!w-10 !h-10 !min-w-0 !p-0 bg-background shadow-lg ${timelineStore.isEnabled ? "bg-primary/10" : ""}`,
16693
+ className: `!w-10 !h-10 !min-w-0 !p-0 bg-background shadow-lg ${timelineEnabled ? "bg-primary/10" : ""}`,
16271
16694
  "aria-label": "Toggle timeline",
16272
- "aria-pressed": timelineStore.isEnabled,
16695
+ "aria-pressed": timelineEnabled,
16273
16696
  "data-testid": "button-toggle-timeline"
16274
16697
  }
16275
16698
  ) })
@@ -16328,6 +16751,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
16328
16751
  onMapStyleChange: handleMapStyleChange,
16329
16752
  onUpdateTraceConfig: handleUpdateTraceConfig,
16330
16753
  getAvailableTraceFields,
16754
+ getSuggestedTraceField,
16331
16755
  getFieldValueDistribution,
16332
16756
  onUpdateHeatmapConfig: handleUpdateHeatmapConfig,
16333
16757
  onUpdateClusterConfig: handleUpdateClusterConfig,
@@ -16407,10 +16831,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
16407
16831
  selectionMode
16408
16832
  }
16409
16833
  ),
16410
- enableTimeline && timelineStore.isEnabled && /* @__PURE__ */ jsxRuntime.jsx(
16834
+ enableTimeline && timelineEnabled && /* @__PURE__ */ jsxRuntime.jsx(
16411
16835
  Timebar,
16412
16836
  {
16413
- onFilterChange: handleTimelineFilterChange,
16414
16837
  selectedFeatureIds,
16415
16838
  selectedFeatureColors,
16416
16839
  timebarExtra
@@ -16445,7 +16868,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
16445
16868
  IngestProgressOverlay,
16446
16869
  {
16447
16870
  store: ingestProgressStore,
16448
- bottomPx: timelineStore.isEnabled ? TIMEBAR_HEIGHT + TIMEBAR_BOTTOM_OFFSET + 8 : 32
16871
+ bottomPx: timelineEnabled ? TIMEBAR_HEIGHT + TIMEBAR_BOTTOM_OFFSET + 8 : 32
16449
16872
  }
16450
16873
  ),
16451
16874
  /* @__PURE__ */ jsxRuntime.jsx(