@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.mjs CHANGED
@@ -3,13 +3,13 @@ import { useRef, useLayoutEffect, useState, useEffect, useSyncExternalStore, use
3
3
  import maplibregl from "maplibre-gl";
4
4
  import MapboxDraw from "@mapbox/mapbox-gl-draw";
5
5
  import * as turf from "@turf/turf";
6
- import { distance, point } from "@turf/turf";
6
+ import { distance as distance$1, point } from "@turf/turf";
7
7
  import * as THREE from "three";
8
8
  import proj4 from "proj4";
9
9
  import { Button, Modal, Input, App, message, Tooltip, Dropdown, Divider, Popover, Switch, Slider, Tag, Select, Segmented, Collapse, ColorPicker, Tabs, Card, Table, DatePicker } from "antd";
10
10
  import { clsx } from "clsx";
11
11
  import { twMerge } from "tailwind-merge";
12
- import { MousePointer2, Square, Hexagon, Circle, MoreVertical, ChevronDown, Filter, X, Move, Ruler, Search, Scan, Pencil, Database, MapPin, Minus, Pentagon, Type, MoveRight, Undo2, Redo2, Trash2, Navigation, Loader2, Map as Map$1, Satellite, FolderOpen, Upload, Download, MoreHorizontal, Focus, Box, Layers, Plus, ChevronRight, Eye, EyeOff, Lock, Smile, Package, Copy, FolderInput, Save, Calendar, Palette, Blend, RefreshCw, ExternalLink, Info, SkipBack, Pause, Play, Clock, AlertTriangle, TestTube, Users, GripVertical, Plane, FileJson, Check, Phone, Car, AlertCircle } from "lucide-react";
12
+ import { MousePointer2, Square, Hexagon, Circle, MoreVertical, ChevronDown, Filter, X, Move, Ruler, Search, Scan, Pencil, Database, MapPin, Minus, Pentagon, Type, MoveRight, Undo2, Redo2, Trash2, Navigation, Loader2, Map as Map$1, Satellite, FolderOpen, Upload, Download, MoreHorizontal, Focus, Box, Layers, Plus, ChevronRight, Eye, EyeOff, Lock, Smile, Package, Copy, FolderInput, Save, Calendar, Palette, Blend, RefreshCw, ExternalLink, Info, ChevronLeft, SkipBack, Pause, Play, Clock, AlertTriangle, TestTube, Users, GripVertical, Plane, FileJson, Check, Phone, Car, AlertCircle } from "lucide-react";
13
13
  import { createPortal } from "react-dom";
14
14
  import { format } from "date-fns";
15
15
  import { createStore, useStore } from "zustand";
@@ -1692,7 +1692,7 @@ function traceSegmentStats(group, fromIndex, toIndex) {
1692
1692
  if (cached) return cached;
1693
1693
  const from = group.points[fromIndex].geometry;
1694
1694
  const to = group.points[toIndex].geometry;
1695
- const distanceKm = distance(point(from.coordinates), point(to.coordinates), { units: "kilometers" });
1695
+ const distanceKm = distance$1(point(from.coordinates), point(to.coordinates), { units: "kilometers" });
1696
1696
  const durationMs = group.times[toIndex] - group.times[fromIndex];
1697
1697
  const durationHours = durationMs / (1e3 * 60 * 60);
1698
1698
  const avgSpeedKmh = durationHours > 0 ? distanceKm / durationHours : 0;
@@ -2036,9 +2036,9 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2036
2036
  });
2037
2037
  }
2038
2038
  }
2039
- let labelPriority = DEFAULT_LABEL_PRIORITY;
2039
+ let labelPriority2 = DEFAULT_LABEL_PRIORITY;
2040
2040
  if (((_i = f.properties) == null ? void 0 : _i.kind) === "text") {
2041
- labelPriority = ((_j = f.properties) == null ? void 0 : _j.fontWeight) === "bold" ? 8 : 10;
2041
+ labelPriority2 = ((_j = f.properties) == null ? void 0 : _j.fontWeight) === "bold" ? 8 : 10;
2042
2042
  } else {
2043
2043
  const idStr = String(featureId);
2044
2044
  let h = 0;
@@ -2046,7 +2046,7 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2046
2046
  h = (h << 5) - h + idStr.charCodeAt(i);
2047
2047
  h |= 0;
2048
2048
  }
2049
- labelPriority = DEFAULT_LABEL_PRIORITY + Math.abs(h) % 1e3;
2049
+ labelPriority2 = DEFAULT_LABEL_PRIORITY + Math.abs(h) % 1e3;
2050
2050
  }
2051
2051
  const visibleStrokeOpacity = hideFlatFor3DOnly ? 0 : baseOpacity;
2052
2052
  const visibleFillOpacity = hideFlatFor3DOnly ? 0 : ((_k = f.properties) == null ? void 0 : _k["fill-opacity"]) ?? DEFAULT_VISIBLE_FILL_OPACITY;
@@ -2073,7 +2073,7 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2073
2073
  fill: strokeColor,
2074
2074
  "fill-opacity": visibleFillOpacity,
2075
2075
  pointRadius,
2076
- _labelPriority: labelPriority,
2076
+ _labelPriority: labelPriority2,
2077
2077
  [LABEL_NEVER_HIDE_PROP]: computeLabelNeverHide((_l = layer == null ? void 0 : layer.visualConfig) == null ? void 0 : _l.label)
