@octostar/map-component 0.3.2 → 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 (47) hide show
  1. package/README.md +14 -0
  2. package/dist/index.cjs +898 -475
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.mjs +898 -475
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/types/components/layers-panel.d.ts +3 -1
  7. package/dist/types/components/layers-panel.d.ts.map +1 -1
  8. package/dist/types/components/map-editor-canvas.d.ts.map +1 -1
  9. package/dist/types/components/timebar.d.ts +7 -1
  10. package/dist/types/components/timebar.d.ts.map +1 -1
  11. package/dist/types/lib/custom-layer-stack.d.ts +2 -1
  12. package/dist/types/lib/custom-layer-stack.d.ts.map +1 -1
  13. package/dist/types/lib/label-pinning.d.ts +4 -1
  14. package/dist/types/lib/label-pinning.d.ts.map +1 -1
  15. package/dist/types/lib/paint-feature.d.ts +9 -27
  16. package/dist/types/lib/paint-feature.d.ts.map +1 -1
  17. package/dist/types/lib/selection-diff.d.ts +0 -51
  18. package/dist/types/lib/selection-diff.d.ts.map +1 -1
  19. package/dist/types/lib/selection-overlay.d.ts +0 -8
  20. package/dist/types/lib/selection-overlay.d.ts.map +1 -1
  21. package/dist/types/lib/selection-paint.d.ts +9 -1
  22. package/dist/types/lib/selection-paint.d.ts.map +1 -1
  23. package/dist/types/lib/selection-state.d.ts +2 -2
  24. package/dist/types/lib/selection-state.d.ts.map +1 -1
  25. package/dist/types/lib/shard-locator.d.ts +2 -0
  26. package/dist/types/lib/shard-locator.d.ts.map +1 -1
  27. package/dist/types/lib/shard-pipeline.d.ts +4 -5
  28. package/dist/types/lib/shard-pipeline.d.ts.map +1 -1
  29. package/dist/types/lib/shard-registry.d.ts +0 -28
  30. package/dist/types/lib/shard-registry.d.ts.map +1 -1
  31. package/dist/types/lib/timeline-index.d.ts +56 -0
  32. package/dist/types/lib/timeline-index.d.ts.map +1 -0
  33. package/dist/types/lib/timeline-state.d.ts +64 -0
  34. package/dist/types/lib/timeline-state.d.ts.map +1 -0
  35. package/dist/types/lib/timeline-window.d.ts +19 -0
  36. package/dist/types/lib/timeline-window.d.ts.map +1 -0
  37. package/dist/types/lib/trace-group-suggestion.d.ts +17 -0
  38. package/dist/types/lib/trace-group-suggestion.d.ts.map +1 -0
  39. package/dist/types/lib/trace-groups.d.ts +6 -5
  40. package/dist/types/lib/trace-groups.d.ts.map +1 -1
  41. package/dist/types/lib/trace-timeline.d.ts +56 -49
  42. package/dist/types/lib/trace-timeline.d.ts.map +1 -1
  43. package/dist/types/lib/visible-feature-count.d.ts +18 -4
  44. package/dist/types/lib/visible-feature-count.d.ts.map +1 -1
  45. package/package.json +3 -1
  46. package/dist/types/lib/timeline-diff.d.ts +0 -43
  47. package/dist/types/lib/timeline-diff.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -752,6 +752,10 @@ const SELECTED_STATE_KEY = "selected";
752
752
  const SELECTED = ["boolean", ["feature-state", SELECTED_STATE_KEY], false];
753
753
  const SELECTED_STATE = Object.freeze({ [SELECTED_STATE_KEY]: true });
754
754
  const SELECTION_COLOR = "#06b6d4";
755
+ const TIMELINE_HIDDEN_KEY = "timelineHidden";
756
+ const TIMELINE_HIDDEN = ["boolean", ["feature-state", TIMELINE_HIDDEN_KEY], false];
757
+ const TRACE_ENDPOINT_KEY = "traceEndpoint";
758
+ const TRACE_ENDPOINT = ["boolean", ["feature-state", TRACE_ENDPOINT_KEY], false];
755
759
  const LABEL_NEVER_HIDE_PROP = "_labelNeverHide";
756
760
  const PINNED_LABEL_FILTER = ["==", ["get", LABEL_NEVER_HIDE_PROP], 1];
757
761
  const UNPINNED_LABEL_FILTER = ["!=", ["get", LABEL_NEVER_HIDE_PROP], 1];
@@ -760,8 +764,8 @@ function computeLabelNeverHide(label) {
760
764
  }
761
765
  function buildCustomLabelLayout() {
762
766
  return {
763
- // Hide labels for trace points (except last point which has isTraceLabel),
764
- // arrows handled by the custom-arrow-labels layer. Features blanked by
767
+ // Hide labels for trace points (a group's endpoint label is the trace
768
+ // source's, trace-timeline.ts), arrows handled by the custom-arrow-labels layer.Features blanked by
765
769
  // heatmap/cluster modes stay blank in BOTH layers: "never hide"
766
770
  // exempts labels from collision and density culling, it does not resurrect
767
771
  // labels other mode choices explicitly blank.
@@ -773,33 +777,28 @@ function buildCustomLabelLayout() {
773
777
  "",
774
778
  ["==", ["get", "kind"], "arrow"],
775
779
  "",
776
- // Trace points: only show label if isTraceLabel is true (last point in group)
777
- ["all", ["==", ["get", "isTracePoint"], true], ["!=", ["get", "isTraceLabel"], true]],
780
+ ["==", ["get", "isTracePoint"], true],
778
781
  "",
779
782
  ["==", ["get", "kind"], "text"],
780
783
  ["coalesce", ["get", "label"], ["get", "text"], "New Label"],
781
784
  ["coalesce", ["get", "name"], ""]
782
785
  ],
783
- // Text features use their fontSize property; trace labels 14px; others 12px
786
+ // Text features use their fontSize property; others 12px
784
787
  "text-size": [
785
788
  "case",
786
789
  ["==", ["get", "kind"], "text"],
787
790
  ["coalesce", ["get", "fontSize"], 14],
788
- ["==", ["get", "isTraceLabel"], true],
789
- 14,
790
791
  12
791
792
  ],
792
793
  // Text features: center anchor; others: top anchor
793
794
  "text-anchor": ["case", ["==", ["get", "kind"], "text"], "center", "top"],
794
795
  "text-offset": ["case", ["==", ["get", "kind"], "text"], ["literal", [0, 0]], ["literal", [0, 0.8]]],
795
796
  "text-padding": 2,
796
- // Bold font for text features with fontWeight=bold, trace labels, others regular
797
+ // Bold font for text features with fontWeight=bold, others regular
797
798
  "text-font": [
798
799
  "case",
799
800
  ["all", ["==", ["get", "kind"], "text"], ["==", ["get", "fontWeight"], "bold"]],
800
801
  ["literal", ["Montserrat SemiBold", "Noto Sans Regular"]],
801
- ["==", ["get", "isTraceLabel"], true],
802
- ["literal", ["Montserrat Medium", "Noto Sans Regular"]],
803
802
  ["literal", ["Montserrat Regular", "Noto Sans Regular"]]
804
803
  ]
805
804
  };
@@ -815,16 +814,14 @@ function buildCustomLabelPaint(opts) {
815
814
  "#1f2937"
816
815
  ],
817
816
  "text-halo-color": "#ffffff",
818
- // Thicker halo for trace labels and text features
817
+ // Thicker halo for text features
819
818
  "text-halo-width": [
820
819
  "case",
821
820
  ["==", ["get", "kind"], "text"],
822
821
  2,
823
- ["==", ["get", "isTraceLabel"], true],
824
- 2,
825
822
  1.5
826
823
  ],
827
- "text-opacity": (opts == null ? void 0 : opts.hideSelected) ? ["case", SELECTED, 0, visibleOpacity] : visibleOpacity
824
+ "text-opacity": (opts == null ? void 0 : opts.hideSelected) ? ["case", TIMELINE_HIDDEN, 0, SELECTED, 0, visibleOpacity] : visibleOpacity
828
825
  };
829
826
  }
830
827
  const CUSTOM_LAYER_ROLES = [
@@ -894,6 +891,10 @@ function shardInsertAnchor(role) {
894
891
  return "custom-arrow-heads";
895
892
  }
896
893
  }
