@octostar/map-component 0.3.9 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -2056,9 +2056,9 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2056
2056
  });
2057
2057
  }
2058
2058
  }
2059
- let labelPriority = DEFAULT_LABEL_PRIORITY;
2059
+ let labelPriority2 = DEFAULT_LABEL_PRIORITY;
2060
2060
  if (((_i = f.properties) == null ? void 0 : _i.kind) === "text") {
2061
- labelPriority = ((_j = f.properties) == null ? void 0 : _j.fontWeight) === "bold" ? 8 : 10;
2061
+ labelPriority2 = ((_j = f.properties) == null ? void 0 : _j.fontWeight) === "bold" ? 8 : 10;
2062
2062
  } else {
2063
2063
  const idStr = String(featureId);
2064
2064
  let h = 0;
@@ -2066,7 +2066,7 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2066
2066
  h = (h << 5) - h + idStr.charCodeAt(i);
2067
2067
  h |= 0;
2068
2068
  }
2069
- labelPriority = DEFAULT_LABEL_PRIORITY + Math.abs(h) % 1e3;
2069
+ labelPriority2 = DEFAULT_LABEL_PRIORITY + Math.abs(h) % 1e3;
2070
2070
  }
2071
2071
  const visibleStrokeOpacity = hideFlatFor3DOnly ? 0 : baseOpacity;
2072
2072
  const visibleFillOpacity = hideFlatFor3DOnly ? 0 : ((_k = f.properties) == null ? void 0 : _k["fill-opacity"]) ?? DEFAULT_VISIBLE_FILL_OPACITY;
@@ -2093,7 +2093,7 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2093
2093
  fill: strokeColor,
2094
2094
  "fill-opacity": visibleFillOpacity,
2095
2095
  pointRadius,
2096
- _labelPriority: labelPriority,
2096
+ _labelPriority: labelPriority2,
2097
2097
  [LABEL_NEVER_HIDE_PROP]: computeLabelNeverHide((_l = layer == null ? void 0 : layer.visualConfig) == null ? void 0 : _l.label)
2098
2098
  }
2099
2099
  }
@@ -5424,6 +5424,114 @@ function LayersPanel({
5424
5424
  }
5425
5425
  );
5426
5426
  }
5427
+ function deepClone(value) {
5428
+ try {
5429
+ return structuredClone(value);
5430
+ } catch {
5431
+ return JSON.parse(JSON.stringify(value));
5432
+ }
5433
+ }
5434
+ function cloneFeatures(features) {
5435
+ try {
5436
+ return structuredClone(features);
5437
+ } catch {
5438
+ return features.map((f) => deepClone(f));
5439
+ }
5440
+ }
5441
+ function renderedFeatureId(f) {
5442
+ var _a;
5443
+ const fromProps = (_a = f.properties) == null ? void 0 : _a.id;
5444
+ if (fromProps !== void 0 && fromProps !== null && fromProps !== "") return String(fromProps);
5445
+ if (f.id !== void 0 && f.id !== null && f.id !== "") return String(f.id);
5446
+ return null;
5447
+ }
5448
+ function resolveTooltipFeature(rendered, lookup) {
5449
+ const id = renderedFeatureId(rendered);
5450
+ const stored = id === null ? null : lookup(id);
5451
+ if (stored) {
5452
+ return deepClone({
5453
+ type: "Feature",
5454
+ geometry: stored.geometry,
5455
+ properties: stored.properties ?? {},
5456
+ id: stored.id
5457
+ });
5458
+ }
5459
+ return {
5460
+ type: "Feature",
5461
+ geometry: rendered.geometry,
5462
+ properties: { ...rendered.properties ?? {} },
5463
+ id: rendered.id
5464
+ };
5465
+ }
5466
+ const DEFAULT_POINT_RADIUS = 5;
5467
+ const MAX_POINT_RADIUS = 18;
5468
+ const SAME_SPOT_PX = 1;
5469
+ const CROWD = 16;
5470
+ const SCAN_LIMIT = 256;
5471
+ const isDot = (m) => m.center !== null;
5472
+ const distance = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
5473
+ function paintedRadius(f) {
5474
+ var _a, _b;
5475
+ const p = f.properties ?? {};
5476
+ const hidden = ((_a = f.state) == null ? void 0 : _a[TIMELINE_HIDDEN_KEY]) === true || p.isHiddenByCluster === 1 || p.isHiddenByHeatmap === 1 || typeof p.icon === "string" && p.icon !== "";
5477
+ if (hidden) return 0;
5478
+ const r = ((_b = f.state) == null ? void 0 : _b[TRACE_ENDPOINT_KEY]) === true ? p._endpointRadius : p.pointRadius;
5479
+ return typeof r === "number" && Number.isFinite(r) ? r : DEFAULT_POINT_RADIUS;
5480
+ }
5481
+ function labelPriority(f) {
5482
+ var _a;
5483
+ const v = (_a = f.properties) == null ? void 0 : _a._labelPriority;
5484
+ return typeof v === "number" && Number.isFinite(v) ? v : DEFAULT_LABEL_PRIORITY;
5485
+ }
5486
+ function members(features, project, maxDots = Infinity) {
5487
+ const seen = /* @__PURE__ */ new Set();
5488
+ const out = [];
5489
+ let dots = 0;
5490
+ for (const feature of features) {
5491
+ const id = renderedFeatureId(feature);
5492
+ if (id === null || seen.has(id)) continue;
5493
+ if (seen.size === SCAN_LIMIT || dots === maxDots) return { members: out, cut: true };
5494
+ seen.add(id);
5495
+ if (feature.geometry.type !== "Point") {
5496
+ out.push({ id, feature, center: null, radius: 0 });
5497
+ continue;
5498
+ }
5499
+ const radius = paintedRadius(feature);
5500
+ if (radius <= 0) continue;
5501
+ out.push({ id, feature, center: project(feature.geometry.coordinates), radius });
5502
+ dots++;
5503
+ }
5504
+ return { members: out, cut: false };
5505
+ }
5506
+ function searchBox(dot) {
5507
+ const reach = dot.radius + MAX_POINT_RADIUS;
5508
+ return [[dot.center.x - reach, dot.center.y - reach], [dot.center.x + reach, dot.center.y + reach]];
5509
+ }
5510
+ const MORE_POINTS_HINT = "More points overlap here: zoom in to reach them";
5511
+ function featureStackAt(point, hits, queryBox, project) {
5512
+ const hit = members(hits, project, CROWD + 1).members;
5513
+ const under = hit.filter(isDot);
5514
+ if (under.length === 0) return { features: hit.length > 0 ? [hit[0].feature] : [], more: false };
5515
+ const fromCursor = (d) => distance(d.center, point);
5516
+ const byCursor = (a, b) => fromCursor(a) - fromCursor(b);
5517
+ let dots;
5518
+ let more;
5519
+ if (under.length > CROWD) {
5520
+ dots = under.sort(byCursor).slice(0, CROWD);
5521
+ more = true;
5522
+ } else {
5523
+ const nearest = under.reduce((a, b) => fromCursor(b) < fromCursor(a) ? b : a);
5524
+ const taken = new Set(under.map((d) => d.id));
5525
+ const box = members(queryBox(searchBox(nearest)), project);
5526
+ const neighbours = box.members.filter(isDot).filter((m) => !taken.has(m.id) && distance(m.center, nearest.center) <= m.radius + nearest.radius);
5527
+ dots = [...under, ...neighbours].sort(byCursor);
5528
+ more = box.cut;
5529
+ }
5530
+ const spot = dots[0].center;
5531
+ const onSpot = dots.filter((d) => distance(d.center, spot) < SAME_SPOT_PX).sort((a, b) => labelPriority(a.feature) - labelPriority(b.feature));
5532
+ const rest = dots.filter((d) => distance(d.center, spot) >= SAME_SPOT_PX);
5533
+ return { features: [...onSpot, ...rest].map((d) => d.feature), more };
5534
+ }
5427
5535
  const { TextArea } = antd.Input;