2078
2078
  }
2079
2079
  }
@@ -5404,6 +5404,114 @@ function LayersPanel({
5404
5404
  }
5405
5405
  );
5406
5406
  }
5407
+ function deepClone(value) {
5408
+ try {
5409
+ return structuredClone(value);
5410
+ } catch {
5411
+ return JSON.parse(JSON.stringify(value));
5412
+ }
5413
+ }
5414
+ function cloneFeatures(features) {
5415
+ try {
5416
+ return structuredClone(features);
5417
+ } catch {
5418
+ return features.map((f) => deepClone(f));
5419
+ }
5420
+ }
5421
+ function renderedFeatureId(f) {
5422
+ var _a;
5423
+ const fromProps = (_a = f.properties) == null ? void 0 : _a.id;
5424
+ if (fromProps !== void 0 && fromProps !== null && fromProps !== "") return String(fromProps);
5425
+ if (f.id !== void 0 && f.id !== null && f.id !== "") return String(f.id);
5426
+ return null;
5427
+ }
5428
+ function resolveTooltipFeature(rendered, lookup) {
5429
+ const id = renderedFeatureId(rendered);
5430
+ const stored = id === null ? null : lookup(id);
5431
+ if (stored) {
5432
+ return deepClone({
5433
+ type: "Feature",
5434
+ geometry: stored.geometry,
5435
+ properties: stored.properties ?? {},
5436
+ id: stored.id
5437
+ });
5438
+ }
5439
+ return {
5440
+ type: "Feature",
5441
+ geometry: rendered.geometry,
5442
+ properties: { ...rendered.properties ?? {} },
5443
+ id: rendered.id
5444
+ };
5445
+ }
5446
+ const DEFAULT_POINT_RADIUS = 5;
5447
+ const MAX_POINT_RADIUS = 18;
5448
+ const SAME_SPOT_PX = 1;
5449
+ const CROWD = 16;
5450
+ const SCAN_LIMIT = 256;
5451
+ const isDot = (m) => m.center !== null;
5452
+ const distance = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
5453
+ function paintedRadius(f) {
5454
+ var _a, _b;
5455
+ const p = f.properties ?? {};
5456
+ 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 !== "";
5457
+ if (hidden) return 0;
5458
+ const r = ((_b = f.state) == null ? void 0 : _b[TRACE_ENDPOINT_KEY]) === true ? p._endpointRadius : p.pointRadius;
5459
+ return typeof r === "number" && Number.isFinite(r) ? r : DEFAULT_POINT_RADIUS;
5460
+ }
5461
+ function labelPriority(f) {
5462
+ var _a;
5463
+ const v = (_a = f.properties) == null ? void 0 : _a._labelPriority;
5464
+ return typeof v === "number" && Number.isFinite(v) ? v : DEFAULT_LABEL_PRIORITY;
5465
+ }
5466
+ function members(features, project, maxDots = Infinity) {
5467
+ const seen = /* @__PURE__ */ new Set();
5468
+ const out = [];
5469
+ let dots = 0;
5470
+ for (const feature of features) {
5471
+ const id = renderedFeatureId(feature);
5472
+ if (id === null || seen.has(id)) continue;
5473
+ if (seen.size === SCAN_LIMIT || dots === maxDots) return { members: out, cut: true };
5474
+ seen.add(id);
5475
+ if (feature.geometry.type !== "Point") {
5476
+ out.push({ id, feature, center: null, radius: 0 });
5477
+ continue;
5478
+ }
5479
+ const radius = paintedRadius(feature);
5480
+ if (radius <= 0) continue;
5481
+ out.push({ id, feature, center: project(feature.geometry.coordinates), radius });
5482
+ dots++;
5483
+ }
5484
+ return { members: out, cut: false };
5485
+ }
5486
+ function searchBox(dot) {
5487
+ const reach = dot.radius + MAX_POINT_RADIUS;
5488
+ return [[dot.center.x - reach, dot.center.y - reach], [dot.center.x + reach, dot.center.y + reach]];
5489
+ }
5490
+ const MORE_POINTS_HINT = "More points overlap here: zoom in to reach them";
5491
+ function featureStackAt(point2, hits, queryBox, project) {
5492
+ const hit = members(hits, project, CROWD + 1).members;
5493
+ const under = hit.filter(isDot);
5494
+ if (under.length === 0) return { features: hit.length > 0 ? [hit[0].feature] : [], more: false };
5495
+ const fromCursor = (d) => distance(d.center, point2);
5496
+ const byCursor = (a, b) => fromCursor(a) - fromCursor(b);
5497
+ let dots;
5498
+ let more;
5499
+ if (under.length > CROWD) {
5500
+ dots = under.sort(byCursor).slice(0, CROWD);
5501
+ more = true;
5502
+ } else {
5503
+ const nearest = under.reduce((a, b) => fromCursor(b) < fromCursor(a) ? b : a);
5504
+ const taken = new Set(under.map((d) => d.id));
5505
+ const box = members(queryBox(searchBox(nearest)), project);
5506
+ const neighbours = box.members.filter(isDot).filter((m) => !taken.has(m.id) && distance(m.center, nearest.center) <= m.radius + nearest.radius);
5507
+ dots = [...under, ...neighbours].sort(byCursor);
5508
+ more = box.cut;
5509
+ }
5510
+ const spot = dots[0].center;
5511
+ const onSpot = dots.filter((d) => distance(d.center, spot) < SAME_SPOT_PX).sort((a, b) => labelPriority(a.feature) - labelPriority(b.feature));
5512
+ const rest = dots.filter((d) => distance(d.center, spot) >= SAME_SPOT_PX);
5513
+ return { features: [...onSpot, ...rest].map((d) => d.feature), more };
5514
+ }
5407
5515
  const { TextArea } = Input;
