@octostar/map-component 0.1.27 → 0.1.29

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
@@ -1553,11 +1553,133 @@ function ColorPickerPopover({ value, onChange, testId }) {
1553
1553
  }
1554
1554
  );
1555
1555
  }
1556
+ function categoricalKey(raw) {
1557
+ if (raw == null) return null;
1558
+ if (typeof raw === "string") return raw === "" ? null : raw;
1559
+ return String(raw);
1560
+ }
1561
+ const SELECTION_HUE = 187;
1562
+ const SELECTION_HUE_HALF_WIDTH = 12;
1563
+ function fnv1aHash(str) {
1564
+ let hash = 2166136261;
1565
+ for (let i = 0; i < str.length; i++) {
1566
+ hash ^= str.charCodeAt(i);
1567
+ hash = Math.imul(hash, 16777619);
1568
+ }
1569
+ return hash >>> 0;
1570
+ }
1571
+ function hslToHex(h, s, l) {
1572
+ const sNorm = s / 100;
1573
+ const lNorm = l / 100;
1574
+ const k = (n) => (n + h / 30) % 12;
1575
+ const a = sNorm * Math.min(lNorm, 1 - lNorm);
1576
+ const f = (n) => {
1577
+ const value = lNorm - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
1578
+ return Math.round(value * 255);
1579
+ };
1580
+ const toHex = (n) => n.toString(16).padStart(2, "0");
1581
+ return `#${toHex(f(0))}${toHex(f(8))}${toHex(f(4))}`;
1582
+ }
1583
+ function hashStringToColor(str) {
1584
+ const hash = fnv1aHash(str);
1585
+ let hue = hash * 137.508 % 360;
1586
+ if (hue < 0) hue += 360;
1587
+ const delta = (hue - SELECTION_HUE + 540) % 360 - 180;
1588
+ if (Math.abs(delta) < SELECTION_HUE_HALF_WIDTH) {
1589
+ hue = (SELECTION_HUE + (delta >= 0 ? SELECTION_HUE_HALF_WIDTH : -SELECTION_HUE_HALF_WIDTH) + 360) % 360;
1590
+ }
1591
+ const sat = 60 + (hash >>> 8) % 30;
1592
+ const light = 45 + (hash >>> 16) % 18;
1593
+ return hslToHex(hue, sat, light);
1594
+ }
1556
1595
  const MAP_STYLES = [
1557
1596
  { id: "streets", name: "Streets", icon: Map$1 },
1558
1597
  { id: "satellite", name: "Satellite", icon: Satellite },
1559
1598
  { id: "dark", name: "Dark", icon: Map$1 }
1560
1599
  ];
1600
+ const LEGEND_MAX_VALUES = 50;
1601
+ const LEGEND_INITIAL_VISIBLE = 8;
1602
+ function ColorByFieldLegend({
1603
+ layerId,
1604
+ fieldName,
1605
+ getFieldValueDistribution
1606
+ }) {
1607
+ const [expanded, setExpanded] = useState(false);
1608
+ const [filter, setFilter] = useState("");
1609
+ useEffect(() => {
1610
+ setFilter("");
1611
+ setExpanded(false);
1612
+ }, [layerId, fieldName]);
1613
+ const distribution = useMemo(
1614
+ () => getFieldValueDistribution(layerId, fieldName, LEGEND_MAX_VALUES),
1615
+ [getFieldValueDistribution, layerId, fieldName]
1616
+ );
1617
+ const filtered = useMemo(() => {
1618
+ const q = filter.trim().toLowerCase();
1619
+ if (!q) return distribution;
1620
+ return distribution.filter((d) => d.value.toLowerCase().includes(q));
1621
+ }, [distribution, filter]);
1622
+ if (distribution.length === 0) return null;
1623
+ const visible = expanded ? filtered : filtered.slice(0, LEGEND_INITIAL_VISIBLE);
1624
+ const hiddenCount = filtered.length - visible.length;
1625
+ return /* @__PURE__ */ jsxs(
1626
+ "div",
1627
+ {
1628
+ className: "mt-1 rounded border border-border/50 bg-background/40 p-1.5",
1629
+ "data-testid": `legend-color-by-${layerId}`,
1630
+ children: [
1631
+ /* @__PURE__ */ jsxs("div", { className: "text-[10px] uppercase tracking-wide text-muted-foreground mb-1", children: [
1632
+ "Legend",
1633
+ distribution.length >= LEGEND_MAX_VALUES ? ` (top ${LEGEND_MAX_VALUES})` : ""
1634
+ ] }),
1635
+ (distribution.length > LEGEND_INITIAL_VISIBLE || expanded) && /* @__PURE__ */ jsx(
1636
+ Input,
1637
+ {
1638
+ size: "small",
1639
+ allowClear: true,
1640
+ placeholder: "Filter values…",
1641
+ value: filter,
1642
+ onChange: (e) => setFilter(e.target.value),
1643
+ className: "mb-1 !text-[11px]",
1644
+ "data-testid": `legend-filter-${layerId}`
1645
+ }
1646
+ ),
1647
+ /* @__PURE__ */ jsxs("div", { className: "space-y-0.5 max-h-40 overflow-y-auto", children: [
1648
+ visible.map(({ value, count }) => /* @__PURE__ */ jsxs(
1649
+ "div",
1650
+ {
1651
+ className: "flex items-center gap-1.5 text-[11px]",
1652
+ title: `${value} (${count})`,
1653
+ children: [
1654
+ /* @__PURE__ */ jsx(
1655
+ "span",
1656
+ {
1657
+ className: "inline-block w-2.5 h-2.5 rounded-sm shrink-0 border border-black/10",
1658
+ style: { backgroundColor: hashStringToColor(value) }
1659
+ }
1660
+ ),
1661
+ /* @__PURE__ */ jsx("span", { className: "truncate flex-1 text-foreground", children: value }),
1662
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground tabular-nums", children: count })
1663
+ ]
1664
+ },
1665
+ value
1666
+ )),
1667
+ visible.length === 0 && /* @__PURE__ */ jsx("div", { className: "text-[11px] text-muted-foreground italic", children: "No matches" })
1668
+ ] }),
1669
+ (hiddenCount > 0 || expanded && filtered.length > LEGEND_INITIAL_VISIBLE) && /* @__PURE__ */ jsx(
1670
+ "button",
1671
+ {
1672
+ type: "button",
1673
+ className: "mt-1 text-[11px] text-primary hover:underline",
1674
+ onClick: () => setExpanded((e) => !e),
1675
+ "data-testid": `legend-toggle-${layerId}`,
1676
+ children: expanded ? "Show less" : `Show all (${filtered.length})`
1677
+ }
1678
+ )
1679
+ ]
1680
+ }
1681
+ );
1682
+ }
1561
1683
  function LayersPanel({
1562
1684
  layers,
1563
1685
  onAddLayer,
@@ -1585,6 +1707,7 @@ function LayersPanel({
1585
1707
  onUpdateTraceConfig,
1586
1708
  getAvailableTraceFields,
1587
1709
  getLayerFields,
1710
+ getFieldValueDistribution,
1588
1711
  onUpdateHeatmapConfig,
1589
1712
  onUpdateClusterConfig,
1590
1713
  onUpdateVisualConfig,
@@ -1601,6 +1724,7 @@ function LayersPanel({
1601
1724
  hideBasemapSwitcher = false,
1602
1725
  externalPersistence = false,
1603
1726
  customGlobalMenuItems,
1727
+ extraLayerToolbarButtons,
1604
1728
  layerBadgeProvider,
1605
1729
  featureCountProvider
1606
1730
  }) {
@@ -1693,7 +1817,7 @@ function LayersPanel({
1693
1817
  });
1694
1818
  }, [onRemoveLayer]);
1695
1819
  const renderLayerItem = (layer) => {
1696
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$;
1820
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba;
1697
1821
  const customCount = featureCountProvider == null ? void 0 : featureCountProvider(layer.id);
1698
1822
  const featureCount = customCount != null ? customCount : getFeatureCount(layer.id);
1699
1823
  const isExpanded = expandedLayers.has(layer.id);
@@ -1888,6 +2012,8 @@ function LayersPanel({
1888
2012
  groupByField: val === "all" ? null : val
1889
2013
  }),
1890
2014
  className: "w-full text-xs",
2015
+ showSearch: true,
2016
+ optionFilterProp: "label",
1891
2017
  options: [
1892
2018
  { value: "all", label: "Connect all points" },
1893
2019
  ...getAvailableTraceFields(layer.id).map((f) => ({ value: f, label: `Group by ${f}` }))
@@ -1904,12 +2030,11 @@ function LayersPanel({
1904
2030
  size: "small",
1905
2031
  checked: ((_d = layer.heatmapConfig) == null ? void 0 : _d.enabled) ?? false,
1906
2032
  onChange: (checked) => {
1907
- var _a2, _b2, _c2;
2033
+ var _a2, _b2;
1908
2034
  return onUpdateHeatmapConfig(layer.id, {
1909
2035
  enabled: checked,
1910
2036
  intensity: ((_a2 = layer.heatmapConfig) == null ? void 0 : _a2.intensity) ?? 1,
1911
- radius: ((_b2 = layer.heatmapConfig) == null ? void 0 : _b2.radius) ?? 20,
1912
- hideFeatures: ((_c2 = layer.heatmapConfig) == null ? void 0 : _c2.hideFeatures) ?? false
2037
+ radius: ((_b2 = layer.heatmapConfig) == null ? void 0 : _b2.radius) ?? 20
1913
2038
  });
1914
2039
  },
1915
2040
  "data-testid": `switch-heatmap-${layer.id}`
@@ -1951,20 +2076,6 @@ function LayersPanel({
1951
2076
  })
1952
2077
  }
1953
2078
  )
1954
- ] }),
1955
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
1956
- /* @__PURE__ */ jsx(
1957
- Switch,
1958
- {
1959
- size: "small",
1960
- checked: layer.heatmapConfig.hideFeatures ?? false,
1961
- onChange: (checked) => onUpdateHeatmapConfig(layer.id, {
1962
- ...layer.heatmapConfig,
1963
- hideFeatures: checked
1964
- })
1965
- }
1966
- ),
1967
- /* @__PURE__ */ jsx("span", { className: "text-[10px]", children: "Hide points" })
1968
2079
  ] })
1969
2080
  ] })
1970
2081
  ] }),
@@ -2000,6 +2111,8 @@ function LayersPanel({
2000
2111
  groupByField: val === "count" ? null : val
2001
2112
  }),
2002
2113
  className: "w-full text-xs",
2114
+ showSearch: true,
2115
+ optionFilterProp: "label",
2003
2116
  options: [
2004
2117
  { value: "count", label: "Simple count" },
2005
2118
  ...getLayerFields(layer.id).filter((f) => !f.isNumeric).map((f) => ({ value: f.name, label: `Pie by ${f.name}` }))
@@ -2101,6 +2214,8 @@ function LayersPanel({
2101
2214
  }),
2102
2215
  className: "w-full text-sm",
2103
2216
  placeholder: "Select field...",
2217
+ showSearch: true,
2218
+ optionFilterProp: "label",
2104
2219
  options: getLayerFields(layer.id).map((f) => ({ value: f.name, label: f.name })),
2105
2220
  "data-testid": `select-label-field-${layer.id}`
2106
2221
  }
@@ -2152,6 +2267,8 @@ function LayersPanel({
2152
2267
  }),
2153
2268
  className: "w-full text-sm",
2154
2269
  placeholder: "Select numeric field...",
2270
+ showSearch: true,
2271
+ optionFilterProp: "label",
2155
2272
  options: getLayerFields(layer.id).filter((f) => f.isNumeric).map((f) => ({ value: f.name, label: f.name })),
2156
2273
  "data-testid": `select-size-field-${layer.id}`
2157
2274
  }
@@ -2195,25 +2312,37 @@ function LayersPanel({
2195
2312
  "data-testid": `select-color-mode-${layer.id}`
2196
2313
  }
2197
2314
  ),