5428
5536
  function formatDateForState(value) {
5429
5537
  if (!value) return "";
@@ -5464,6 +5572,40 @@ function EntityCardsList({
5464
5572
  ] })
5465
5573
  ] });
5466
5574
  }
5575
+ function StackPager({ stack }) {
5576
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-3 py-1 border-b border-border shrink-0 text-xs text-muted-foreground", children: [
5577
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Tooltip, { title: "Previous overlapping point", children: /* @__PURE__ */ jsxRuntime.jsx(
5578
+ antd.Button,
5579
+ {
5580
+ type: "text",
5581
+ icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeft, { className: "w-3.5 h-3.5" }),
5582
+ disabled: stack.position === 0,
5583
+ onClick: () => stack.onStep(-1),
5584
+ className: "!w-6 !h-6 !min-w-0 !p-0",
5585
+ "aria-label": "Previous overlapping point",
5586
+ "data-testid": "button-stack-prev"
5587
+ }
5588
+ ) }),
5589
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Tooltip, { title: stack.more ? MORE_POINTS_HINT : void 0, children: /* @__PURE__ */ jsxRuntime.jsxs("span", { "data-testid": "panel-stack-position", children: [
5590
+ stack.position + 1,
5591
+ " / ",
5592
+ stack.count,
5593
+ stack.more ? "+" : ""
5594
+ ] }) }),
5595
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Tooltip, { title: "Next overlapping point", children: /* @__PURE__ */ jsxRuntime.jsx(
5596
+ antd.Button,
5597
+ {
5598
+ type: "text",
5599
+ icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { className: "w-3.5 h-3.5" }),
5600
+ disabled: stack.position === stack.count - 1,
5601
+ onClick: () => stack.onStep(1),
5602
+ className: "!w-6 !h-6 !min-w-0 !p-0",
5603
+ "aria-label": "Next overlapping point",
5604
+ "data-testid": "button-stack-next"
5605
+ }
5606
+ ) })
5607
+ ] });
5608
+ }
5467
5609
  function getFeatureTypeIcon(geometryType, kind, size = "sm") {
5468
5610
  const cls = size === "lg" ? "w-5 h-5" : "w-4 h-4";
5469
5611
  if (kind === "text") {
@@ -5684,7 +5826,7 @@ function RecordFieldsSection({ feature }) {
5684
5826
  );
5685
5827
  }
5686
5828
  let persistedTabPreference = "properties";
5687
- function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometry, onClose, isEditMode = true, isReadOnlyLayer = false, layerName, layerId, autoFocusLabel = false, entityCardProvider, entityCardPlacement = "tab", inlineEntityCardLabel = "Point Detail", typePickerProvider, featureSaveProvider, featureRefreshProvider, onFeatureSaved, onDeleteFeatures, onOpenInNewTab, onEntityContextMenu, layers, onMoveFeaturesToLayer, onCopyFeaturesToLayer, onCreateLayerAndMoveFeatures, onCreateLayerAndCopyFeatures, getFeatureColor, anchorEl }) {
5829
+ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometry, onClose, isEditMode = true, isReadOnlyLayer = false, layerName, layerId, autoFocusLabel = false, entityCardProvider, entityCardPlacement = "tab", inlineEntityCardLabel = "Point Detail", typePickerProvider, featureSaveProvider, featureRefreshProvider, onFeatureSaved, onDeleteFeatures, onOpenInNewTab, onEntityContextMenu, layers, onMoveFeaturesToLayer, onCopyFeaturesToLayer, onCreateLayerAndMoveFeatures, onCreateLayerAndCopyFeatures, getFeatureColor, anchorEl, stack }) {
5688
5830
  var _a, _b, _c, _d, _e;
5689
5831
  const feature = selectedFeatures[0];
5690
5832
  const { toast } = useToast();
@@ -6979,6 +7121,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
6979
7121
  /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { type: "text", icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "w-4 h-4" }), onClick: onClose, className: "!w-6 !h-6 !min-w-0 !p-0 shrink-0", "data-testid": "button-close-properties" })