5408
5516
  function formatDateForState(value) {
5409
5517
  if (!value) return "";
@@ -5444,6 +5552,40 @@ function EntityCardsList({
5444
5552
  ] })
5445
5553
  ] });
5446
5554
  }
5555
+ function StackPager({ stack }) {
5556
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-3 py-1 border-b border-border shrink-0 text-xs text-muted-foreground", children: [
5557
+ /* @__PURE__ */ jsx(Tooltip, { title: "Previous overlapping point", children: /* @__PURE__ */ jsx(
5558
+ Button,
5559
+ {
5560
+ type: "text",
5561
+ icon: /* @__PURE__ */ jsx(ChevronLeft, { className: "w-3.5 h-3.5" }),
5562
+ disabled: stack.position === 0,
5563
+ onClick: () => stack.onStep(-1),
5564
+ className: "!w-6 !h-6 !min-w-0 !p-0",
5565
+ "aria-label": "Previous overlapping point",
5566
+ "data-testid": "button-stack-prev"
5567
+ }
5568
+ ) }),
5569
+ /* @__PURE__ */ jsx(Tooltip, { title: stack.more ? MORE_POINTS_HINT : void 0, children: /* @__PURE__ */ jsxs("span", { "data-testid": "panel-stack-position", children: [
5570
+ stack.position + 1,
5571
+ " / ",
5572
+ stack.count,
5573
+ stack.more ? "+" : ""
5574
+ ] }) }),
5575
+ /* @__PURE__ */ jsx(Tooltip, { title: "Next overlapping point", children: /* @__PURE__ */ jsx(
5576
+ Button,
5577
+ {
5578
+ type: "text",
5579
+ icon: /* @__PURE__ */ jsx(ChevronRight, { className: "w-3.5 h-3.5" }),
5580
+ disabled: stack.position === stack.count - 1,
5581
+ onClick: () => stack.onStep(1),
5582
+ className: "!w-6 !h-6 !min-w-0 !p-0",
5583
+ "aria-label": "Next overlapping point",
5584
+ "data-testid": "button-stack-next"
5585
+ }
5586
+ ) })
5587
+ ] });
5588
+ }
5447
5589
  function getFeatureTypeIcon(geometryType, kind, size = "sm") {
5448
5590
  const cls = size === "lg" ? "w-5 h-5" : "w-4 h-4";
5449
5591
  if (kind === "text") {
@@ -5664,7 +5806,7 @@ function RecordFieldsSection({ feature }) {
5664
5806
  );
5665
5807
  }
5666
5808
  let persistedTabPreference = "properties";
5667
- 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 }) {
5809
+ 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 }) {
5668
5810
  var _a, _b, _c, _d, _e;
5669
5811
  const feature = selectedFeatures[0];
5670
5812
  const { toast } = useToast();
@@ -6959,6 +7101,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
6959
7101
  /* @__PURE__ */ jsx(Button, { type: "text", icon: /* @__PURE__ */ jsx(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" })
6960
7102
  ] })
6961
7103
  ] }),
7104
+ stack && !hasMultipleSelection && /* @__PURE__ */ jsx(StackPager, { stack }),
6962
7105
  /* @__PURE__ */ jsx(
6963
7106
  Tabs,
6964
7107
  {
@@ -7091,6 +7234,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
7091
7234
  /* @__PURE__ */ jsx(Button, { type: "text", icon: /* @__PURE__ */ jsx(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" })
7092
7235
  ] })
7093
7236
  ] }),
7237
+ stack && /* @__PURE__ */ jsx(StackPager, { stack }),
7094
7238
  /* @__PURE__ */ jsx("div", { className: "flex-1 overflow-y-auto overflow-x-hidden scrollbar-visible", children: panelContent })
7095
7239
  ]
7096
7240
  }
@@ -8540,20 +8684,6 @@ function suggestTraceGroupField(features, fields) {
8540
8684
  };
8541
8685
  return ((_a = candidates.find((c) => splitsIntoTracks(c.field))) == null ? void 0 : _a.field) ?? null;
8542
8686
  }
8543
- function deepClone(value) {
8544
- try {
8545
- return structuredClone(value);
8546
- } catch {
8547
- return JSON.parse(JSON.stringify(value));
8548
- }
8549
- }
8550
- function cloneFeatures(features) {
8551
- try {
8552
- return structuredClone(features);
8553
- } catch {
8554
- return features.map((f) => deepClone(f));
8555
- }
8556
- }
8557
8687
  function numberEquals(a, b) {
8558
8688
  return a === b || !Number.isFinite(a) && !Number.isFinite(b);
8559
8689
  }
@@ -8819,31 +8949,6 @@ function buildSelectionOverlayData(ids, styleFor) {
8819
8949
  });