2198
- ((_K = (_J = layer.visualConfig) == null ? void 0 : _J.color) == null ? void 0 : _K.mode) === "field" && /* @__PURE__ */ jsx(
2199
- Select,
2200
- {
2201
- size: "small",
2202
- value: ((_M = (_L = layer.visualConfig) == null ? void 0 : _L.color) == null ? void 0 : _M.fieldName) ?? "",
2203
- onChange: (val) => onUpdateVisualConfig(layer.id, {
2204
- ...layer.visualConfig,
2205
- color: { mode: "field", fieldName: val }
2206
- }),
2207
- className: "w-full text-sm",
2208
- placeholder: "Select field...",
2209
- options: getLayerFields(layer.id).map((f) => ({ value: f.name, label: f.name })),
2210
- "data-testid": `select-color-field-${layer.id}`
2211
- }
2212
- ),
2213
- ((_O = (_N = layer.visualConfig) == null ? void 0 : _N.color) == null ? void 0 : _O.mode) === "fixed" && /* @__PURE__ */ jsx(
2315
+ ((_K = (_J = layer.visualConfig) == null ? void 0 : _J.color) == null ? void 0 : _K.mode) === "field" && /* @__PURE__ */ jsxs(Fragment, { children: [
2316
+ /* @__PURE__ */ jsx(
2317
+ Select,
2318
+ {
2319
+ size: "small",
2320
+ value: ((_M = (_L = layer.visualConfig) == null ? void 0 : _L.color) == null ? void 0 : _M.fieldName) ?? "",
2321
+ onChange: (val) => onUpdateVisualConfig(layer.id, {
2322
+ ...layer.visualConfig,
2323
+ color: { mode: "field", fieldName: val }
2324
+ }),
2325
+ className: "w-full text-sm",
2326
+ placeholder: "Select field...",
2327
+ showSearch: true,
2328
+ optionFilterProp: "label",
2329
+ options: getLayerFields(layer.id).map((f) => ({ value: f.name, label: f.name })),
2330
+ "data-testid": `select-color-field-${layer.id}`
2331
+ }
2332
+ ),
2333
+ ((_O = (_N = layer.visualConfig) == null ? void 0 : _N.color) == null ? void 0 : _O.fieldName) && getFieldValueDistribution && /* @__PURE__ */ jsx(
2334
+ ColorByFieldLegend,
2335
+ {
2336
+ layerId: layer.id,
2337
+ fieldName: layer.visualConfig.color.fieldName,
2338
+ getFieldValueDistribution
2339
+ }
2340
+ )
2341
+ ] }),
2342
+ ((_Q = (_P = layer.visualConfig) == null ? void 0 : _P.color) == null ? void 0 : _Q.mode) === "fixed" && /* @__PURE__ */ jsx(
2214
2343
  ColorPickerPopover,
2215
2344
  {
2216
- value: ((_Q = (_P = layer.visualConfig) == null ? void 0 : _P.color) == null ? void 0 : _Q.fixedColor) ?? "#3b82f6",
2345
+ value: ((_S = (_R = layer.visualConfig) == null ? void 0 : _R.color) == null ? void 0 : _S.fixedColor) ?? "#3b82f6",
2217
2346
  onChange: (color) => {
2218
2347
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
2219
2348
  ...layer.visualConfig,
@@ -2226,7 +2355,7 @@ function LayersPanel({
2226
2355
  testId: `color-fixed-${layer.id}`
2227
2356
  }
2228
2357
  ),
2229
- (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_R = layer.metadata) == null ? void 0 : _R.hidePointFeatures) && /* @__PURE__ */ jsxs(Fragment, { children: [
2358
+ (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_T = layer.metadata) == null ? void 0 : _T.hidePointFeatures) && /* @__PURE__ */ jsxs(Fragment, { children: [
2230
2359
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 text-sm text-muted-foreground pt-0.5", children: [
2231
2360
  /* @__PURE__ */ jsx(Smile, { className: "w-3.5 h-3.5" }),
2232
2361
  /* @__PURE__ */ jsx("span", { children: "Point Icon" })
@@ -2236,7 +2365,7 @@ function LayersPanel({
2236
2365
  Switch,
2237
2366
  {
2238
2367
  size: "small",
2239
- checked: ((_T = (_S = layer.visualConfig) == null ? void 0 : _S.icon) == null ? void 0 : _T.enabled) ?? false,
2368
+ checked: ((_V = (_U = layer.visualConfig) == null ? void 0 : _U.icon) == null ? void 0 : _V.enabled) ?? false,
2240
2369
  onChange: (checked) => {
2241
2370
  var _a2, _b2, _c2, _d2;
2242
2371
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
@@ -2251,11 +2380,11 @@ function LayersPanel({
2251
2380
  "data-testid": `switch-icon-${layer.id}`
2252
2381
  }
2253
2382
  ),
2254
- ((_V = (_U = layer.visualConfig) == null ? void 0 : _U.icon) == null ? void 0 : _V.enabled) && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 flex-1", children: [
2383
+ ((_X = (_W = layer.visualConfig) == null ? void 0 : _W.icon) == null ? void 0 : _X.enabled) && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 flex-1", children: [
2255
2384
  /* @__PURE__ */ jsx(
2256
2385
  IconPicker,
2257
2386
  {
2258
- value: ((_X = (_W = layer.visualConfig) == null ? void 0 : _W.icon) == null ? void 0 : _X.icon) ?? "📍",
2387
+ value: ((_Z = (_Y = layer.visualConfig) == null ? void 0 : _Y.icon) == null ? void 0 : _Z.icon) ?? "📍",
2259
2388
  onChange: (icon) => {
2260
2389
  var _a2, _b2;
2261
2390
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
@@ -2272,7 +2401,7 @@ function LayersPanel({
2272
2401
  /* @__PURE__ */ jsx(
2273
2402
  Slider,
2274
2403
  {
2275
- value: ((_Z = (_Y = layer.visualConfig) == null ? void 0 : _Y.icon) == null ? void 0 : _Z.size) ?? 24,
2404
+ value: ((_$ = (__ = layer.visualConfig) == null ? void 0 : __.icon) == null ? void 0 : _$.size) ?? 24,
2276
2405
  min: 12,
2277
2406
  max: 48,
2278
2407
  step: 2,
@@ -2290,7 +2419,7 @@ function LayersPanel({
2290
2419
  }
2291
2420
  }
2292
2421
  ),
2293
- /* @__PURE__ */ jsx("span", { className: "text-sm w-6 text-right", children: ((_$ = (__ = layer.visualConfig) == null ? void 0 : __.icon) == null ? void 0 : _$.size) ?? 24 })
2422
+ /* @__PURE__ */ jsx("span", { className: "text-sm w-6 text-right", children: ((_ba = (_aa = layer.visualConfig) == null ? void 0 : _aa.icon) == null ? void 0 : _ba.size) ?? 24 })
2294
2423
  ] })
2295
2424
  ] })
2296
2425
  ] })
@@ -2372,6 +2501,7 @@ function LayersPanel({
2372
2501
  ) })
2373
2502
  }
2374
2503
  ),
2504
+ extraLayerToolbarButtons,
2375
2505
  /* @__PURE__ */ jsx(
2376
2506
  Dropdown,
2377
2507
  {
@@ -2654,6 +2784,56 @@ function getFeatureTypeIcon(geometryType, kind, size = "sm") {
2654
2784
  return null;
2655
2785
  }
2656
2786
  }
2787
+ function colorPickerNoHexPanel(_panel, extra) {
2788
+ const { Picker, Presets } = extra.components;
2789
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2 min-w-[220px]", children: [
2790
+ /* @__PURE__ */ jsx(Picker, {}),
2791
+ /* @__PURE__ */ jsx(Presets, {})
2792
+ ] });
2793
+ }
2794
+ function LatLngFields(props) {
2795
+ const { latitude, longitude, isEditable, testIdPrefix } = props;
2796
+ if (!isEditable) {
2797
+ return /* @__PURE__ */ jsxs(
2798
+ "div",
2799
+ {
2800
+ className: "flex items-center gap-2 text-[13px] font-mono text-foreground px-1 py-1",
2801
+ "data-testid": `${testIdPrefix}-display`,
2802
+ children: [
2803
+ /* @__PURE__ */ jsx("span", { "data-testid": `${testIdPrefix}-latitude-text`, children: latitude || "—" }),
2804
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "/" }),
2805
+ /* @__PURE__ */ jsx("span", { "data-testid": `${testIdPrefix}-longitude-text`, children: longitude || "—" })
2806
+ ]
2807
+ }
2808
+ );
2809
+ }
2810
+ return /* @__PURE__ */ jsxs("div", { className: "flex gap-1", children: [
2811
+ /* @__PURE__ */ jsx(
2812
+ Input,
2813
+ {
2814
+ value: latitude,
2815
+ onChange: (e) => props.onLatChange(e.target.value),
2816
+ onFocus: props.onLatFocus,
2817
+ onBlur: props.onLatBlur,
2818
+ placeholder: "Latitude",
2819
+ className: "!h-6 text-[13px] flex-1",
2820
+ "data-testid": `${testIdPrefix}-latitude`
2821
+ }
2822
+ ),
2823
+ /* @__PURE__ */ jsx(
2824
+ Input,
2825
+ {
2826
+ value: longitude,
2827
+ onChange: (e) => props.onLngChange(e.target.value),
2828
+ onFocus: props.onLngFocus,
2829
+ onBlur: props.onLngBlur,
2830
+ placeholder: "Longitude",
2831
+ className: "!h-6 text-[13px] flex-1",
2832
+ "data-testid": `${testIdPrefix}-longitude`
2833
+ }
2834
+ )
2835
+ ] });
2836
+ }
2657
2837
  function PointColorDot({ color, size = 20 }) {
2658
2838
  return /* @__PURE__ */ jsx("svg", { width: size, height: size, viewBox: "0 0 20 20", className: "shrink-0", children: /* @__PURE__ */ jsx("circle", { cx: "10", cy: "10", r: "7", fill: color, stroke: color, strokeWidth: "2", opacity: "0.9" }) });
2659
2839
  }
@@ -2707,8 +2887,21 @@ const RECORD_EXCLUDE_KEYS = /* @__PURE__ */ new Set([
2707
2887
  "entityType",
2708
2888
  "startDate",
2709
2889
  "endDate",
2710
- "description"
2890
+ // The feature's color is already conveyed by the colored dot in the panel
2891
+ // header; showing it again as a property row (`#0C66E4`) is just noise.
2892
+ "color"
2893
+ // NOTE: 'description' intentionally NOT excluded — we surface it as a regular
2894
+ // property row instead of giving it its own labelled section.
2711
2895
  ]);
2896
+ function buildKeyExclusionPredicate(set) {
2897
+ const lowered = new Set(Array.from(set, (k) => k.toLowerCase()));
2898
+ return (key) => {
2899
+ if (set.has(key)) return true;
2900
+ const normalized = key.toLowerCase().replace(/^[^a-z0-9_-]+/, "");
2901
+ return lowered.has(normalized);
2902
+ };
2903
+ }
2904
+ const isExcludedRecordKey = buildKeyExclusionPredicate(RECORD_EXCLUDE_KEYS);
2712
2905
  const RECORD_FIELDS_HIDDEN_PREFIXES = ["_", "os_"];
2713
2906
  function parseRecordFields(feature) {
2714
2907
  const raw = feature.properties._recordFields;
@@ -2735,14 +2928,14 @@ function RecordFieldsSection({ feature }) {
2735
2928
  Collapse,
2736
2929
  {
2737
2930
  size: "small",
2738
- defaultActiveKey: ["record-fields"],
2931
+ defaultActiveKey: [],
2739
2932
  ghost: true,
2740
2933
  className: "[&_.ant-collapse-header]:!px-0 [&_.ant-collapse-header]:!py-1 [&_.ant-collapse-content-box]:!px-0 [&_.ant-collapse-content-box]:!py-1",
2741
2934
  items: [{
2742
2935
  key: "record-fields",
2743
2936
  label: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
2744
2937
  /* @__PURE__ */ jsx(Info, { className: "w-3 h-3 text-foreground" }),
2745
- /* @__PURE__ */ jsx("span", { className: "text-xs font-medium", children: "Record Fields" }),
2938
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] font-bold uppercase tracking-wide text-foreground", children: "Record Fields" }),
2746
2939
  /* @__PURE__ */ jsxs("span", { className: "text-[10px] text-muted-foreground ml-1", children: [
2747
2940
  "(",
2748
2941
  fields.length,
@@ -2758,7 +2951,7 @@ function RecordFieldsSection({ feature }) {
2758
2951
  );
2759
2952
  }
2760
2953
  let persistedTabPreference = "properties";
2761
- function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometry, onClose, isEditMode = true, isReadOnlyLayer = false, layerName, layerId, autoFocusLabel = false, entityCardProvider, typePickerProvider, featureSaveProvider, featureRefreshProvider, onFeatureSaved, onDeleteFeatures, onOpenInNewTab, onEntityContextMenu, layers, onMoveFeaturesToLayer, onCopyFeaturesToLayer, onCreateLayerAndMoveFeatures, onCreateLayerAndCopyFeatures }) {
2954
+ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometry, onClose, isEditMode = true, isReadOnlyLayer = false, layerName, layerId, autoFocusLabel = false, entityCardProvider, typePickerProvider, featureSaveProvider, featureRefreshProvider, onFeatureSaved, onDeleteFeatures, onOpenInNewTab, onEntityContextMenu, layers, onMoveFeaturesToLayer, onCopyFeaturesToLayer, onCreateLayerAndMoveFeatures, onCreateLayerAndCopyFeatures, getFeatureColor }) {
2762
2955
  var _a, _b, _c, _d, _e;
2763
2956
  const feature = selectedFeatures[0];
2764
2957
  const { toast } = useToast();
@@ -2833,6 +3026,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
2833
3026
  const [endDate, setEndDate] = useState("");
2834
3027
  const [customProperties, setCustomProperties] = useState([]);
2835
3028
  const [newPropertyKey, setNewPropertyKey] = useState("");
3029
+ const headerDotColor = feature && (getFeatureColor == null ? void 0 : getFeatureColor(feature.id)) || (feature == null ? void 0 : feature.properties.stroke) || "#3b82f6";
2836
3030
  const [strokeColor, setStrokeColor] = useState("#3b82f6");
2837
3031
  const [strokeWidth, setStrokeWidth] = useState(2);
2838
3032
  const [strokeOpacity, setStrokeOpacity] = useState(1);
@@ -2891,10 +3085,46 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
2891
3085
  setLatitude("");
2892
3086
  }
2893
3087
  }
2894
- const reserved = ["name", "description", "startDate", "endDate", "stroke", "stroke-width", "stroke-opacity", "fill", "fill-opacity", "kind", "label", "fontSize", "fontColor", "fontWeight", "arrowSize", "circleCenter", "circleRadius", "icon", "iconSize", "pointIcon", "pointIconSize", "entityType", "entity_id", "entity_type", "entity_label", "os_workspace", "workspace", "source_name", "id", "latitude", "longitude"];
3088
+ const reserved = /* @__PURE__ */ new Set([
3089
+ "name",
3090
+ "description",
3091
+ "startDate",
3092
+ "endDate",
3093
+ "stroke",
3094
+ "stroke-width",
3095
+ "stroke-opacity",
3096
+ "fill",
3097
+ "fill-opacity",
3098
+ "kind",
3099
+ "label",
3100
+ "fontSize",
3101
+ "fontColor",
3102
+ "fontWeight",
3103
+ "arrowSize",
3104
+ "circleCenter",
3105
+ "circleRadius",
3106
+ "icon",
3107
+ "iconSize",
3108
+ "pointIcon",
3109
+ "pointIconSize",
3110
+ "entityType",
3111
+ "entity_id",
3112
+ "entity_type",
3113
+ "entity_label",
3114
+ "os_workspace",
3115
+ "workspace",
3116
+ "source_name",
3117
+ "id",
3118
+ "latitude",
3119
+ "longitude",
3120
+ // The marker color is shown via the colored dot in the panel header,
3121
+ // so we don't repeat it as an editable property row.
3122
+ "color"
3123
+ ]);
3124
+ const isReservedKey = buildKeyExclusionPredicate(reserved);
2895
3125
  const custom = [];
2896
3126
  Object.entries(feature.properties).forEach(([key, value]) => {
2897
- if (!reserved.includes(key) && value !== void 0 && value !== null && !key.startsWith("_") && !key.startsWith("os_") && !key.startsWith("isHidden")) {
3127
+ if (!isReservedKey(key) && value !== void 0 && value !== null && !key.startsWith("_") && !key.startsWith("os_") && !key.startsWith("isHidden")) {
2898
3128
  custom.push({ key, value: String(value) });
2899
3129
  }
2900
3130
  });
@@ -3078,7 +3308,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3078
3308
  handleRefresh(true);
3079
3309
  }, [feature == null ? void 0 : feature.id, isRecord, featureRefreshProvider, feature, handleRefresh]);
3080
3310
  const recordProperties = feature ? Object.entries(feature.properties).filter(
3081
- ([key, value]) => !RECORD_EXCLUDE_KEYS.has(key) && value !== void 0 && value !== null && !key.startsWith("_") && !key.startsWith("isHidden")
3311
+ ([key, value]) => !isExcludedRecordKey(key) && value !== void 0 && value !== null && !key.startsWith("_") && !key.startsWith("os_") && !key.startsWith("isHidden")
3082
3312
  ).map(([key, value]) => ({ key, value: String(value) })) : [];
3083
3313
  const entityCardsContent = /* @__PURE__ */ jsx("div", { className: "p-2 space-y-2", children: entityCardProvider ? selectedFeatures.map((f) => {
3084
3314
  const geoFeature = {
@@ -3095,7 +3325,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3095
3325
  return /* @__PURE__ */ jsxs(
3096
3326
  "div",
3097
3327
  {
3098
- className: "absolute top-4 right-4 z-10 w-72 bg-background/95 floating-panel rounded-lg shadow-lg border border-border",
3328
+ className: "absolute top-4 right-4 z-10 w-80 bg-background/95 floating-panel rounded-lg shadow-lg border border-border",
3099
3329
  "data-testid": "panel-properties",
3100
3330
  children: [
3101
3331
  /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2 px-2.5 py-2 border-b border-border", children: [
@@ -3131,21 +3361,20 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3131
3361
  onMoveFeaturesToLayer && /* @__PURE__ */ jsx(Dropdown, { menu: { items: buildLayerMenuItems("move") }, trigger: ["click"], placement: "bottomRight", children: /* @__PURE__ */ jsx(Tooltip, { title: "Move to layer", children: /* @__PURE__ */ jsx(Button, { type: "text", icon: /* @__PURE__ */ jsx(FolderInput, { className: "w-3.5 h-3.5" }), className: "!w-5 !h-5 !min-w-0 !p-0", "data-testid": "button-move-to-layer-prop" }) }) })
3132
3362
  ] })
3133
3363
  ] }),
3134
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 flex-wrap", children: [
3135
- isRecord ? /* @__PURE__ */ jsx(Tag, { color: "cyan", className: "!text-[10px] !px-1.5 !py-0 !leading-4 !m-0", children: "Octostar record" }) : /* @__PURE__ */ jsx(Tag, { color: "blue", className: "!text-[10px] !px-1.5 !py-0 !leading-4 !m-0", children: "Local map feature" }),
3136
- isUnsaved && /* @__PURE__ */ jsx(Tag, { color: "orange", className: "!text-[10px] !px-1.5 !py-0 !leading-4 !border-0 !m-0", children: "unsaved" }),
3364
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 flex-wrap", children: [
3365
+ isRecord ? /* @__PURE__ */ jsx(Tag, { color: "cyan", className: "!text-[12px] !px-2.5 !py-0.5 !leading-5 !m-0 !font-semibold", children: "Octostar record" }) : /* @__PURE__ */ jsx(Tag, { color: "blue", className: "!text-[12px] !px-2.5 !py-0.5 !leading-5 !m-0 !font-semibold", children: "Local map feature" }),
3366
+ isUnsaved && /* @__PURE__ */ jsx(Tag, { color: "orange", className: "!text-[12px] !px-2.5 !py-0.5 !leading-5 !border-0 !m-0 !font-semibold", children: "Unsaved" }),
3137
3367
  !isRecord && featureSaveProvider && /* @__PURE__ */ jsx(
3138
3368
  Button,
3139
3369
  {
3140
3370
  type: "primary",
3141
- size: "small",
3142
- icon: /* @__PURE__ */ jsx(Save, { className: "w-3 h-3" }),
3371
+ size: "middle",
3372
+ icon: /* @__PURE__ */ jsx(Save, { className: "w-3.5 h-3.5" }),
3143
3373
  loading: isSaving,
3144
3374
  onClick: handleFeatureSave,
3145
- className: "!h-5 !px-1.5 !text-[11px]",
3146
- style: { padding: "1px 6px" },
3375
+ className: "!h-7 !px-3 !text-[12px] !font-medium",
3147
3376
  "data-testid": "button-save-feature",
3148
- children: "Create entity…"
3377
+ children: "Create entity"
3149
3378
  }
3150
3379
  )
3151
3380
  ] })
@@ -3229,92 +3458,57 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3229
3458
  /* @__PURE__ */ jsx("label", { className: "text-xs text-muted-foreground", children: "Lat / Lng" }),
3230
3459
  feature.geometry.type !== "Point" && /* @__PURE__ */ jsx(Tooltip, { title: "Lat and Lng refer to the centroid of this feature", children: /* @__PURE__ */ jsx("span", { className: "text-[13px] text-muted-foreground cursor-help", children: "*" }) })
3231
3460
  ] }),