6980
7122
  ] })
6981
7123
  ] }),
7124
+ stack && !hasMultipleSelection && /* @__PURE__ */ jsxRuntime.jsx(StackPager, { stack }),
6982
7125
  /* @__PURE__ */ jsxRuntime.jsx(
6983
7126
  antd.Tabs,
6984
7127
  {
@@ -7111,6 +7254,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
7111
7254
  /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { type: "text", icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "w-4 h-4" }), onClick: onClose, className: "!w-6 !h-6 !min-w-0 !p-0 shrink-0", "data-testid": "button-close-properties" })
7112
7255
  ] })
7113
7256
  ] }),
7257
+ stack && /* @__PURE__ */ jsxRuntime.jsx(StackPager, { stack }),
7114
7258
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 overflow-y-auto overflow-x-hidden scrollbar-visible", children: panelContent })
7115
7259
  ]
7116
7260
  }
@@ -8560,20 +8704,6 @@ function suggestTraceGroupField(features, fields) {
8560
8704
  };
8561
8705
  return ((_a = candidates.find((c) => splitsIntoTracks(c.field))) == null ? void 0 : _a.field) ?? null;
8562
8706
  }
8563
- function deepClone(value) {
8564
- try {
8565
- return structuredClone(value);
8566
- } catch {
8567
- return JSON.parse(JSON.stringify(value));
8568
- }
8569
- }
8570
- function cloneFeatures(features) {
8571
- try {
8572
- return structuredClone(features);
8573
- } catch {
8574
- return features.map((f) => deepClone(f));
8575
- }
8576
- }
8577
8707
  function numberEquals(a, b) {
8578
8708
  return a === b || !Number.isFinite(a) && !Number.isFinite(b);
8579
8709
  }
@@ -8839,31 +8969,6 @@ function buildSelectionOverlayData(ids, styleFor) {
8839
8969
  });
8840
8970
  return { type: "FeatureCollection", features };
8841
8971
  }
8842
- function renderedFeatureId(f) {
8843
- var _a;
8844
- const fromProps = (_a = f.properties) == null ? void 0 : _a.id;
8845
- if (fromProps !== void 0 && fromProps !== null && fromProps !== "") return String(fromProps);
8846
- if (f.id !== void 0 && f.id !== null && f.id !== "") return String(f.id);
8847
- return null;
8848
- }
8849
- function resolveTooltipFeature(rendered, lookup) {
8850
- const id = renderedFeatureId(rendered);
8851
- const stored = id === null ? null : lookup(id);
8852
- if (stored) {
8853
- return deepClone({
8854
- type: "Feature",
8855
- geometry: stored.geometry,
8856
- properties: stored.properties ?? {},
8857
- id: stored.id
8858
- });
8859
- }
8860
- return {
8861
- type: "Feature",
8862
- geometry: rendered.geometry,
8863
- properties: { ...rendered.properties ?? {} },
8864
- id: rendered.id
8865
- };
8866
- }
8867
8972
  const CLUSTER_COUNT_VALUE_PROP = "__cluster_count_value";
8868
8973
  const CLUSTER_SUM_PROP = "value_sum";
8869
8974
  const CLUSTER_MEMBER_ID_PROP = "__cluster_fid";
@@ -9939,6 +10044,25 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9939
10044
  }
9940
10045
  return getReadOnlyFeatureById(id);
9941
10046
  }, [getReadOnlyFeatureById]);
10047
+ const stackFromHits = react.useCallback((point, hits) => {
10048
+ var _a;
10049
+ const m = map.current;
10050
+ const layers2 = ((_a = shardRegistryRef.current) == null ? void 0 : _a.interactiveLayerIds()) ?? [];
10051
+ if (!m || layers2.length === 0) return { features: [], more: false };
10052
+ return featureStackAt(point, hits, (box) => m.queryRenderedFeatures(box, { layers: layers2 }), (lngLat) => m.project(lngLat));
10053
+ }, []);
10054
+ const featureStackAtPoint = react.useCallback((point) => {
10055
+ var _a;
10056
+ const m = map.current;
10057
+ const layers2 = ((_a = shardRegistryRef.current) == null ? void 0 : _a.interactiveLayerIds()) ?? [];
10058
+ if (!m || layers2.length === 0) return { features: [], more: false };
10059
+ return stackFromHits(point, m.queryRenderedFeatures([point.x, point.y], { layers: layers2 }));
10060
+ }, [stackFromHits]);
10061
+ const [selectionStack, setSelectionStack] = react.useState(null);
10062
+ const selectionStackPosition = selectionStack && selectedFeatureIds.length === 1 ? selectionStack.ids.indexOf(selectedFeatureIds[0]) : -1;
10063
+ react.useEffect(() => {
10064
+ if (selectionStack && selectionStackPosition < 0) setSelectionStack(null);
10065
+ }, [selectionStack, selectionStackPosition]);
9942
10066
  const appliedSelectionRef = react.useRef(/* @__PURE__ */ new Map());