8820
8950
  return { type: "FeatureCollection", features };
8821
8951
  }
8822
- function renderedFeatureId(f) {
8823
- var _a;
8824
- const fromProps = (_a = f.properties) == null ? void 0 : _a.id;
8825
- if (fromProps !== void 0 && fromProps !== null && fromProps !== "") return String(fromProps);
8826
- if (f.id !== void 0 && f.id !== null && f.id !== "") return String(f.id);
8827
- return null;
8828
- }
8829
- function resolveTooltipFeature(rendered, lookup) {
8830
- const id = renderedFeatureId(rendered);
8831
- const stored = id === null ? null : lookup(id);
8832
- if (stored) {
8833
- return deepClone({
8834
- type: "Feature",
8835
- geometry: stored.geometry,
8836
- properties: stored.properties ?? {},
8837
- id: stored.id
8838
- });
8839
- }
8840
- return {
8841
- type: "Feature",
8842
- geometry: rendered.geometry,
8843
- properties: { ...rendered.properties ?? {} },
8844
- id: rendered.id
8845
- };
8846
- }
8847
8952
  const CLUSTER_COUNT_VALUE_PROP = "__cluster_count_value";
8848
8953
  const CLUSTER_SUM_PROP = "value_sum";
8849
8954
  const CLUSTER_MEMBER_ID_PROP = "__cluster_fid";
@@ -9919,6 +10024,25 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9919
10024
  }
9920
10025
  return getReadOnlyFeatureById(id);
9921
10026
  }, [getReadOnlyFeatureById]);
10027
+ const stackFromHits = useCallback((point2, hits) => {
10028
+ var _a;
10029
+ const m = map.current;
10030
+ const layers2 = ((_a = shardRegistryRef.current) == null ? void 0 : _a.interactiveLayerIds()) ?? [];
10031
+ if (!m || layers2.length === 0) return { features: [], more: false };
10032
+ return featureStackAt(point2, hits, (box) => m.queryRenderedFeatures(box, { layers: layers2 }), (lngLat) => m.project(lngLat));
10033
+ }, []);
10034
+ const featureStackAtPoint = useCallback((point2) => {
10035
+ var _a;
10036
+ const m = map.current;
10037
+ const layers2 = ((_a = shardRegistryRef.current) == null ? void 0 : _a.interactiveLayerIds()) ?? [];
10038
+ if (!m || layers2.length === 0) return { features: [], more: false };
10039
+ return stackFromHits(point2, m.queryRenderedFeatures([point2.x, point2.y], { layers: layers2 }));
10040
+ }, [stackFromHits]);
10041
+ const [selectionStack, setSelectionStack] = useState(null);
10042
+ const selectionStackPosition = selectionStack && selectedFeatureIds.length === 1 ? selectionStack.ids.indexOf(selectedFeatureIds[0]) : -1;
10043
+ useEffect(() => {
10044
+ if (selectionStack && selectionStackPosition < 0) setSelectionStack(null);
10045
+ }, [selectionStack, selectionStackPosition]);
9922
10046
  const appliedSelectionRef = useRef(/* @__PURE__ */ new Map());
9923
10047
  const locatorCacheRef = useRef(createLocatorCache());
9924
10048
  const shardedLayerIdsRef = useRef(EMPTY_ID_SET);
@@ -9999,11 +10123,19 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9999
10123
  }
10000
10124
  scheduleSync("selection");
10001
10125
  if (readOnlyIds.length > 0) {
10002
- queueMicrotask(() => {
10126
+ requestAnimationFrame(() => {
10003
10127
  isSelectingReadOnlyRef.current = false;
10004
10128
  });
10005
10129
  }
10006
10130
  }, [isMapLoaded, getFeatureById, onFeatureSelect]);
10131
+ const applySelectionStateRef = useRef(applySelectionState$1);
10132
+ applySelectionStateRef.current = applySelectionState$1;
10133
+ const stepSelectionStack = useCallback((delta) => {
10134
+ if (!selectionStack || selectionStackPosition < 0) return;
10135
+ const next = selectionStack.ids[selectionStackPosition + delta];
10136
+ if (next === void 0 || getFeatureById(next) === null) return;
10137
+ applySelectionState$1([next], { focusProperties: true });
10138
+ }, [selectionStack, selectionStackPosition, getFeatureById, applySelectionState$1]);
10007
10139
  const updateFeatureCount = useCallback(() => {
10008
10140
  const drawFeatureCount = draw.current ? draw.current.getAll().features.length : 0;
10009
10141
  let hiddenCount = 0;
@@ -11140,7 +11272,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11140
11272
  }
11141
11273
  const tooltipEl2 = document.createElement("div");
11142
11274
  tooltipEl2.className = "feature-tooltip-fixed";
11143
- tooltipEl2.style.cssText = "position:fixed;z-index:1000;pointer-events:auto;display:none;max-width:480px;";
11275
+ tooltipEl2.style.cssText = "position:fixed;z-index:1000;pointer-events:auto;display:none;max-width:480px;box-sizing:border-box;";
11144
11276
  document.body.appendChild(tooltipEl2);
11145
11277
  tooltipElRef.current = tooltipEl2;
11146
11278
  let tooltipLngLat = null;
@@ -11148,6 +11280,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11148
11280
  let tooltipShowTimeout = null;
11149
11281
  let isMouseOverPopup = false;
11150
11282
  let tooltipFeatures = [];
11283
+ let tooltipMore = false;
11151
11284
  let tooltipPageIndex = 0;
11152
11285
  let tooltipLngLatForPagination = null;
11153
11286
  let lastHoveredGeomType = null;
@@ -11191,6 +11324,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11191
11324
  tooltipEl2.style.minHeight = "";
11192
11325
  tooltipLngLat = null;
11193
11326
  tooltipFeatures = [];
11327
+ tooltipMore = false;
11194
11328
  tooltipPageIndex = 0;
11195
11329
  tooltipLngLatForPagination = null;
11196
11330
  };