3232
- /* @__PURE__ */ jsxs("div", { className: "flex gap-1", children: [
3233
- /* @__PURE__ */ jsx(
3234
- Input,
3235
- {
3236
- value: latitude,
3237
- onChange: (e) => setLatitude(e.target.value),
3238
- onFocus: () => {
3239
- latInputFocused.current = true;
3240
- },
3241
- onBlur: () => {
3242
- latInputFocused.current = false;
3243
- if (feature.geometry.type === "Point" && isEditMode && !isReadOnlyLayer && onUpdateGeometry) {
3244
- const lat = parseFloat(latitude);
3245
- const lng = parseFloat(longitude);
3246
- const coords = feature.geometry.coordinates;
3247
- if (isNaN(lat)) {
3248
- toast({ title: "Invalid latitude", description: "Please enter a valid number", variant: "destructive" });
3249
- setLatitude(coords[1].toFixed(6));
3250
- } else if (lat < -90 || lat > 90) {
3251
- toast({ title: "Invalid latitude", description: "Latitude must be between -90 and 90", variant: "destructive" });
3252
- setLatitude(coords[1].toFixed(6));
3253
- } else if (isNaN(lng) || lng < -180 || lng > 180) ;
3254
- else {
3255
- onUpdateGeometry(feature.id, {
3256
- type: "Point",
3257
- coordinates: [lng, lat]
3258
- });
3259
- }
3461
+ /* @__PURE__ */ jsx(
3462
+ LatLngFields,
3463
+ {
3464
+ latitude,
3465
+ longitude,
3466
+ isEditable: feature.geometry.type === "Point" && isEditMode && !isReadOnlyLayer,
3467
+ testIdPrefix: "input-feature",
3468
+ onLatChange: setLatitude,
3469
+ onLngChange: setLongitude,
3470
+ onLatFocus: () => {
3471
+ latInputFocused.current = true;
3472
+ },
3473
+ onLngFocus: () => {
3474
+ lngInputFocused.current = true;
3475
+ },
3476
+ onLatBlur: () => {
3477
+ latInputFocused.current = false;
3478
+ if (feature.geometry.type === "Point" && isEditMode && !isReadOnlyLayer && onUpdateGeometry) {
3479
+ const lat = parseFloat(latitude);
3480
+ const lng = parseFloat(longitude);
3481
+ const coords = feature.geometry.coordinates;
3482
+ if (isNaN(lat)) {
3483
+ toast({ title: "Invalid latitude", description: "Please enter a valid number", variant: "destructive" });
3484
+ setLatitude(coords[1].toFixed(6));
3485
+ } else if (lat < -90 || lat > 90) {
3486
+ toast({ title: "Invalid latitude", description: "Latitude must be between -90 and 90", variant: "destructive" });
3487
+ setLatitude(coords[1].toFixed(6));
3488
+ } else if (isNaN(lng) || lng < -180 || lng > 180) ;
3489
+ else {
3490
+ onUpdateGeometry(feature.id, { type: "Point", coordinates: [lng, lat] });
3260
3491
  }
3261
- },
3262
- placeholder: "Latitude",
3263
- readOnly: feature.geometry.type !== "Point" || !isEditMode || isReadOnlyLayer,
3264
- className: "!h-6 text-[13px] flex-1",
3265
- "data-testid": "input-feature-latitude"
3266
- }
3267
- ),
3268
- /* @__PURE__ */ jsx(
3269
- Input,
3270
- {
3271
- value: longitude,
3272
- onChange: (e) => setLongitude(e.target.value),
3273
- onFocus: () => {
3274
- lngInputFocused.current = true;
3275
- },
3276
- onBlur: () => {
3277
- lngInputFocused.current = false;
3278
- if (feature.geometry.type === "Point" && isEditMode && !isReadOnlyLayer && onUpdateGeometry) {
3279
- const lat = parseFloat(latitude);
3280
- const lng = parseFloat(longitude);
3281
- const coords = feature.geometry.coordinates;
3282
- if (isNaN(lng)) {
3283
- toast({ title: "Invalid longitude", description: "Please enter a valid number", variant: "destructive" });
3284
- setLongitude(coords[0].toFixed(6));
3285
- } else if (lng < -180 || lng > 180) {
3286
- toast({ title: "Invalid longitude", description: "Longitude must be between -180 and 180", variant: "destructive" });
3287
- setLongitude(coords[0].toFixed(6));
3288
- } else if (isNaN(lat) || lat < -90 || lat > 90) ;
3289
- else {
3290
- onUpdateGeometry(feature.id, {
3291
- type: "Point",
3292
- coordinates: [lng, lat]
3293
- });
3294
- }
3492
+ }
3493
+ },
3494
+ onLngBlur: () => {
3495
+ lngInputFocused.current = false;
3496
+ if (feature.geometry.type === "Point" && isEditMode && !isReadOnlyLayer && onUpdateGeometry) {
3497
+ const lat = parseFloat(latitude);
3498
+ const lng = parseFloat(longitude);
3499
+ const coords = feature.geometry.coordinates;
3500
+ if (isNaN(lng)) {
3501
+ toast({ title: "Invalid longitude", description: "Please enter a valid number", variant: "destructive" });
3502
+ setLongitude(coords[0].toFixed(6));
3503
+ } else if (lng < -180 || lng > 180) {
3504
+ toast({ title: "Invalid longitude", description: "Longitude must be between -180 and 180", variant: "destructive" });
3505
+ setLongitude(coords[0].toFixed(6));
3506
+ } else if (isNaN(lat) || lat < -90 || lat > 90) ;
3507
+ else {
3508
+ onUpdateGeometry(feature.id, { type: "Point", coordinates: [lng, lat] });
3295
3509
  }
3296
- },
3297
- placeholder: "Longitude",
3298
- readOnly: feature.geometry.type !== "Point" || !isEditMode || isReadOnlyLayer,
3299
- className: "!h-6 text-[13px] flex-1",
3300
- "data-testid": "input-feature-longitude"
3510
+ }
3301
3511
  }
3302
- )
3303
- ] })
3304
- ] }),
3305
- /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
3306
- /* @__PURE__ */ jsx("label", { htmlFor: "feature-description", className: "text-xs text-muted-foreground", children: "Description" }),
3307
- /* @__PURE__ */ jsx(
3308
- TextArea,
3309
- {
3310
- id: "feature-description",
3311
- value: description,
3312
- onChange: (e) => setDescription(e.target.value),
3313
- onBlur: () => handleSave(),
3314
- placeholder: isEditMode ? "Add description..." : "No description",
3315
- className: "!min-h-[50px] resize-none text-[13px]",
3316
- readOnly: !isEditMode,
3317
- "data-testid": "input-feature-description"
3318
3512
  }
3319
3513
  )
3320
3514
  ] }),
@@ -3330,7 +3524,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3330
3524
  key: "temporal",
3331
3525
  label: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
3332
3526
  /* @__PURE__ */ jsx(Calendar, { className: "w-3 h-3 text-foreground" }),
3333
- /* @__PURE__ */ jsx("span", { className: "text-xs font-medium", children: "Temporal" }),
3527
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] font-bold uppercase tracking-wide text-foreground", children: "Temporal" }),
3334
3528
  (startDate || endDate) && /* @__PURE__ */ jsxs("span", { className: "text-[10px] text-muted-foreground ml-1", children: [
3335
3529
  "(",
3336
3530
  startDate && endDate ? "2 dates" : "1 date",
@@ -3417,10 +3611,10 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3417
3611
  }
3418
3612
  ),
3419
3613
  /* @__PURE__ */ jsx(Divider, { className: "!my-1.5" }),
3420
- /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
3614
+ /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
3421
3615
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
3422
3616
  /* @__PURE__ */ jsx(Palette, { className: "w-3 h-3 text-foreground" }),
3423
- /* @__PURE__ */ jsx("span", { className: "text-xs font-medium", children: "Style" })
3617
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] font-bold uppercase tracking-wide text-foreground", children: "Style" })
3424
3618
  ] }),
3425
3619
  feature.properties.kind === "text" && /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
3426
3620
  /* @__PURE__ */ jsxs("div", { children: [
@@ -3537,6 +3731,8 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3537
3731
  disabled: !isEditMode,
3538
3732
  size: "small",
3539
3733
  showText: false,
3734
+ disabledAlpha: true,
3735
+ panelRender: colorPickerNoHexPanel,
3540
3736
  "data-testid": "color-picker-stroke"
3541
3737
  }
3542
3738
  ) }) }),
@@ -3611,6 +3807,8 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3611
3807
  disabled: !isEditMode,
3612
3808
  size: "small",
3613
3809
  showText: false,
3810
+ disabledAlpha: true,
3811
+ panelRender: colorPickerNoHexPanel,
3614
3812
  "data-testid": "color-picker-fill"
3615
3813
  }
3616
3814
  ) }) }),
@@ -3667,49 +3865,67 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3667
3865
  ] })
3668
3866
  ] }),
3669
3867
  /* @__PURE__ */ jsx(Divider, { className: "!my-1.5" }),
3670
- /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
3671
- /* @__PURE__ */ jsx("span", { className: "text-xs font-medium", children: "Custom Properties" }),
3672
- customProperties.length === 0 && !isEditMode && /* @__PURE__ */ jsx("p", { className: "text-[13px] text-muted-foreground", children: "None" }),
3673
- customProperties.length > 0 && /* @__PURE__ */ jsx("div", { className: "space-y-0.5", children: customProperties.map((prop, index) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-0.5", children: [
3674
- /* @__PURE__ */ jsx(
3675
- Input,
3676
- {
3677
- value: prop.key,
3678
- onChange: (e) => handlePropertyKeyChange(index, e.target.value),
3679
- onBlur: () => handleSave(),
3680
- placeholder: "Key",
3681
- className: "flex-1 text-[13px] font-mono !h-5 !px-1",
3682
- readOnly: !isEditMode,
3683
- "data-testid": `input-property-key-${index}`
3684
- }
3685
- ),
3686
- /* @__PURE__ */ jsx(
3687
- Input,
3688
- {
3689
- value: prop.value,
3690
- onChange: (e) => handlePropertyValueChange(index, e.target.value),
3691
- onBlur: () => handleSave(),
3692
- placeholder: "Val",
3693
- className: "flex-1 text-[13px] !h-5 !px-1",
3694
- readOnly: !isEditMode,
3695
- "data-testid": `input-property-value-${index}`
3696
- }
3697
- ),
3698
- isEditMode && /* @__PURE__ */ jsx(
3699
- "button",
3700
- {
3701
- type: "button",
3702
- onClick: () => {
3703
- handleRemoveProperty(index);
3704
- setTimeout(() => handleSave(), 0);
3705
- },
3706
- className: "text-destructive shrink-0 h-5 w-5 flex items-center justify-center",
3707
- "data-testid": `button-remove-property-${index}`,
3708
- children: /* @__PURE__ */ jsx(Trash2, { className: "w-2.5 h-2.5" })
3709
- }
3710
- )
3711
- ] }, index)) }),
3712
- isEditMode && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-0.5", children: [
3868
+ /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
3869
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] font-bold uppercase tracking-wide text-foreground", children: "Properties" }),
3870
+ /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
3871
+ /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-1", children: [
3872
+ /* @__PURE__ */ jsx("div", { className: "text-[13px] font-mono text-muted-foreground shrink-0 w-24 px-1 leading-6 select-none", children: "description" }),
3873
+ /* @__PURE__ */ jsx(
3874
+ TextArea,
3875
+ {
3876
+ id: "feature-description",
3877
+ value: description,
3878
+ onChange: (e) => setDescription(e.target.value),
3879
+ onBlur: () => handleSave(),
3880
+ autoSize: { minRows: 1, maxRows: 5 },
3881
+ placeholder: isEditMode ? "—" : "",
3882
+ readOnly: !isEditMode,
3883
+ className: "flex-1 !text-[13px] !px-1.5 !py-0.5 resize-none",
3884
+ "data-testid": "input-feature-description"
3885
+ }
3886
+ )
3887
+ ] }),
3888
+ customProperties.map((prop, index) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
3889
+ /* @__PURE__ */ jsx(
3890
+ Input,
3891
+ {
3892
+ value: prop.key,
3893
+ onChange: (e) => handlePropertyKeyChange(index, e.target.value),
3894
+ onBlur: () => handleSave(),
3895
+ placeholder: "Key",
3896
+ className: "shrink-0 w-24 text-[13px] font-mono !h-6 !px-1",
3897
+ readOnly: !isEditMode,
3898
+ "data-testid": `input-property-key-${index}`
3899
+ }
3900
+ ),
3901
+ /* @__PURE__ */ jsx(
3902
+ Input,
3903
+ {
3904
+ value: prop.value,
3905
+ onChange: (e) => handlePropertyValueChange(index, e.target.value),
3906
+ onBlur: () => handleSave(),
3907
+ placeholder: "Value",
3908
+ className: "flex-1 text-[13px] !h-6 !px-1.5",
3909
+ readOnly: !isEditMode,
3910
+ "data-testid": `input-property-value-${index}`
3911
+ }
3912
+ ),
3913
+ isEditMode && /* @__PURE__ */ jsx(
3914
+ "button",
3915
+ {
3916
+ type: "button",
3917
+ onClick: () => {
3918
+ handleRemoveProperty(index);
3919
+ setTimeout(() => handleSave(), 0);
3920
+ },
3921
+ className: "text-destructive shrink-0 h-6 w-6 flex items-center justify-center rounded hover:bg-destructive/10 transition-colors",
3922
+ "data-testid": `button-remove-property-${index}`,
3923
+ children: /* @__PURE__ */ jsx(Trash2, { className: "w-3 h-3" })
3924
+ }
3925
+ )
3926
+ ] }, index))
3927
+ ] }),
3928
+ isEditMode && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 pt-0.5", children: [
3713
3929
  /* @__PURE__ */ jsx(
3714
3930
  Input,
3715
3931
  {
@@ -3721,8 +3937,8 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3721
3937
  handleAddProperty();
3722
3938
  }
3723
3939
  },