9943
10067
  const locatorCacheRef = react.useRef(createLocatorCache());
9944
10068
  const shardedLayerIdsRef = react.useRef(EMPTY_ID_SET);
@@ -10019,11 +10143,19 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10019
10143
  }
10020
10144
  scheduleSync("selection");
10021
10145
  if (readOnlyIds.length > 0) {
10022
- queueMicrotask(() => {
10146
+ requestAnimationFrame(() => {
10023
10147
  isSelectingReadOnlyRef.current = false;
10024
10148
  });
10025
10149
  }
10026
10150
  }, [isMapLoaded, getFeatureById, onFeatureSelect]);
10151
+ const applySelectionStateRef = react.useRef(applySelectionState$1);
10152
+ applySelectionStateRef.current = applySelectionState$1;
10153
+ const stepSelectionStack = react.useCallback((delta) => {
10154
+ if (!selectionStack || selectionStackPosition < 0) return;
10155
+ const next = selectionStack.ids[selectionStackPosition + delta];
10156
+ if (next === void 0 || getFeatureById(next) === null) return;
10157
+ applySelectionState$1([next], { focusProperties: true });
10158
+ }, [selectionStack, selectionStackPosition, getFeatureById, applySelectionState$1]);
10027
10159
  const updateFeatureCount = react.useCallback(() => {
10028
10160
  const drawFeatureCount = draw.current ? draw.current.getAll().features.length : 0;
10029
10161
  let hiddenCount = 0;
@@ -11160,7 +11292,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11160
11292
  }
11161
11293
  const tooltipEl2 = document.createElement("div");
11162
11294
  tooltipEl2.className = "feature-tooltip-fixed";
11163
- tooltipEl2.style.cssText = "position:fixed;z-index:1000;pointer-events:auto;display:none;max-width:480px;";
11295
+ tooltipEl2.style.cssText = "position:fixed;z-index:1000;pointer-events:auto;display:none;max-width:480px;box-sizing:border-box;";
11164
11296
  document.body.appendChild(tooltipEl2);
11165
11297
  tooltipElRef.current = tooltipEl2;
11166
11298
  let tooltipLngLat = null;
@@ -11168,6 +11300,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11168
11300
  let tooltipShowTimeout = null;
11169
11301
  let isMouseOverPopup = false;
11170
11302
  let tooltipFeatures = [];
11303
+ let tooltipMore = false;
11171
11304
  let tooltipPageIndex = 0;
11172
11305
  let tooltipLngLatForPagination = null;
11173
11306
  let lastHoveredGeomType = null;
@@ -11211,6 +11344,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11211
11344
  tooltipEl2.style.minHeight = "";
11212
11345
  tooltipLngLat = null;
11213
11346
  tooltipFeatures = [];
11347
+ tooltipMore = false;
11214
11348
  tooltipPageIndex = 0;
11215
11349
  tooltipLngLatForPagination = null;
11216
11350
  };
@@ -11292,23 +11426,28 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11292
11426
  html += "</div>";
11293
11427
  return html;
11294
11428
  };