@@ -11272,23 +11406,28 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11272
11406
  html += "</div>";
11273
11407
  return html;
11274
11408
  };
11275
- const renderTooltipPage = () => {
11276
- if (tooltipFeatures.length === 0 || !tooltipLngLatForPagination) return;
11277
- const feature = tooltipFeatures[tooltipPageIndex];
11409
+ const tooltipPageHtml = () => {
11410
+ const feature = resolveRendered(tooltipFeatures[tooltipPageIndex]);
11278
11411
  let html = null;
11279
11412
  if (tooltipProviderRef.current) {
11280
11413
  html = tooltipProviderRef.current(feature);
11281
11414
  } else {
11282
11415
  html = buildBuiltinTooltipHtml(feature);
11283
11416
  }
11284
- if (!html) return;
11417
+ if (!html) return null;
11285
11418
  if (tooltipFeatures.length > 1) {
11286
11419
  const prevDisabled = tooltipPageIndex === 0;
11287
11420
  const nextDisabled = tooltipPageIndex === tooltipFeatures.length - 1;
11288
11421
  const btnBase = "background:none;border-radius:4px;padding:1px 8px;font-size:12px;line-height:1.4;";
11289
- 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>`;
11422
+ 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>`;
11290
11423
  html = navHtml + html;
11291
11424
  }
11425
+ return html;
11426
+ };
11427
+ const renderTooltipPage = () => {
11428
+ if (tooltipFeatures.length === 0 || !tooltipLngLatForPagination) return;
11429
+ const html = tooltipPageHtml();
11430
+ if (!html) return;
11292
11431
  if (tooltipPageIndex > 0 && tooltipFeatures.length > 1) {
11293
11432
  tooltipEl2.style.minWidth = tooltipEl2.offsetWidth + "px";
11294
11433
  tooltipEl2.style.minHeight = tooltipEl2.offsetHeight + "px";
@@ -11320,8 +11459,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11320
11459
  }
11321
11460
  return fallback;
11322
11461
  };
11323
- const showTooltipForFeatures = (e) => {
11462
+ const stackKey = (stack) => stack.features.map(getFeatureKey).join("\n") + (stack.more ? "\n+" : "");
11463
+ const showTooltipForFeatures = (e, hover) => {
11324
11464
  var _a2;
11465
+ const stack = hover.features;
11325
11466
  if (tooltipShowTimeout) {
11326
11467
  clearTimeout(tooltipShowTimeout);
11327
11468
  tooltipShowTimeout = null;
@@ -11338,63 +11479,22 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11338
11479
  clearTimeout(tooltipHideTimeout);
11339
11480
  tooltipHideTimeout = null;
11340
11481
  }
11341
- if (!e.features || e.features.length === 0) return;
11342
- const topFeature = e.features[0];
11482
+ if (stack.length === 0) return;
11483
+ const topFeature = stack[0];
11343
11484
  const topGeomType = (_a2 = topFeature.geometry) == null ? void 0 : _a2.type;
11344
11485
  const topIsPolygon = topGeomType === "Polygon" || topGeomType === "MultiPolygon";
11345
11486
  const coordinates = topIsPolygon ? e.lngLat : getFeatureAnchor(topFeature, e.lngLat);
11346
- lastHoveredFeatureKey = getFeatureKey(topFeature);
11487
+ lastHoveredFeatureKey = stackKey(hover);
11347
11488
  lastHoveredGeomType = topGeomType || null;
11348
11489
  tooltipShowTimeout = setTimeout(() => {
11349
- var _a3, _b2, _c, _d;
11490
+ var _a3, _b2;
11350
11491
  tooltipShowTimeout = null;
11351
11492
  if (isDrawingSelection.current) return;
11352
11493
  const drawMode = (_b2 = (_a3 = draw.current) == null ? void 0 : _a3.getMode) == null ? void 0 : _b2.call(_a3);
11353
11494
  const tooltipAllowedModes = ["simple_select", "direct_select", "view_select"];
11354
11495
  if (drawMode && !tooltipAllowedModes.includes(drawMode)) return;
11355
- if (!((_c = e.features) == null ? void 0 : _c.length)) return;
11356
- const hoveredFeature = e.features[0];
11357
- const hoveredGeom = hoveredFeature.geometry;
11358
- let hoveredCoords = null;
11359
- if (hoveredGeom.type === "Point") {
11360
- hoveredCoords = hoveredGeom.coordinates;
11361
- }
11362
- const seen = /* @__PURE__ */ new Set();
11363
- const uniqueFeatures = [];
11364
- const addUnique = (f) => {
11365
- const fid = String((f.properties || {}).id || f.id || "");
11366
- if (fid && seen.has(fid)) return;
11367
- if (fid) seen.add(fid);
11368
- uniqueFeatures.push({
11369
- type: "Feature",
11370
- geometry: f.geometry,
11371
- properties: { ...f.properties || {} },
11372
- id: f.id
11373
- });
11374
- };
11375
- addUnique(resolveRendered(hoveredFeature));
11376
- if (hoveredCoords) {
11377
- const allFeatures = [];
11378
- if (draw.current) {
11379
- pushAll(allFeatures, draw.current.getAll().features);
11380
- }
11381
- readOnlyFeatures.current.forEach((features, lid) => {
11382
- const layer = layersRef.current.find((l) => l.id === lid);
11383
- if (layer == null ? void 0 : layer.visible) pushAll(allFeatures, features);
11384
- });
11385
- const EPS = 1e-6;
11386
- for (const cf of allFeatures) {
11387
- if (((_d = cf.geometry) == null ? void 0 : _d.type) !== "Point") continue;
11388
- const cc = cf.geometry.coordinates;
11389
- if (Math.abs(cc[0] - hoveredCoords[0]) < EPS && Math.abs(cc[1] - hoveredCoords[1]) < EPS) {
11390
- addUnique(cf);
11391
- }
11392
- }
11393
- }
11394
- if (uniqueFeatures.length === 0) {
11395
- addUnique(resolveRendered(hoveredFeature));
11396
- }
11397
- tooltipFeatures = uniqueFeatures;
11496
+ tooltipFeatures = stack;
11497
+ tooltipMore = hover.more;
11398
11498
  tooltipPageIndex = 0;
11399
11499
  tooltipLngLatForPagination = coordinates;
11400
11500
  if (tooltipHideTimeout) {
@@ -11404,56 +11504,74 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11404
11504
  renderTooltipPage();
11405
11505
  }, 250);
11406
11506
  };
11507
+ const moveTooltip = (e, hover) => {
11508
+ var _a2;
11509
+ const stack = hover.features;
11510
+ if (stack.length === 0) return;
11511
+ const geomType = (_a2 = stack[0].geometry) == null ? void 0 : _a2.type;
11512
+ const isPolygon = geomType === "Polygon" || geomType === "MultiPolygon";
11513
+ if (isPolygon && tooltipEl2.style.display !== "none" && !isMouseOverPopup) {
11514
+ tooltipLngLat = e.lngLat;
11515
+ tooltipLngLatForPagination = e.lngLat;
11516
+ positionTooltip();
11517
+ }
11518
+ const currentKey = stackKey(hover);
11519
+ if (currentKey === lastHoveredFeatureKey) return;
11520
+ if (tooltipEl2.style.display !== "none") {
11521
+ if (tooltipShowTimeout) {
11522
+ clearTimeout(tooltipShowTimeout);
11523
+ tooltipShowTimeout = null;
11524
+ }
11525
+ if (tooltipHideTimeout) {
11526
+ clearTimeout(tooltipHideTimeout);
11527
+ tooltipHideTimeout = null;
11528
+ }
11529
+ lastHoveredFeatureKey = currentKey;
11530
+ lastHoveredGeomType = geomType || null;
11531
+ const anchorLngLat = isPolygon ? e.lngLat : getFeatureAnchor(stack[0], e.lngLat);
11532
+ tooltipFeatures = stack;
11533
+ tooltipMore = hover.more;
11534
+ tooltipPageIndex = 0;
11535
+ tooltipLngLatForPagination = anchorLngLat;
11536
+ tooltipEl2.style.minWidth = "";
11537
+ tooltipEl2.style.minHeight = "";
11538
+ const html = tooltipPageHtml();
11539
+ if (html) {
11540
+ tooltipEl2.innerHTML = html;
11541
+ tooltipLngLat = anchorLngLat;
11542
+ positionTooltip();
11543
+ }
11544
+ } else {
11545
+ showTooltipForFeatures(e, hover);
11546
+ }
11547
+ };
11548
+ let pendingHover = null;
11549
+ const flushHover = ({ e, hits, entered }) => {
11550
+ if (hits.length === 0) return;
11551
+ const order = mapInstance.getLayersOrder();
11552
+ const z = (list) => order.indexOf(list[0].layer.id);
11553
+ const all = hits.length === 1 ? hits[0] : [].concat(...[...hits].sort((a, b) => z(b) - z(a)));
11554
+ const hover = stackFromHits(e.point, all);
11555
+ if (entered) showTooltipForFeatures(e, hover);
11556
+ else moveTooltip(e, hover);
11557
+ };
11558
+ const collectHover = (e, entered) => {
11559
+ var _a2;
11560
+ if (!pendingHover || pendingHover.e.originalEvent !== e.originalEvent) {
11561
+ const pending = { e, hits: [], entered: false };
11562
+ pendingHover = pending;
11563
+ queueMicrotask(() => flushHover(pending));
11564
+ }
11565
+ if (entered) pendingHover.entered = true;
11566
+ else if ((_a2 = e.features) == null ? void 0 : _a2.length) pendingHover.hits.push(e.features);
11567
+ };
11407
11568
  const bindHoverHandlers = (layerId) => {
11408
11569
  if (hoverHandlersByLayer.has(layerId)) return;
11409
11570
  const onMouseEnter = (e) => {
11410
11571
  mapInstance.getCanvas().style.cursor = "pointer";
11411
- showTooltipForFeatures(e);
11412
- };
11413
- const onMouseMove = (e) => {
11414
- var _a2;
11415
- if (!e.features || e.features.length === 0) return;
11416
- const geomType = (_a2 = e.features[0].geometry) == null ? void 0 : _a2.type;
11417
- const isPolygon = geomType === "Polygon" || geomType === "MultiPolygon";
11418
- if (isPolygon && tooltipEl2.style.display !== "none" && !isMouseOverPopup) {
11419
- tooltipLngLat = e.lngLat;
11420
- tooltipLngLatForPagination = e.lngLat;
11421
- positionTooltip();
11422
- }
11423
- const currentKey = getFeatureKey(e.features[0]);
11424
- if (currentKey === lastHoveredFeatureKey) return;
11425
- if (tooltipEl2.style.display !== "none") {
11426
- if (tooltipShowTimeout) {
11427
- clearTimeout(tooltipShowTimeout);
11428
- tooltipShowTimeout = null;
11429
- }
11430
- if (tooltipHideTimeout) {
11431
- clearTimeout(tooltipHideTimeout);
11432
- tooltipHideTimeout = null;
11433
- }
11434
- lastHoveredFeatureKey = currentKey;
11435
- lastHoveredGeomType = geomType || null;
11436
- const feature = e.features[0];
11437
- const featureObj = resolveRendered(feature);
11438
- const anchorLngLat = isPolygon ? e.lngLat : getFeatureAnchor(feature, e.lngLat);
11439
- tooltipFeatures = [featureObj];
11440
- tooltipPageIndex = 0;
11441
- tooltipLngLatForPagination = anchorLngLat;
11442
- let html = null;
11443
- if (tooltipProviderRef.current) {
11444
- html = tooltipProviderRef.current(featureObj);
11445
- } else {
11446
- html = buildBuiltinTooltipHtml(featureObj);
11447
- }
11448
- if (html) {
11449
- tooltipEl2.innerHTML = html;
11450
- tooltipLngLat = anchorLngLat;
11451
- positionTooltip();
11452
- }
11453
- } else {
11454
- showTooltipForFeatures(e);
11455
- }
11572
+ collectHover(e, true);
11456
11573
  };
11574
+ const onMouseMove = (e) => collectHover(e, false);
11457
11575
  const onMouseLeave = () => {
11458
11576
  mapInstance.getCanvas().style.cursor = "";
11459
11577
  const wasPolygon = lastHoveredGeomType === "Polygon" || lastHoveredGeomType === "MultiPolygon";
@@ -11906,15 +12024,18 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11906
12024
  scheduleSync();
11907
12025
  });
11908
12026
  mapInstance.on("click", (e) => {
11909
- var _a, _b, _c;
12027
+ var _a, _b;
11910
12028
  if (!enableSelectionRef.current) return;
11911
12029
  if (e.originalEvent.button !== 0) return;
11912
12030
  if (contextMenuFiredRef.current) return;
11913
12031
  if (Date.now() - shiftSelectionRef.current.completedAt < 300) return;
11914
12032
  const isModifierKey = e.originalEvent.ctrlKey || e.originalEvent.metaKey;
11915
- const features = mapInstance.queryRenderedFeatures(e.point, {
11916
- layers: ((_a = shardRegistryRef.current) == null ? void 0 : _a.interactiveLayerIds()) ?? []
11917
- });
12033
+ const stack = featureStackAtPoint(e.point);
12034
+ const features = stack.features;
12035
+ const stackIds = isModifierKey || e.originalEvent.shiftKey ? [] : features.map((f) => {
12036
+ var _a2;
12037
+ return String(((_a2 = f.properties) == null ? void 0 : _a2.id) ?? "");
12038
+ }).filter((id) => id !== "" && getFeatureById(id) !== null);
11918
12039
  let clusteredFeatureId = null;
11919
12040
  if (features.length === 0) {
11920
12041
  const clusterOverlayIds = layersRef.current.filter((l) => {
@@ -11928,11 +12049,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11928
12049
  }
11929
12050
  return;
11930
12051
  }
11931
- const memberId = (_b = clusterHit.properties) == null ? void 0 : _b[CLUSTER_MEMBER_ID_PROP];
12052
+ const memberId = (_a = clusterHit.properties) == null ? void 0 : _a[CLUSTER_MEMBER_ID_PROP];
11932
12053
  if (memberId == null || memberId === "") return;
11933
12054
  clusteredFeatureId = String(memberId);
11934
12055
  }
11935
- const featureId = clusteredFeatureId ?? ((_c = features[0].properties) == null ? void 0 : _c.id);
12056
+ const featureId = clusteredFeatureId ?? ((_b = features[0].properties) == null ? void 0 : _b.id);
11936
12057
  if (!featureId) return;
11937
12058
  let isReadOnly = false;
11938
12059
  readOnlyFeatures.current.forEach((layerFeatures) => {
@@ -11941,8 +12062,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11941
12062
  }
11942
12063
  });
11943
12064
  if (!isReadOnly) {
11944
- const currentMode = drawInstance.getMode();
11945
- if (currentMode !== "simple_select") return;
12065
+ const mode = drawInstance.getMode();
12066
+ if (stackIds.length > 1 && (mode === "simple_select" || mode === "view_select")) {
12067
+ setSelectionStack({ ids: stackIds, more: stack.more });
12068
+ applySelectionStateRef.current([String(featureId)]);
12069
+ }
11946
12070
  return;
11947
12071
  }
11948
12072
  const fid = String(featureId);
@@ -11954,6 +12078,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11954
12078
  } else {
11955
12079
  nextIds = isAlreadySelected ? currentSelection2.filter((id) => id !== fid) : [fid];
11956
12080
  }
12081
+ setSelectionStack(stackIds.length > 1 && nextIds.length === 1 && nextIds[0] === fid ? { ids: stackIds, more: stack.more } : null);
11957
12082
  isSelectingReadOnlyRef.current = true;
11958
12083
  if (drawInstance.getSelected().features.length > 0) {
11959
12084
  drawInstance.changeMode("simple_select", { featureIds: [] });
@@ -11970,9 +12095,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11970
12095
  });
11971
12096
  }
11972
12097
  onFeatureSelect == null ? void 0 : onFeatureSelect(selectedFeatures2);
11973
- setTimeout(() => {
12098
+ requestAnimationFrame(() => {
11974
12099
  isSelectingReadOnlyRef.current = false;
11975
- }, 0);
12100
+ });
11976
12101
  });