3724
- placeholder: "New property...",
3725
- className: "flex-1 text-[13px] !h-5 !px-1",
3940
+ placeholder: "New property…",
3941
+ className: "flex-1 text-[13px] !h-6 !px-1.5",
3726
3942
  "data-testid": "input-new-property-key"
3727
3943
  }
3728
3944
  ),
@@ -3732,9 +3948,9 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3732
3948
  type: "button",
3733
3949
  onClick: handleAddProperty,
3734
3950
  disabled: !newPropertyKey.trim(),
3735
- className: "h-5 w-5 flex items-center justify-center border border-border rounded disabled:opacity-50",
3951
+ className: "h-6 w-6 flex items-center justify-center border border-border rounded disabled:opacity-50 hover:bg-muted transition-colors",
3736
3952
  "data-testid": "button-add-property",
3737
- children: /* @__PURE__ */ jsx(Plus, { className: "w-2.5 h-2.5" })
3953
+ children: /* @__PURE__ */ jsx(Plus, { className: "w-3 h-3" })
3738
3954
  }
3739
3955
  )
3740
3956
  ] })
@@ -3754,7 +3970,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3754
3970
  /* @__PURE__ */ jsx("span", { className: "text-[12px] text-muted-foreground", children: "Layer:" }),
3755
3971
  /* @__PURE__ */ jsx("span", { className: "text-[12px] text-foreground truncate", children: layerName })
3756
3972
  ] }),
3757
- /* @__PURE__ */ jsx("div", { className: "flex items-center gap-1.5 flex-wrap", children: /* @__PURE__ */ jsx(Tag, { color: "cyan", className: "!text-[10px] !px-1.5 !py-0 !leading-4 !m-0", children: "Octostar record" }) })
3973
+ /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2 flex-wrap", children: /* @__PURE__ */ jsx(Tag, { color: "cyan", className: "!text-[12px] !px-2.5 !py-0.5 !leading-5 !m-0 !font-semibold", children: "Octostar record" }) })
3758
3974
  ] }),
3759
3975
  /* @__PURE__ */ jsx(Divider, { className: "!my-1.5" }),
3760
3976
  /* @__PURE__ */ jsx("div", { className: "space-y-1", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
@@ -3775,93 +3991,73 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3775
3991
  ) })
3776
3992
  ] }) }),
3777
3993
  /* @__PURE__ */ jsx(Divider, { className: "!my-1.5" }),
3778
- feature.properties.description && /* @__PURE__ */ jsxs(Fragment, { children: [
3779
- /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
3780
- /* @__PURE__ */ jsx("label", { className: "text-xs text-muted-foreground", children: "Description" }),
3781
- /* @__PURE__ */ jsx("p", { className: "text-[13px] text-foreground whitespace-pre-wrap break-words m-0", children: String(feature.properties.description) })
3782
- ] }),
3783
- /* @__PURE__ */ jsx(Divider, { className: "!my-1.5" })
3784
- ] }),
3785
3994
  /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
3786
3995
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
3787
3996
  /* @__PURE__ */ jsx(MapPin, { className: "w-3 h-3 text-muted-foreground" }),
3788
3997
  /* @__PURE__ */ jsx("label", { className: "text-xs text-muted-foreground", children: "Lat / Lng" }),
3789
3998
  feature.geometry.type !== "Point" && /* @__PURE__ */ jsx(Tooltip, { title: "Lat and Lng refer to the centroid of this feature", children: /* @__PURE__ */ jsx("span", { className: "text-[13px] text-muted-foreground cursor-help", children: "*" }) })
3790
3999
  ] }),
3791
- /* @__PURE__ */ jsxs("div", { className: "flex gap-1", children: [
3792
- /* @__PURE__ */ jsx(
3793
- Input,
3794
- {
3795
- value: latitude,
3796
- onChange: (e) => setLatitude(e.target.value),
3797
- onFocus: () => {
3798
- latInputFocused.current = true;
3799
- },
3800
- onBlur: () => {
3801
- latInputFocused.current = false;
3802
- if (feature.geometry.type === "Point" && isEditMode && !isReadOnlyLayer && onUpdateGeometry) {
3803
- const lat = parseFloat(latitude);
3804
- const lng = parseFloat(longitude);
3805
- const coords = feature.geometry.coordinates;
3806
- if (isNaN(lat)) {
3807
- toast({ title: "Invalid latitude", description: "Please enter a valid number", variant: "destructive" });
3808
- setLatitude(coords[1].toFixed(6));
3809
- } else if (lat < -90 || lat > 90) {
3810
- toast({ title: "Invalid latitude", description: "Latitude must be between -90 and 90", variant: "destructive" });
3811
- setLatitude(coords[1].toFixed(6));
3812
- } else if (isNaN(lng) || lng < -180 || lng > 180) ;
3813
- else {
3814
- onUpdateGeometry(feature.id, { type: "Point", coordinates: [lng, lat] });
3815
- }
4000
+ /* @__PURE__ */ jsx(
4001
+ LatLngFields,
4002
+ {
4003
+ latitude,
4004
+ longitude,
4005
+ isEditable: feature.geometry.type === "Point" && isEditMode && !isReadOnlyLayer,
4006
+ testIdPrefix: "input-record",
4007
+ onLatChange: setLatitude,
4008
+ onLngChange: setLongitude,
4009
+ onLatFocus: () => {
4010
+ latInputFocused.current = true;
4011
+ },
4012
+ onLngFocus: () => {
4013
+ lngInputFocused.current = true;
4014
+ },
4015
+ onLatBlur: () => {
4016
+ latInputFocused.current = false;
4017
+ if (feature.geometry.type === "Point" && isEditMode && !isReadOnlyLayer && onUpdateGeometry) {
4018
+ const lat = parseFloat(latitude);
4019
+ const lng = parseFloat(longitude);
4020
+ const coords = feature.geometry.coordinates;
4021
+ if (isNaN(lat)) {
4022
+ toast({ title: "Invalid latitude", description: "Please enter a valid number", variant: "destructive" });
4023
+ setLatitude(coords[1].toFixed(6));
4024
+ } else if (lat < -90 || lat > 90) {
4025
+ toast({ title: "Invalid latitude", description: "Latitude must be between -90 and 90", variant: "destructive" });
4026
+ setLatitude(coords[1].toFixed(6));
4027
+ } else if (isNaN(lng) || lng < -180 || lng > 180) ;
4028
+ else {
4029
+ onUpdateGeometry(feature.id, { type: "Point", coordinates: [lng, lat] });
3816
4030
  }
3817
- },
3818
- placeholder: "Latitude",
3819
- readOnly: feature.geometry.type !== "Point" || !isEditMode || isReadOnlyLayer,
3820
- className: "!h-6 text-[13px] flex-1",
3821
- "data-testid": "input-record-latitude"
3822
- }
3823
- ),
3824
- /* @__PURE__ */ jsx(
3825
- Input,
3826
- {
3827
- value: longitude,
3828
- onChange: (e) => setLongitude(e.target.value),
3829
- onFocus: () => {
3830
- lngInputFocused.current = true;
3831
- },
3832
- onBlur: () => {
3833
- lngInputFocused.current = false;
3834
- if (feature.geometry.type === "Point" && isEditMode && !isReadOnlyLayer && onUpdateGeometry) {
3835
- const lat = parseFloat(latitude);
3836
- const lng = parseFloat(longitude);
3837
- const coords = feature.geometry.coordinates;
3838
- if (isNaN(lng)) {
3839
- toast({ title: "Invalid longitude", description: "Please enter a valid number", variant: "destructive" });
3840
- setLongitude(coords[0].toFixed(6));
3841
- } else if (lng < -180 || lng > 180) {
3842
- toast({ title: "Invalid longitude", description: "Longitude must be between -180 and 180", variant: "destructive" });
3843
- setLongitude(coords[0].toFixed(6));
3844
- } else if (isNaN(lat) || lat < -90 || lat > 90) ;
3845
- else {
3846
- onUpdateGeometry(feature.id, { type: "Point", coordinates: [lng, lat] });
3847
- }
4031
+ }
4032
+ },
4033
+ onLngBlur: () => {
4034
+ lngInputFocused.current = false;
4035
+ if (feature.geometry.type === "Point" && isEditMode && !isReadOnlyLayer && onUpdateGeometry) {
4036
+ const lat = parseFloat(latitude);
4037
+ const lng = parseFloat(longitude);
4038
+ const coords = feature.geometry.coordinates;
4039
+ if (isNaN(lng)) {
4040
+ toast({ title: "Invalid longitude", description: "Please enter a valid number", variant: "destructive" });
4041
+ setLongitude(coords[0].toFixed(6));
4042
+ } else if (lng < -180 || lng > 180) {
4043
+ toast({ title: "Invalid longitude", description: "Longitude must be between -180 and 180", variant: "destructive" });
4044
+ setLongitude(coords[0].toFixed(6));
4045
+ } else if (isNaN(lat) || lat < -90 || lat > 90) ;
4046
+ else {
4047
+ onUpdateGeometry(feature.id, { type: "Point", coordinates: [lng, lat] });
3848
4048
  }
3849
- },
3850
- placeholder: "Longitude",
3851
- readOnly: feature.geometry.type !== "Point" || !isEditMode || isReadOnlyLayer,
3852
- className: "!h-6 text-[13px] flex-1",
3853
- "data-testid": "input-record-longitude"
4049
+ }
3854
4050
  }
3855
- )
3856
- ] })
4051
+ }
4052
+ )
3857
4053
  ] }),
3858
4054
  recordProperties.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
3859
4055
  /* @__PURE__ */ jsx(Divider, { className: "!my-1.5" }),
3860
4056
  /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
3861
- /* @__PURE__ */ jsx("span", { className: "text-xs font-medium", children: "Properties" }),
4057
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] font-bold uppercase tracking-wide text-foreground", children: "Properties" }),
3862
4058
  /* @__PURE__ */ jsx("div", { className: "space-y-0.5", children: recordProperties.map(({ key, value }) => /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-2 py-0.5", children: [
3863
4059
  /* @__PURE__ */ jsx("span", { className: "text-[11px] text-muted-foreground shrink-0 pt-px min-w-[80px]", children: formatPropertyKey(key) }),
3864
- /* @__PURE__ */ jsx("span", { className: "text-[13px] text-foreground break-all", children: value })
4060
+ /* @__PURE__ */ jsx("span", { className: "text-[13px] text-foreground whitespace-pre-wrap break-words", children: value })
3865
4061
  ] }, key)) })
3866
4062
  ] })
3867
4063
  ] }),
@@ -3881,7 +4077,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3881
4077
  return /* @__PURE__ */ jsxs(
3882
4078
  "div",
3883
4079
  {
3884
- className: "absolute top-4 right-4 z-10 w-72 bg-background/95 floating-panel rounded-lg shadow-lg border border-border flex flex-col overflow-hidden",
4080
+ className: "absolute top-4 right-4 z-10 w-80 bg-background/95 floating-panel rounded-lg shadow-lg border border-border flex flex-col overflow-hidden",
3885
4081
  style: { maxHeight: "calc(100vh - 6rem)" },
3886
4082
  "data-testid": "panel-properties",
3887
4083
  children: [
@@ -3950,7 +4146,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3950
4146
  e.currentTarget.style.borderColor = "transparent";
3951
4147
  },
3952
4148
  "data-testid": "button-title-icon-picker",
3953
- children: pointIcon ? /* @__PURE__ */ jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsx(PointColorDot, { color: feature.properties.stroke || "#3b82f6", size: 24 })
4149
+ children: pointIcon ? /* @__PURE__ */ jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsx(PointColorDot, { color: headerDotColor, size: 24 })
3954
4150
  }
3955
4151
  ) }),
3956
4152
  /* @__PURE__ */ jsx(
@@ -3967,7 +4163,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3967
4163
  }
3968
4164
  )
3969
4165
  ] }),
3970
- !hasMultipleSelection && feature.geometry.type === "Point" && feature.properties.kind !== "text" && !isEditMode && /* @__PURE__ */ jsx("span", { className: "shrink-0 w-9 h-9 flex items-center justify-center", children: pointIcon ? /* @__PURE__ */ jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsx(PointColorDot, { color: feature.properties.stroke || "#3b82f6", size: 24 }) }),
4166
+ !hasMultipleSelection && feature.geometry.type === "Point" && feature.properties.kind !== "text" && !isEditMode && /* @__PURE__ */ jsx("span", { className: "shrink-0 w-9 h-9 flex items-center justify-center", children: pointIcon ? /* @__PURE__ */ jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsx(PointColorDot, { color: headerDotColor, size: 24 }) }),
3971
4167
  !hasMultipleSelection && (feature.geometry.type !== "Point" || feature.properties.kind === "text") && /* @__PURE__ */ jsx("span", { className: "text-primary shrink-0 w-9 h-9 flex items-center justify-center", children: getFeatureTypeIcon(feature.geometry.type, feature.properties.kind, "lg") }),
3972
4168
  onDeleteFeatures && /* @__PURE__ */ jsx(Tooltip, { title: `Delete ${selectedFeatures.length} feature${selectedFeatures.length > 1 ? "s" : ""}`, children: /* @__PURE__ */ jsx(Button, { type: "text", danger: true, icon: /* @__PURE__ */ jsx(Trash2, { className: "w-4 h-4" }), onClick: onDeleteFeatures, className: "!w-6 !h-6 !min-w-0 !p-0", "data-testid": "button-delete-features" }) }),