11295
- const renderTooltipPage = () => {
11296
- if (tooltipFeatures.length === 0 || !tooltipLngLatForPagination) return;
11297
- const feature = tooltipFeatures[tooltipPageIndex];
11429
+ const tooltipPageHtml = () => {
11430
+ const feature = resolveRendered(tooltipFeatures[tooltipPageIndex]);
11298
11431
  let html = null;
11299
11432
  if (tooltipProviderRef.current) {
11300
11433
  html = tooltipProviderRef.current(feature);
11301
11434
  } else {
11302
11435
  html = buildBuiltinTooltipHtml(feature);
11303
11436
  }
11304
- if (!html) return;
11437
+ if (!html) return null;
11305
11438
  if (tooltipFeatures.length > 1) {
11306
11439
  const prevDisabled = tooltipPageIndex === 0;
11307
11440
  const nextDisabled = tooltipPageIndex === tooltipFeatures.length - 1;
11308
11441
  const btnBase = "background:none;border-radius:4px;padding:1px 8px;font-size:12px;line-height:1.4;";
11309
- const navHtml = `<div style="display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid #eee;padding:4px 0 6px;margin-bottom:4px;font-size:12px;color:#666;user-select:none"><button data-tooltip-nav="prev" style="${btnBase}border:1px solid ${prevDisabled ? "#eee" : "#ddd"};cursor:${prevDisabled ? "default" : "pointer"};color:${prevDisabled ? "#ccc" : "#444"}"${prevDisabled ? " disabled" : ""}>&lsaquo;</button><span>${tooltipPageIndex + 1} / ${tooltipFeatures.length}</span><button data-tooltip-nav="next" style="${btnBase}border:1px solid ${nextDisabled ? "#eee" : "#ddd"};cursor:${nextDisabled ? "default" : "pointer"};color:${nextDisabled ? "#ccc" : "#444"}"${nextDisabled ? " disabled" : ""}>&rsaquo;</button></div>`;
11442
+ const navHtml = `<div style="display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid #eee;padding:4px 0 6px;margin-bottom:4px;font-size:12px;color:#666;user-select:none"><button data-tooltip-nav="prev" style="${btnBase}border:1px solid ${prevDisabled ? "#eee" : "#ddd"};cursor:${prevDisabled ? "default" : "pointer"};color:${prevDisabled ? "#ccc" : "#444"}"${prevDisabled ? " disabled" : ""}>&lsaquo;</button><span${tooltipMore ? ` title="${MORE_POINTS_HINT}"` : ""}>${tooltipPageIndex + 1} / ${tooltipFeatures.length}${tooltipMore ? "+" : ""}</span><button data-tooltip-nav="next" style="${btnBase}border:1px solid ${nextDisabled ? "#eee" : "#ddd"};cursor:${nextDisabled ? "default" : "pointer"};color:${nextDisabled ? "#ccc" : "#444"}"${nextDisabled ? " disabled" : ""}>&rsaquo;</button></div>`;
11310
11443
  html = navHtml + html;
11311
11444
  }
11445
+ return html;
11446
+ };
11447
+ const renderTooltipPage = () => {
11448
+ if (tooltipFeatures.length === 0 || !tooltipLngLatForPagination) return;
11449
+ const html = tooltipPageHtml();
11450
+ if (!html) return;
11312
11451
  if (tooltipPageIndex > 0 && tooltipFeatures.length > 1) {
11313
11452
  tooltipEl2.style.minWidth = tooltipEl2.offsetWidth + "px";
11314
11453
  tooltipEl2.style.minHeight = tooltipEl2.offsetHeight + "px";
@@ -11340,8 +11479,10 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11340
11479
  }
11341
11480
  return fallback;
11342
11481
  };
11343
- const showTooltipForFeatures = (e) => {
11482
+ const stackKey = (stack) => stack.features.map(getFeatureKey).join("\n") + (stack.more ? "\n+" : "");
11483
+ const showTooltipForFeatures = (e, hover) => {
11344
11484
  var _a2;
11485
+ const stack = hover.features;
11345
11486
  if (tooltipShowTimeout) {
11346
11487
  clearTimeout(tooltipShowTimeout);
11347
11488
  tooltipShowTimeout = null;
@@ -11358,63 +11499,22 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11358
11499
  clearTimeout(tooltipHideTimeout);
11359
11500
  tooltipHideTimeout = null;
11360
11501
  }
11361
- if (!e.features || e.features.length === 0) return;
11362
- const topFeature = e.features[0];
11502
+ if (stack.length === 0) return;
11503
+ const topFeature = stack[0];
11363
11504
  const topGeomType = (_a2 = topFeature.geometry) == null ? void 0 : _a2.type;
11364
11505
  const topIsPolygon = topGeomType === "Polygon" || topGeomType === "MultiPolygon";
11365
11506
  const coordinates = topIsPolygon ? e.lngLat : getFeatureAnchor(topFeature, e.lngLat);
11366
- lastHoveredFeatureKey = getFeatureKey(topFeature);
11507
+ lastHoveredFeatureKey = stackKey(hover);
11367
11508
  lastHoveredGeomType = topGeomType || null;
11368
11509
  tooltipShowTimeout = setTimeout(() => {
11369
- var _a3, _b2, _c, _d;
11510
+ var _a3, _b2;
11370
11511
  tooltipShowTimeout = null;
11371
11512
  if (isDrawingSelection.current) return;
11372
11513
  const drawMode = (_b2 = (_a3 = draw.current) == null ? void 0 : _a3.getMode) == null ? void 0 : _b2.call(_a3);
11373
11514
  const tooltipAllowedModes = ["simple_select", "direct_select", "view_select"];
11374
11515
  if (drawMode && !tooltipAllowedModes.includes(drawMode)) return;
11375
- if (!((_c = e.features) == null ? void 0 : _c.length)) return;
11376
- const hoveredFeature = e.features[0];
11377
- const hoveredGeom = hoveredFeature.geometry;
11378
- let hoveredCoords = null;
11379
- if (hoveredGeom.type === "Point") {
11380
- hoveredCoords = hoveredGeom.coordinates;
11381
- }
11382
- const seen = /* @__PURE__ */ new Set();
11383
- const uniqueFeatures = [];
11384
- const addUnique = (f) => {
11385
- const fid = String((f.properties || {}).id || f.id || "");
11386
- if (fid && seen.has(fid)) return;
11387
- if (fid) seen.add(fid);
11388
- uniqueFeatures.push({
11389
- type: "Feature",
11390
- geometry: f.geometry,
11391
- properties: { ...f.properties || {} },
11392
- id: f.id
11393
- });
11394
- };
11395
- addUnique(resolveRendered(hoveredFeature));
11396
- if (hoveredCoords) {
11397
- const allFeatures = [];
11398
- if (draw.current) {
11399
- pushAll(allFeatures, draw.current.getAll().features);
11400
- }
11401
- readOnlyFeatures.current.forEach((features, lid) => {
11402
- const layer = layersRef.current.find((l) => l.id === lid);
11403
- if (layer == null ? void 0 : layer.visible) pushAll(allFeatures, features);
11404
- });
11405
- const EPS = 1e-6;
11406
- for (const cf of allFeatures) {
11407
- if (((_d = cf.geometry) == null ? void 0 : _d.type) !== "Point") continue;
11408
- const cc = cf.geometry.coordinates;
11409
- if (Math.abs(cc[0] - hoveredCoords[0]) < EPS && Math.abs(cc[1] - hoveredCoords[1]) < EPS) {
11410
- addUnique(cf);
11411
- }
11412
- }
11413
- }
11414
- if (uniqueFeatures.length === 0) {
11415
- addUnique(resolveRendered(hoveredFeature));
11416
- }
11417
- tooltipFeatures = uniqueFeatures;
11516
+ tooltipFeatures = stack;
11517
+ tooltipMore = hover.more;
11418
11518
  tooltipPageIndex = 0;
11419
11519
  tooltipLngLatForPagination = coordinates;
11420
11520
  if (tooltipHideTimeout) {
@@ -11424,56 +11524,74 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11424
11524
  renderTooltipPage();
11425
11525
  }, 250);
11426
11526
  };
11527
+ const moveTooltip = (e, hover) => {
11528
+ var _a2;
11529
+ const stack = hover.features;
11530
+ if (stack.length === 0) return;
11531
+ const geomType = (_a2 = stack[0].geometry) == null ? void 0 : _a2.type;
11532
+ const isPolygon = geomType === "Polygon" || geomType === "MultiPolygon";
11533
+ if (isPolygon && tooltipEl2.style.display !== "none" && !isMouseOverPopup) {
11534
+ tooltipLngLat = e.lngLat;
11535
+ tooltipLngLatForPagination = e.lngLat;
11536
+ positionTooltip();
11537
+ }
11538
+ const currentKey = stackKey(hover);
11539
+ if (currentKey === lastHoveredFeatureKey) return;
11540
+ if (tooltipEl2.style.display !== "none") {
11541
+ if (tooltipShowTimeout) {
11542
+ clearTimeout(tooltipShowTimeout);
11543
+ tooltipShowTimeout = null;
11544
+ }
11545
+ if (tooltipHideTimeout) {
11546
+ clearTimeout(tooltipHideTimeout);
11547
+ tooltipHideTimeout = null;
11548
+ }
11549
+ lastHoveredFeatureKey = currentKey;
11550
+ lastHoveredGeomType = geomType || null;
11551
+ const anchorLngLat = isPolygon ? e.lngLat : getFeatureAnchor(stack[0], e.lngLat);
11552
+ tooltipFeatures = stack;
11553
+ tooltipMore = hover.more;
11554
+ tooltipPageIndex = 0;
11555
+ tooltipLngLatForPagination = anchorLngLat;
11556
+ tooltipEl2.style.minWidth = "";
11557
+ tooltipEl2.style.minHeight = "";
11558
+ const html = tooltipPageHtml();
11559
+ if (html) {
11560
+ tooltipEl2.innerHTML = html;
11561
+ tooltipLngLat = anchorLngLat;
11562
+ positionTooltip();
11563
+ }
11564
+ } else {
11565
+ showTooltipForFeatures(e, hover);
11566
+ }
11567
+ };
11568
+ let pendingHover = null;
11569
+ const flushHover = ({ e, hits, entered }) => {
11570
+ if (hits.length === 0) return;
11571
+ const order = mapInstance.getLayersOrder();
11572
+ const z = (list) => order.indexOf(list[0].layer.id);
11573
+ const all = hits.length === 1 ? hits[0] : [].concat(...[...hits].sort((a, b) => z(b) - z(a)));
11574
+ const hover = stackFromHits(e.point, all);
11575
+ if (entered) showTooltipForFeatures(e, hover);
11576
+ else moveTooltip(e, hover);
11577
+ };
11578
+ const collectHover = (e, entered) => {
11579
+ var _a2;
11580
+ if (!pendingHover || pendingHover.e.originalEvent !== e.originalEvent) {
11581
+ const pending = { e, hits: [], entered: false };
11582
+ pendingHover = pending;
11583
+ queueMicrotask(() => flushHover(pending));
11584
+ }
11585
+ if (entered) pendingHover.entered = true;
11586
+ else if ((_a2 = e.features) == null ? void 0 : _a2.length) pendingHover.hits.push(e.features);
11587
+ };
11427
11588
  const bindHoverHandlers = (layerId) => {
11428
11589
  if (hoverHandlersByLayer.has(layerId)) return;
11429
11590
  const onMouseEnter = (e) => {
11430
11591
  mapInstance.getCanvas().style.cursor = "pointer";
11431
- showTooltipForFeatures(e);
11432
- };
11433
- const onMouseMove = (e) => {
11434
- var _a2;
11435
- if (!e.features || e.features.length === 0) return;
11436
- const geomType = (_a2 = e.features[0].geometry) == null ? void 0 : _a2.type;
11437
- const isPolygon = geomType === "Polygon" || geomType === "MultiPolygon";
11438
- if (isPolygon && tooltipEl2.style.display !== "none" && !isMouseOverPopup) {
11439
- tooltipLngLat = e.lngLat;
11440
- tooltipLngLatForPagination = e.lngLat;
11441
- positionTooltip();
11442
- }
11443
- const currentKey = getFeatureKey(e.features[0]);
11444
- if (currentKey === lastHoveredFeatureKey) return;
11445
- if (tooltipEl2.style.display !== "none") {
11446
- if (tooltipShowTimeout) {
11447
- clearTimeout(tooltipShowTimeout);
11448
- tooltipShowTimeout = null;
11449
- }
11450
- if (tooltipHideTimeout) {
11451
- clearTimeout(tooltipHideTimeout);
11452
- tooltipHideTimeout = null;
11453
- }
11454
- lastHoveredFeatureKey = currentKey;
11455
- lastHoveredGeomType = geomType || null;
11456
- const feature = e.features[0];
11457
- const featureObj = resolveRendered(feature);
11458
- const anchorLngLat = isPolygon ? e.lngLat : getFeatureAnchor(feature, e.lngLat);
11459
- tooltipFeatures = [featureObj];
11460
- tooltipPageIndex = 0;
11461
- tooltipLngLatForPagination = anchorLngLat;
11462
- let html = null;
11463
- if (tooltipProviderRef.current) {
11464
- html = tooltipProviderRef.current(featureObj);
11465
- } else {
11466
- html = buildBuiltinTooltipHtml(featureObj);
11467
- }
11468
- if (html) {
11469
- tooltipEl2.innerHTML = html;
11470
- tooltipLngLat = anchorLngLat;
11471
- positionTooltip();
11472
- }
11473
- } else {
11474
- showTooltipForFeatures(e);
11475
- }
11592
+ collectHover(e, true);
11476
11593
  };
11594
+ const onMouseMove = (e) => collectHover(e, false);
11477
11595
  const onMouseLeave = () => {
11478
11596
  mapInstance.getCanvas().style.cursor = "";
11479
11597
  const wasPolygon = lastHoveredGeomType === "Polygon" || lastHoveredGeomType === "MultiPolygon";
@@ -11511,7 +11629,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11511
11629
  if (e.features && e.features.length > 0) {
11512
11630
  const props = e.features[0].properties || {};
11513
11631
  const duration = props.duration || "";
11514
- const distance = props.distance || "";
11632
+ const distance2 = props.distance || "";
11515
11633
  const avgSpeed = props.avgSpeed || "";
11516
11634
  const group = props.group !== "__all__" ? props.group : null;
11517
11635
  const fromName = props.fromName || "";
@@ -11522,7 +11640,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11522
11640
  }
11523
11641
  html += '<div class="space-y-0.5">';
11524
11642
  html += `<div><span class="text-muted-foreground">Duration:</span> <span class="font-medium">${duration}</span></div>`;
11525
- html += `<div><span class="text-muted-foreground">Distance:</span> <span class="font-medium">${distance}</span></div>`;
11643
+ html += `<div><span class="text-muted-foreground">Distance:</span> <span class="font-medium">${distance2}</span></div>`;
11526
11644
  html += `<div><span class="text-muted-foreground">Avg Speed:</span> <span class="font-medium">${avgSpeed}</span></div>`;
11527
11645
  html += "</div>";
11528
11646
  if (group) {
@@ -11926,15 +12044,18 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11926
12044
  scheduleSync();
11927
12045
  });
11928
12046
  mapInstance.on("click", (e) => {
11929
- var _a, _b, _c;
12047
+ var _a, _b;
11930
12048
  if (!enableSelectionRef.current) return;
11931
12049
  if (e.originalEvent.button !== 0) return;
11932
12050
  if (contextMenuFiredRef.current) return;
11933
12051
  if (Date.now() - shiftSelectionRef.current.completedAt < 300) return;
11934
12052
  const isModifierKey = e.originalEvent.ctrlKey || e.originalEvent.metaKey;
11935
- const features = mapInstance.queryRenderedFeatures(e.point, {
11936
- layers: ((_a = shardRegistryRef.current) == null ? void 0 : _a.interactiveLayerIds()) ?? []
11937
- });
12053
+ const stack = featureStackAtPoint(e.point);
12054
+ const features = stack.features;
12055
+ const stackIds = isModifierKey || e.originalEvent.shiftKey ? [] : features.map((f) => {
12056
+ var _a2;
12057
+ return String(((_a2 = f.properties) == null ? void 0 : _a2.id) ?? "");
12058
+ }).filter((id) => id !== "" && getFeatureById(id) !== null);
11938
12059
  let clusteredFeatureId = null;
11939
12060
  if (features.length === 0) {
11940
12061
  const clusterOverlayIds = layersRef.current.filter((l) => {
@@ -11948,11 +12069,11 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11948
12069
  }
11949
12070
  return;
11950
12071
  }
11951
- const memberId = (_b = clusterHit.properties) == null ? void 0 : _b[CLUSTER_MEMBER_ID_PROP];
12072
+ const memberId = (_a = clusterHit.properties) == null ? void 0 : _a[CLUSTER_MEMBER_ID_PROP];
11952
12073
  if (memberId == null || memberId === "") return;
11953
12074
  clusteredFeatureId = String(memberId);
11954
12075
  }
11955
- const featureId = clusteredFeatureId ?? ((_c = features[0].properties) == null ? void 0 : _c.id);
12076
+ const featureId = clusteredFeatureId ?? ((_b = features[0].properties) == null ? void 0 : _b.id);
11956
12077
  if (!featureId) return;
11957
12078
  let isReadOnly = false;
11958
12079
  readOnlyFeatures.current.forEach((layerFeatures) => {
@@ -11961,8 +12082,11 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11961
12082
  }
11962
12083
  });
11963
12084
  if (!isReadOnly) {
11964
- const currentMode = drawInstance.getMode();
11965
- if (currentMode !== "simple_select") return;
12085
+ const mode = drawInstance.getMode();
12086
+ if (stackIds.length > 1 && (mode === "simple_select" || mode === "view_select")) {
12087
+ setSelectionStack({ ids: stackIds, more: stack.more });
12088
+ applySelectionStateRef.current([String(featureId)]);
12089
+ }
11966
12090
  return;
11967
12091
  }
11968
12092
  const fid = String(featureId);
@@ -11974,6 +12098,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11974
12098
  } else {
11975
12099
  nextIds = isAlreadySelected ? currentSelection2.filter((id) => id !== fid) : [fid];
11976
12100
  }
12101
+ setSelectionStack(stackIds.length > 1 && nextIds.length === 1 && nextIds[0] === fid ? { ids: stackIds, more: stack.more } : null);
11977
12102
  isSelectingReadOnlyRef.current = true;
11978
12103
  if (drawInstance.getSelected().features.length > 0) {
11979
12104
  drawInstance.changeMode("simple_select", { featureIds: [] });
@@ -11990,9 +12115,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11990
12115
  });
11991
12116
  }
11992
12117
  onFeatureSelect == null ? void 0 : onFeatureSelect(selectedFeatures2);
11993
- setTimeout(() => {
12118
+ requestAnimationFrame(() => {
11994
12119
  isSelectingReadOnlyRef.current = false;
11995
- }, 0);
12120
+ });
11996
12121
  });