11977
12102
  mapInstance.on("error", (e) => {
11978
12103
  var _a, _b;
@@ -13152,20 +13277,17 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13152
13277
  onFeatureCreate == null ? void 0 : onFeatureCreate(feature);
13153
13278
  }, [isMapLoaded, externalPersistence, enableProperties, autoOpenProperties, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, onFeatureCreate]);
13154
13279
  const handleFeatureContextMenu = useCallback((e) => {
13155
- var _a, _b, _c;
13280
+ var _a, _b;
13156
13281
  contextMenuFiredRef.current = true;
13157
13282
  setTimeout(() => {
13158
13283
  contextMenuFiredRef.current = false;
13159
13284
  }, 0);
13160
13285
  if (!map.current) return;
13161
13286
  const mapInstance = map.current;
13162
- const point2 = [e.offsetX, e.offsetY];
13163
- const clickedFeatures = mapInstance.queryRenderedFeatures(point2, {
13164
- layers: ((_a = shardRegistryRef.current) == null ? void 0 : _a.interactiveLayerIds()) ?? []
13165
- });
13287
+ const clickedFeatures = featureStackAtPoint({ x: e.offsetX, y: e.offsetY }).features;
13166
13288
  let features = [];
13167
13289
  if (clickedFeatures.length > 0) {
13168
- const clickedId = String(((_b = clickedFeatures[0].properties) == null ? void 0 : _b.id) || clickedFeatures[0].id);
13290
+ const clickedId = String(((_a = clickedFeatures[0].properties) == null ? void 0 : _a.id) || clickedFeatures[0].id);
13169
13291
  let clickedFeature = null;
13170
13292
  readOnlyFeatures.current.forEach((layerFeatures) => {
13171
13293
  const found = layerFeatures.find((f) => String(f.id) === clickedId);
@@ -13181,7 +13303,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13181
13303
  }
13182
13304
  const lngLat = mapInstance.unproject([e.offsetX, e.offsetY]);
13183
13305
  const clickCoords = [lngLat.lng, lngLat.lat];
13184
- if (features.length > 0 && ((_c = features[0].properties) == null ? void 0 : _c.entity_id) && onEntityContextMenu) {
13306
+ if (features.length > 0 && ((_b = features[0].properties) == null ? void 0 : _b.entity_id) && onEntityContextMenu) {
13185
13307
  e.preventDefault();
13186
13308
  const f = features[0];
13187
13309
  const geoFeature = {
@@ -13254,7 +13376,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13254
13376
  ];
13255
13377
  setContextMenu({ x: e.clientX, y: e.clientY, items });
13256
13378
  }
13257
- }, [contextMenuProvider, isEditMode, hasEditableLayer, onEntityContextMenu, createPointAtCoords, hiddenDrawingTools]);
13379
+ }, [contextMenuProvider, isEditMode, hasEditableLayer, onEntityContextMenu, createPointAtCoords, hiddenDrawingTools, featureStackAtPoint]);
13258
13380
  useEffect(() => {
13259
13381
  if (!isMapLoaded || !map.current) return;
13260
13382
  const canvas = map.current.getCanvas();
@@ -16887,7 +17009,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
16887
17009
  onCreateLayerAndMoveFeatures: handleCreateLayerAndMoveFeatures,
16888
17010
  onCreateLayerAndCopyFeatures: handleCreateLayerAndCopyFeatures,
16889
17011
  getFeatureColor: (featureId) => selectedFeatureColors.get(featureId),
16890
- anchorEl: isMapLoaded ? ((_b = map.current) == null ? void 0 : _b.getContainer()) ?? null : null
17012
+ anchorEl: isMapLoaded ? ((_b = map.current) == null ? void 0 : _b.getContainer()) ?? null : null,
17013
+ stack: selectionStack && selectionStackPosition >= 0 ? { position: selectionStackPosition, count: selectionStack.ids.length, more: selectionStack.more, onStep: stepSelectionStack } : void 0
16891
17014
  }
16892
17015
  );
16893
17016
  })(),