3973
4169
  /* @__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" })
@@ -4014,7 +4210,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
4014
4210
  return /* @__PURE__ */ jsxs(
4015
4211
  "div",
4016
4212
  {
4017
- className: "absolute top-4 right-4 z-10 w-64 bg-background/95 floating-panel rounded-lg shadow-lg border border-border flex flex-col overflow-hidden",
4213
+ className: "absolute top-4 right-4 z-10 w-72 bg-background/95 floating-panel rounded-lg shadow-lg border border-border flex flex-col overflow-hidden",
4018
4214
  style: { maxHeight: "calc(100vh - 6rem)" },
4019
4215
  "data-testid": "panel-properties",
4020
4216
  children: [
@@ -4080,7 +4276,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
4080
4276
  e.currentTarget.style.borderColor = "transparent";
4081
4277
  },
4082
4278
  "data-testid": "button-title-icon-picker",
4083
- children: pointIcon ? /* @__PURE__ */ jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsx(PointColorDot, { color: feature.properties.stroke || "#3b82f6", size: 24 })
4279
+ children: pointIcon ? /* @__PURE__ */ jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsx(PointColorDot, { color: headerDotColor, size: 24 })
4084
4280
  }
4085
4281
  ) }),
4086
4282
  /* @__PURE__ */ jsx(
@@ -4097,7 +4293,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
4097
4293
  }
4098
4294
  )
4099
4295
  ] }),
4100
- feature.geometry.type === "Point" && feature.properties.kind !== "text" && !isEditMode && /* @__PURE__ */ jsx("span", { className: "shrink-0 w-9 h-9 flex items-center justify-center", children: pointIcon ? /* @__PURE__ */ jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsx(PointColorDot, { color: feature.properties.stroke || "#3b82f6", size: 24 }) }),
4296
+ feature.geometry.type === "Point" && feature.properties.kind !== "text" && !isEditMode && /* @__PURE__ */ jsx("span", { className: "shrink-0 w-9 h-9 flex items-center justify-center", children: pointIcon ? /* @__PURE__ */ jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsx(PointColorDot, { color: headerDotColor, size: 24 }) }),
4101
4297
  (feature.geometry.type !== "Point" || feature.properties.kind === "text") && /* @__PURE__ */ jsx("span", { className: "text-primary shrink-0 w-9 h-9 flex items-center justify-center", children: getFeatureTypeIcon(feature.geometry.type, feature.properties.kind, "lg") }),
4102
4298
  onDeleteFeatures && /* @__PURE__ */ jsx(Tooltip, { title: "Delete feature", children: /* @__PURE__ */ jsx(Button, { type: "text", danger: true, icon: /* @__PURE__ */ jsx(Trash2, { className: "w-4 h-4" }), onClick: onDeleteFeatures, className: "!w-6 !h-6 !min-w-0 !p-0", "data-testid": "button-delete-features" }) }),
4103
4299
  /* @__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" })
@@ -4445,12 +4641,11 @@ function formatDateTime(date) {
4445
4641
  minute: "2-digit"
4446
4642
  });
4447
4643
  }
4448
- function Histogram({ bins, maxCount, selectedBins, colorGroupedBins }) {
4644
+ function Histogram({ bins, maxCount, colorGroupedBins }) {
4449
4645
  const [hoveredBin, setHoveredBin] = useState(null);
4450
4646
  const containerRef = useRef(null);
4451
4647
  if (bins.length === 0 || maxCount === 0) return null;
4452
4648
  const hasColorGroups = colorGroupedBins && colorGroupedBins.length > 0 && colorGroupedBins.some((group) => group.bins.some((count) => count > 0));
4453
- const hasSelection = !hasColorGroups && selectedBins && selectedBins.length > 0 && selectedBins.some((count) => count > 0);
4454
4649
  return /* @__PURE__ */ jsxs("div", { className: "relative h-16", ref: containerRef, children: [
4455
4650
  /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-end gap-px", children: bins.map((bin, i) => {
4456
4651
  const height = bin.count / maxCount * 100;
@@ -4490,22 +4685,6 @@ function Histogram({ bins, maxCount, selectedBins, colorGroupedBins }) {
4490
4685
  groupIndex
4491
4686
  );
4492
4687
  }) }),
4493
- hasSelection && /* @__PURE__ */ jsx("svg", { className: "absolute inset-0 pointer-events-none w-full h-full", viewBox: "0 0 100 100", preserveAspectRatio: "none", children: /* @__PURE__ */ jsx(
4494
- "polyline",
4495
- {
4496
- fill: "none",
4497
- stroke: "hsl(var(--foreground))",
4498
- strokeWidth: "1.5",
4499
- strokeLinejoin: "round",
4500
- strokeLinecap: "round",
4501
- vectorEffect: "non-scaling-stroke",
4502
- points: selectedBins.map((count, i) => {
4503
- const x = (i + 0.5) * (100 / bins.length);
4504
- const y = 100 - count / maxCount * 100;
4505
- return `${x},${y}`;
4506
- }).join(" ")
4507
- }
4508
- ) }),
4509
4688
  hoveredBin !== null && bins[hoveredBin] && /* @__PURE__ */ jsxs(
4510
4689
  "div",
4511
4690
  {
@@ -4521,12 +4700,7 @@ function Histogram({ bins, maxCount, selectedBins, colorGroupedBins }) {
4521
4700
  /* @__PURE__ */ jsxs("div", { className: "text-muted-foreground", children: [
4522
4701
  bins[hoveredBin].count,
4523
4702
  " event",
4524
- bins[hoveredBin].count !== 1 ? "s" : "",
4525
- selectedBins && selectedBins[hoveredBin] > 0 && /* @__PURE__ */ jsxs("span", { className: "ml-1 text-foreground font-medium", children: [
4526
- "(",
4527
- selectedBins[hoveredBin],
4528
- " selected)"
4529
- ] })
4703
+ bins[hoveredBin].count !== 1 ? "s" : ""
4530
4704
  ] })
4531
4705
  ]
4532
4706
  }
@@ -4558,13 +4732,32 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4558
4732
  rangeStart,
4559
4733
  rangeEnd,
4560
4734
  isPlaying,
4561
- histogramBins,
4735
+ histogramBins: storeHistogramBins,
4562
4736
  setRange,
4563
4737
  setPlaying
4564
4738
  } = useTimelineStore();
4565
- const colorGroupedBins = histogramBins.length > 0 && selectedFeatureIds.length > 0 && selectedFeatureColors && selectedFeatureColors.size > 0 && globalMinDate && globalMaxDate ? (() => {
4739
+ const hasSelection = selectedFeatureIds.length > 0;
4740
+ const selectedTemporalFeatures = useMemo(() => {
4741
+ if (!hasSelection) return temporalFeatures;
4566
4742
  const selectedSet = new Set(selectedFeatureIds);
4567
- const selectedTemporalFeatures = temporalFeatures.filter((f) => selectedSet.has(f.id));
4743
+ return temporalFeatures.filter((f) => selectedSet.has(f.id));
4744
+ }, [hasSelection, selectedFeatureIds, temporalFeatures]);
4745
+ const histogramBins = useMemo(() => {
4746
+ if (!hasSelection || storeHistogramBins.length === 0) return storeHistogramBins;
4747
+ return storeHistogramBins.map((bin, binIndex) => {
4748
+ const isLastBin = binIndex === storeHistogramBins.length - 1;
4749
+ let count = 0;
4750
+ for (const f of selectedTemporalFeatures) {
4751
+ if (!f.startDate) continue;
4752
+ const t = f.startDate.getTime();
4753
+ if (t >= bin.start.getTime() && (isLastBin ? t <= bin.end.getTime() : t < bin.end.getTime())) {
4754
+ count++;
4755
+ }
4756
+ }
4757
+ return { ...bin, count };
4758
+ });
4759
+ }, [hasSelection, storeHistogramBins, selectedTemporalFeatures]);
4760
+ const colorGroupedBins = histogramBins.length > 0 && hasSelection && selectedFeatureColors && selectedFeatureColors.size > 0 && globalMinDate && globalMaxDate ? (() => {
4568
4761
  if (selectedTemporalFeatures.length === 0) return [];
4569
4762
  const colorGroups = /* @__PURE__ */ new Map();
4570
4763
  selectedTemporalFeatures.forEach((f) => {
@@ -4572,6 +4765,7 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4572
4765
  if (!colorGroups.has(color)) colorGroups.set(color, []);
4573
4766
  colorGroups.get(color).push(f);
4574
4767
  });
4768
+ if (colorGroups.size <= 1) return [];
4575
4769
  const result = [];
4576
4770
  colorGroups.forEach((features, color) => {
4577
4771
  const bins = histogramBins.map((bin, binIndex) => {
@@ -4588,21 +4782,6 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4588
4782
  });
4589
4783
  return result;
4590
4784
  })() : [];
4591
- const selectedBins = histogramBins.length > 0 && selectedFeatureIds.length > 0 && (!selectedFeatureColors || selectedFeatureColors.size === 0) && globalMinDate && globalMaxDate ? (() => {
4592
- const selectedSet = new Set(selectedFeatureIds);
4593
- const selectedTemporalFeatures = temporalFeatures.filter((f) => selectedSet.has(f.id));
4594
- if (selectedTemporalFeatures.length === 0) return [];
4595
- return histogramBins.map((bin, binIndex) => {
4596
- let count = 0;
4597
- const isLastBin = binIndex === histogramBins.length - 1;
4598
- selectedTemporalFeatures.forEach((f) => {
4599
- if (!f.startDate) return;
4600
- const t = f.startDate.getTime();
4601
- if (t >= bin.start.getTime() && (isLastBin ? t <= bin.end.getTime() : t < bin.end.getTime())) count++;
4602
- });
4603
- return count;
4604
- });
4605
- })() : [];
4606
4785
  const animationFrameRef = useRef(null);
4607
4786
  const lastFrameTimeRef = useRef(0);
4608
4787
  const playbackDuration = 1e4;
@@ -4703,7 +4882,6 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4703
4882
  {
4704
4883
  bins: histogramBins,
4705
4884
  maxCount: maxBinCount,
4706
- selectedBins,
4707
4885
  colorGroupedBins
4708
4886
  }
4709
4887
  ),
@@ -4753,11 +4931,14 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4753
4931
  className: "!h-7 !w-7 !p-0 !min-w-0"
4754
4932
  }
4755
4933
  ),
4756
- /* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground ml-1", children: [
4757
- temporalFeatures.length,
4758
- " feature",
4759
- temporalFeatures.length !== 1 ? "s" : ""
4760
- ] })
4934
+ /* @__PURE__ */ jsx(
4935
+ "span",
4936
+ {
4937
+ className: "text-xs text-muted-foreground ml-1",
4938
+ "data-testid": "text-timeline-feature-count",
4939
+ children: hasSelection ? `${selectedTemporalFeatures.length} of ${temporalFeatures.length} selected` : `${temporalFeatures.length} feature${temporalFeatures.length !== 1 ? "s" : ""}`
4940
+ }
4941
+ )
4761
4942
  ] }),
4762
4943
  timebarExtra,
4763
4944
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-xs text-muted-foreground font-mono", children: [
@@ -4851,6 +5032,12 @@ function MapDropZone({ onDrop, children }) {
4851
5032
  }
4852
5033
  );
4853
5034
  }