11997
12122
  mapInstance.on("error", (e) => {
11998
12123
  var _a, _b;
@@ -13172,20 +13297,17 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13172
13297
  onFeatureCreate == null ? void 0 : onFeatureCreate(feature);
13173
13298
  }, [isMapLoaded, externalPersistence, enableProperties, autoOpenProperties, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, onFeatureCreate]);
13174
13299
  const handleFeatureContextMenu = react.useCallback((e) => {
13175
- var _a, _b, _c;
13300
+ var _a, _b;
13176
13301
  contextMenuFiredRef.current = true;
13177
13302
  setTimeout(() => {
13178
13303
  contextMenuFiredRef.current = false;
13179
13304
  }, 0);
13180
13305
  if (!map.current) return;
13181
13306
  const mapInstance = map.current;
13182
- const point = [e.offsetX, e.offsetY];
13183
- const clickedFeatures = mapInstance.queryRenderedFeatures(point, {
13184
- layers: ((_a = shardRegistryRef.current) == null ? void 0 : _a.interactiveLayerIds()) ?? []
13185
- });
13307
+ const clickedFeatures = featureStackAtPoint({ x: e.offsetX, y: e.offsetY }).features;
13186
13308
  let features = [];
13187
13309
  if (clickedFeatures.length > 0) {
13188
- const clickedId = String(((_b = clickedFeatures[0].properties) == null ? void 0 : _b.id) || clickedFeatures[0].id);
13310
+ const clickedId = String(((_a = clickedFeatures[0].properties) == null ? void 0 : _a.id) || clickedFeatures[0].id);
13189
13311
  let clickedFeature = null;
13190
13312
  readOnlyFeatures.current.forEach((layerFeatures) => {
13191
13313
  const found = layerFeatures.find((f) => String(f.id) === clickedId);
@@ -13201,7 +13323,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13201
13323
  }
13202
13324
  const lngLat = mapInstance.unproject([e.offsetX, e.offsetY]);
13203
13325
  const clickCoords = [lngLat.lng, lngLat.lat];
13204
- if (features.length > 0 && ((_c = features[0].properties) == null ? void 0 : _c.entity_id) && onEntityContextMenu) {
13326
+ if (features.length > 0 && ((_b = features[0].properties) == null ? void 0 : _b.entity_id) && onEntityContextMenu) {
13205
13327
  e.preventDefault();
13206
13328
  const f = features[0];
13207
13329
  const geoFeature = {
@@ -13274,7 +13396,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
13274
13396
  ];
13275
13397
  setContextMenu({ x: e.clientX, y: e.clientY, items });
13276
13398
  }
13277
- }, [contextMenuProvider, isEditMode, hasEditableLayer, onEntityContextMenu, createPointAtCoords, hiddenDrawingTools]);
13399
+ }, [contextMenuProvider, isEditMode, hasEditableLayer, onEntityContextMenu, createPointAtCoords, hiddenDrawingTools, featureStackAtPoint]);
13278
13400
  react.useEffect(() => {
13279
13401
  if (!isMapLoaded || !map.current) return;
13280
13402
  const canvas = map.current.getCanvas();
@@ -15106,11 +15228,11 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
15106
15228
  const updated = [...prev, newPoint];
15107
15229
  if (measureMode === "distance" && updated.length >= 2) {
15108
15230
  const line = turf__namespace.lineString(updated);
15109
- const distance = turf__namespace.length(line, { units: "kilometers" });
15110
- if (distance < 1) {
15111
- setMeasureResult(`${(distance * 1e3).toFixed(1)} m`);
15231
+ const distance2 = turf__namespace.length(line, { units: "kilometers" });
15232
+ if (distance2 < 1) {
15233
+ setMeasureResult(`${(distance2 * 1e3).toFixed(1)} m`);
15112
15234
  } else {
15113
- setMeasureResult(`${distance.toFixed(2)} km`);
15235
+ setMeasureResult(`${distance2.toFixed(2)} km`);
15114
15236
  }
15115
15237
  } else if (measureMode === "area" && updated.length >= 3) {
15116
15238
  const closed = [...updated, updated[0]];
@@ -16907,7 +17029,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
16907
17029
  onCreateLayerAndMoveFeatures: handleCreateLayerAndMoveFeatures,
16908
17030
  onCreateLayerAndCopyFeatures: handleCreateLayerAndCopyFeatures,
16909
17031
  getFeatureColor: (featureId) => selectedFeatureColors.get(featureId),
16910
- anchorEl: isMapLoaded ? ((_b = map.current) == null ? void 0 : _b.getContainer()) ?? null : null
17032
+ anchorEl: isMapLoaded ? ((_b = map.current) == null ? void 0 : _b.getContainer()) ?? null : null,
17033
+ stack: selectionStack && selectionStackPosition >= 0 ? { position: selectionStackPosition, count: selectionStack.ids.length, more: selectionStack.more, onStep: stepSelectionStack } : void 0
16911
17034
  }
16912
17035
  );
16913
17036
  })(),
@@ -17382,9 +17505,9 @@ function generateNYCPoints(count) {
17382
17505
  };
17383
17506
  const features = Array.from({ length: count }, (_, i) => {
17384
17507
  const angle = Math.random() * Math.PI * 2;
17385
- const distance = Math.random() * Math.random() * spread;
17386
- const lng = nycCenter.lng + Math.cos(angle) * distance;
17387
- const lat = nycCenter.lat + Math.sin(angle) * distance * 0.7;
17508
+ const distance2 = Math.random() * Math.random() * spread;
17509
+ const lng = nycCenter.lng + Math.cos(angle) * distance2;
17510
+ const lat = nycCenter.lat + Math.sin(angle) * distance2 * 0.7;
17388
17511
  const type = getRandomType();
17389
17512
  const maxOccupancy = getMaxOccupancy(type);
17390
17513
  return {