894
+ const POINT_RADIUS = ["case", TRACE_ENDPOINT, ["get", "_endpointRadius"], ["coalesce", ["get", "pointRadius"], 5]];
895
+ function unlessTimelineHidden(value) {
896
+ return ["case", TIMELINE_HIDDEN, 0, value];
897
+ }
897
898
  function buildLayer(role, sourceId, opts) {
898
899
  const id = customLayerId(role, sourceId);
899
900
  switch (role) {
@@ -906,7 +907,7 @@ function buildLayer(role, sourceId, opts) {
906
907
  filter: ["==", "$type", "Polygon"],
907
908
  paint: {
908
909
  "fill-color": ["get", "fill"],
909
- "fill-opacity": ["get", "fill-opacity"]
910
+ "fill-opacity": unlessTimelineHidden(["get", "fill-opacity"])
910
911
  }
911
912
  };
912
913
  case "polygon-stroke":
@@ -918,7 +919,7 @@ function buildLayer(role, sourceId, opts) {
918
919
  paint: {
919
920
  "line-color": ["get", "stroke"],
920
921
  "line-width": ["get", "stroke-width"],
921
- "line-opacity": ["get", "stroke-opacity"]
922
+ "line-opacity": unlessTimelineHidden(["get", "stroke-opacity"])
922
923
  }
923
924
  };
924
925
  // Custom line layer - preserves original styling
@@ -931,7 +932,7 @@ function buildLayer(role, sourceId, opts) {
931
932
  paint: {
932
933
  "line-color": ["get", "stroke"],
933
934
  "line-width": ["get", "stroke-width"],
934
- "line-opacity": ["get", "stroke-opacity"]
935
+ "line-opacity": unlessTimelineHidden(["get", "stroke-opacity"])
935
936
  }
936
937
  };
937
938
  // Shadow layer rendered beneath points for depth (hidden when emoji icon is set)
@@ -945,7 +946,7 @@ function buildLayer(role, sourceId, opts) {
945
946
  "circle-color": "rgba(0, 0, 0, 0.2)",
946
947
  "circle-radius": [
947
948
  "case",
948
- ["==", ["get", "isTimelineHidden"], 1],
949
+ TIMELINE_HIDDEN,
949
950
  0,
950
951
  ["==", ["get", "isHiddenByCluster"], 1],
951
952
  0,
@@ -953,7 +954,7 @@ function buildLayer(role, sourceId, opts) {
953
954
  0,
954
955
  ["!=", ["get", "icon"], ""],
955
956
  0,
956
- ["+", ["coalesce", ["get", "pointRadius"], 5], 1.5]
957
+ ["+", POINT_RADIUS, 1.5]
957
958
  ],
958
959
  "circle-blur": 0.5,
959
960
  "circle-opacity": [
@@ -981,7 +982,7 @@ function buildLayer(role, sourceId, opts) {
981
982
  "circle-color": ["coalesce", ["get", "stroke"], "#3b82f6"],
982
983
  "circle-radius": [
983
984
  "case",
984
- ["==", ["get", "isTimelineHidden"], 1],
985
+ TIMELINE_HIDDEN,
985
986
  0,
986
987
  ["==", ["get", "isHiddenByCluster"], 1],
987
988
  0,
@@ -989,7 +990,7 @@ function buildLayer(role, sourceId, opts) {
989
990
  0,
990
991
  ["!=", ["get", "icon"], ""],
991
992
  0,
992
- ["coalesce", ["get", "pointRadius"], 5]
993
+ POINT_RADIUS
993
994
  ],
994
995
  "circle-opacity": [
995
996
  "case",
@@ -1004,7 +1005,7 @@ function buildLayer(role, sourceId, opts) {
1004
1005
  "circle-stroke-color": ["case", SELECTED, SELECTION_COLOR, "#555555"],
1005
1006
  "circle-stroke-width": [
1006
1007
  "case",
1007
- ["==", ["get", "isTimelineHidden"], 1],
1008
+ TIMELINE_HIDDEN,
1008
1009
  0,
1009
1010
  ["==", ["get", "isHiddenByCluster"], 1],
1010
1011
  0,
@@ -1044,6 +1045,8 @@ function buildLayer(role, sourceId, opts) {
1044
1045
  paint: {
1045
1046
  "icon-opacity": [
1046
1047
  "case",
1048
+ TIMELINE_HIDDEN,
1049
+ 0,
1047
1050
  ["==", ["get", "isHiddenByCluster"], 1],
1048
1051
  0,
1049
1052
  ["==", ["get", "isHiddenByHeatmap"], 1],
@@ -1053,7 +1056,7 @@ function buildLayer(role, sourceId, opts) {
1053
1056
  }
1054
1057
  };
1055
1058
  // Label layer for all features - shows 'name' property, or 'text' for text features
1056
- // Trace labels are slightly bigger and bolder, hidden points have no labels
1059
+ // Trace points have no label here: a group's label is the trace source's
1057
1060
  // Arrow labels are handled separately by the custom-arrow-labels layer.
1058
1061
  // Shared layout/paint live in label-pinning.ts so this layer and its
1059
1062
  // pinned twin below cannot drift.
@@ -1191,77 +1194,6 @@ function shardFingerprintsEqual(a, b) {
1191
1194
  if (!a || !b) return false;
1192
1195
  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);
1193
1196
  }
1194
- const DEFAULT_VISIBLE_STROKE_OPACITY = 1;
1195
- const DEFAULT_VISIBLE_FILL_OPACITY = 0.2;
1196
- function createSelectionPaintCache() {
1197
- return {
1198
- presentIds: /* @__PURE__ */ new Set(),
1199
- appliedHiddenIds: /* @__PURE__ */ new Set(),
1200
- visibleStrokeOpacityById: /* @__PURE__ */ new Map(),
1201
- visibleFillOpacityById: /* @__PURE__ */ new Map(),
1202
- updatable: true
1203
- };
1204
- }
1205
- function recordPaintedFeature(cache2, featureId, visibleStrokeOpacity, visibleFillOpacity, isTimelineHidden) {
1206
- if (cache2.presentIds.has(featureId)) {
1207
- cache2.updatable = false;
1208
- } else {
1209
- cache2.presentIds.add(featureId);
1210
- }
1211
- if (visibleStrokeOpacity !== DEFAULT_VISIBLE_STROKE_OPACITY) {
1212
- cache2.visibleStrokeOpacityById.set(featureId, visibleStrokeOpacity);
1213
- }
1214
- if (visibleFillOpacity !== DEFAULT_VISIBLE_FILL_OPACITY) {
1215
- cache2.visibleFillOpacityById.set(featureId, visibleFillOpacity);
1216
- }
1217
- if (isTimelineHidden) cache2.appliedHiddenIds.add(featureId);
1218
- }
1219
- function needsDrawSelectionUpdate(input) {
1220
- return input.editableSelectionCount > 0 || input.drawSelectedCount > 0 || input.currentMode !== input.targetMode;
1221
- }
1222
- function buildTimelineVisibilityDiff(cache2, nextVisibleSet) {
1223
- const update = [];
1224
- const nextHiddenIds = /* @__PURE__ */ new Set();
1225
- cache2.presentIds.forEach((id) => {
1226
- const nextHidden = nextVisibleSet !== null && !nextVisibleSet.has(id);
1227
- if (nextHidden) nextHiddenIds.add(id);
1228
- if (nextHidden === cache2.appliedHiddenIds.has(id)) return;
1229
- if (nextHidden) {
1230
- update.push({
1231
- id,
1232
- addOrUpdateProperties: [
1233
- { key: "stroke-opacity", value: 0 },
1234
- { key: "fill-opacity", value: 0 },
1235
- { key: "isTimelineHidden", value: 1 }
1236
- ]
1237
- });
1238
- } else {
1239
- update.push({
1240
- id,
1241
- addOrUpdateProperties: [
1242
- { key: "stroke-opacity", value: cache2.visibleStrokeOpacityById.get(id) ?? DEFAULT_VISIBLE_STROKE_OPACITY },
1243
- { key: "fill-opacity", value: cache2.visibleFillOpacityById.get(id) ?? DEFAULT_VISIBLE_FILL_OPACITY },
1244
- { key: "isTimelineHidden", value: 0 }
1245
- ]
1246
- });
1247
- }
1248
- });
1249
- return { diff: update.length > 0 ? { update } : null, nextHiddenIds };
1250
- }
1251
- function applyTimelineFastPath(cache2, nextVisibleSet, source) {
1252
- var _a;
1253
- if (!cache2 || !cache2.updatable || !source) return { applied: false, toggled: 0 };
1254
- const { diff, nextHiddenIds } = buildTimelineVisibilityDiff(cache2, nextVisibleSet);
1255
- if (diff) {
1256
- try {
1257
- source.updateData(diff);
1258
- } catch {
1259
- return { applied: false, toggled: 0 };
1260
- }
1261
- }
1262
- cache2.appliedHiddenIds = nextHiddenIds;
1263
- return { applied: true, toggled: ((_a = diff == null ? void 0 : diff.update) == null ? void 0 : _a.length) ?? 0 };
1264
- }
1265
1197
  const INTERACTIVE_ROLES = ["point", "line", "polygon-fill"];
1266
1198
  function createShardRegistry(host, hooks) {
1267
1199
  const states = /* @__PURE__ */ new Map();
@@ -1269,7 +1201,7 @@ function createShardRegistry(host, hooks) {
1269
1201
  const ensure = (layerId) => {
1270
1202
  let state = states.get(layerId);
1271
1203
  if (!state) {
1272
- state = { layerId, stacks: [], caches: [], fingerprint: null, inFlightFingerprint: null, generation: 0, visible: true, arrowLines: [] };
1204
+ state = { layerId, stacks: [], fingerprint: null, inFlightFingerprint: null, generation: 0, visible: true, arrowLines: [] };
1273
1205
  states.set(layerId, state);
1274
1206
  }
1275
1207
  return state;
@@ -1316,7 +1248,6 @@ function createShardRegistry(host, hooks) {
1316
1248
  removeStack(state.stacks[i]);
1317
1249
  }
1318
1250
  state.stacks.length = Math.min(state.stacks.length, index);
1319
- state.caches.length = state.stacks.length;
1320
1251
  };
1321
1252
  return {
1322
1253
  registerShared(layerIds) {
@@ -1411,50 +1342,9 @@ function createShardRegistry(host, hooks) {
1411
1342
  });
1412
1343
  });
1413
1344
  return ids;
1414
- },
1415
- sourceFor(layerId, index) {
1416
- var _a;
1417
- const stack = (_a = states.get(layerId)) == null ? void 0 : _a.stacks[index];
1418
- return stack ? host.getSource(stack.sourceId) : void 0;
1419
- },
1420
- sourceById(sourceId) {
1421
- return host.getSource(sourceId);
1422
- },
1423
- everyPaintedShard(visit) {
1424
- let ok = true;
1425
- states.forEach((state) => {
1426
- if (!ok) return;
1427
- state.stacks.forEach((stack, i) => {
1428
- if (!ok) return;
1429
- const cache2 = state.caches[i];
1430
- if (!cache2) return;
1431
- if (!visit(cache2, stack.sourceId)) ok = false;
1432
- });
1433
- });
1434
- return ok;
1435
1345
  }
1436
1346
  };
1437
1347
  }
1438
- function reconcileShardCaches(registry, layerId, expectedShards, visibleIds) {
1439
- const state = registry.state(layerId);
1440
- if (!state || state.stacks.length !== expectedShards) return false;
1441
- for (let i = 0; i < expectedShards; i++) {
1442
- const cache2 = state.caches[i];
1443
- if (!cache2) return false;
1444
- const source = registry.sourceFor(layerId, i);
1445
- if (!source) return false;
1446
- if (!applyTimelineFastPath(cache2, visibleIds, source).applied) return false;
1447
- }
1448
- return true;
1449
- }
1450
- function forEachShardCache(registry, apply) {
1451
- if (!registry) return true;
1452
- return registry.everyPaintedShard((cache2, sourceId) => {
1453
- const source = registry.sourceById(sourceId);
1454
- if (!source) return false;
1455
- return apply(cache2, source);
1456
- });
1457
- }
1458
1348
  function categoricalKey(raw) {
1459
1349
  if (raw == null) return null;
1460
1350
  if (typeof raw === "string") return raw === "" ? null : raw;
@@ -1573,6 +1463,158 @@ function formatGradientStop(value) {
1573
1463
  }
1574
1464
  return new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 }).format(value);
1575
1465
  }
1466
+ function windowFromRange(start, end) {
1467
+ if (!start || !end) return null;
1468
+ const t0 = start.getTime();
1469
+ const t1 = end.getTime();
1470
+ return Number.isFinite(t0) && Number.isFinite(t1) ? { t0, t1 } : null;
1471
+ }
1472
+ function sameWindow(a, b) {
1473
+ if (a === null || b === null) return a === b;
1474
+ return a.t0 === b.t0 && a.t1 === b.t1;
1475
+ }
1476
+ function isIntervalVisible(s, e, w) {
1477
+ if (w === null) return true;
1478
+ const noStart = Number.isNaN(s);
1479
+ const noEnd = Number.isNaN(e);
1480
+ if (noStart && noEnd) return true;
1481
+ return (noStart ? e : s) <= w.t1 && (noEnd ? s : e) >= w.t0;
1482
+ }
1483
+ const interval = { s: NaN, e: NaN };
1484
+ function readInterval(f) {
1485
+ interval.s = NaN;
1486
+ interval.e = NaN;
1487
+ const props = f.properties;
1488
+ if (!props || !hasAnyTemporalValue(props)) return;
1489
+ const { startDate, endDate } = normalizeTemporalProperties(props);
1490
+ const s = startDate ? startDate.getTime() : NaN;
1491
+ const e = endDate ? endDate.getTime() : NaN;
1492
+ interval.s = Number.isNaN(s) ? e : s;
1493
+ interval.e = Number.isNaN(e) ? s : e;
1494
+ }
1495
+ function featureInterval(f) {
1496
+ readInterval(f);
1497
+ return { s: interval.s, e: interval.e };
1498
+ }
1499
+ function isFeatureVisible(f, w) {
1500
+ if (w === null) return true;
1501
+ readInterval(f);
1502
+ return isIntervalVisible(interval.s, interval.e, w);
1503
+ }
1504
+ function collectRepeats(features) {
1505
+ const first = /* @__PURE__ */ new Map();
1506
+ const repeats = /* @__PURE__ */ new Map();
1507
+ for (let i = 0; i < features.length; i++) {
1508
+ const id = features[i].id;
1509
+ if (id === void 0 || id === null) continue;
1510
+ const key = String(id);
1511
+ const at = first.get(key);
1512
+ if (at === void 0) first.set(key, i);
1513
+ else {
1514
+ const more = repeats.get(key);
1515
+ if (more) more.push(i);
1516
+ else repeats.set(key, [at, i]);
1517
+ }
1518
+ }
1519
+ return repeats;
1520
+ }
1521
+ function buildIndex(features) {
1522
+ const size = features.length;
1523
+ const starts = new Float64Array(size);
1524
+ const ends = new Float64Array(size);
1525
+ let timed = 0;
1526
+ for (let i = 0; i < size; i++) {
1527
+ readInterval(features[i]);
1528
+ starts[i] = interval.s;
1529
+ ends[i] = interval.e;
1530
+ if (!Number.isNaN(interval.s)) timed++;
1531
+ }
1532
+ const byStart = new Uint32Array(timed);
1533
+ for (let i = 0, k = 0; i < size; i++) {
1534
+ if (!Number.isNaN(starts[i])) byStart[k++] = i;
1535
+ }
1536
+ const byEnd = byStart.slice();
1537
+ byStart.sort((a, b) => starts[a] - starts[b]);
1538
+ byEnd.sort((a, b) => ends[a] - ends[b]);
1539
+ return {
1540
+ size,
1541
+ starts,
1542
+ ends,
1543
+ byStart,
1544
+ sortedStarts: Float64Array.from(byStart, (p) => starts[p]),
1545
+ byEnd,
1546
+ sortedEnds: Float64Array.from(byEnd, (p) => ends[p]),
1547
+ untimedCount: size - timed,
1548
+ repeats: collectRepeats(features),
1549
+ mark: new Uint8Array(size)
1550
+ };
1551
+ }
1552
+ const cache$1 = /* @__PURE__ */ new WeakMap();
1553
+ function getTimelineIndex(features) {
1554
+ let index = cache$1.get(features);
1555
+ if (!index) {
1556
+ const started = performance.now();
1557
+ index = buildIndex(features);
1558
+ cache$1.set(features, index);
1559
+ mapPerfLog("timeline", "index built", { n: features.length, ms: Math.round(performance.now() - started) });
1560
+ }
1561
+ return index;
1562
+ }
1563
+ function isVisibleAt(index, position, w) {
1564
+ return isIntervalVisible(index.starts[position], index.ends[position], w);
1565
+ }
1566
+ function upperBound(keys, x) {
1567
+ let lo = 0;
1568
+ let hi = keys.length;
1569
+ while (lo < hi) {
1570
+ const mid = lo + hi >>> 1;
1571
+ if (keys[mid] <= x) lo = mid + 1;
1572
+ else hi = mid;
1573
+ }
1574
+ return lo;
1575
+ }
1576
+ function lowerBound(keys, x) {
1577
+ let lo = 0;
1578
+ let hi = keys.length;
1579
+ while (lo < hi) {
1580
+ const mid = lo + hi >>> 1;
1581
+ if (keys[mid] < x) lo = mid + 1;
1582
+ else hi = mid;
1583
+ }
1584
+ return lo;
1585
+ }
1586
+ const ALL = { t0: -Infinity, t1: Infinity };
1587
+ function flippedPositions(index, from, to, out) {
1588
+ const a = from ?? ALL;
1589
+ const b = to ?? ALL;
1590
+ const { starts, ends, byStart, byEnd, mark } = index;
1591
+ const flips = (p) => isIntervalVisible(starts[p], ends[p], a) !== isIntervalVisible(starts[p], ends[p], b);
1592
+ const s0 = upperBound(index.sortedStarts, Math.min(a.t1, b.t1));
1593
+ const s1 = upperBound(index.sortedStarts, Math.max(a.t1, b.t1));
1594
+ const e0 = lowerBound(index.sortedEnds, Math.min(a.t0, b.t0));
1595
+ const e1 = lowerBound(index.sortedEnds, Math.max(a.t0, b.t0));
1596
+ for (let k = s0; k < s1; k++) {
1597
+ const p = byStart[k];
1598
+ mark[p] = 1;
1599
+ if (flips(p)) out.push(p);
1600
+ }
1601
+ for (let k = e0; k < e1; k++) {
1602
+ const p = byEnd[k];
1603
+ if (mark[p] === 0 && flips(p)) out.push(p);
1604
+ }
1605
+ for (let k = s0; k < s1; k++) mark[byStart[k]] = 0;
1606
+ }
1607
+ function countVisible(index, w) {
1608
+ if (w === null) return index.size;
1609
+ if (w.t0 > w.t1) {
1610
+ let timed = 0;
1611
+ index.byStart.forEach((p) => {
1612
+ if (isVisibleAt(index, p, w)) timed++;
1613
+ });
1614
+ return timed + index.untimedCount;
1615
+ }
1616
+ return upperBound(index.sortedStarts, w.t1) - lowerBound(index.sortedEnds, w.t0) + index.untimedCount;
1617
+ }
1576
1618
  const TRACE_DEFAULT_COLOR = "#3b82f6";
1577
1619
  const TRACE_UNGROUPED_KEY = "__all__";
1578
1620
  const cache = /* @__PURE__ */ new WeakMap();
@@ -1604,16 +1646,17 @@ function compareStaged(a, b) {
1604
1646
  function buildTraceGroups(features, field) {
1605
1647
  var _a;
1606
1648
  const staged = /* @__PURE__ */ new Map();
1607
- for (const feature of features) {
1649
+ for (let position = 0; position < features.length; position++) {
1650
+ const feature = features[position];
1608
1651
  if (feature.id == null || feature.geometry.type !== "Point" || !((_a = feature.properties) == null ? void 0 : _a.startDate)) continue;
1609
1652
  const raw = field ? feature.properties[field] : void 0;
1610
- const key = field && raw ? String(raw) : TRACE_UNGROUPED_KEY;
1653
+ const key = field && raw != null && raw !== "" ? String(raw) : TRACE_UNGROUPED_KEY;
1611
1654
  let bucket = staged.get(key);
1612
1655
  if (!bucket) {
1613
1656
  bucket = [];
1614
1657
  staged.set(key, bucket);
1615
1658
  }
1616
- bucket.push({ feature, time: new Date(feature.properties.startDate).getTime() });
1659
+ bucket.push({ feature, time: new Date(feature.properties.startDate).getTime(), position });
1617
1660
  }
1618
1661
  const count = staged.size;
1619
1662
  const groups = [];
@@ -1624,6 +1667,7 @@ function buildTraceGroups(features, field) {
1624
1667
  points: bucket.map((p) => p.feature),
1625
1668
  ids: bucket.map((p) => String(p.feature.id)),
1626
1669
  times: bucket.map((p) => p.time),
1670
+ positions: bucket.map((p) => p.position),
1627
1671
  color: traceGroupColor(key, groups.length, count),
1628
1672
  label: field && key !== TRACE_UNGROUPED_KEY ? key : null,
1629
1673
  pairStats: /* @__PURE__ */ new Map()
@@ -1637,14 +1681,11 @@ function traceGroupColor(key, index, count) {
1637
1681
  }
1638
1682
  function visibleTraceIndices(group, isVisible) {
1639
1683
  const indices = [];
1640
- for (let i = 0; i < group.ids.length; i++) {
1641
- if (isVisible(group.ids[i])) indices.push(i);
1684
+ for (let i = 0; i < group.positions.length; i++) {
1685
+ if (isVisible(group.positions[i])) indices.push(i);
1642
1686
  }
1643
1687
  return indices;
1644
1688
  }
1645
- function timelineVisibility(visibleSet) {
1646
- return visibleSet === null ? () => true : (id) => visibleSet.has(id);
1647
- }
1648
1689
  function traceSegmentStats(group, fromIndex, toIndex) {
1649
1690
  const key = `${fromIndex}:${toIndex}`;
1650
1691
  const cached = group.pairStats.get(key);
@@ -1694,43 +1735,161 @@ function traceSegmentFeature(group, groupIndex, fromIndex, toIndex) {
1694
1735
  }
1695
1736
  };
1696
1737
  }
1697
- const TRACE_ENDPOINT_LABEL_PRIORITY = 5;
1698
1738
  const TRACE_POINT_RADIUS = 2;
1699
1739
  const TRACE_ENDPOINT_MIN_RADIUS = 8;
1700
- function buildTraceTimelineDiff(trace, paint, nextVisibleSet) {
1701
- const diff = { pointUpdates: [], segmentAdd: [], segmentRemove: [] };
1702
- const paintedVisible = (id) => !paint.appliedHiddenIds.has(id);
1703
- const nextVisible = timelineVisibility(nextVisibleSet);
1704
- trace.groups.forEach((group, groupIndex) => {
1705
- const prev = visibleTraceIndices(group, paintedVisible);
1706
- const next = visibleTraceIndices(group, nextVisible);
1707
- const prevEndpoint = prev.length > 0 ? prev[prev.length - 1] : -1;
1708
- const nextEndpoint = next.length > 0 ? next[next.length - 1] : -1;
1709
- if (prevEndpoint !== nextEndpoint) {
1710
- if (prevEndpoint >= 0) pushEndpointUpdate(diff, trace, group, group.ids[prevEndpoint], false);
1711
- if (nextEndpoint >= 0) pushEndpointUpdate(diff, trace, group, group.ids[nextEndpoint], true);
1740
+ const TRACE_SOURCE_ID = "trace-features";
1741
+ const TRACE_ENDPOINT_LABEL_LAYER_ID = "trace-endpoint-labels";
1742
+ const ENDPOINT_LABEL_KIND = "endpoint-label";
1743
+ const ENDPOINT_STATE = Object.freeze({ [TRACE_ENDPOINT_KEY]: true });
1744
+ function buildTraceEndpointLabelLayer() {
1745
+ return {
1746
+ id: TRACE_ENDPOINT_LABEL_LAYER_ID,
1747
+ type: "symbol",
1748
+ source: TRACE_SOURCE_ID,
1749
+ filter: ["==", ["get", "kind"], ENDPOINT_LABEL_KIND],
1750
+ layout: {
1751
+ "text-field": ["get", "name"],
1752
+ "text-size": 14,
1753
+ "text-font": ["Montserrat Medium", "Noto Sans Regular"],
1754
+ "text-anchor": "top",
1755
+ "text-offset": [0, 0.8],
1756
+ "text-padding": 2,
1757
+ "text-allow-overlap": false,
1758
+ "text-ignore-placement": false,
1759
+ "text-optional": true
1760
+ },
1761
+ paint: {
1762
+ "text-color": "#1f2937",
1763
+ "text-halo-color": "#ffffff",
1764
+ "text-halo-width": 2,
1765
+ "text-opacity": ["*", 0.9, ["coalesce", ["get", "stroke-opacity"], 1]]
1712
1766
  }
1767
+ };
1768
+ }
1769
+ function visibleGroupIndices(group, index, w) {
1770
+ return visibleTraceIndices(group, (position) => isVisibleAt(index, position, w));
1771
+ }
1772
+ const instantStarts = /* @__PURE__ */ new WeakMap();
1773
+ function instantsOf(group, index) {
1774
+ const cached = instantStarts.get(group);
1775
+ if (cached !== void 0) return cached;
1776
+ const starts = new Float64Array(group.positions.length);
1777
+ let instants = starts;
1778
+ for (let i = 0; i < starts.length; i++) {
1779
+ const p = group.positions[i];
1780
+ const s = index.starts[p];
1781
+ if (Number.isNaN(s) || s !== index.ends[p] || i > 0 && s < starts[i - 1]) {
1782
+ instants = null;
1783
+ break;
1784
+ }
1785
+ starts[i] = s;
1786
+ }
1787
+ instantStarts.set(group, instants);
1788
+ return instants;
1789
+ }
1790
+ function firstAbove(keys, x, inclusive) {
1791
+ let lo = 0;
1792
+ let hi = keys.length;
1793
+ while (lo < hi) {
1794
+ const mid = lo + hi >>> 1;
1795
+ if (keys[mid] < x || !inclusive && keys[mid] === x) lo = mid + 1;
1796
+ else hi = mid;
1797
+ }
1798
+ return lo;
1799
+ }
1800
+ function visibleRun(instants, w) {
1801
+ if (w === null) return { lo: 0, hi: instants.length };
1802
+ const lo = firstAbove(instants, w.t0, true);
1803
+ return { lo, hi: Math.max(lo, firstAbove(instants, w.t1, false)) };
1804
+ }
1805
+ function pairsOutside(a, b, visit) {
1806
+ const aEnd = a.hi - 1;
1807
+ const bEnd = b.hi - 1;
1808
+ if (bEnd <= b.lo) {
1809
+ for (let i = a.lo; i < aEnd; i++) visit(i);
1810
+ return;
1811
+ }
1812
+ for (let i = a.lo; i < Math.min(aEnd, b.lo); i++) visit(i);
1813
+ for (let i = Math.max(a.lo, bEnd); i < aEnd; i++) visit(i);
1814
+ }
1815
+ function traceEndpointLabelId(groupIndex) {
1816
+ return `label:${groupIndex}`;
1817
+ }
1818
+ function endpointLabel(group, groupIndex, pointIndex) {
1819
+ var _a;
1820
+ const point2 = group.points[pointIndex];
1821
+ const opacity = (_a = point2.properties) == null ? void 0 : _a["stroke-opacity"];
1822
+ return {
1823
+ type: "Feature",
1824
+ id: traceEndpointLabelId(groupIndex),
1825
+ geometry: point2.geometry,
1826
+ properties: {
1827
+ kind: ENDPOINT_LABEL_KIND,
1828
+ name: group.label,
1829
+ ...typeof opacity === "number" && { "stroke-opacity": opacity }
1830
+ }
1831
+ };
1832
+ }
1833
+ function diffGroup(diff, group, groupIndex, index, from, to) {
1834
+ let prevEndpoint;
1835
+ let nextEndpoint;
1836
+ const instants = instantsOf(group, index);
1837
+ if (instants) {
1838
+ const prev = visibleRun(instants, from);
1839
+ const next = visibleRun(instants, to);
1840
+ prevEndpoint = prev.hi > prev.lo ? prev.hi - 1 : -1;
1841
+ nextEndpoint = next.hi > next.lo ? next.hi - 1 : -1;
1842
+ pairsOutside(prev, next, (i) => diff.remove.push(traceSegmentId(groupIndex, i, i + 1)));
1843
+ pairsOutside(next, prev, (i) => diff.add.push(traceSegmentFeature(group, groupIndex, i, i + 1)));
1844
+ } else {
1845
+ const prev = visibleGroupIndices(group, index, from);
1846
+ const next = visibleGroupIndices(group, index, to);
1847
+ prevEndpoint = prev.length > 0 ? prev[prev.length - 1] : -1;
1848
+ nextEndpoint = next.length > 0 ? next[next.length - 1] : -1;
1713
1849
  diffConsecutivePairs(
1714
1850
  prev,
1715
1851
  next,
1716
- (from, to) => diff.segmentRemove.push(traceSegmentId(groupIndex, from, to)),
1717
- (from, to) => diff.segmentAdd.push(traceSegmentFeature(group, groupIndex, from, to))
1852
+ (a, b) => diff.remove.push(traceSegmentId(groupIndex, a, b)),
1853
+ (a, b) => diff.add.push(traceSegmentFeature(group, groupIndex, a, b))
1718
1854
  );
1855
+ }
1856
+ if (prevEndpoint === nextEndpoint) return;
1857
+ if (prevEndpoint >= 0) diff.endpointOff.push(group.ids[prevEndpoint]);
1858
+ if (nextEndpoint >= 0) diff.endpointOn.push(group.ids[nextEndpoint]);
1859
+ if (group.label === null) return;
1860
+ if (nextEndpoint >= 0) diff.add.push(endpointLabel(group, groupIndex, nextEndpoint));
1861
+ else diff.remove.push(traceEndpointLabelId(groupIndex));
1862
+ }
1863
+ function buildTraceTimelineDiff(trace, nextWindow) {
1864
+ const diff = { endpointOff: [], endpointOn: [], add: [], remove: [] };
1865
+ trace.groups.forEach((group, groupIndex) => {
1866
+ diffGroup(diff, group, groupIndex, trace.indexes[groupIndex], trace.window, nextWindow);
1719
1867
  });
1720
1868
  return diff;
1721
1869
  }
1722
- function pushEndpointUpdate(diff, trace, group, id, isEndpoint) {
1723
- const point2 = trace.pointPaint.get(id);
1724
- if (!point2) return;
1725
- const labelled = isEndpoint && group.label !== null;
1726
- diff.pointUpdates.push({
1727
- id,
1728
- addOrUpdateProperties: [
1729
- { key: "pointRadius", value: isEndpoint ? point2.endpointRadius : TRACE_POINT_RADIUS },
1730
- { key: "name", value: labelled ? group.label : point2.name },
1731
- { key: "isTraceLabel", value: labelled },
1732
- { key: "_labelPriority", value: labelled ? TRACE_ENDPOINT_LABEL_PRIORITY : point2.basePriority }
1733
- ]
1870
+ function paintTraceAt(groups, indexes, w) {
1871
+ const endpoints = [];
1872
+ const features = [];
1873
+ groups.forEach((group, groupIndex) => {
1874
+ const visible = visibleGroupIndices(group, indexes[groupIndex], w);
1875
+ if (visible.length === 0) return;
1876
+ const endpoint = visible[visible.length - 1];
1877
+ endpoints.push(group.ids[endpoint]);
1878
+ for (let k = 1; k < visible.length; k++) {
1879
+ features.push(traceSegmentFeature(group, groupIndex, visible[k - 1], visible[k]));
1880
+ }
1881
+ if (group.label !== null) features.push(endpointLabel(group, groupIndex, endpoint));
1882
+ });
1883
+ return { endpoints, features };
1884
+ }
1885
+ function setTraceEndpoints(host, applied, off, on) {
1886
+ off.forEach((id) => {
1887
+ if (applied.delete(id)) host.removeFeatureState(SHARED_SOURCE_ID, id, TRACE_ENDPOINT_KEY);
1888
+ });
1889
+ on.forEach((id) => {
1890
+ if (applied.has(id)) return;
1891
+ host.setFeatureState(SHARED_SOURCE_ID, id, ENDPOINT_STATE);
1892
+ applied.add(id);
1734
1893
  });
1735
1894
  }
1736
1895
  function diffConsecutivePairs(prev, next, onRemove, onAdd) {
@@ -1753,19 +1912,19 @@ function diffConsecutivePairs(prev, next, onRemove, onAdd) {
1753
1912
  }
1754
1913
  }
1755
1914
  }
1756
- function applyTraceTimelineDiff(diff, pointSource, segmentSource) {
1915
+ function applyTraceTimelineDiff(diff, traceSource, host, appliedEndpoints) {
1757
1916
  try {
1758
- if (diff.pointUpdates.length > 0) pointSource.updateData({ update: diff.pointUpdates });
1759
- if (diff.segmentAdd.length > 0 || diff.segmentRemove.length > 0) {
1760
- segmentSource.updateData({ add: diff.segmentAdd, remove: diff.segmentRemove });
1761
- }
1917
+ if (diff.add.length > 0 || diff.remove.length > 0) traceSource.updateData({ add: diff.add, remove: diff.remove });
1762
1918
  } catch (error) {
1763
1919
  console.error("Trace timeline fast path failed; falling back to the full sync:", error);
1764
1920
  return false;
1765
1921
  }
1922
+ setTraceEndpoints(host, appliedEndpoints, diff.endpointOff, diff.endpointOn);
1766
1923
  return true;
1767
1924
  }
1768
1925
  const DEFAULT_LABEL_PRIORITY = 100;
1926
+ const DEFAULT_VISIBLE_STROKE_OPACITY = 1;
1927
+ const DEFAULT_VISIBLE_FILL_OPACITY = 0.2;
1769
1928
  const RENDER_PASSTHROUGH_KEYS = ["_dvl_h3"];
1770
1929
  const ANNOTATION_PASSTHROUGH_KEYS = [
1771
1930
  "kind",
@@ -1782,11 +1941,21 @@ function sanitizeValue(value) {
1782
1941
  if (value instanceof Date) return value.toISOString();
1783
1942
  return String(value);
1784
1943
  }
1944
+ const heatmapHidesPoints = (layer) => {
1945
+ var _a;
1946
+ return ((_a = layer == null ? void 0 : layer.heatmapConfig) == null ? void 0 : _a.enabled) === true;
1947
+ };
1948
+ const clusterHidesPoints = (layer) => {
1949
+ var _a;
1950
+ return ((_a = layer == null ? void 0 : layer.clusterConfig) == null ? void 0 : _a.enabled) === true && !layer.clusterConfig.showPointDots;
1951
+ };
1952
+ function layerHidesPoints(layer) {
1953
+ return heatmapHidesPoints(layer) || clusterHidesPoints(layer);
1954
+ }
1785
1955
  function styleFeatureForPaint(f, layer, ctx, slim) {
1786
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1956
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1787
1957
  const featureId = String(f.id);
1788
1958
  const visualConfig = layer == null ? void 0 : layer.visualConfig;
1789
- const isTimelineVisible = ctx.timelineVisibleIds === null || ctx.timelineVisibleIds.has(featureId);
1790
1959
  const baseOpacity = ((_a = f.properties) == null ? void 0 : _a["stroke-opacity"]) ?? DEFAULT_VISIBLE_STROKE_OPACITY;
1791
1960
  let strokeColor = ((_b = f.properties) == null ? void 0 : _b.stroke) || "#3b82f6";
1792
1961
  const colorConfig = visualConfig == null ? void 0 : visualConfig.color;
@@ -1818,14 +1987,12 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
1818
1987
  }
1819
1988
  }
1820
1989
  }
1821
- const isTracePoint = ctx.tracePointIds.has(featureId);
1822
- const isLastTracePoint = ctx.lastTracePointIds.has(featureId);
1823
- const traceLabel = ctx.lastTracePointLabels.get(featureId);
1824
- let traceEndpointRadius = null;
1825
- if (isTracePoint && f.geometry.type === "Point") {
1990
+ const isTracePoint2 = ctx.tracePointIds.has(featureId);
1991
+ let endpointRadius = 0;
1992
+ if (isTracePoint2 && f.geometry.type === "Point") {
1826
1993
  strokeColor = ctx.tracePointColors.get(featureId) || strokeColor;
1827
- traceEndpointRadius = Math.max(pointRadius, TRACE_ENDPOINT_MIN_RADIUS);
1828
- pointRadius = isLastTracePoint ? traceEndpointRadius : TRACE_POINT_RADIUS;
1994
+ endpointRadius = Math.max(pointRadius, TRACE_ENDPOINT_MIN_RADIUS);
1995
+ pointRadius = TRACE_POINT_RADIUS;
1829
1996
  }
1830
1997
  let labelText = ((_d = f.properties) == null ? void 0 : _d.name) || "";
1831
1998
  const labelConfig = visualConfig == null ? void 0 : visualConfig.label;
@@ -1839,10 +2006,6 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
1839
2006
  labelText = fieldValue !== void 0 && fieldValue !== null ? String(fieldValue) : "";
1840
2007
  }
1841
2008
  }
1842
- const nonTraceLabelText = labelText;
1843
- if (traceLabel) {
1844
- labelText = traceLabel;
1845
- }
1846
2009
  let featureIcon = ((_e = f.properties) == null ? void 0 : _e.pointIcon) || ((_f = f.properties) == null ? void 0 : _f.icon);
1847
2010
  let featureIconSize = ((_g = f.properties) == null ? void 0 : _g.pointIconSize) || ((_h = f.properties) == null ? void 0 : _h.iconSize) || 24;
1848
2011
  const iconConfig = visualConfig == null ? void 0 : visualConfig.icon;
@@ -1851,8 +2014,8 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
1851
2014
  featureIconSize = iconConfig.size ?? 24;
1852
2015
  }
1853
2016
  const isPoint = f.geometry.type === "Point";
1854
- const hideByHeatmap = isPoint && ((_i = layer == null ? void 0 : layer.heatmapConfig) == null ? void 0 : _i.enabled) === true;
1855
- 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);
2017
+ const hideByHeatmap = isPoint && heatmapHidesPoints(layer);
2018
+ const hideByCluster = isPoint && clusterHidesPoints(layer);
1856
2019
  const isLine = f.geometry.type === "LineString" || f.geometry.type === "MultiLineString";
1857
2020
  const hideFlatFor3DOnly = isLine && (layer == null ? void 0 : layer.hasAltitudeData) && (layer == null ? void 0 : layer.altitudeDisplayMode) === "3d";
1858
2021
  const sanitizedProps = {};
@@ -1873,9 +2036,9 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
1873
2036
  });
1874
2037
  }
1875
2038
  }
1876
- let nonTracePriority = DEFAULT_LABEL_PRIORITY;
1877
- if (((_l = f.properties) == null ? void 0 : _l.kind) === "text") {
1878
- nonTracePriority = ((_m = f.properties) == null ? void 0 : _m.fontWeight) === "bold" ? 8 : 10;
2039
+ let labelPriority = DEFAULT_LABEL_PRIORITY;
2040
+ if (((_i = f.properties) == null ? void 0 : _i.kind) === "text") {
2041
+ labelPriority = ((_j = f.properties) == null ? void 0 : _j.fontWeight) === "bold" ? 8 : 10;
1879
2042
  } else {
1880
2043
  const idStr = String(featureId);
1881
2044
  let h = 0;
@@ -1883,11 +2046,10 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
1883
2046
  h = (h << 5) - h + idStr.charCodeAt(i);
1884
2047
  h |= 0;
1885
2048
  }
1886
- nonTracePriority = DEFAULT_LABEL_PRIORITY + Math.abs(h) % 1e3;
2049
+ labelPriority = DEFAULT_LABEL_PRIORITY + Math.abs(h) % 1e3;
1887
2050
  }
1888
- const labelPriority = traceLabel ? TRACE_ENDPOINT_LABEL_PRIORITY : nonTracePriority;
1889
2051
  const visibleStrokeOpacity = hideFlatFor3DOnly ? 0 : baseOpacity;
1890
- const visibleFillOpacity = hideFlatFor3DOnly ? 0 : ((_n = f.properties) == null ? void 0 : _n["fill-opacity"]) ?? DEFAULT_VISIBLE_FILL_OPACITY;
2052
+ const visibleFillOpacity = hideFlatFor3DOnly ? 0 : ((_k = f.properties) == null ? void 0 : _k["fill-opacity"]) ?? DEFAULT_VISIBLE_FILL_OPACITY;
1891
2053
  return {
1892
2054
  feature: {
1893
2055
  type: "Feature",
@@ -1901,28 +2063,20 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
1901
2063
  name: labelText,
1902
2064
  isHiddenByHeatmap: hideByHeatmap ? 1 : 0,
1903
2065
  isHiddenByCluster: hideByCluster ? 1 : 0,
1904
- isTracePoint: isTracePoint ? true : false,
1905
- isTraceLabel: traceLabel ? true : false,
2066
+ isTracePoint: isTracePoint2 ? true : false,
2067
+ _endpointRadius: endpointRadius,
1906
2068
  icon: featureIcon || "",
1907
2069
  iconSize: featureIconSize,
1908
2070
  stroke: strokeColor,
1909
2071
  "stroke-width": strokeWidth,
1910
- "stroke-opacity": isTimelineVisible ? visibleStrokeOpacity : 0,
2072
+ "stroke-opacity": visibleStrokeOpacity,
1911
2073
  fill: strokeColor,
1912
- "fill-opacity": isTimelineVisible ? visibleFillOpacity : 0,
2074
+ "fill-opacity": visibleFillOpacity,
1913
2075
  pointRadius,
1914
- isTimelineHidden: isTimelineVisible ? 0 : 1,
1915
2076
  _labelPriority: labelPriority,
1916
- [LABEL_NEVER_HIDE_PROP]: computeLabelNeverHide((_o = layer == null ? void 0 : layer.visualConfig) == null ? void 0 : _o.label)
2077
+ [LABEL_NEVER_HIDE_PROP]: computeLabelNeverHide((_l = layer == null ? void 0 : layer.visualConfig) == null ? void 0 : _l.label)
1917
2078
  }
1918
- },
1919
- paint: {
1920
- featureId,
1921
- visibleStrokeOpacity,
1922
- visibleFillOpacity,
1923
- timelineHidden: !isTimelineVisible
1924
- },
1925
- tracePaint: traceEndpointRadius !== null ? { name: nonTraceLabelText, endpointRadius: traceEndpointRadius, basePriority: nonTracePriority } : null
2079
+ }
1926
2080
  };
1927
2081
  }
1928
2082
  function layerFieldRanges(visualConfig, forEachProperties) {
@@ -1959,37 +2113,32 @@ async function runShardPass(input) {
1959
2113
  var _a, _b;
1960
2114
  const { features, layer, shardSize, host } = input;
1961
2115
  const ranges = shardRanges(features.length, shardSize);
1962
- const caches = [];
1963
2116
  const arrowLines = [];
1964
2117
  for (let index = 0; index < ranges.length; index++) {
1965
2118
  const { start, end } = ranges[index];
1966
2119
  const slice = features.slice(start, end);
1967
2120
  const roles = rolesForGeometry(geometryClassesOf(slice));
1968
2121
  const ctx = input.contextForShard();
1969
- const cache2 = createSelectionPaintCache();
1970
2122
  const shardArrows = [];
1971
2123
  const painted = slice.map((f) => {
1972
2124
  var _a2;
1973
2125
  const styled = styleFeatureForPaint(f, layer, ctx, true);
1974
- const p = styled.paint;
1975
- recordPaintedFeature(cache2, p.featureId, p.visibleStrokeOpacity, p.visibleFillOpacity, p.timelineHidden);
1976
2126
  if (((_a2 = styled.feature.properties) == null ? void 0 : _a2.kind) === "arrow" && styled.feature.geometry.type === "LineString") {
1977
2127
  shardArrows.push(styled.feature);
1978
2128
  }
1979
2129
  return styled.feature;
1980
2130
  });
1981
2131
  host.paintShard(index, roles, { type: "FeatureCollection", features: painted });
1982
- caches[index] = cache2;
1983
2132
  if (shardArrows.length > 0) pushAll$1(arrowLines, shardArrows);
1984
- (_a = input.onShardPainted) == null ? void 0 : _a.call(input, index, cache2, shardArrows);
2133
+ (_a = input.onShardPainted) == null ? void 0 : _a.call(input, index, start, end);
1985
2134
  (_b = input.onProgress) == null ? void 0 : _b.call(input, end, features.length);
1986
2135
  await input.yieldFrame();
1987
2136
  if (!input.isCurrent()) {
1988
- return { completed: false, shardCount: index + 1, caches, arrowLines };
2137
+ return { completed: false, shardCount: index + 1, arrowLines };
1989
2138
  }
1990
2139
  }
1991
2140
  host.dropShardsFrom(ranges.length);
1992
- return { completed: true, shardCount: ranges.length, caches, arrowLines };
2141
+ return { completed: true, shardCount: ranges.length, arrowLines };
1993
2142
  }
1994
2143
  function pushAll$1(target, source) {
1995
2144
  for (let i = 0; i < source.length; i++) target.push(source[i]);
@@ -4015,6 +4164,7 @@ function LayersPanel({
4015
4164
  onMapStyleChange,
4016
4165
  onUpdateTraceConfig,
4017
4166
  getAvailableTraceFields,
4167
+ getSuggestedTraceField,
4018
4168
  getLayerFields,
4019
4169
  getFieldValueDistribution,
4020
4170
  onUpdateHeatmapConfig,
@@ -4338,13 +4488,12 @@ function LayersPanel({
4338
4488
  {
4339
4489
  size: "small",
4340
4490
  checked: ((_h = layer.traceConfig) == null ? void 0 : _h.enabled) ?? false,
4341
- onChange: (checked) => {
4342
- var _a2;
4343
- return onUpdateTraceConfig(layer.id, {
4344
- enabled: checked,
4345
- groupByField: ((_a2 = layer.traceConfig) == null ? void 0 : _a2.groupByField) ?? null
4346
- });
4347
- },
4491
+ onChange: (checked) => onUpdateTraceConfig(layer.id, {
4492
+ enabled: checked,
4493
+ // A layer that has never had trace settings starts grouped; a
4494
+ // choice made before, "Connect all points" included, is kept.
4495
+ groupByField: layer.traceConfig ? layer.traceConfig.groupByField ?? null : checked ? (getSuggestedTraceField == null ? void 0 : getSuggestedTraceField(layer.id)) ?? null : null
4496
+ }),
4348
4497
  "data-testid": `switch-trace-${layer.id}`
4349
4498
  }
4350
4499
  ),
@@ -7394,6 +7543,7 @@ function Timebar({
7394
7543
  const targetFps = 30;
7395
7544
  const frameInterval = 1e3 / targetFps;
7396
7545
  const applyFilter = useCallback(() => {
7546
+ if (!onFilterChange) return;
7397
7547
  const visibleIds = [];
7398
7548
  const hiddenIds = [];
7399
7549
  temporalFeatures.forEach((feature) => {
@@ -7815,30 +7965,138 @@ function buildReadOnlyFeatureIndex(store) {
7815
7965
  });
7816
7966
  return { sources: new Map(store), byId };
7817
7967
  }
7818
- function countFeaturesInBounds(featureGroups, bounds, options) {
7819
- var _a;
7820
- const { west, east, south, north } = bounds;
7821
- const { threshold, visibleSet } = options;
7968
+ function inViewTest({ west, east, south, north }) {
7822
7969
  const fullWidth = east - west >= 360;
7823
- const inView = (lng, lat) => {
7970
+ return (lng, lat) => {
7824
7971
  if (lat < south || lat > north) return false;
7825
7972
  if (fullWidth) return true;
7826
7973
  return lng >= west && lng <= east || lng + 360 >= west && lng + 360 <= east || lng - 360 >= west && lng - 360 <= east;
7827
7974
  };
7975
+ }
7976
+ function counts(group, p, inView) {
7977
+ var _a;
7978
+ if (group.isVisible && !group.isVisible(p)) return false;
7979
+ const f = group.features[p];
7980
+ if (((_a = f.geometry) == null ? void 0 : _a.type) !== "Point") return true;
7981
+ const [lng, lat] = f.geometry.coordinates;
7982
+ return inView(lng, lat);
7983
+ }
7984
+ function countLinear(group, inView, start, threshold) {
7985
+ let count = start;
7986
+ for (let p = 0; p < group.features.length; p++) {
7987
+ if (!counts(group, p, inView)) continue;
7988
+ count += 1;
7989
+ if (count > threshold) return count;
7990
+ }
7991
+ return count;
7992
+ }
7993
+ function countIndexed(group, { spatial, visibleTotal }, bounds, inView, start, threshold) {
7994
+ const tree = spatial.tree;
7995
+ if (!tree) return start;
7996
+ const { west, east, south, north } = bounds;
7997
+ const fullWidth = east - west >= 360;
7998
+ if ((fullWidth || west <= tree.minX && east >= tree.maxX) && south <= tree.minY && north >= tree.maxY) {
7999
+ return Math.min(start + visibleTotal, threshold + 1);
8000
+ }
8001
+ let count = start;
8002
+ const visit = (item) => {
8003
+ if (count <= threshold && counts(group, spatial.positions[item], inView)) count += 1;
8004
+ return false;
8005
+ };
8006
+ if (fullWidth) {
8007
+ tree.search(-Infinity, south, Infinity, north, visit);
8008
+ return count;
8009
+ }
8010
+ tree.search(west, south, east, north, visit);
8011
+ if (west < -180) tree.search(west + 360, south, Math.min(east + 360, 180), north, visit);
8012
+ if (east > 180) tree.search(Math.max(west - 360, -180), south, east - 360, north, visit);
8013
+ return count;
8014
+ }
8015
+ function countFeaturesInBounds(groups, bounds, options) {
8016
+ const inView = inViewTest(bounds);
7828
8017
  let count = 0;
7829
- for (const features of featureGroups) {
7830
- for (const f of features) {
7831
- if (visibleSet && f.id != null && !visibleSet.has(String(f.id))) continue;
7832
- if (((_a = f.geometry) == null ? void 0 : _a.type) === "Point") {
7833
- const [lng, lat] = f.geometry.coordinates;
7834
- if (!inView(lng, lat)) continue;
7835
- }
7836
- count += 1;
7837
- if (count > threshold) return count;
7838
- }
8018
+ for (const group of groups) {
8019
+ count = group.indexed ? countIndexed(group, group.indexed, bounds, inView, count, options.threshold) : countLinear(group, inView, count, options.threshold);
8020
+ if (count > options.threshold) return count;
7839
8021
  }
7840
8022
  return count;
7841
8023
  }
8024
+ function extendBounds(bounds, coords) {
8025
+ if (!Array.isArray(coords) || coords.length === 0) return;
8026
+ if (typeof coords[0] === "number") {
8027
+ const lng = coords[0];
8028
+ const lat = coords[1];
8029
+ if (lng < bounds.minLng) bounds.minLng = lng;
8030
+ if (lng > bounds.maxLng) bounds.maxLng = lng;
8031
+ if (lat < bounds.minLat) bounds.minLat = lat;
8032
+ if (lat > bounds.maxLat) bounds.maxLat = lat;
8033
+ return;
8034
+ }
8035
+ for (const nested of coords) extendBounds(bounds, nested);
8036
+ }
8037
+ function computeBounds(coords) {
8038
+ const bounds = { minLng: Infinity, minLat: Infinity, maxLng: -Infinity, maxLat: -Infinity };
8039
+ extendBounds(bounds, coords);
8040
+ return bounds;
8041
+ }
8042
+ function boundsDisjoint(a, b) {
8043
+ return a.maxLng < b.minLng || a.minLng > b.maxLng || a.maxLat < b.minLat || a.minLat > b.maxLat;
8044
+ }
8045
+ function pointInBounds(lng, lat, b) {
8046
+ return lng >= b.minLng && lng <= b.maxLng && lat >= b.minLat && lat <= b.maxLat;
8047
+ }
8048
+ function buildGroupSpatialIndex(features) {
8049
+ var _a;
8050
+ const boxes = [];
8051
+ const positions = [];
8052
+ for (let p = 0; p < features.length; p++) {
8053
+ const geom = (_a = features[p]) == null ? void 0 : _a.geometry;
8054
+ const b = computeBounds(geom == null ? void 0 : geom.coordinates);
8055
+ if (!isFinite(b.minLng) || !isFinite(b.minLat) || !isFinite(b.maxLng) || !isFinite(b.maxLat)) {
8056
+ continue;
8057
+ }
8058
+ boxes.push(b.minLng, b.minLat, b.maxLng, b.maxLat);
8059
+ positions.push(p);
8060
+ }
8061
+ if (positions.length === 0) {
8062
+ return { tree: null, positions, size: features.length };
8063
+ }
8064
+ const startedAt = performance.now();
8065
+ const tree = new Flatbush(positions.length);
8066
+ for (let i = 0; i < boxes.length; i += 4) {
8067
+ tree.add(boxes[i], boxes[i + 1], boxes[i + 2], boxes[i + 3]);
8068
+ }
8069
+ tree.finish();
8070
+ mapPerfLog("spatial-index", "built group index", {
8071
+ indexed: positions.length,
8072
+ of: features.length,
8073
+ ms: Math.round(performance.now() - startedAt)
8074
+ });
8075
+ return { tree, positions, size: features.length };
8076
+ }
8077
+ const indexCache = /* @__PURE__ */ new WeakMap();
8078
+ const failedBuilds = /* @__PURE__ */ new WeakSet();
8079
+ function getGroupSpatialIndex(features) {
8080
+ if (failedBuilds.has(features)) return void 0;
8081
+ let index = indexCache.get(features);
8082
+ if (!index) {
8083
+ try {
8084
+ index = buildGroupSpatialIndex(features);
8085
+ } catch {
8086
+ failedBuilds.add(features);
8087
+ return void 0;
8088
+ }
8089
+ indexCache.set(features, index);
8090
+ }
8091
+ return index;
8092
+ }
8093
+ function queryCandidatePositions(index, bounds) {
8094
+ if (!index.tree) return [];
8095
+ const items = index.tree.search(bounds.minLng, bounds.minLat, bounds.maxLng, bounds.maxLat);
8096
+ const positions = items.map((i) => index.positions[i]);
8097
+ positions.sort((a, b) => a - b);
8098
+ return positions;
8099
+ }
7842
8100
  const rafScheduler = {
7843
8101
  request: (cb) => requestAnimationFrame(() => cb()),
7844
8102
  cancel: (handle) => cancelAnimationFrame(handle)
@@ -7882,13 +8140,16 @@ function createRafCoalescer(run, scheduler = rafScheduler) {
7882
8140
  }
7883
8141
  };
7884
8142
  }
8143
+ function needsDrawSelectionUpdate(input) {
8144
+ return input.editableSelectionCount > 0 || input.drawSelectedCount > 0 || input.currentMode !== input.targetMode;
8145
+ }
7885
8146
  const EMPTY = /* @__PURE__ */ new Set();
7886
8147
  function isLive(host, entry) {
7887
8148
  return host.source(entry.sourceId) === entry.handle;
7888
8149
  }
7889
8150
  function remove(host, entry, id) {
7890
8151
  if (!isLive(host, entry)) return false;
7891
- host.removeFeatureState(entry.sourceId, id);
8152
+ host.removeFeatureState(entry.sourceId, id, SELECTED_STATE_KEY);
7892
8153
  return true;
7893
8154
  }
7894
8155
  function set(host, sourceId, id) {
@@ -7987,7 +8248,7 @@ function forEachIndex(index, id, visit) {
7987
8248
  function locateFeatureHolders(id, readOnly, cache2) {
7988
8249
  const holders = [];
7989
8250
  readOnly.forEach((features, layerId) => {
7990
- forEachIndex(indexOfIds(features, cache2), id, (at) => holders.push({ layerId, feature: features[at] }));
8251
+ forEachIndex(indexOfIds(features, cache2), id, (at) => holders.push({ layerId, feature: features[at], position: at }));
7991
8252
  });
7992
8253
  return holders;
7993
8254
  }
@@ -8005,6 +8266,210 @@ function locateFeatureSources(id, inputs, cache2) {
8005
8266
  if (sources.length === 0) add(SHARED_SOURCE_ID);
8006
8267
  return sources;
8007
8268
  }
8269
+ const HIDDEN_STATE = Object.freeze({ [TIMELINE_HIDDEN_KEY]: true });
8270
+ function sameSlices(a, b) {
8271
+ return a.length === b.length && a.every((s, i) => s.features === b[i].features && s.start === b[i].start && s.end === b[i].end);
8272
+ }
8273
+ function pushCopy(copies, id, copy, first) {
8274
+ const list = copies.get(id);
8275
+ if (list) list.push(copy);
8276
+ else copies.set(id, [first, copy]);
8277
+ }
8278
+ function collectCopies(slices) {
8279
+ const copies = /* @__PURE__ */ new Map();
8280
+ if (slices.length === 1) {
8281
+ const { features, start, end } = slices[0];
8282
+ const index = getTimelineIndex(features);
8283
+ index.repeats.forEach((positions, id) => {
8284
+ const inside = positions.filter((p) => p >= start && p < end);
8285
+ if (inside.length > 1) copies.set(id, inside.map((position) => ({ index, position })));
8286
+ });
8287
+ return copies;
8288
+ }
8289
+ const first = /* @__PURE__ */ new Map();
8290
+ slices.forEach(({ features, start, end }) => {
8291
+ const index = getTimelineIndex(features);
8292
+ for (let position = start; position < end; position++) {
8293
+ const raw = features[position].id;
8294
+ if (raw === void 0 || raw === null) continue;
8295
+ const id = String(raw);
8296
+ const copy = { index, position };
8297
+ const seen = first.get(id);
8298
+ if (seen) pushCopy(copies, id, copy, seen);
8299
+ else first.set(id, copy);
8300
+ }
8301
+ });
8302
+ return copies;
8303
+ }
8304
+ function copiesOf(record) {
8305
+ record.copies ?? (record.copies = collectCopies(record.slices));
8306
+ return record.copies;
8307
+ }
8308
+ function shouldHide(record, id, index, position, w) {
8309
+ if (isVisibleAt(index, position, w)) return false;
8310
+ const copies = copiesOf(record).get(id);
8311
+ return !copies || copies.every((c) => !isVisibleAt(c.index, c.position, w));
8312
+ }
8313
+ function setHidden(host, record, id, hide) {
8314
+ if (hide === record.hidden.has(id)) return false;
8315
+ if (hide) {
8316
+ host.setFeatureState(record.sourceId, id, HIDDEN_STATE);
8317
+ record.hidden.add(id);
8318
+ } else {
8319
+ host.removeFeatureState(record.sourceId, id, TIMELINE_HIDDEN_KEY);
8320
+ record.hidden.delete(id);
8321
+ }
8322
+ return true;
8323
+ }
8324
+ function idAt(features, position) {
8325
+ const raw = features[position].id;
8326
+ return raw === void 0 || raw === null ? null : String(raw);
8327
+ }
8328
+ function seedTimelineSource(host, applied, sourceId, slices, w) {
8329
+ const handle = host.source(sourceId);
8330
+ const old = applied.get(sourceId);
8331
+ if (!handle) {
8332
+ applied.delete(sourceId);
8333
+ return 0;
8334
+ }
8335
+ if (old && old.handle === handle && sameSlices(old.slices, slices)) return 0;
8336
+ const record = {
8337
+ sourceId,
8338
+ handle,
8339
+ slices,
8340
+ hidden: (old == null ? void 0 : old.handle) === handle ? old.hidden : /* @__PURE__ */ new Set(),
8341
+ copies: null,
8342
+ window: w
8343
+ };
8344
+ applied.set(sourceId, record);
8345
+ const hide = /* @__PURE__ */ new Set();
8346
+ if (w !== null) {
8347
+ slices.forEach(({ features, start, end }) => {
8348
+ const index = getTimelineIndex(features);
8349
+ for (let position = start; position < end; position++) {
8350
+ const id = idAt(features, position);
8351
+ if (id !== null && shouldHide(record, id, index, position, w)) hide.add(id);
8352
+ }
8353
+ });
8354
+ }
8355
+ let calls = 0;
8356
+ Array.from(record.hidden).forEach((id) => {
8357
+ if (!hide.has(id) && setHidden(host, record, id, false)) calls++;
8358
+ });
8359
+ hide.forEach((id) => {
8360
+ if (setHidden(host, record, id, true)) calls++;
8361
+ });
8362
+ return calls;
8363
+ }
8364
+ function isTimelineHiddenOn(applied, sourceId, id) {
8365
+ var _a;
8366
+ return ((_a = applied.get(sourceId)) == null ? void 0 : _a.hidden.has(id)) ?? false;
8367
+ }
8368
+ function ownerOf(owners, position) {
8369
+ let lo = 0;
8370
+ let hi = owners.length - 1;
8371
+ let found = null;
8372
+ while (lo <= hi) {
8373
+ const mid = lo + hi >>> 1;
8374
+ if (owners[mid].start <= position) {
8375
+ found = owners[mid];
8376
+ lo = mid + 1;
8377
+ } else {
8378
+ hi = mid - 1;
8379
+ }
8380
+ }
8381
+ return found && position < found.end ? found : null;
8382
+ }
8383
+ function groupBySliceArray(host, applied, next, isActive) {
8384
+ const groups = [];
8385
+ applied.forEach((record, sourceId) => {
8386
+ if (host.source(sourceId) !== record.handle) {
8387
+ applied.delete(sourceId);
8388
+ return;
8389
+ }
8390
+ if (!isActive(sourceId) || sameWindow(record.window, next)) return;
8391
+ record.slices.forEach(({ features, start, end }) => {
8392
+ let group = groups.find((g) => g.features === features && sameWindow(g.from, record.window));
8393
+ if (!group) {
8394
+ group = { features, from: record.window, owners: [] };
8395
+ groups.push(group);
8396
+ }
8397
+ group.owners.push({ record, start, end });
8398
+ });
8399
+ record.window = next;
8400
+ });
8401
+ return groups;
8402
+ }
8403
+ function applyTimelineWindow(host, applied, next, isActive = () => true) {
8404
+ const flipped = [];
8405
+ const positions = [];
8406
+ groupBySliceArray(host, applied, next, isActive).forEach(({ features, from, owners }) => {
8407
+ owners.sort((a, b) => a.start - b.start);
8408
+ const index = getTimelineIndex(features);
8409
+ positions.length = 0;
8410
+ flippedPositions(index, from, next, positions);
8411
+ positions.forEach((position) => {
8412
+ const owner = ownerOf(owners, position);
8413
+ const id = owner ? idAt(features, position) : null;
8414
+ if (!owner || id === null) return;
8415
+ if (setHidden(host, owner.record, id, shouldHide(owner.record, id, index, position, next))) flipped.push(id);
8416
+ });
8417
+ });
8418
+ return flipped;
8419
+ }
8420
+ const IDENTITY_PATTERNS = [
8421
+ /person|people|individual|subject|suspect/,
8422
+ /target/,
8423
+ /entity/,
8424
+ /device|imei|imsi|msisdn|phone/,
8425
+ /mmsi|vessel|ship/,
8426
+ /vehicle|plate|car_?id/,
8427
+ /callsign|flight|aircraft|icao/,
8428
+ /user|account|owner|driver/,
8429
+ /track|trajectory/,
8430
+ /(^|[^a-z])id$|_id$|^id_|uuid/
8431
+ ];
8432
+ const NOT_IDENTITY = /* @__PURE__ */ new Set(["id", "name", "startdate", "enddate", "opacity", "timestamp", "time", "date"]);
8433
+ const CATEGORY_SUFFIX = /(type|kind|category|class|status|model|role)$/;
8434
+ const MIN_COVERAGE = 0.9;
8435
+ const MAX_GROUPS = 500;
8436
+ const MIN_POINTS_PER_GROUP = 2;
8437
+ const MAX_SAMPLES = 1e4;
8438
+ function isTracePoint(f) {
8439
+ var _a, _b;
8440
+ return !!f && f.id != null && ((_a = f.geometry) == null ? void 0 : _a.type) === "Point" && !!((_b = f.properties) == null ? void 0 : _b.startDate);
8441
+ }
8442
+ function identityRank(field) {
8443
+ const name = field.toLowerCase();
8444
+ if (NOT_IDENTITY.has(name) || CATEGORY_SUFFIX.test(name)) return -1;
8445
+ return IDENTITY_PATTERNS.findIndex((pattern) => pattern.test(name));
8446
+ }
8447
+ function suggestTraceGroupField(features, fields) {
8448
+ var _a;
8449
+ 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));
8450
+ if (candidates.length === 0) return null;
8451
+ const step = Math.max(1, Math.ceil(features.length / MAX_SAMPLES));
8452
+ const points = [];
8453
+ for (let i = 0; i < features.length && points.length < MAX_SAMPLES; i += step) {
8454
+ const f = features[i];
8455
+ if (isTracePoint(f)) points.push(f);
8456
+ }
8457
+ if (points.length < 2) return null;
8458
+ const splitsIntoTracks = (field) => {
8459
+ var _a2;
8460
+ const values = /* @__PURE__ */ new Set();
8461
+ let present = 0;
8462
+ for (const f of points) {
8463
+ const raw = (_a2 = f.properties) == null ? void 0 : _a2[field];
8464
+ if (raw === null || raw === void 0 || raw === "") continue;
8465
+ present++;
8466
+ values.add(String(raw));
8467
+ if (values.size > MAX_GROUPS) return false;
8468
+ }
8469
+ return present >= points.length * MIN_COVERAGE && values.size >= 2 && present >= values.size * MIN_POINTS_PER_GROUP;
8470
+ };
8471
+ return ((_a = candidates.find((c) => splitsIntoTracks(c.field))) == null ? void 0 : _a.field) ?? null;
8472
+ }
8008
8473
  function deepClone(value) {
8009
8474
  try {
8010
8475
  return structuredClone(value);
@@ -8141,82 +8606,6 @@ function shouldDiffDrawRender({ mode, pointerDown, hasSelection }) {
8141
8606
  if (mode === "simple_select" || mode === "direct_select") return pointerDown && hasSelection;
8142
8607
  return true;
8143
8608
  }
8144
- function extendBounds(bounds, coords) {
8145
- if (!Array.isArray(coords) || coords.length === 0) return;
8146
- if (typeof coords[0] === "number") {
8147
- const lng = coords[0];
8148
- const lat = coords[1];
8149
- if (lng < bounds.minLng) bounds.minLng = lng;
8150
- if (lng > bounds.maxLng) bounds.maxLng = lng;
8151
- if (lat < bounds.minLat) bounds.minLat = lat;
8152
- if (lat > bounds.maxLat) bounds.maxLat = lat;
8153
- return;
8154
- }
8155
- for (const nested of coords) extendBounds(bounds, nested);
8156
- }
8157
- function computeBounds(coords) {
8158
- const bounds = { minLng: Infinity, minLat: Infinity, maxLng: -Infinity, maxLat: -Infinity };
8159
- extendBounds(bounds, coords);
8160
- return bounds;
8161
- }
8162
- function boundsDisjoint(a, b) {
8163
- return a.maxLng < b.minLng || a.minLng > b.maxLng || a.maxLat < b.minLat || a.minLat > b.maxLat;
8164
- }
8165
- function pointInBounds(lng, lat, b) {
8166
- return lng >= b.minLng && lng <= b.maxLng && lat >= b.minLat && lat <= b.maxLat;
8167
- }
8168
- function buildGroupSpatialIndex(features) {
8169
- var _a;
8170
- const boxes = [];
8171
- const positions = [];
8172
- for (let p = 0; p < features.length; p++) {
8173
- const geom = (_a = features[p]) == null ? void 0 : _a.geometry;
8174
- const b = computeBounds(geom == null ? void 0 : geom.coordinates);
8175
- if (!isFinite(b.minLng) || !isFinite(b.minLat) || !isFinite(b.maxLng) || !isFinite(b.maxLat)) {
8176
- continue;
8177
- }
8178
- boxes.push(b.minLng, b.minLat, b.maxLng, b.maxLat);
8179
- positions.push(p);
8180
- }
8181
- if (positions.length === 0) {
8182
- return { tree: null, positions, size: features.length };
8183
- }
8184
- const startedAt = performance.now();
8185
- const tree = new Flatbush(positions.length);
8186
- for (let i = 0; i < boxes.length; i += 4) {
8187
- tree.add(boxes[i], boxes[i + 1], boxes[i + 2], boxes[i + 3]);
8188
- }
8189
- tree.finish();
8190
- mapPerfLog("spatial-index", "built group index", {
8191
- indexed: positions.length,
8192
- of: features.length,
8193
- ms: Math.round(performance.now() - startedAt)
8194
- });
8195
- return { tree, positions, size: features.length };
8196
- }
8197
- const indexCache = /* @__PURE__ */ new WeakMap();
8198
- const failedBuilds = /* @__PURE__ */ new WeakSet();
8199
- function getGroupSpatialIndex(features) {
8200
- if (failedBuilds.has(features)) return void 0;
8201
- let index = indexCache.get(features);
8202
- if (!index) {
8203
- try {
8204
- index = buildGroupSpatialIndex(features);
8205
- } catch {
8206
- failedBuilds.add(features);
8207
- return void 0;
8208
- }
8209
- indexCache.set(features, index);
8210
- }
8211
- return index;
8212
- }
8213
- function queryCandidatePositions(index, bounds) {
8214
- if (!index.tree) return [];
8215
- const items = index.tree.search(bounds.minLng, bounds.minLat, bounds.maxLng, bounds.maxLat);
8216
- const positions = items.map((i) => index.positions[i]);
8217
- positions.sort((a, b) => a - b);
8218
- return positions;
8219
- }
8220
8609
  function collectVisibleFeatureGroups(drawFeatures, readOnlyByLayer, layers) {
8221
8610
  const groups = [];
8222
8611
  if (drawFeatures) groups.push({ features: drawFeatures });
@@ -8334,19 +8723,6 @@ function buildSelectionOverlayStack() {
8334
8723
  }
8335
8724
  ];
8336
8725
  }
8337
- function overlayTimelineInputs(ids, visible) {
8338
- const hidden = /* @__PURE__ */ new Set();
8339
- if (visible !== null) ids.forEach((id) => {
8340
- if (!visible.has(id)) hidden.add(id);
8341
- });
8342
- return { ids, hidden };
8343
- }
8344
- function sameIds(a, b) {
8345
- return a.size === b.size && Array.from(a).every((id) => b.has(id));
8346
- }
8347
- function sameOverlayTimelineInputs(a, b) {
8348
- return sameIds(a.ids, b.ids) && sameIds(a.hidden, b.hidden);
8349
- }
8350
8726
  function buildSelectionOverlayData(ids, styleFor) {
8351
8727
  const features = [];
8352
8728
  ids.forEach((id) => {
@@ -8733,8 +9109,8 @@ function hideTooltip() {
8733
9109
  tooltipEl.style.display = "none";
8734
9110
  }
8735
9111
  }
8736
- function fingerprintCluster(pointCount, counts, size, badgeValue) {
8737
- return `${size}|${pointCount}|${badgeValue ?? ""}|${counts.join(",")}`;
9112
+ function fingerprintCluster(pointCount, counts2, size, badgeValue) {
9113
+ return `${size}|${pointCount}|${badgeValue ?? ""}|${counts2.join(",")}`;
8738
9114
  }
8739
9115
  function buildPieElement(categories, pointCount, size, source, clusterId, map, coords, badgeValue) {
8740
9116
  const el = createPieSVG(categories, pointCount, size, (cat, event) => {
@@ -8886,6 +9262,8 @@ const EMPTY_ID_SET = /* @__PURE__ */ new Set();
8886
9262
  const EMPTY_SOURCES = [];
8887
9263
  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"];
8888
9264
  const EMPTY_LABEL_MAP = /* @__PURE__ */ new Map();
9265
+ const TICK_COUNT_SETTLE_MS = 300;
9266
+ const SPATIAL_COUNT_MIN_FEATURES = 5e3;
8889
9267
  function renderEmojiToCanvas(emoji, size = EMOJI_CANVAS_SIZE) {
8890
9268
  const ratio = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
8891
9269
  const canvas = document.createElement("canvas");
@@ -9093,7 +9471,7 @@ function basemapInsertAnchor(map) {
9093
9471
  function featureStateHostFor(m) {
9094
9472
  return {
9095
9473
  setFeatureState: (source, id, state) => m.setFeatureState({ source, id }, state),
9096
- removeFeatureState: (source, id) => m.removeFeatureState({ source, id }),
9474
+ removeFeatureState: (source, id, key) => m.removeFeatureState({ source, id }, key),
9097
9475
  source: (source) => m.getSource(source)
9098
9476
  };
9099
9477
  }
@@ -9276,6 +9654,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9276
9654
  const justCreatedFeatureRef = useRef(false);
9277
9655
  const [autoLabelConfig, setAutoLabelConfig] = useState({ enabled: true, threshold: 220 });
9278
9656
  const [visibleFeatureCount, setVisibleFeatureCount] = useState(Infinity);
9657
+ const visibleFeatureCountRef = useRef(visibleFeatureCount);
9658
+ visibleFeatureCountRef.current = visibleFeatureCount;
9659
+ const tickCountTimerRef = useRef(null);
9279
9660
  const lastLabelVisibility = useRef(false);
9280
9661
  const shardRegistryRef = useRef(null);
9281
9662
  const applyShardedLayersRef = useRef(null);
@@ -9283,9 +9664,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9283
9664
  const bindHoverHandlersRef = useRef(null);
9284
9665
  const unbindHoverHandlersRef = useRef(null);
9285
9666
  const [labelsSuppressed, setLabelsSuppressed] = useState(true);
9667
+ const labelsSuppressedRef = useRef(labelsSuppressed);
9668
+ labelsSuppressedRef.current = labelsSuppressed;
9286
9669
  const [contextMenu, setContextMenu] = useState(null);
9287
9670
  const [timelineStoreApi] = useState(createTimelineStore);
9288
- const timelineStore = useStore(timelineStoreApi);
9671
+ const timelineEnabled = useStore(timelineStoreApi, (s) => s.isEnabled);
9672
+ const timelineHasData = useStore(timelineStoreApi, (s) => s.hasTemporalData);
9289
9673
  const { toast: internalToast } = useToast();
9290
9674
  const toast = toastProvider ?? internalToast;
9291
9675
  const featureCap = useMemo(() => resolveFeatureCap(maxFeaturesPerLayer), [maxFeaturesPerLayer]);
@@ -9546,7 +9930,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9546
9930
  });
9547
9931
  setFeatureCount(drawFeatureCount + hiddenCount + readOnlyCount);
9548
9932
  }, []);
9549
- const timelineVisibleIdsRef = useRef(null);
9933
+ const timelineWindowRef = useRef(null);
9934
+ const appliedTimelineRef = useRef(/* @__PURE__ */ new Map());
9935
+ const isTimelineSourceActive = useCallback((sourceId) => {
9936
+ var _a;
9937
+ const shard = parseShardSourceId(sourceId);
9938
+ return !shard || ((_a = layersRef.current.find((l) => l.id === shard.layerId)) == null ? void 0 : _a.visible) === true;
9939
+ }, []);
9550
9940
  const syncRef = useRef(() => {
9551
9941
  });
9552
9942
  const trySelectionFastPathRef = useRef(null);
@@ -9578,6 +9968,19 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9578
9968
  }
9579
9969
  (_b = syncCoalescerRef.current) == null ? void 0 : _b.schedule(reason);
9580
9970
  }, []);
9971
+ useEffect(() => {
9972
+ const windowOf = (state) => state.isEnabled && state.hasTemporalData ? windowFromRange(state.rangeStart, state.rangeEnd) : null;
9973
+ const follow = (state) => {
9974
+ var _a;
9975
+ const next = windowOf(state);
9976
+ if (sameWindow(next, timelineWindowRef.current)) return;
9977
+ timelineWindowRef.current = next;
9978
+ scheduleSync("timeline");
9979
+ (_a = update3DFlightPathsRef.current) == null ? void 0 : _a.call(update3DFlightPathsRef);
9980
+ };
9981
+ follow(timelineStoreApi.getState());
9982
+ return timelineStoreApi.subscribe(follow);
9983
+ }, [timelineStoreApi, scheduleSync]);
9581
9984
  useEffect(() => {
9582
9985
  scheduleSync();
9583
9986
  }, [layers, scheduleSync]);
@@ -9641,21 +10044,33 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9641
10044
  const m = map.current;
9642
10045
  if (!m) return 0;
9643
10046
  const bounds = m.getBounds();
10047
+ const w = timelineWindowRef.current;
10048
+ const groupOf = (features) => {
10049
+ if (w === null) return { features };
10050
+ const index = getTimelineIndex(features);
10051
+ const group = { features, isVisible: (p) => isVisibleAt(index, p, w) };
10052
+ const spatial = features.length >= SPATIAL_COUNT_MIN_FEATURES ? getGroupSpatialIndex(features) : void 0;
10053
+ if (spatial) group.indexed = { spatial, visibleTotal: countVisible(index, w) };
10054
+ return group;
10055
+ };
9644
10056
  const groups = [];
9645
- if (draw.current) groups.push(draw.current.getAll().features);
10057
+ if (draw.current) {
10058
+ const features = draw.current.getAll().features;
10059
+ groups.push(w === null ? { features } : { features, isVisible: (p) => isFeatureVisible(features[p], w) });
10060
+ }
9646
10061
  readOnlyFeatures.current.forEach((features, layerId) => {
9647
10062
  const layer = layersRef.current.find((l) => l.id === layerId);
9648
- if (layer == null ? void 0 : layer.visible) groups.push(features);
10063
+ if (layer == null ? void 0 : layer.visible) groups.push(groupOf(features));
9649
10064
  });
9650
10065
  return countFeaturesInBounds(
9651
10066
  groups,
9652
10067
  { west: bounds.getWest(), east: bounds.getEast(), south: bounds.getSouth(), north: bounds.getNorth() },
9653
- { threshold, visibleSet: timelineVisibleIdsRef.current }
10068
+ { threshold }
9654
10069
  );
9655
10070
  }, []);
9656
10071
  const isSyncingRef = useRef(false);
9657
- const selectionPaintCacheRef = useRef(null);
9658
10072
  const tracePaintCacheRef = useRef(null);
10073
+ const traceEndpointsRef = useRef(/* @__PURE__ */ new Set());
9659
10074
  const paintedArrowLinesRef = useRef([]);
9660
10075
  const renderArrowOverlays = useCallback((arrowLines) => {
9661
10076
  const mapInstance = map.current;
@@ -9761,7 +10176,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9761
10176
  const source = map.current.getSource("custom-features");
9762
10177
  if (!source) return;
9763
10178
  const drawFeatures = draw.current ? draw.current.getAll() : { type: "FeatureCollection", features: [] };
9764
- const visibleSet = timelineVisibleIdsRef.current;
10179
+ const timelineWindow = timelineWindowRef.current;
9765
10180
  const currentLayers = layersRef.current;
9766
10181
  const isLayerVisible = (layer) => {
9767
10182
  return layer.visible;
@@ -9774,11 +10189,17 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9774
10189
  });
9775
10190
  shardedLayerIdsRef.current = shardedLayerIds;
9776
10191
  const allFeatures = [...drawFeatures.features];
10192
+ const sharedSlices = [];
10193
+ const addSlice = (features) => {
10194
+ if (features.length > 0) sharedSlices.push({ features, start: 0, end: features.length });
10195
+ };
10196
+ addSlice(drawFeatures.features);
9777
10197
  readOnlyFeatures.current.forEach((features, layerId) => {
9778
10198
  if (shardedLayerIds.has(layerId)) return;
9779
10199
  const layer = currentLayers.find((l) => l.id === layerId);
9780
10200
  if (layer && isLayerVisible(layer)) {
9781
10201
  pushAll(allFeatures, features);
10202
+ addSlice(features);
9782
10203
  }
9783
10204
  });
9784
10205
  const featureById = /* @__PURE__ */ new Map();
@@ -9826,71 +10247,69 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9826
10247
  if (sizeField && isFinite(sMin)) sizeFieldRanges.set(layer.id, { min: sMin, max: sMax });
9827
10248
  if (colorField && isFinite(cMin)) colorFieldRanges.set(layer.id, { min: cMin, max: cMax });
9828
10249
  });
9829
- const lastTracePointIds = /* @__PURE__ */ new Set();
9830
10250
  const tracePointColors = /* @__PURE__ */ new Map();
9831
- const lastTracePointLabels = /* @__PURE__ */ new Map();
9832
10251
  const tracePointIds = /* @__PURE__ */ new Set();
9833
10252
  const paintedTraceGroups = [];
9834
- const traceSegments = [];
9835
- const tracePointPaint = /* @__PURE__ */ new Map();
9836
- const isTimelineVisibleId = timelineVisibility(visibleSet);
10253
+ const traceIndexes = [];
9837
10254
  currentLayers.forEach((layer) => {
9838
10255
  var _a2;
9839
10256
  if (!((_a2 = layer.traceConfig) == null ? void 0 : _a2.enabled) || !layer.visible) return;
9840
- const groups = getTraceGroups(traceSourceFeatures(layer, featureById), layer.traceConfig.groupByField);
10257
+ const traceFeatures = traceSourceFeatures(layer, featureById);
10258
+ const traceIndex = getTimelineIndex(traceFeatures);
10259
+ const groups = getTraceGroups(traceFeatures, layer.traceConfig.groupByField);
10260
+ const pointsHidden = layerHidesPoints(layer);
9841
10261
  for (const group of groups) {
9842
- const groupIndex = paintedTraceGroups.push(group) - 1;
10262
+ paintedTraceGroups.push(pointsHidden && group.label !== null ? { ...group, label: null } : group);
10263
+ traceIndexes.push(traceIndex);
9843
10264
  for (const id of group.ids) {
9844
10265
  tracePointIds.add(id);
9845
10266
  tracePointColors.set(id, group.color);
9846
10267
  }
9847
- const visible = visibleTraceIndices(group, isTimelineVisibleId);
9848
- if (visible.length === 0) continue;
9849
- const endpointId = group.ids[visible[visible.length - 1]];
9850
- lastTracePointIds.add(endpointId);
9851
- if (group.label !== null) lastTracePointLabels.set(endpointId, group.label);
9852
- for (let k = 1; k < visible.length; k++) {
9853
- traceSegments.push(traceSegmentFeature(group, groupIndex, visible[k - 1], visible[k]));
9854
- }
9855
10268
  }
9856
10269
  });
9857
- const paintCache = createSelectionPaintCache();
9858
10270
  const paintContext = {
9859
- timelineVisibleIds: visibleSet,
9860
10271
  sizeFieldRanges,
9861
10272
  colorFieldRanges,
9862
10273
  tracePointIds,
9863
- lastTracePointIds,
9864
- lastTracePointLabels,
9865
10274
  tracePointColors
9866
10275
  };
9867
10276
  const drawFeatureCount = drawFeatures.features.length;
9868
10277
  const sourceData = {
9869
10278
  type: "FeatureCollection",
9870
10279
  features: allFeatures.map((f, i) => {
9871
- const styled = styleFeatureForPaint(f, featureToLayer.get(String(f.id)), paintContext, i >= drawFeatureCount);
9872
- const p = styled.paint;
9873
- recordPaintedFeature(paintCache, p.featureId, p.visibleStrokeOpacity, p.visibleFillOpacity, p.timelineHidden);
9874
- if (styled.tracePaint) tracePointPaint.set(p.featureId, styled.tracePaint);
9875
- return styled.feature;
10280
+ return styleFeatureForPaint(f, featureToLayer.get(String(f.id)), paintContext, i >= drawFeatureCount).feature;
9876
10281
  })
9877
10282
  };
9878
10283
  source.setData(sourceData);
9879
- selectionPaintCacheRef.current = paintCache;
9880
10284
  overlayPaintContextRef.current = paintContext;
10285
+ const stateHost = featureStateHostFor(map.current);
10286
+ seedTimelineSource(stateHost, appliedTimelineRef.current, SHARED_SOURCE_ID, sharedSlices, timelineWindow);
10287
+ applyTimelineWindow(stateHost, appliedTimelineRef.current, timelineWindow, isTimelineSourceActive);
9881
10288
  (_a = reconcileSelectionRef.current) == null ? void 0 : _a.call(reconcileSelectionRef);
9882
- const traceSource = map.current.getSource("trace-features");
9883
- if (traceSource) traceSource.setData({ type: "FeatureCollection", features: traceSegments });
9884
- tracePaintCacheRef.current = traceSource && paintedTraceGroups.length > 0 ? { groups: paintedTraceGroups, pointPaint: tracePointPaint } : null;
10289
+ const traceSource = map.current.getSource(TRACE_SOURCE_ID);
10290
+ const tracePaint = paintTraceAt(paintedTraceGroups, traceIndexes, timelineWindow);
10291
+ if (traceSource) traceSource.setData({ type: "FeatureCollection", features: tracePaint.features });
10292
+ const endpoints2 = new Set(tracePaint.endpoints);
10293
+ setTraceEndpoints(
10294
+ featureStateHostFor(map.current),
10295
+ traceEndpointsRef.current,
10296
+ Array.from(traceEndpointsRef.current).filter((id) => !endpoints2.has(id)),
10297
+ tracePaint.endpoints
10298
+ );
10299
+ tracePaintCacheRef.current = traceSource && paintedTraceGroups.length > 0 ? { groups: paintedTraceGroups, indexes: traceIndexes, window: timelineWindow } : null;
9885
10300
  {
9886
10301
  let sawArrowFeature = false;
9887
10302
  const arrowLines = [];
9888
- sourceData.features.forEach((f) => {
10303
+ const pushArrow = (styled, record) => {
10304
+ const { s, e } = record ? featureInterval(record) : { s: NaN, e: NaN };
10305
+ arrowLines.push(isIntervalVisible(s, e, timelineWindow) ? styled : { ...styled, properties: { ...styled.properties, "stroke-opacity": 0, "fill-opacity": 0 } });
10306
+ };
10307
+ sourceData.features.forEach((f, i) => {
9889
10308
  var _a2;
9890
10309
  const isArrow = ((_a2 = f.properties) == null ? void 0 : _a2.kind) === "arrow" || arrowFeatureIdsRef.current.has(String(f.id));
9891
10310
  if (!isArrow) return;
9892
10311
  sawArrowFeature = true;
9893
- if (f.geometry.type === "LineString") arrowLines.push(f);
10312
+ if (f.geometry.type === "LineString") pushArrow(f, allFeatures[i]);
9894
10313
  });
9895
10314
  const shardArrows = ((_b = shardRegistryRef.current) == null ? void 0 : _b.arrowLines((id) => {
9896
10315
  var _a2;
@@ -9898,7 +10317,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9898
10317
  })) ?? [];
9899
10318
  if (shardArrows.length > 0) {
9900
10319
  sawArrowFeature = true;
9901
- pushAll(arrowLines, shardArrows);
10320
+ shardArrows.forEach((f) => pushArrow(f, getReadOnlyFeatureById(String(f.id))));
9902
10321
  }
9903
10322
  hasArrowFeaturesRef.current = sawArrowFeature;
9904
10323
  paintedArrowLinesRef.current = arrowLines;
@@ -9928,7 +10347,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9928
10347
  } finally {
9929
10348
  isSyncingRef.current = false;
9930
10349
  }
9931
- }, [layers, hashStringToColor$1, autoLabelConfig, countVisibleFeatures, renderArrowOverlays]);
10350
+ }, [layers, hashStringToColor$1, autoLabelConfig, countVisibleFeatures, renderArrowOverlays, getReadOnlyFeatureById, isTimelineSourceActive]);
9932
10351
  const update3DFlightPaths = useCallback(() => {
9933
10352
  var _a;
9934
10353
  if (!map.current || !is3DTerrainEnabled) {
@@ -9942,11 +10361,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9942
10361
  return;
9943
10362
  }
9944
10363
  const mapInstance = map.current;
9945
- const visibleSet = timelineVisibleIdsRef.current;
9946
- const isFeatureVisibleInTimeline = (feature) => {
9947
- if (visibleSet === null) return true;
9948
- const featureId = String(feature.id);
9949
- return visibleSet.has(featureId);
10364
+ const timelineWindow = timelineWindowRef.current;
10365
+ const visibleIn = (features) => {
10366
+ if (timelineWindow === null) return [...features];
10367
+ const index = getTimelineIndex(features);
10368
+ return features.filter((_, p) => isVisibleAt(index, p, timelineWindow));
9950
10369
  };
9951
10370
  const allFeatures = [];
9952
10371
  const currentLayers = layersRef.current;
@@ -9956,9 +10375,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9956
10375
  if (((_a = l.traceConfig) == null ? void 0 : _a.enabled) !== true) continue;
9957
10376
  for (const featureId of l.featureIds) traceFeatureIds.add(featureId);
9958
10377
  }
9959
- const drawFeatures = draw.current.getAll().features.filter(
9960
- (feature) => isFeatureVisibleInTimeline(feature) && traceFeatureIds.has(feature.id)
9961
- );
10378
+ const drawFeatures = draw.current.getAll().features.filter((feature) => traceFeatureIds.has(feature.id) && isFeatureVisible(feature, timelineWindow));
9962
10379
  pushAll(allFeatures, drawFeatures);
9963
10380
  }
9964
10381
  readOnlyFeatures.current.forEach((features, layerId2) => {
@@ -9967,8 +10384,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9967
10384
  const altitudeMode = (layer2 == null ? void 0 : layer2.altitudeDisplayMode) ?? "both";
9968
10385
  const traceEnabled = ((_a2 = layer2 == null ? void 0 : layer2.traceConfig) == null ? void 0 : _a2.enabled) === true;
9969
10386
  if ((layer2 == null ? void 0 : layer2.visible) && traceEnabled && (altitudeMode === "3d" || altitudeMode === "both")) {
9970
- const visibleFeatures = features.filter(isFeatureVisibleInTimeline);
9971
- pushAll(allFeatures, visibleFeatures);
10387
+ pushAll(allFeatures, visibleIn(features));
9972
10388
  }
9973
10389
  });
9974
10390
  const flightPaths = extract3DFlightPaths(allFeatures);
@@ -10027,11 +10443,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10027
10443
  const fingerprint = buildShardFingerprint(layer, features, shardSize2);
10028
10444
  const expectedShards = shardRanges(features.length, shardSize2).length;
10029
10445
  if (shardFingerprintsEqual(state.fingerprint, fingerprint) && state.stacks.length === expectedShards) {
10030
- if (reconcileShardCaches(registry, state.layerId, expectedShards, timelineVisibleIdsRef.current)) {
10031
- setLayerImporting(layer.id, false);
10032
- mapPerfLog("shards", "pass skipped (fingerprint)", { layerId: layer.id, shards: expectedShards });
10033
- return;
10034
- }
10446
+ setLayerImporting(layer.id, false);
10447
+ mapPerfLog("shards", "pass skipped (fingerprint)", { layerId: layer.id, shards: expectedShards });
10448
+ return;
10035
10449
  }
10036
10450
  if (shardFingerprintsEqual(state.inFlightFingerprint, fingerprint)) {
10037
10451
  setLayerImporting(layer.id, true);
@@ -10062,19 +10476,22 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10062
10476
  isCurrent: () => map.current !== null && state.generation === generation,
10063
10477
  contextForShard: () => {
10064
10478
  return {
10065
- timelineVisibleIds: timelineVisibleIdsRef.current,
10066
10479
  sizeFieldRanges,
10067
10480
  colorFieldRanges,
10068
10481
  // Trace-enabled layers are never sharded, so these are empty by construction.
10069
10482
  tracePointIds: EMPTY_ID_SET,
10070
- lastTracePointIds: EMPTY_ID_SET,
10071
- lastTracePointLabels: EMPTY_LABEL_MAP,
10072
10483
  tracePointColors: EMPTY_LABEL_MAP
10073
10484
  };
10074
10485
  },
10075
- onShardPainted: (index, cache2) => {
10486
+ onShardPainted: (index, start, end) => {
10076
10487
  var _a2;
10077
- state.caches[index] = cache2;
10488
+ seedTimelineSource(
10489
+ featureStateHostFor(m),
10490
+ appliedTimelineRef.current,
10491
+ shardSourceId(layer.id, index),
10492
+ [{ features, start, end }],
10493
+ timelineWindowRef.current
10494
+ );
10078
10495
  (_a2 = reconcileSelectionRef.current) == null ? void 0 : _a2.call(reconcileSelectionRef, { overlay: !overlayRestyled });
10079
10496
  overlayRestyled = true;
10080
10497
  },
@@ -10108,7 +10525,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10108
10525
  }, [update3DFlightPaths]);
10109
10526
  useEffect(() => {
10110
10527
  update3DFlightPaths();
10111
- }, [update3DFlightPaths, layers, is3DTerrainEnabled, timelineStore.isEnabled, timelineStore.rangeStart, timelineStore.rangeEnd]);
10528
+ }, [update3DFlightPaths, layers, is3DTerrainEnabled]);
10112
10529
  useEffect(() => {
10113
10530
  if (map.current && is3DTerrainEnabled) {
10114
10531
  const timer = setTimeout(() => {
@@ -10601,7 +11018,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10601
11018
  "text-opacity": ["coalesce", ["get", "stroke-opacity"], 1]
10602
11019
  }
10603
11020
  });
10604
- mapInstance.addSource("trace-features", {
11021
+ mapInstance.addSource(TRACE_SOURCE_ID, {
10605
11022
  type: "geojson",
10606
11023
  data: { type: "FeatureCollection", features: [] },
10607
11024
  maxzoom: 22
@@ -10609,13 +11026,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10609
11026
  mapInstance.addLayer({
10610
11027
  id: "trace-lines",
10611
11028
  type: "line",
10612
- source: "trace-features",
11029
+ source: TRACE_SOURCE_ID,
11030
+ filter: ["==", "$type", "LineString"],
10613
11031
  paint: {
10614
11032
  "line-color": ["get", "color"],
10615
11033
  "line-width": 2,
10616
11034
  "line-opacity": 0.7
10617
11035
  }
10618
11036
  });
11037
+ mapInstance.addLayer(buildTraceEndpointLabelLayer());
10619
11038
  mapInstance.addSource(SELECTION_OVERLAY_SOURCE_ID, {
10620
11039
  type: "geojson",
10621
11040
  data: { type: "FeatureCollection", features: [] },
@@ -13273,8 +13692,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13273
13692
  if (!m.getLayer(id)) return;
13274
13693
  m.moveLayer(id, firstVisibleBasemapSymbol == null ? void 0 : firstVisibleBasemapSymbol.id);
13275
13694
  });
13276
- if (!firstVisibleBasemapSymbol && m.getLayer(SELECTION_OVERLAY_LAYER_IDS.label)) {
13277
- m.moveLayer(SELECTION_OVERLAY_LAYER_IDS.label);
13695
+ if (!firstVisibleBasemapSymbol) {
13696
+ [TRACE_ENDPOINT_LABEL_LAYER_ID, SELECTION_OVERLAY_LAYER_IDS.label].forEach((id) => {
13697
+ if (m.getLayer(id)) m.moveLayer(id);
13698
+ });
13278
13699
  }
13279
13700
  } catch (e) {
13280
13701
  console.warn("[map-component] moveLabelsBeforeBasemapSymbols failed:", (e == null ? void 0 : e.message) ?? e);
@@ -13592,7 +14013,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13592
14013
  if (!layer) return [];
13593
14014
  const fieldsMap = /* @__PURE__ */ new Map();
13594
14015
  const excludedFields = /* @__PURE__ */ new Set(["name", "startDate", "endDate", "opacity", ...STYLING_PROPERTY_KEYS]);
13595
- const MAX_SAMPLES = 1e4;
14016
+ const MAX_SAMPLES2 = 1e4;
13596
14017
  let features = [];
13597
14018
  if (layer.readOnly) {
13598
14019
  features = readOnlyFeatures.current.get(layerId) || [];
@@ -13601,8 +14022,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13601
14022
  } else {
13602
14023
  features = hiddenFeatures.current.get(layerId) || [];
13603
14024
  }
13604
- const sampled = !layer.readOnly && features.length > MAX_SAMPLES;
13605
- const sampleFeatures = layer.readOnly ? features : features.slice(0, MAX_SAMPLES);
14025
+ const sampled = !layer.readOnly && features.length > MAX_SAMPLES2;
14026
+ const sampleFeatures = layer.readOnly ? features : features.slice(0, MAX_SAMPLES2);
13606
14027
  sampleFeatures.forEach((f) => {
13607
14028
  if (f && f.properties) {
13608
14029
  Object.entries(f.properties).forEach(([key, value]) => {
@@ -13650,15 +14071,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13650
14071
  } else {
13651
14072
  features = hiddenFeatures.current.get(layerId) || [];
13652
14073
  }
13653
- const MAX_SAMPLES = 1e4;
13654
- const sample = features.slice(0, MAX_SAMPLES);
13655
- const counts = /* @__PURE__ */ new Map();
14074
+ const MAX_SAMPLES2 = 1e4;
14075
+ const sample = features.slice(0, MAX_SAMPLES2);
14076
+ const counts2 = /* @__PURE__ */ new Map();
13656
14077
  for (const f of sample) {
13657
14078
  const key = categoricalKey((_a = f == null ? void 0 : f.properties) == null ? void 0 : _a[fieldName]);
13658
14079
  if (key === null) continue;
13659
- counts.set(key, (counts.get(key) ?? 0) + 1);
14080
+ counts2.set(key, (counts2.get(key) ?? 0) + 1);
13660
14081
  }
13661
- 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 }));
14082
+ 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 }));
13662
14083
  },
13663
14084
  [layers]
13664
14085
  );
@@ -13724,21 +14145,19 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13724
14145
  });
13725
14146
  }
13726
14147
  }, [layers]);
14148
+ const traceFieldSource = useCallback((layer) => {
14149
+ if (layer.readOnly) return readOnlyFeatures.current.get(layer.id) || [];
14150
+ if (layer.visible) return draw.current ? layer.featureIds.map((id) => draw.current.get(id)) : [];
14151
+ return hiddenFeatures.current.get(layer.id) || [];
14152
+ }, []);
13727
14153
  const getAvailableTraceFields = useCallback((layerId) => {
13728
14154
  const layer = layers.find((l) => l.id === layerId);
13729
14155
  if (!layer) return [];
13730
14156
  const fieldsSet = /* @__PURE__ */ new Set();
13731
14157
  const excludedFields = /* @__PURE__ */ new Set(["name", "startDate", "endDate", "opacity"]);
13732
- const MAX_SAMPLES = 1e4;
13733
- let features = [];
13734
- if (layer.readOnly) {
13735
- features = readOnlyFeatures.current.get(layerId) || [];
13736
- } else if (layer.visible) {
13737
- features = draw.current ? layer.featureIds.map((id) => draw.current.get(id)) : [];
13738
- } else {
13739
- features = hiddenFeatures.current.get(layerId) || [];
13740
- }
13741
- const sampleFeatures = features.slice(0, MAX_SAMPLES);
14158
+ const MAX_SAMPLES2 = 1e4;
14159
+ const features = traceFieldSource(layer);
14160
+ const sampleFeatures = features.slice(0, MAX_SAMPLES2);
13742
14161
  sampleFeatures.forEach((f) => {
13743
14162
  if (f && f.properties) {
13744
14163
  Object.entries(f.properties).forEach(([key, value]) => {
@@ -13749,7 +14168,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13749
14168
  }
13750
14169
  });
13751
14170
  return Array.from(fieldsSet).sort();
13752
- }, [layers]);
14171
+ }, [layers, traceFieldSource]);
14172
+ const getSuggestedTraceField = useCallback((layerId) => {
14173
+ const layer = layers.find((l) => l.id === layerId);
14174
+ return layer ? suggestTraceGroupField(traceFieldSource(layer), getAvailableTraceFields(layerId)) : null;
14175
+ }, [layers, traceFieldSource, getAvailableTraceFields]);
13753
14176
  const handleMeasureModeChange = useCallback((mode) => {
13754
14177
  setMeasureMode(mode);
13755
14178
  setMeasurePoints([]);
@@ -13839,18 +14262,24 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13839
14262
  if (ranges.size) sizeFieldRanges.set(layerId, ranges.size);
13840
14263
  if (ranges.color) colorFieldRanges.set(layerId, ranges.color);
13841
14264
  });
13842
- return { ...base, timelineVisibleIds: timelineVisibleIdsRef.current, sizeFieldRanges, colorFieldRanges };
14265
+ return { ...base, sizeFieldRanges, colorFieldRanges };
13843
14266
  }, []);
13844
14267
  const overlayFeatureCountRef = useRef(0);
13845
- const overlayTimelineInputsRef = useRef(overlayTimelineInputs(EMPTY_ID_SET, null));
13846
14268
  const refreshSelectionOverlay = useCallback((m, ids) => {
13847
- overlayTimelineInputsRef.current = overlayTimelineInputs(ids, timelineVisibleIdsRef.current);
13848
14269
  if (ids.size === 0 && overlayFeatureCountRef.current === 0) return;
13849
14270
  const overlay = m.getSource(SELECTION_OVERLAY_SOURCE_ID);
13850
14271
  if (!overlay) return;
13851
14272
  const ctx = ids.size > 0 ? overlayPaintContext() : null;
13852
14273
  const layers2 = layersRef.current;
13853
14274
  const layerById = new Map(layers2.map((l) => [l.id, l]));
14275
+ const styled = (feature, layer, paintCtx, sourceId) => {
14276
+ const out = styleFeatureForPaint(feature, layer, paintCtx, true).feature;
14277
+ if (isTimelineHiddenOn(appliedTimelineRef.current, sourceId, String(feature.id)) && out.properties) {
14278
+ out.properties["stroke-opacity"] = 0;
14279
+ out.properties["fill-opacity"] = 0;
14280
+ }
14281
+ return out;
14282
+ };
13854
14283
  const data = buildSelectionOverlayData(ids, (id) => {
13855
14284
  if (!ctx) return [];
13856
14285
  const holders = locateFeatureHolders(id, readOnlyFeatures.current, locatorCacheRef.current);
@@ -13858,12 +14287,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13858
14287
  return holders.filter((h) => {
13859
14288
  var _a;
13860
14289
  return ((_a = layerById.get(h.layerId)) == null ? void 0 : _a.visible) === true;
13861
- }).map((h) => styleFeatureForPaint(h.feature, layerById.get(h.layerId), ctx, true).feature);
14290
+ }).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));
13862
14291
  }
13863
14292
  const feature = getFeatureById(id);
13864
14293
  if (!feature) return [];
13865
14294
  const layer = layers2.find((l) => !l.readOnly && l.featureIds.includes(id));
13866
- return layer && !layer.visible ? [] : [styleFeatureForPaint(feature, layer, ctx, true).feature];
14295
+ return layer && !layer.visible ? [] : [styled(feature, layer, ctx, SHARED_SOURCE_ID)];
13867
14296
  });
13868
14297
  overlay.setData(data);
13869
14298
  overlayFeatureCountRef.current = data.features.length;
@@ -13919,35 +14348,42 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13919
14348
  const m = map.current;
13920
14349
  if (!m) return true;
13921
14350
  if (hasArrowFeaturesRef.current) return false;
13922
- const source = m.getSource("custom-features");
13923
- const paintCache = selectionPaintCacheRef.current;
13924
- const nextVisible = timelineVisibleIdsRef.current;
14351
+ const start = performance.now();
14352
+ const next = timelineWindowRef.current;
13925
14353
  const trace = tracePaintCacheRef.current;
13926
- const traceSource = trace ? m.getSource("trace-features") : void 0;
13927
- if (trace && !traceSource) return false;
13928
- const traceDiff = trace && paintCache ? buildTraceTimelineDiff(trace, paintCache, nextVisible) : null;
13929
- const { applied, toggled } = applyTimelineFastPath(paintCache, nextVisible, source);
13930
- if (!applied || !paintCache || !source) return false;
13931
- if (traceDiff && (!traceSource || !applyTraceTimelineDiff(traceDiff, source, traceSource))) return false;
13932
- if (!forEachShardCache(shardRegistryRef.current, (cache2, shardSource) => applyTimelineFastPath(cache2, nextVisible, shardSource).applied)) {
13933
- return false;
13934
- }
14354
+ let endpointsMoved = 0;
14355
+ if (trace) {
14356
+ const traceSource = m.getSource(TRACE_SOURCE_ID);
14357
+ if (!traceSource) return false;
14358
+ const traceDiff = buildTraceTimelineDiff(trace, next);
14359
+ if (!applyTraceTimelineDiff(traceDiff, traceSource, featureStateHostFor(m), traceEndpointsRef.current)) return false;
14360
+ trace.window = next;
14361
+ endpointsMoved = traceDiff.endpointOn.length;
14362
+ }
14363
+ const flipped = applyTimelineWindow(featureStateHostFor(m), appliedTimelineRef.current, next, isTimelineSourceActive);
13935
14364
  const threshold = autoLabelConfig.enabled ? autoLabelConfig.threshold : 220;
13936
- setVisibleFeatureCount(countVisibleFeatures(threshold));
13937
- setLabelsSuppressed(false);
14365
+ const count = countVisibleFeatures(threshold);
14366
+ if (tickCountTimerRef.current) clearTimeout(tickCountTimerRef.current);
14367
+ tickCountTimerRef.current = null;
14368
+ if (count < threshold !== visibleFeatureCountRef.current < threshold) setVisibleFeatureCount(count);
14369
+ else if (count !== visibleFeatureCountRef.current) {
14370
+ tickCountTimerRef.current = setTimeout(() => setVisibleFeatureCount(countVisibleFeatures(threshold)), TICK_COUNT_SETTLE_MS);
14371
+ }
14372
+ if (labelsSuppressedRef.current) setLabelsSuppressed(false);
13938
14373
  const selection = currentSelection() ?? EMPTY_ID_SET;
13939
- if (!sameOverlayTimelineInputs(overlayTimelineInputsRef.current, overlayTimelineInputs(selection, nextVisible))) {
13940
- refreshSelectionOverlay(m, selection);
13941
- }
13942
- mapPerfLog("timeline", "fast path applied", {
13943
- toggled,
13944
- endpointsMoved: (traceDiff == null ? void 0 : traceDiff.pointUpdates.length) ?? 0,
13945
- segmentsAdded: (traceDiff == null ? void 0 : traceDiff.segmentAdd.length) ?? 0,
13946
- segmentsRemoved: (traceDiff == null ? void 0 : traceDiff.segmentRemove.length) ?? 0
14374
+ if (selection.size > 0 && flipped.some((id) => selection.has(id))) refreshSelectionOverlay(m, selection);
14375
+ mapPerfLog("timeline", "applied", {
14376
+ flipped: flipped.length,
14377
+ sources: appliedTimelineRef.current.size,
14378
+ endpointsMoved,
14379
+ ms: Math.round(performance.now() - start)
13947
14380
  });
13948
14381
  return true;
13949
- }, [autoLabelConfig, countVisibleFeatures, currentSelection, refreshSelectionOverlay]);
14382
+ }, [autoLabelConfig, countVisibleFeatures, currentSelection, refreshSelectionOverlay, isTimelineSourceActive]);
13950
14383
  tryTimelineFastPathRef.current = tryTimelineFastPath;
14384
+ useEffect(() => () => {
14385
+ if (tickCountTimerRef.current) clearTimeout(tickCountTimerRef.current);
14386
+ }, []);
13951
14387
  const collectSelectionFeatureGroups = useCallback(() => {
13952
14388
  return collectVisibleFeatureGroups(
13953
14389
  draw.current ? draw.current.getAll().features : null,
@@ -15465,25 +15901,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15465
15901
  const handleDropGeoJSONFile = useCallback((name, file) => {
15466
15902
  void ingestDroppedLayer(name, file);
15467
15903
  }, [ingestDroppedLayer]);
15468
- const handleTimelineFilterChange = useCallback((visibleIds, hiddenIds, untimedIds) => {
15469
- if (!draw.current || !map.current) return;
15470
- const nextVisible = new Set(visibleIds);
15471
- untimedIds.forEach((id) => nextVisible.add(id));
15472
- timelineVisibleIdsRef.current = nextVisible;
15473
- scheduleSync("timeline");
15474
- }, [scheduleSync]);
15475
- const prevTimelineEnabledRef = useRef(timelineStore.isEnabled);
15904
+ const prevTimelineEnabledRef = useRef(timelineEnabled);
15476
15905
  useEffect(() => {
15477
15906
  const wasEnabled = prevTimelineEnabledRef.current;
15478
- const isNowEnabled = timelineStore.isEnabled;
15479
- prevTimelineEnabledRef.current = isNowEnabled;
15480
- if (!isNowEnabled || !timelineStore.hasTemporalData) {
15481
- timelineVisibleIdsRef.current = null;
15482
- scheduleSync("timeline");
15483
- } else if (!wasEnabled && isNowEnabled) {
15484
- updateTimelineStore();
15485
- }
15486
- }, [timelineStore.isEnabled, timelineStore.hasTemporalData, scheduleSync, updateTimelineStore, scheduleTimelineUpdate]);
15907
+ prevTimelineEnabledRef.current = timelineEnabled;
15908
+ if (!wasEnabled && timelineEnabled && timelineHasData) updateTimelineStore();
15909
+ }, [timelineEnabled, timelineHasData, updateTimelineStore]);
15487
15910
  useEffect(() => {
15488
15911
  if (!map.current || !draw.current || !isMapLoaded) return;
15489
15912
  const mapInstance = map.current;
@@ -15707,14 +16130,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15707
16130
  let categoryColorMap = {};
15708
16131
  let hasOtherBucket = false;
15709
16132
  if (groupByField) {
15710
- const counts = /* @__PURE__ */ new Map();
16133
+ const counts2 = /* @__PURE__ */ new Map();
15711
16134
  pointFeatures.forEach((f) => {
15712
16135
  var _a2;
15713
16136
  const key = categoricalKey((_a2 = f.properties) == null ? void 0 : _a2[groupByField]);
15714
16137
  if (key === null) return;
15715
- counts.set(key, (counts.get(key) ?? 0) + 1);
16138
+ counts2.set(key, (counts2.get(key) ?? 0) + 1);
15716
16139
  });
15717
- const sorted = Array.from(counts.entries()).sort((a, b) => b[1] - a[1]);
16140
+ const sorted = Array.from(counts2.entries()).sort((a, b) => b[1] - a[1]);
15718
16141
  const topKeys = sorted.slice(0, MAX_CATEGORIES).map(([k]) => k);
15719
16142
  categoryValues = [...topKeys];
15720
16143
  hasOtherBucket = true;
@@ -16235,21 +16658,21 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
16235
16658
  ] })
16236
16659
  }
16237
16660
  ),
16238
- enableTimeline && timelineStore.hasTemporalData && /* @__PURE__ */ jsx(
16661
+ enableTimeline && timelineHasData && /* @__PURE__ */ jsx(
16239
16662
  "div",
16240
16663
  {
16241
16664
  className: "absolute left-4 z-[200] transition-all",
16242
- style: { bottom: timelineStore.isEnabled ? TIMEBAR_HEIGHT + TIMEBAR_BOTTOM_OFFSET + 8 : 48 },
16665
+ style: { bottom: timelineEnabled ? TIMEBAR_HEIGHT + TIMEBAR_BOTTOM_OFFSET + 8 : 48 },
16243
16666
  children: /* @__PURE__ */ jsx(Tooltip, { title: "Timeline", placement: "right", children: /* @__PURE__ */ jsx(
16244
16667
  Button,
16245
16668
  {
16246
16669
  type: "default",
16247
16670
  icon: /* @__PURE__ */ jsx(Clock, { className: "w-5 h-5" }),
16248
- onClick: () => timelineStore.setEnabled(!timelineStore.isEnabled),
16671
+ onClick: () => timelineStoreApi.getState().setEnabled(!timelineEnabled),
16249
16672
  disabled: !isMapLoaded,
16250
- className: `!w-10 !h-10 !min-w-0 !p-0 bg-background shadow-lg ${timelineStore.isEnabled ? "bg-primary/10" : ""}`,
16673
+ className: `!w-10 !h-10 !min-w-0 !p-0 bg-background shadow-lg ${timelineEnabled ? "bg-primary/10" : ""}`,
16251
16674
  "aria-label": "Toggle timeline",
16252
- "aria-pressed": timelineStore.isEnabled,
16675
+ "aria-pressed": timelineEnabled,
16253
16676
  "data-testid": "button-toggle-timeline"
16254
16677
  }
16255
16678
  ) })
@@ -16308,6 +16731,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
16308
16731
  onMapStyleChange: handleMapStyleChange,
16309
16732
  onUpdateTraceConfig: handleUpdateTraceConfig,
16310
16733
  getAvailableTraceFields,
16734
+ getSuggestedTraceField,
16311
16735
  getFieldValueDistribution,
16312
16736
  onUpdateHeatmapConfig: handleUpdateHeatmapConfig,
16313
16737
  onUpdateClusterConfig: handleUpdateClusterConfig,
@@ -16387,10 +16811,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
16387
16811
  selectionMode
16388
16812
  }
16389
16813
  ),
16390
- enableTimeline && timelineStore.isEnabled && /* @__PURE__ */ jsx(
16814
+ enableTimeline && timelineEnabled && /* @__PURE__ */ jsx(
16391
16815
  Timebar,
16392
16816
  {
16393
- onFilterChange: handleTimelineFilterChange,
16394
16817
  selectedFeatureIds,
16395
16818
  selectedFeatureColors,
16396
16819
  timebarExtra
@@ -16425,7 +16848,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
16425
16848
  IngestProgressOverlay,
16426
16849
  {
16427
16850
  store: ingestProgressStore,
16428
- bottomPx: timelineStore.isEnabled ? TIMEBAR_HEIGHT + TIMEBAR_BOTTOM_OFFSET + 8 : 32
16851
+ bottomPx: timelineEnabled ? TIMEBAR_HEIGHT + TIMEBAR_BOTTOM_OFFSET + 8 : 32
16429
16852
  }
16430
16853
  ),
16431
16854
  /* @__PURE__ */ jsx(