5035
+ const OTHER_BUCKET_KEY = "__other__";
5036
+ const OTHER_BUCKET_LABEL = "Other";
5037
+ const OTHER_BUCKET_COLOR = "#9ca3af";
5038
+ function toDisplayName(name) {
5039
+ return name === OTHER_BUCKET_KEY ? OTHER_BUCKET_LABEL : name;
5040
+ }
4854
5041
  function createPieSVG(categories, total, size = 44, onSliceHover) {
4855
5042
  const container = document.createElement("div");
4856
5043
  container.style.width = `${size}px`;
@@ -4869,8 +5056,41 @@ function createPieSVG(categories, total, size = 44, onSliceHover) {
4869
5056
  bgCircle.setAttribute("r", String(radius));
4870
5057
  bgCircle.setAttribute("fill", "white");
4871
5058
  svg.appendChild(bgCircle);
5059
+ const slicesSum = categories.reduce((s, c) => s + c.count, 0);
5060
+ const remainder = Math.max(0, total - slicesSum);
5061
+ const renderList = remainder > 0 ? [...categories, { name: "__remainder__", displayName: "Other", count: remainder, color: OTHER_BUCKET_COLOR }] : categories;
5062
+ const nonZeroSlices = renderList.filter((c) => c.count > 0);
5063
+ const isSingleFullSlice = nonZeroSlices.length === 1 && nonZeroSlices[0].count >= total;
5064
+ if (isSingleFullSlice) {
5065
+ const cat = nonZeroSlices[0];
5066
+ const ring = document.createElementNS("http://www.w3.org/2000/svg", "path");
5067
+ const d = [
5068
+ `M 0 ${radius}`,
5069
+ `a ${radius} ${radius} 0 1 0 ${radius * 2} 0`,
5070
+ `a ${radius} ${radius} 0 1 0 ${-radius * 2} 0`,
5071
+ `M ${radius - innerRadius} ${radius}`,
5072
+ `a ${innerRadius} ${innerRadius} 0 1 1 ${innerRadius * 2} 0`,
5073
+ `a ${innerRadius} ${innerRadius} 0 1 1 ${-innerRadius * 2} 0`,
5074
+ "Z"
5075
+ ].join(" ");
5076
+ ring.setAttribute("d", d);
5077
+ ring.setAttribute("fill-rule", "evenodd");
5078
+ ring.setAttribute("fill", cat.color);
5079
+ ring.setAttribute("stroke", "white");
5080
+ ring.setAttribute("stroke-width", "1");
5081
+ ring.style.transition = "opacity 0.15s";
5082
+ ring.addEventListener("mouseenter", (e) => {
5083
+ ring.style.opacity = "0.8";
5084
+ if (onSliceHover) onSliceHover(cat, e);
5085
+ });
5086
+ ring.addEventListener("mouseleave", (e) => {
5087
+ ring.style.opacity = "1";
5088
+ if (onSliceHover) onSliceHover(null, e);
5089
+ });
5090
+ svg.appendChild(ring);
5091
+ }
4872
5092
  let currentAngle = -90;
4873
- categories.forEach((cat) => {
5093
+ (isSingleFullSlice ? [] : renderList).forEach((cat) => {
4874
5094
  if (cat.count === 0) return;
4875
5095
  const sliceAngle = cat.count / total * 360;
4876
5096
  const startAngle = currentAngle;
@@ -4949,12 +5169,20 @@ function showTooltip(cat, x, y) {
4949
5169
  `;
4950
5170
  document.body.appendChild(tooltipEl);
4951
5171
  }
4952
- tooltipEl.innerHTML = `
4953
- <div style="display: flex; align-items: center; gap: 6px;">
4954
- <span style="width: 10px; height: 10px; border-radius: 2px; background: ${cat.color};"></span>
4955
- <span><strong>${cat.name}</strong>: ${cat.count}</span>
4956
- </div>
4957
- `;
5172
+ while (tooltipEl.firstChild) tooltipEl.removeChild(tooltipEl.firstChild);
5173
+ const row = document.createElement("div");
5174
+ row.style.cssText = "display: flex; align-items: center; gap: 6px;";
5175
+ const swatch = document.createElement("span");
5176
+ swatch.style.cssText = "width: 10px; height: 10px; border-radius: 2px;";
5177
+ swatch.style.backgroundColor = cat.color;
5178
+ row.appendChild(swatch);
5179
+ const label = document.createElement("span");
5180
+ const name = document.createElement("strong");
5181
+ name.textContent = cat.displayName;
5182
+ label.appendChild(name);
5183
+ label.appendChild(document.createTextNode(`: ${cat.count}`));
5184
+ row.appendChild(label);
5185
+ tooltipEl.appendChild(row);
4958
5186
  tooltipEl.style.left = `${x + 12}px`;
4959
5187
  tooltipEl.style.top = `${y - 10}px`;
4960
5188
  tooltipEl.style.display = "block";
@@ -4964,67 +5192,114 @@ function hideTooltip() {
4964
5192
  tooltipEl.style.display = "none";
4965
5193
  }
4966
5194
  }
5195
+ function fingerprintCluster(pointCount, counts, size) {
5196
+ return `${size}|${pointCount}|${counts.join(",")}`;
5197
+ }
5198
+ function buildPieElement(categories, pointCount, size, source, clusterId, map, coords) {
5199
+ const el = createPieSVG(categories, pointCount, size, (cat, event) => {
5200
+ if (cat) {
5201
+ showTooltip(cat, event.clientX, event.clientY);
5202
+ } else {
5203
+ hideTooltip();
5204
+ }
5205
+ });
5206
+ el.addEventListener("click", () => {
5207
+ source.getClusterExpansionZoom(clusterId).then((zoom) => {
5208
+ if (typeof zoom === "number") {
5209
+ map.easeTo({ center: coords, zoom: zoom + 0.5 });
5210
+ }
5211
+ }).catch(() => {
5212
+ });
5213
+ });
5214
+ return el;
5215
+ }
5216
+ function renderClusterPies(map, sourceId, categoryValues, categoryColorMap, markers) {
5217
+ const source = map.getSource(sourceId);
5218
+ if (!source) return;
5219
+ const clusters = map.querySourceFeatures(sourceId, {
5220
+ filter: ["has", "point_count"]
5221
+ });
5222
+ const visibleClusterIds = /* @__PURE__ */ new Set();
5223
+ clusters.forEach((feature) => {
5224
+ var _a, _b;
5225
+ const clusterId = (_a = feature.properties) == null ? void 0 : _a.cluster_id;
5226
+ if (clusterId === void 0) return;
5227
+ const clusterKey = `${clusterId}`;
5228
+ visibleClusterIds.add(clusterKey);
5229
+ const coords = feature.geometry.coordinates;
5230
+ const pointCount = ((_b = feature.properties) == null ? void 0 : _b.point_count) || 0;
5231
+ const allCounts = categoryValues.map((_, i) => {
5232
+ var _a2;
5233
+ return Number(((_a2 = feature.properties) == null ? void 0 : _a2[`cat_${i}`]) || 0);
5234
+ });
5235
+ const categories = categoryValues.map((cat, i) => ({
5236
+ name: cat,
5237
+ displayName: toDisplayName(cat),
5238
+ count: allCounts[i],
5239
+ color: categoryColorMap[cat] || "#3b82f6"
5240
+ })).filter((c) => c.count > 0);
5241
+ const size = pointCount < 100 ? 40 : pointCount < 750 ? 50 : 60;
5242
+ const fingerprint = fingerprintCluster(pointCount, allCounts, size);
5243
+ const existing = markers.get(clusterKey);
5244
+ if (existing && existing.fingerprint === fingerprint) {
5245
+ existing.marker.setLngLat(coords);
5246
+ return;
5247
+ }
5248
+ const el = buildPieElement(categories, pointCount, size, source, clusterId, map, coords);
5249
+ if (existing) {
5250
+ existing.marker.remove();
5251
+ }
5252
+ const marker = new maplibregl.Marker({ element: el }).setLngLat(coords).addTo(map);
5253
+ markers.set(clusterKey, { marker, fingerprint });
5254
+ });
5255
+ markers.forEach((entry, key) => {
5256
+ if (!visibleClusterIds.has(key)) {
5257
+ entry.marker.remove();
5258
+ markers.delete(key);
5259
+ }
5260
+ });
5261
+ }
5262
+ function createClusterPieManager(map, sourceId, categoryValues, categoryColorMap) {
5263
+ const markers = /* @__PURE__ */ new Map();
5264
+ let updateScheduled = false;
5265
+ function scheduleUpdate() {
5266
+ if (updateScheduled) return;
5267
+ updateScheduled = true;
5268
+ requestAnimationFrame(() => {
5269
+ updateScheduled = false;
5270
+ renderClusterPies(map, sourceId, categoryValues, categoryColorMap, markers);
5271
+ });
5272
+ }
5273
+ function onData(e) {
5274
+ if (e.sourceId === sourceId) {
5275
+ scheduleUpdate();
5276
+ }
5277
+ }
5278
+ map.on("moveend", scheduleUpdate);
5279
+ map.on("data", onData);
5280
+ scheduleUpdate();
5281
+ return {
5282
+ update: scheduleUpdate,
5283
+ destroy: () => {
5284
+ map.off("moveend", scheduleUpdate);
5285
+ map.off("data", onData);
5286
+ markers.forEach((entry) => entry.marker.remove());
5287
+ markers.clear();
5288
+ hideTooltip();
5289
+ }
5290
+ };
5291
+ }
4967
5292
  function ClusterPieManager(props) {
4968
- const { map, sourceId, layerId, categoryValues, categoryColorMap, visible } = props;
5293
+ const { map, sourceId, categoryValues, categoryColorMap, visible } = props;
4969
5294
  const markersRef = useRef(/* @__PURE__ */ new Map());
4970
5295
  const updateScheduled = useRef(false);
4971
5296
  const updateMarkers = useCallback(() => {
4972
5297
  if (!map || !visible) {
4973
- markersRef.current.forEach((marker) => marker.remove());
5298
+ markersRef.current.forEach((entry) => entry.marker.remove());
4974
5299
  markersRef.current.clear();
4975
5300
  return;
4976
5301
  }
4977
- const source = map.getSource(sourceId);
4978
- if (!source) return;
4979
- const clusters = map.querySourceFeatures(sourceId, {
4980
- filter: ["has", "point_count"]
4981
- });
4982
- const visibleClusterIds = /* @__PURE__ */ new Set();
4983
- clusters.forEach((feature) => {
4984
- var _a, _b;
4985
- const clusterId = (_a = feature.properties) == null ? void 0 : _a.cluster_id;
4986
- if (clusterId === void 0) return;
4987
- const clusterKey = `${clusterId}`;
4988
- visibleClusterIds.add(clusterKey);
4989
- const coords = feature.geometry.coordinates;
4990
- const pointCount = ((_b = feature.properties) == null ? void 0 : _b.point_count) || 0;
4991
- const categories = categoryValues.map((cat, i) => {
4992
- var _a2;
4993
- return {
4994
- name: cat,
4995
- count: ((_a2 = feature.properties) == null ? void 0 : _a2[`cat_${i}`]) || 0,
4996
- color: categoryColorMap[cat] || "#3b82f6"
4997
- };
4998
- }).filter((c) => c.count > 0);
4999
- const size = pointCount < 100 ? 40 : pointCount < 750 ? 50 : 60;
5000
- const existingMarker = markersRef.current.get(clusterKey);
5001
- if (existingMarker) {
5002
- existingMarker.setLngLat(coords);
5003
- } else {
5004
- const el = createPieSVG(categories, pointCount, size, (cat, event) => {
5005
- if (cat) {
5006
- showTooltip(cat, event.clientX, event.clientY);
5007
- } else {
5008
- hideTooltip();
5009
- }
5010
- });
5011
- el.addEventListener("click", () => {
5012
- source.getClusterExpansionZoom(clusterId, (err, zoom) => {
5013
- if (!err) {
5014
- map.easeTo({ center: coords, zoom: zoom + 0.5 });
5015
- }
5016
- });
5017
- });
5018
- const marker = new maplibregl.Marker({ element: el }).setLngLat(coords).addTo(map);
5019
- markersRef.current.set(clusterKey, marker);
5020
- }
5021
- });
5022
- markersRef.current.forEach((marker, key) => {
5023
- if (!visibleClusterIds.has(key)) {
5024
- marker.remove();
5025
- markersRef.current.delete(key);
5026
- }
5027
- });
5302
+ renderClusterPies(map, sourceId, categoryValues, categoryColorMap, markersRef.current);
5028
5303
  }, [map, sourceId, categoryValues, categoryColorMap, visible]);
5029
5304
  useEffect(() => {
5030
5305
  if (!map) return;
@@ -5036,23 +5311,25 @@ function ClusterPieManager(props) {
5036
5311
  updateMarkers();
5037
5312
  });
5038
5313
  };
5039
- scheduleUpdate();
5040
- map.on("moveend", scheduleUpdate);
5041
- map.on("data", (e) => {
5314
+ const onData = (e) => {
5042
5315
  if (e.sourceId === sourceId) {
5043
5316
  scheduleUpdate();
5044
5317
  }
5045
- });
5318
+ };
5319
+ scheduleUpdate();
5320
+ map.on("moveend", scheduleUpdate);
5321
+ map.on("data", onData);
5046
5322
  return () => {
5047
5323
  map.off("moveend", scheduleUpdate);
5048
- markersRef.current.forEach((marker) => marker.remove());
5324
+ map.off("data", onData);
5325
+ markersRef.current.forEach((entry) => entry.marker.remove());
5049
5326
  markersRef.current.clear();
5050
5327
  hideTooltip();
5051
5328
  };
5052
5329
  }, [map, sourceId, updateMarkers]);
5053
5330
  useEffect(() => {
5054
5331
  if (!visible) {
5055
- markersRef.current.forEach((marker) => marker.remove());
5332
+ markersRef.current.forEach((entry) => entry.marker.remove());
5056
5333
  markersRef.current.clear();
5057
5334
  hideTooltip();
5058
5335
  } else {
@@ -5061,89 +5338,6 @@ function ClusterPieManager(props) {
5061
5338
  }, [visible, updateMarkers]);
5062
5339
  return null;
5063
5340
  }
5064
- function createClusterPieManager(map, sourceId, categoryValues, categoryColorMap) {
5065
- const markers = /* @__PURE__ */ new Map();
5066
- let updateScheduled = false;
5067
- function update() {
5068
- const source = map.getSource(sourceId);
5069
- if (!source) return;
5070
- const clusters = map.querySourceFeatures(sourceId, {
5071
- filter: ["has", "point_count"]
5072
- });
5073
- const visibleClusterIds = /* @__PURE__ */ new Set();
5074
- clusters.forEach((feature) => {
5075
- var _a, _b;
5076
- const clusterId = (_a = feature.properties) == null ? void 0 : _a.cluster_id;
5077
- if (clusterId === void 0) return;
5078
- const clusterKey = `${clusterId}`;
5079
- visibleClusterIds.add(clusterKey);
5080
- const coords = feature.geometry.coordinates;
5081
- const pointCount = ((_b = feature.properties) == null ? void 0 : _b.point_count) || 0;
5082
- const categories = categoryValues.map((cat, i) => {
5083
- var _a2;
5084
- return {
5085
- name: cat,
5086
- count: ((_a2 = feature.properties) == null ? void 0 : _a2[`cat_${i}`]) || 0,
5087
- color: categoryColorMap[cat] || "#3b82f6"
5088
- };
5089
- }).filter((c) => c.count > 0);
5090
- const size = pointCount < 100 ? 40 : pointCount < 750 ? 50 : 60;
5091
- const existingMarker = markers.get(clusterKey);
5092
- if (existingMarker) {
5093
- existingMarker.setLngLat(coords);
5094
- } else {
5095
- const el = createPieSVG(categories, pointCount, size, (cat, event) => {
5096
- if (cat) {
5097
- showTooltip(cat, event.clientX, event.clientY);
5098
- } else {
5099
- hideTooltip();
5100
- }
5101
- });
5102
- el.addEventListener("click", () => {
5103
- source.getClusterExpansionZoom(clusterId, (err, zoom) => {
5104
- if (!err) {
5105
- map.easeTo({ center: coords, zoom: zoom + 0.5 });
5106
- }
5107
- });
5108
- });
5109
- const marker = new maplibregl.Marker({ element: el }).setLngLat(coords).addTo(map);
5110
- markers.set(clusterKey, marker);
5111
- }
5112
- });
5113
- markers.forEach((marker, key) => {
5114
- if (!visibleClusterIds.has(key)) {
5115
- marker.remove();
5116
- markers.delete(key);
5117
- }
5118
- });
5119
- }
5120
- function scheduleUpdate() {
5121
- if (updateScheduled) return;
5122
- updateScheduled = true;
5123
- requestAnimationFrame(() => {
5124
- updateScheduled = false;
5125
- update();
5126
- });
5127
- }
5128
- function onData(e) {
5129
- if (e.sourceId === sourceId) {
5130
- scheduleUpdate();
5131
- }
5132
- }
5133
- map.on("moveend", scheduleUpdate);
5134
- map.on("data", onData);
5135
- scheduleUpdate();
5136
- return {
5137
- update: scheduleUpdate,
5138
- destroy: () => {
5139
- map.off("moveend", scheduleUpdate);
5140
- map.off("data", onData);
5141
- markers.forEach((marker) => marker.remove());
5142
- markers.clear();
5143
- hideTooltip();
5144
- }
5145
- };
5146
- }
5147
5341
  proj4.defs("EPSG:27700", "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs");
5148
5342
  proj4.defs("EPSG:3857", "+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs");
5149
5343
  proj4.defs("EPSG:32630", "+proj=utm +zone=30 +datum=WGS84 +units=m +no_defs");
@@ -5550,6 +5744,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
5550
5744
  enableProperties = true,
5551
5745
  toastProvider,
5552
5746
  customGlobalMenuItems,
5747
+ extraLayerToolbarButtons,
5553
5748
  layerBadgeProvider,
5554
5749
  featureCountProvider,
5555
5750
  fitBoundsProvider,
@@ -5632,6 +5827,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
5632
5827
  const [cursorCoords, setCursorCoords] = useState(null);
5633
5828
  const [contextMenu, setContextMenu] = useState(null);
5634
5829
  const timelineStore = useTimelineStore();
5830
+ useEffect(() => () => useTimelineStore.getState().reset(), []);
5635
5831
  const { toast: internalToast } = useToast();
5636
5832
  const toast = toastProvider ?? internalToast;
5637
5833
  useEffect(() => {
@@ -5808,56 +6004,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
5808
6004
  const timelineVisibleIdsRef = useRef(null);
5809
6005
  const syncRef = useRef(() => {
5810
6006
  });
5811
- const hashStringToColor = useCallback((str) => {
5812
- const palette = [
5813
- "#4e79a7",
5814
- // steel blue
5815
- "#f28e2b",
5816
- // orange
5817
- "#e15759",
5818
- // red
5819
- "#76b7b2",
5820
- // teal
5821
- "#59a14f",
5822
- // green
5823
- "#edc948",
5824
- // yellow
5825
- "#b07aa1",
5826
- // purple
5827
- "#ff9da7",
5828
- // pink
5829
- "#9c755f",
5830
- // brown
5831
- "#bab0ac",
5832
- // gray
5833
- "#5fa2ce",
5834
- // light blue
5835
- "#ffbe7d",
5836
- // light orange
5837
- "#ff9888",
5838
- // salmon
5839
- "#8cd17d",
5840
- // light green
5841
- "#b6992d",
5842
- // olive
5843
- "#f1ce63",
5844
- // gold
5845
- "#d4a6c8",
5846
- // lavender
5847
- "#86bcb6",
5848
- // aqua
5849
- "#d37295",
5850
- // rose
5851
- "#499894"
5852
- // dark teal
5853
- ];
5854
- let hash = 0;
5855
- for (let i = 0; i < str.length; i++) {
5856
- hash = (hash << 5) - hash + str.charCodeAt(i);
5857
- hash = hash & hash;
5858
- }
5859
- return palette[Math.abs(hash) % palette.length];
5860
- }, []);
6007
+ const hashStringToColor$1 = useCallback((str) => hashStringToColor(str), []);
5861
6008
  const selectedFeatureColors = useMemo(() => {
5862
6009
  if (selectedFeatureIds.length === 0) return /* @__PURE__ */ new Map();
5863
6010
  const colorMap = /* @__PURE__ */ new Map();
@@ -5915,16 +6062,16 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
5915
6062
  if (colorConfig.mode === "fixed" && colorConfig.fixedColor) {
5916
6063
  color = colorConfig.fixedColor;
5917
6064
  } else if (colorConfig.mode === "field" && colorConfig.fieldName && feature.properties) {
5918
- const fieldValue = feature.properties[colorConfig.fieldName];
5919
- if (fieldValue !== void 0 && fieldValue !== null) {
5920
- color = hashStringToColor(String(fieldValue));
6065
+ const key = categoricalKey(feature.properties[colorConfig.fieldName]);
6066
+ if (key !== null) {
6067
+ color = hashStringToColor$1(key);
5921
6068
  }
5922
6069
  }
5923
6070
  }
5924
6071
  colorMap.set(fid, color);
5925
6072
  });
5926
6073
  return colorMap;
5927
- }, [selectedFeatureIds, layers, getAllFeatures, hashStringToColor]);
6074
+ }, [selectedFeatureIds, layers, getAllFeatures, hashStringToColor$1]);
5928
6075
  const isSyncingRef = useRef(false);
5929
6076
  const syncFeaturesToCustomLayers = useCallback(() => {
5930
6077
  if (!map.current) return;
@@ -6044,7 +6191,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6044
6191
  const sourceData = {
6045
6192
  type: "FeatureCollection",
6046
6193
  features: allFeatures.map((f) => {
6047
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
6194
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
6048
6195
  const featureId = String(f.id);
6049
6196
  const layer = featureToLayer.get(featureId);
6050
6197
  const visualConfig = layer == null ? void 0 : layer.visualConfig;
@@ -6056,9 +6203,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6056
6203
  if (colorConfig.mode === "fixed" && colorConfig.fixedColor) {
6057
6204
  strokeColor = colorConfig.fixedColor;
6058
6205
  } else if (colorConfig.mode === "field" && colorConfig.fieldName && f.properties) {
6059
- const fieldValue = f.properties[colorConfig.fieldName];
6060
- if (fieldValue !== void 0 && fieldValue !== null) {
6061
- strokeColor = hashStringToColor(String(fieldValue));
6206
+ const key = categoricalKey(f.properties[colorConfig.fieldName]);
6207
+ if (key !== null) {
6208
+ strokeColor = hashStringToColor$1(key);
6062
6209
  }
6063
6210
  }
6064
6211
  }
@@ -6116,8 +6263,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6116
6263
  featureIconSize = iconConfig.size ?? 24;
6117
6264
  }
6118
6265
  const isPoint = f.geometry.type === "Point";
6119
- const hideByHeatmap = isPoint && ((_i = layer == null ? void 0 : layer.heatmapConfig) == null ? void 0 : _i.enabled) && ((_j = layer == null ? void 0 : layer.heatmapConfig) == null ? void 0 : _j.hideFeatures);
6120
- const hideByCluster = isPoint && ((_k = layer == null ? void 0 : layer.clusterConfig) == null ? void 0 : _k.enabled) === true && !((_l = layer == null ? void 0 : layer.clusterConfig) == null ? void 0 : _l.showPointDots);
6266
+ const hideByHeatmap = isPoint && ((_i = layer == null ? void 0 : layer.heatmapConfig) == null ? void 0 : _i.enabled) === true;
6267
+ 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);
6121
6268
  const isSelected = selectedIds.includes(featureId);
6122
6269
  const hideByTrace = false;
6123
6270
  const isLine = f.geometry.type === "LineString" || f.geometry.type === "MultiLineString";
@@ -6148,7 +6295,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6148
6295
  id: featureId,
6149
6296
  name: labelText,
6150
6297
  isSelected: isFeatureSelected,
6151
- isHiddenByHeatmap: hideByHeatmap ? true : false,
6298
+ isHiddenByHeatmap: hideByHeatmap ? 1 : 0,
6152
6299
  isHiddenByCluster: hideByCluster ? 1 : 0,
6153
6300
  isHiddenByTrace: hideByTrace ? true : false,
6154
6301
  isTracePoint: isTracePoint ? true : false,
@@ -6159,7 +6306,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6159
6306
  "stroke-width": strokeWidth,
6160
6307
  "stroke-opacity": hideFlatFor3DOnly ? 0 : isTimelineVisible ? baseOpacity : 0,
6161
6308
  fill: strokeColor,
6162
- "fill-opacity": hideFlatFor3DOnly ? 0 : isTimelineVisible ? ((_m = f.properties) == null ? void 0 : _m["fill-opacity"]) ?? 0.2 : 0,
6309
+ "fill-opacity": hideFlatFor3DOnly ? 0 : isTimelineVisible ? ((_l = f.properties) == null ? void 0 : _l["fill-opacity"]) ?? 0.2 : 0,
6163
6310
  pointRadius,
6164
6311
  isHiddenFor3DOnly: hideFlatFor3DOnly ? 1 : 0,
6165
6312
  isTimelineHidden: isTimelineVisible ? 0 : 1
@@ -6385,7 +6532,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6385
6532
  } finally {
6386
6533
  isSyncingRef.current = false;
6387
6534
  }
6388
- }, [layers, hashStringToColor, autoLabelConfig]);
6535
+ }, [layers, hashStringToColor$1, autoLabelConfig]);
6389
6536
  const update3DFlightPaths = useCallback(() => {
6390
6537
  if (!map.current || !is3DTerrainEnabled) {
6391
6538
  if (map.current && flightPath3DLayerId.current) {
@@ -6545,8 +6692,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6545
6692
  attributionControl: false,
6546
6693
  boxZoom: false,
6547
6694
  // Disable default box zoom - we use shift+drag for selection instead
6548
- maxPitch: 80
6695
+ maxPitch: 80,
6549
6696
  // Allow steep camera angles for 3D terrain viewing
6697
+ // Required for `getCanvas().toDataURL()` (used by `captureScreenshot()`
6698
+ // on the imperative handle) to return a populated image instead of a
6699
+ // blank one. In maplibre-gl v5 this lives under
6700
+ // `canvasContextAttributes`, not at the top level. Modern desktop GPUs
6701
+ // absorb the small extra cost without measurable impact on this
6702
+ // editor-grade map.
6703
+ canvasContextAttributes: { preserveDrawingBuffer: true }
6550
6704
  });
6551
6705
  const attrCtrl = new maplibregl.AttributionControl({
6552
6706
  compact: true,
@@ -6653,6 +6807,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6653
6807
  0,
6654
6808
  ["==", ["get", "isHiddenByCluster"], 1],
6655
6809
  0,
6810
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6811
+ 0,
6656
6812
  ["!=", ["get", "icon"], ""],
6657
6813
  0,
6658
6814
  ["+", ["coalesce", ["get", "pointRadius"], 5], 1.5]
@@ -6662,6 +6818,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6662
6818
  "case",
6663
6819
  ["==", ["get", "isHiddenByCluster"], 1],
6664
6820
  0,
6821
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6822
+ 0,
6665
6823
  ["!=", ["get", "icon"], ""],
6666
6824
  0,
6667
6825
  ["coalesce", ["get", "stroke-opacity"], 1]
@@ -6682,6 +6840,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6682
6840
  0,
6683
6841
  ["==", ["get", "isHiddenByCluster"], 1],
6684
6842
  0,
6843
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6844
+ 0,
6685
6845
  ["!=", ["get", "icon"], ""],
6686
6846
  0,
6687
6847
  ["coalesce", ["get", "pointRadius"], 5]
@@ -6690,6 +6850,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6690
6850
  "case",
6691
6851
  ["==", ["get", "isHiddenByCluster"], 1],
6692
6852
  0,
6853
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6854
+ 0,
6693
6855
  ["!=", ["get", "icon"], ""],
6694
6856
  0,
6695
6857
  ["coalesce", ["get", "stroke-opacity"], 1]
@@ -6701,6 +6863,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6701
6863
  0,
6702
6864
  ["==", ["get", "isHiddenByCluster"], 1],
6703
6865
  0,
6866
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6867
+ 0,
6704
6868
  ["!=", ["get", "icon"], ""],
6705
6869
  0,
6706
6870
  ["==", ["get", "isSelected"], 1],
@@ -6711,6 +6875,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6711
6875
  "case",
6712
6876
  ["==", ["get", "isHiddenByCluster"], 1],
6713
6877
  0,
6878
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6879
+ 0,
6714
6880
  ["!=", ["get", "icon"], ""],
6715
6881
  0,
6716
6882
  1
@@ -6733,6 +6899,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6733
6899
  "case",
6734
6900
  ["==", ["get", "isHiddenByCluster"], 1],
6735
6901
  0,
6902
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6903
+ 0,
6736
6904
  ["coalesce", ["get", "stroke-opacity"], 1]
6737
6905
  ]
6738
6906
  }
@@ -6741,7 +6909,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6741
6909
  id: "custom-point-icon-selection",
6742
6910
  type: "circle",
6743
6911
  source: "custom-features",
6744
- filter: ["all", ["==", "$type", "Point"], ["!=", "icon", ""], ["==", "isSelected", 1]],
6912
+ filter: ["all", ["==", "$type", "Point"], ["!=", "icon", ""], ["==", "isSelected", 1], ["!=", "isHiddenByHeatmap", 1]],
6745
6913
  paint: {
6746
6914
  "circle-color": "transparent",
6747
6915
  "circle-radius": ["/", ["coalesce", ["get", "iconSize"], 24], 1.6],
@@ -6783,6 +6951,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6783
6951
  "case",
6784
6952
  ["==", ["get", "isHiddenByTrace"], true],
6785
6953
  "",
6954
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6955
+ "",
6956
+ ["==", ["get", "isHiddenByCluster"], 1],
6957
+ "",
6786
6958
  ["==", ["get", "kind"], "arrow"],
6787
6959
  "",
6788
6960
  // Arrows use custom-arrow-labels layer
@@ -6805,7 +6977,26 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6805
6977
  // Text features: center anchor; others: top anchor
6806
6978
  "text-anchor": ["case", ["==", ["get", "kind"], "text"], "center", "top"],
6807
6979
  "text-offset": ["case", ["==", ["get", "kind"], "text"], ["literal", [0, 0]], ["literal", [0, 0.8]]],
6808
- "text-allow-overlap": true,
6980
+ // Collision behaviour for entity labels.
6981
+ //
6982
+ // `kind === 'text'` features are sticky-note style annotations
6983
+ // where the text IS the content (this layer has no icon-image,
6984
+ // and `text-optional` cannot fall back to anything). If we let
6985
+ // collision detection hide them, the user is left with a tiny
6986
+ // 5px circle and no visible note. Same for trace endpoint
6987
+ // labels — the label IS the meaningful marker.
6988
+ //
6989
+ // Plain entity-name labels are supplementary to the icon/dot,
6990
+ // so it's safe to let MapLibre thin them out in dense areas
6991
+ // (this is the "no more black mass of stacked labels" win).
6992
+ "text-allow-overlap": [
6993
+ "case",
6994
+ ["==", ["get", "kind"], "text"],
6995
+ true,
6996
+ ["==", ["get", "isTraceLabel"], true],
6997
+ true,
6998
+ false
6999
+ ],
6809
7000
  "text-ignore-placement": false,
6810
7001
  "text-optional": true,
6811
7002
  // Bold font for text features with fontWeight=bold, trace labels, others regular
@@ -7328,12 +7519,26 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7328
7519
  mapInstance.addLayer(newLayer, beforeLayer);
7329
7520
  addedLayerIds.push(prefixedLayerId);
7330
7521
  } catch (e) {
7522
+ console.warn(
7523
+ `[map-component] failed to add basemap layer ${prefixedLayerId}:`,
7524
+ (e == null ? void 0 : e.message) ?? e
7525
+ );
7331
7526
  }
7332
7527
  }
7333
7528
  }
7334
7529
  }
7335
7530
  basemapLayerIds.current.set(baseMapStyle, addedLayerIds);
7336
7531
  loadedBasemaps.current.add(baseMapStyle);
7532
+ const triggerResize = () => {
7533
+ try {
7534
+ mapInstance.resize();
7535
+ } catch {
7536
+ }
7537
+ };
7538
+ requestAnimationFrame(triggerResize);
7539
+ setTimeout(triggerResize, 200);
7540
+ setTimeout(triggerResize, 600);
7541
+ setTimeout(triggerResize, 1500);
7337
7542
  }).catch((err) => {
7338
7543
  console.error("Failed to load initial basemap:", err);
7339
7544
  });
@@ -7620,7 +7825,19 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7620
7825
  }, 0);
7621
7826
  });
7622
7827
  mapInstance.on("error", (e) => {
7623
- console.error("Map error:", e);
7828
+ var _a, _b;
7829
+ const err = e == null ? void 0 : e.error;
7830
+ const details = {
7831
+ message: err == null ? void 0 : err.message,
7832
+ name: err == null ? void 0 : err.name,
7833
+ stack: err == null ? void 0 : err.stack,
7834
+ status: err == null ? void 0 : err.status,
7835
+ url: err == null ? void 0 : err.url,
7836
+ sourceId: e == null ? void 0 : e.sourceId,
7837
+ tileId: ((_b = (_a = e == null ? void 0 : e.tile) == null ? void 0 : _a.tileID) == null ? void 0 : _b.canonical) ? `${e.tile.tileID.canonical.z}/${e.tile.tileID.canonical.x}/${e.tile.tileID.canonical.y}` : void 0
7838
+ };
7839
+ for (const k of Object.keys(details)) if (details[k] === void 0) delete details[k];
7840
+ console.error("Map error:", details, e);
7624
7841
  });
7625
7842
  } catch (error) {
7626
7843
  console.error("Failed to initialize map:", error);
@@ -7698,6 +7915,101 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7698
7915
  if (!map.current || !isMapLoadedRef.current) return;
7699
7916
  map.current.flyTo({ center: coords, zoom: zoom ?? map.current.getZoom(), duration: (options == null ? void 0 : options.duration) ?? 2e3 });
7700
7917
  },
7918
+ updateLayerConfig: (layerId, config) => {
7919
+ const idx = layersRef.current.findIndex((l) => l.id === layerId);
7920
+ if (idx < 0) return false;
7921
+ const current = layersRef.current[idx];
7922
+ const next = { ...current };
7923
+ if ("visible" in config) {
7924
+ const wantedVisible = config.visible ?? true;
7925
+ if (wantedVisible !== current.visible && !current.readOnly && draw.current) {
7926
+ if (wantedVisible) {
7927
+ const hidden = hiddenFeatures.current.get(layerId) || [];
7928
+ const newIds = [];
7929
+ isApiAddingRef.current = true;
7930
+ try {
7931
+ hidden.forEach((f) => {
7932
+ const ids = draw.current.add(f);
7933
+ newIds.push(ids[0]);
7934
+ });
7935
+ } finally {
7936
+ isApiAddingRef.current = false;
7937
+ }
7938
+ hiddenFeatures.current.delete(layerId);
7939
+ next.visible = true;
7940
+ next.featureIds = newIds;
7941
+ } else {
7942
+ const features = current.featureIds.map((id) => draw.current.get(id)).filter(Boolean);
7943
+ hiddenFeatures.current.set(layerId, features);
7944
+ current.featureIds.forEach((id) => {
7945
+ try {
7946
+ draw.current.delete(id);
7947
+ } catch {
7948
+ }
7949
+ });
7950
+ next.visible = false;
7951
+ next.featureIds = [];
7952
+ }
7953
+ } else {
7954
+ next.visible = wantedVisible;
7955
+ }
7956
+ }
7957
+ if ("visualConfig" in config) next.visualConfig = config.visualConfig;
7958
+ if ("traceConfig" in config) next.traceConfig = config.traceConfig;
7959
+ if ("heatmapConfig" in config) next.heatmapConfig = config.heatmapConfig;
7960
+ if ("clusterConfig" in config) next.clusterConfig = config.clusterConfig;
7961
+ if ("altitudeDisplayMode" in config) next.altitudeDisplayMode = config.altitudeDisplayMode;
7962
+ const updated = [...layersRef.current];
7963
+ updated[idx] = next;
7964
+ layersRef.current = updated;
7965
+ setLayers(updated);
7966
+ if ("visible" in config) {
7967
+ updateFeatureCount();
7968
+ scheduleTimelineUpdate();
7969
+ }
7970
+ requestAnimationFrame(() => syncRef.current());
7971
+ return true;
7972
+ },
7973
+ captureScreenshot: async (options) => {
7974
+ const m = map.current;
7975
+ if (!m || !isMapLoadedRef.current) {
7976
+ toast({
7977
+ title: "Screenshot failed",
7978
+ description: "Map is not ready yet.",
7979
+ variant: "destructive"
7980
+ });
7981
+ throw new Error("Map is not ready");
7982
+ }
7983
+ const SCREENSHOT_RENDER_TIMEOUT_MS = 1e4;
7984
+ try {
7985
+ await new Promise((resolve, reject) => {
7986
+ const onRender = () => {
7987
+ clearTimeout(timeoutId);
7988
+ resolve();
7989
+ };
7990
+ const timeoutId = setTimeout(() => {
7991
+ try {
7992
+ m.off("render", onRender);
7993
+ } catch {
7994
+ }
7995
+ reject(new Error("Screenshot timed out waiting for render (map may have been destroyed)"));
7996
+ }, SCREENSHOT_RENDER_TIMEOUT_MS);
7997
+ m.once("render", onRender);
7998
+ m.triggerRepaint();
7999
+ });
8000
+ } catch (err) {
8001
+ toast({
8002
+ title: "Screenshot failed",
8003
+ description: err instanceof Error ? err.message : "The map did not render in time. Please try again.",
8004
+ variant: "destructive"
8005
+ });
8006
+ throw err;
8007
+ }
8008
+ const canvas = m.getCanvas();
8009
+ const fmt = (options == null ? void 0 : options.format) === "jpeg" ? "image/jpeg" : "image/png";
8010
+ const dataUrl = fmt === "image/jpeg" ? canvas.toDataURL(fmt, options == null ? void 0 : options.quality) : canvas.toDataURL(fmt);
8011
+ return { dataUrl, width: canvas.width, height: canvas.height };
8012
+ },
7701
8013
  fitToData: (layerIds) => {
7702
8014
  if (!map.current || !isMapLoadedRef.current) return;
7703
8015
  const drawFeatures = draw.current ? draw.current.getAll().features : [];
@@ -7736,11 +8048,25 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7736
8048
  const newLayer = {
7737
8049
  id: layerId,
7738
8050
  name,
7739
- visible: true,
8051
+ // Default to visible. The optional `visible` flag lets restore-flows
8052
+ // recreate a layer that the user had previously hidden, without
8053
+ // racing a follow-up `setLayerVisibility(id, false)` call (which
8054
+ // briefly flashes the layer on screen between addLayer and the
8055
+ // visibility toggle).
8056
+ visible: (options == null ? void 0 : options.visible) ?? true,
7740
8057
  featureIds: [],
7741
8058
  readOnly: options == null ? void 0 : options.readOnly,
7742
8059
  group: options == null ? void 0 : options.group,
7743
- metadata: options == null ? void 0 : options.metadata
8060
+ metadata: options == null ? void 0 : options.metadata,
8061
+ // Per-layer visual configs are passed through verbatim so that hosts
8062
+ // restoring a saved map (workspace auto-save, file merge, etc.) can
8063
+ // recreate heatmap / cluster / color-by-field / label / size / trace
8064
+ // settings without a follow-up "update visual config" round-trip.
8065
+ visualConfig: options == null ? void 0 : options.visualConfig,
8066
+ traceConfig: options == null ? void 0 : options.traceConfig,
8067
+ heatmapConfig: options == null ? void 0 : options.heatmapConfig,
8068
+ clusterConfig: options == null ? void 0 : options.clusterConfig,
8069
+ altitudeDisplayMode: options == null ? void 0 : options.altitudeDisplayMode
7744
8070
  };
7745
8071
  if (geojson) {
7746
8072
  if (options == null ? void 0 : options.readOnly) {
@@ -7779,6 +8105,17 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7779
8105
  }
7780
8106
  }
7781
8107
  }
8108
+ if (newLayer.visible === false && !(options == null ? void 0 : options.readOnly) && draw.current && newLayer.featureIds.length > 0) {
8109
+ const features = newLayer.featureIds.map((id) => draw.current.get(id)).filter(Boolean);
8110
+ hiddenFeatures.current.set(layerId, features);
8111
+ newLayer.featureIds.forEach((id) => {
8112
+ try {
8113
+ draw.current.delete(id);
8114
+ } catch {
8115
+ }
8116
+ });
8117
+ newLayer.featureIds = [];
8118
+ }
7782
8119
  const updatedLayers = [...layersRef.current, newLayer];
7783
8120
  layersRef.current = updatedLayers;
7784
8121
  setLayers(updatedLayers);
@@ -9592,6 +9929,31 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9592
9929
  });
9593
9930
  return Array.from(fieldsMap.entries()).map(([name, isNumeric]) => ({ name, isNumeric })).sort((a, b) => a.name.localeCompare(b.name));
9594
9931
  }, [layers]);
9932
+ const getFieldValueDistribution = useCallback(
9933
+ (layerId, fieldName, maxValues = 50) => {
9934
+ var _a;
9935
+ const layer = layers.find((l) => l.id === layerId);
9936
+ if (!layer) return [];
9937
+ let features = [];
9938
+ if (layer.readOnly) {
9939
+ features = readOnlyFeatures.current.get(layerId) || [];
9940
+ } else if (layer.visible) {
9941
+ features = draw.current ? layer.featureIds.map((id) => draw.current.get(id)) : [];
9942
+ } else {
9943
+ features = hiddenFeatures.current.get(layerId) || [];
9944
+ }
9945
+ const MAX_SAMPLES = 1e4;
9946
+ const sample = features.slice(0, MAX_SAMPLES);
9947
+ const counts = /* @__PURE__ */ new Map();
9948
+ for (const f of sample) {
9949
+ const key = categoricalKey((_a = f == null ? void 0 : f.properties) == null ? void 0 : _a[fieldName]);
9950
+ if (key === null) continue;
9951
+ counts.set(key, (counts.get(key) ?? 0) + 1);
9952
+ }
9953
+ 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 }));
9954
+ },
9955
+ [layers]
9956
+ );
9595
9957
  const handleFitToLayerFeatures = useCallback((layerId) => {
9596
9958
  if (!map.current) return;
9597
9959
  const customBounds = fitBoundsProvider == null ? void 0 : fitBoundsProvider(layerId);
@@ -11428,45 +11790,38 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11428
11790
  }
11429
11791
  if (pointFeatures.length === 0) return;
11430
11792
  const groupByField = (_b = layer.clusterConfig) == null ? void 0 : _b.groupByField;
11431
- const categoryColors = [
11432
- "#3b82f6",
11433
- "#ef4444",
11434
- "#22c55e",
11435
- "#f59e0b",
11436
- "#8b5cf6",
11437
- "#ec4899",
11438
- "#06b6d4",
11439
- "#f97316",
11440
- "#84cc16",
11441
- "#6366f1",
11442
- "#14b8a6",
11443
- "#d946ef",
11444
- "#0ea5e9",
11445
- "#a855f7",
11446
- "#10b981"
11447
- ];
11793
+ const OTHER_COLOR = OTHER_BUCKET_COLOR;
11794
+ const MAX_CATEGORIES = 15;
11448
11795
  try {
11449
11796
  const layerColor = ((_d = (_c = layer.visualConfig) == null ? void 0 : _c.color) == null ? void 0 : _d.fixedColor) || "#3b82f6";
11450
11797
  let clusterProperties = {};
11451
11798
  let categoryValues = [];
11452
11799
  let categoryColorMap = {};
11800
+ let hasOtherBucket = false;
11453
11801
  if (groupByField) {
11454
- const uniqueCategories = /* @__PURE__ */ new Set();
11802
+ const counts = /* @__PURE__ */ new Map();
11455
11803
  pointFeatures.forEach((f) => {
11456
11804
  var _a2;
11457
- const val = (_a2 = f.properties) == null ? void 0 : _a2[groupByField];
11458
- if (val !== void 0 && val !== null) {
11459
- uniqueCategories.add(String(val));
11460
- }
11805
+ const key = categoricalKey((_a2 = f.properties) == null ? void 0 : _a2[groupByField]);
11806
+ if (key === null) return;
11807
+ counts.set(key, (counts.get(key) ?? 0) + 1);
11461
11808
  });
11462
- categoryValues = Array.from(uniqueCategories).slice(0, 15);
11463
- categoryValues.forEach((cat, i) => {
11464
- categoryColorMap[cat] = categoryColors[i % categoryColors.length];
11809
+ const sorted = Array.from(counts.entries()).sort((a, b) => b[1] - a[1]);
11810
+ const topKeys = sorted.slice(0, MAX_CATEGORIES).map(([k]) => k);
11811
+ categoryValues = [...topKeys];
11812
+ hasOtherBucket = true;
11813
+ const fieldAsString = ["to-string", ["coalesce", ["get", groupByField], ""]];
11814
+ topKeys.forEach((cat, i) => {
11815
+ categoryColorMap[cat] = hashStringToColor$1(cat);
11465
11816
  clusterProperties[`cat_${i}`] = [
11466
11817
  "+",
11467
- ["case", ["==", ["get", groupByField], cat], 1, 0]
11818
+ ["case", ["==", fieldAsString, cat], 1, 0]
11468
11819
  ];
11469
11820
  });
11821
+ categoryValues.push(OTHER_BUCKET_KEY);
11822
+ categoryColorMap[OTHER_BUCKET_KEY] = OTHER_COLOR;
11823
+ const otherExpr = topKeys.length === 0 ? 1 : ["match", fieldAsString, topKeys, 0, 1];
11824
+ clusterProperties[`cat_${categoryValues.length - 1}`] = ["+", otherExpr];
11470
11825
  }
11471
11826
  const mapStyleMaxZoom = typeof mapInstance.getMaxZoom === "function" ? mapInstance.getMaxZoom() : 24;
11472
11827
  const clusterMaxZoom = Math.min(24, Math.max(1, mapStyleMaxZoom - 1));
@@ -11540,11 +11895,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11540
11895
  }
11541
11896
  });
11542
11897
  }
11543
- const unclusteredColor = groupByField ? [
11898
+ const renderableTopKeys = categoryValues.filter((c) => c !== OTHER_BUCKET_KEY);
11899
+ const unclusteredColor = groupByField && renderableTopKeys.length > 0 ? [
11544
11900
  "match",
11545
- ["get", groupByField],
11546
- ...categoryValues.flatMap((cat) => [cat, categoryColorMap[cat] || layerColor]),
11547
- layerColor
11901
+ ["to-string", ["coalesce", ["get", groupByField], ""]],
11902
+ ...renderableTopKeys.flatMap((cat) => [cat, categoryColorMap[cat] || layerColor]),
11903
+ hasOtherBucket ? OTHER_COLOR : layerColor
11548
11904
  ] : layerColor;
11549
11905
  mapInstance.addLayer({
11550
11906
  id: unclusteredLayerId,
@@ -11600,7 +11956,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11600
11956
  } catch {
11601
11957
  }
11602
11958
  };
11603
- }, [isMapLoaded, layers, currentMapStyle]);
11959
+ }, [isMapLoaded, layers, currentMapStyle, hashStringToColor$1]);
11604
11960
  if (mapError) {
11605
11961
  return /* @__PURE__ */ jsx("div", { className: `flex items-center justify-center h-full bg-muted/30 ${className || ""}`, "data-testid": "map-error", children: /* @__PURE__ */ jsxs(Card, { className: "max-w-md", children: [
11606
11962
  /* @__PURE__ */ jsx("div", { className: "p-4 border-b border-border", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
@@ -11983,6 +12339,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11983
12339
  onMapStyleChange: handleMapStyleChange,
11984
12340
  onUpdateTraceConfig: handleUpdateTraceConfig,
11985
12341
  getAvailableTraceFields,
12342
+ getFieldValueDistribution,
11986
12343
  onUpdateHeatmapConfig: handleUpdateHeatmapConfig,
11987
12344
  onUpdateClusterConfig: handleUpdateClusterConfig,
11988
12345
  hasPointFeatures,
@@ -12001,6 +12358,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12001
12358
  hideBasemapSwitcher,
12002
12359
  externalPersistence,
12003
12360
  customGlobalMenuItems,
12361
+ extraLayerToolbarButtons,
12004
12362
  layerBadgeProvider,
12005
12363
  featureCountProvider
12006
12364
  }
@@ -12041,7 +12399,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12041
12399
  onMoveFeaturesToLayer: handleMoveFeaturesToLayer,
12042
12400
  onCopyFeaturesToLayer: handleCopyFeaturesToLayer,
12043
12401
  onCreateLayerAndMoveFeatures: handleCreateLayerAndMoveFeatures,
12044
- onCreateLayerAndCopyFeatures: handleCreateLayerAndCopyFeatures
12402
+ onCreateLayerAndCopyFeatures: handleCreateLayerAndCopyFeatures,
12403
+ getFeatureColor: (featureId) => selectedFeatureColors.get(featureId)
12045
12404
  }
12046
12405
  );
12047
12406
  })(),