@octostar/map-component 0.1.26 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1574,11 +1574,133 @@ function ColorPickerPopover({ value, onChange, testId }) {
1574
1574
  }
1575
1575
  );
1576
1576
  }
1577
+ function categoricalKey(raw) {
1578
+ if (raw == null) return null;
1579
+ if (typeof raw === "string") return raw === "" ? null : raw;
1580
+ return String(raw);
1581
+ }
1582
+ const SELECTION_HUE = 187;
1583
+ const SELECTION_HUE_HALF_WIDTH = 12;
1584
+ function fnv1aHash(str) {
1585
+ let hash = 2166136261;
1586
+ for (let i = 0; i < str.length; i++) {
1587
+ hash ^= str.charCodeAt(i);
1588
+ hash = Math.imul(hash, 16777619);
1589
+ }
1590
+ return hash >>> 0;
1591
+ }
1592
+ function hslToHex(h, s, l) {
1593
+ const sNorm = s / 100;
1594
+ const lNorm = l / 100;
1595
+ const k = (n) => (n + h / 30) % 12;
1596
+ const a = sNorm * Math.min(lNorm, 1 - lNorm);
1597
+ const f = (n) => {
1598
+ const value = lNorm - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
1599
+ return Math.round(value * 255);
1600
+ };
1601
+ const toHex = (n) => n.toString(16).padStart(2, "0");
1602
+ return `#${toHex(f(0))}${toHex(f(8))}${toHex(f(4))}`;
1603
+ }
1604
+ function hashStringToColor(str) {
1605
+ const hash = fnv1aHash(str);
1606
+ let hue = hash * 137.508 % 360;
1607
+ if (hue < 0) hue += 360;
1608
+ const delta = (hue - SELECTION_HUE + 540) % 360 - 180;
1609
+ if (Math.abs(delta) < SELECTION_HUE_HALF_WIDTH) {
1610
+ hue = (SELECTION_HUE + (delta >= 0 ? SELECTION_HUE_HALF_WIDTH : -SELECTION_HUE_HALF_WIDTH) + 360) % 360;
1611
+ }
1612
+ const sat = 60 + (hash >>> 8) % 30;
1613
+ const light = 45 + (hash >>> 16) % 18;
1614
+ return hslToHex(hue, sat, light);
1615
+ }
1577
1616
  const MAP_STYLES = [
1578
1617
  { id: "streets", name: "Streets", icon: lucideReact.Map },
1579
1618
  { id: "satellite", name: "Satellite", icon: lucideReact.Satellite },
1580
1619
  { id: "dark", name: "Dark", icon: lucideReact.Map }
1581
1620
  ];
1621
+ const LEGEND_MAX_VALUES = 50;
1622
+ const LEGEND_INITIAL_VISIBLE = 8;
1623
+ function ColorByFieldLegend({
1624
+ layerId,
1625
+ fieldName,
1626
+ getFieldValueDistribution
1627
+ }) {
1628
+ const [expanded, setExpanded] = react.useState(false);
1629
+ const [filter, setFilter] = react.useState("");
1630
+ react.useEffect(() => {
1631
+ setFilter("");
1632
+ setExpanded(false);
1633
+ }, [layerId, fieldName]);
1634
+ const distribution = react.useMemo(
1635
+ () => getFieldValueDistribution(layerId, fieldName, LEGEND_MAX_VALUES),
1636
+ [getFieldValueDistribution, layerId, fieldName]
1637
+ );
1638
+ const filtered = react.useMemo(() => {
1639
+ const q = filter.trim().toLowerCase();
1640
+ if (!q) return distribution;
1641
+ return distribution.filter((d) => d.value.toLowerCase().includes(q));
1642
+ }, [distribution, filter]);
1643
+ if (distribution.length === 0) return null;
1644
+ const visible = expanded ? filtered : filtered.slice(0, LEGEND_INITIAL_VISIBLE);
1645
+ const hiddenCount = filtered.length - visible.length;
1646
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1647
+ "div",
1648
+ {
1649
+ className: "mt-1 rounded border border-border/50 bg-background/40 p-1.5",
1650
+ "data-testid": `legend-color-by-${layerId}`,
1651
+ children: [
1652
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-[10px] uppercase tracking-wide text-muted-foreground mb-1", children: [
1653
+ "Legend",
1654
+ distribution.length >= LEGEND_MAX_VALUES ? ` (top ${LEGEND_MAX_VALUES})` : ""
1655
+ ] }),
1656
+ (distribution.length > LEGEND_INITIAL_VISIBLE || expanded) && /* @__PURE__ */ jsxRuntime.jsx(
1657
+ antd.Input,
1658
+ {
1659
+ size: "small",
1660
+ allowClear: true,
1661
+ placeholder: "Filter values…",
1662
+ value: filter,
1663
+ onChange: (e) => setFilter(e.target.value),
1664
+ className: "mb-1 !text-[11px]",
1665
+ "data-testid": `legend-filter-${layerId}`
1666
+ }
1667
+ ),
1668
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-0.5 max-h-40 overflow-y-auto", children: [
1669
+ visible.map(({ value, count }) => /* @__PURE__ */ jsxRuntime.jsxs(
1670
+ "div",
1671
+ {
1672
+ className: "flex items-center gap-1.5 text-[11px]",
1673
+ title: `${value} (${count})`,
1674
+ children: [
1675
+ /* @__PURE__ */ jsxRuntime.jsx(
1676
+ "span",
1677
+ {
1678
+ className: "inline-block w-2.5 h-2.5 rounded-sm shrink-0 border border-black/10",
1679
+ style: { backgroundColor: hashStringToColor(value) }
1680
+ }
1681
+ ),
1682
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate flex-1 text-foreground", children: value }),
1683
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground tabular-nums", children: count })
1684
+ ]
1685
+ },
1686
+ value
1687
+ )),
1688
+ visible.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-[11px] text-muted-foreground italic", children: "No matches" })
1689
+ ] }),
1690
+ (hiddenCount > 0 || expanded && filtered.length > LEGEND_INITIAL_VISIBLE) && /* @__PURE__ */ jsxRuntime.jsx(
1691
+ "button",
1692
+ {
1693
+ type: "button",
1694
+ className: "mt-1 text-[11px] text-primary hover:underline",
1695
+ onClick: () => setExpanded((e) => !e),
1696
+ "data-testid": `legend-toggle-${layerId}`,
1697
+ children: expanded ? "Show less" : `Show all (${filtered.length})`
1698
+ }
1699
+ )
1700
+ ]
1701
+ }
1702
+ );
1703
+ }
1582
1704
  function LayersPanel({
1583
1705
  layers,
1584
1706
  onAddLayer,
@@ -1606,6 +1728,7 @@ function LayersPanel({
1606
1728
  onUpdateTraceConfig,
1607
1729
  getAvailableTraceFields,
1608
1730
  getLayerFields,
1731
+ getFieldValueDistribution,
1609
1732
  onUpdateHeatmapConfig,
1610
1733
  onUpdateClusterConfig,
1611
1734
  onUpdateVisualConfig,
@@ -1714,7 +1837,7 @@ function LayersPanel({
1714
1837
  });
1715
1838
  }, [onRemoveLayer]);
1716
1839
  const renderLayerItem = (layer) => {
1717
- 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, __, _$;
1840
+ 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;
1718
1841
  const customCount = featureCountProvider == null ? void 0 : featureCountProvider(layer.id);
1719
1842
  const featureCount = customCount != null ? customCount : getFeatureCount(layer.id);
1720
1843
  const isExpanded = expandedLayers.has(layer.id);
@@ -1909,6 +2032,8 @@ function LayersPanel({
1909
2032
  groupByField: val === "all" ? null : val
1910
2033
  }),
1911
2034
  className: "w-full text-xs",
2035
+ showSearch: true,
2036
+ optionFilterProp: "label",
1912
2037
  options: [
1913
2038
  { value: "all", label: "Connect all points" },
1914
2039
  ...getAvailableTraceFields(layer.id).map((f) => ({ value: f, label: `Group by ${f}` }))
@@ -2021,6 +2146,8 @@ function LayersPanel({
2021
2146
  groupByField: val === "count" ? null : val
2022
2147
  }),
2023
2148
  className: "w-full text-xs",
2149
+ showSearch: true,
2150
+ optionFilterProp: "label",
2024
2151
  options: [
2025
2152
  { value: "count", label: "Simple count" },
2026
2153
  ...getLayerFields(layer.id).filter((f) => !f.isNumeric).map((f) => ({ value: f.name, label: `Pie by ${f.name}` }))
@@ -2122,6 +2249,8 @@ function LayersPanel({
2122
2249
  }),
2123
2250
  className: "w-full text-sm",
2124
2251
  placeholder: "Select field...",
2252
+ showSearch: true,
2253
+ optionFilterProp: "label",
2125
2254
  options: getLayerFields(layer.id).map((f) => ({ value: f.name, label: f.name })),
2126
2255
  "data-testid": `select-label-field-${layer.id}`
2127
2256
  }
@@ -2173,6 +2302,8 @@ function LayersPanel({
2173
2302
  }),
2174
2303
  className: "w-full text-sm",
2175
2304
  placeholder: "Select numeric field...",
2305
+ showSearch: true,
2306
+ optionFilterProp: "label",
2176
2307
  options: getLayerFields(layer.id).filter((f) => f.isNumeric).map((f) => ({ value: f.name, label: f.name })),
2177
2308
  "data-testid": `select-size-field-${layer.id}`
2178
2309
  }
@@ -2216,25 +2347,37 @@ function LayersPanel({
2216
2347
  "data-testid": `select-color-mode-${layer.id}`
2217
2348
  }
2218
2349
  ),
2219
- ((_K = (_J = layer.visualConfig) == null ? void 0 : _J.color) == null ? void 0 : _K.mode) === "field" && /* @__PURE__ */ jsxRuntime.jsx(
2220
- antd.Select,
2221
- {
2222
- size: "small",
2223
- value: ((_M = (_L = layer.visualConfig) == null ? void 0 : _L.color) == null ? void 0 : _M.fieldName) ?? "",
2224
- onChange: (val) => onUpdateVisualConfig(layer.id, {
2225
- ...layer.visualConfig,
2226
- color: { mode: "field", fieldName: val }
2227
- }),
2228
- className: "w-full text-sm",
2229
- placeholder: "Select field...",
2230
- options: getLayerFields(layer.id).map((f) => ({ value: f.name, label: f.name })),
2231
- "data-testid": `select-color-field-${layer.id}`
2232
- }
2233
- ),
2234
- ((_O = (_N = layer.visualConfig) == null ? void 0 : _N.color) == null ? void 0 : _O.mode) === "fixed" && /* @__PURE__ */ jsxRuntime.jsx(
2350
+ ((_K = (_J = layer.visualConfig) == null ? void 0 : _J.color) == null ? void 0 : _K.mode) === "field" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2351
+ /* @__PURE__ */ jsxRuntime.jsx(
2352
+ antd.Select,
2353
+ {
2354
+ size: "small",
2355
+ value: ((_M = (_L = layer.visualConfig) == null ? void 0 : _L.color) == null ? void 0 : _M.fieldName) ?? "",
2356
+ onChange: (val) => onUpdateVisualConfig(layer.id, {
2357
+ ...layer.visualConfig,
2358
+ color: { mode: "field", fieldName: val }
2359
+ }),
2360
+ className: "w-full text-sm",
2361
+ placeholder: "Select field...",
2362
+ showSearch: true,
2363
+ optionFilterProp: "label",
2364
+ options: getLayerFields(layer.id).map((f) => ({ value: f.name, label: f.name })),
2365
+ "data-testid": `select-color-field-${layer.id}`
2366
+ }
2367
+ ),
2368
+ ((_O = (_N = layer.visualConfig) == null ? void 0 : _N.color) == null ? void 0 : _O.fieldName) && getFieldValueDistribution && /* @__PURE__ */ jsxRuntime.jsx(
2369
+ ColorByFieldLegend,
2370
+ {
2371
+ layerId: layer.id,
2372
+ fieldName: layer.visualConfig.color.fieldName,
2373
+ getFieldValueDistribution
2374
+ }
2375
+ )
2376
+ ] }),
2377
+ ((_Q = (_P = layer.visualConfig) == null ? void 0 : _P.color) == null ? void 0 : _Q.mode) === "fixed" && /* @__PURE__ */ jsxRuntime.jsx(
2235
2378
  ColorPickerPopover,
2236
2379
  {
2237
- value: ((_Q = (_P = layer.visualConfig) == null ? void 0 : _P.color) == null ? void 0 : _Q.fixedColor) ?? "#3b82f6",
2380
+ value: ((_S = (_R = layer.visualConfig) == null ? void 0 : _R.color) == null ? void 0 : _S.fixedColor) ?? "#3b82f6",
2238
2381
  onChange: (color) => {
2239
2382
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
2240
2383
  ...layer.visualConfig,
@@ -2247,7 +2390,7 @@ function LayersPanel({
2247
2390
  testId: `color-fixed-${layer.id}`
2248
2391
  }
2249
2392
  ),
2250
- (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_R = layer.metadata) == null ? void 0 : _R.hidePointFeatures) && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2393
+ (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_T = layer.metadata) == null ? void 0 : _T.hidePointFeatures) && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2251
2394
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1 text-sm text-muted-foreground pt-0.5", children: [
2252
2395
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Smile, { className: "w-3.5 h-3.5" }),
2253
2396
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: "Point Icon" })
@@ -2257,7 +2400,7 @@ function LayersPanel({
2257
2400
  antd.Switch,
2258
2401
  {
2259
2402
  size: "small",
2260
- checked: ((_T = (_S = layer.visualConfig) == null ? void 0 : _S.icon) == null ? void 0 : _T.enabled) ?? false,
2403
+ checked: ((_V = (_U = layer.visualConfig) == null ? void 0 : _U.icon) == null ? void 0 : _V.enabled) ?? false,
2261
2404
  onChange: (checked) => {
2262
2405
  var _a2, _b2, _c2, _d2;
2263
2406
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
@@ -2272,11 +2415,11 @@ function LayersPanel({
2272
2415
  "data-testid": `switch-icon-${layer.id}`
2273
2416
  }
2274
2417
  ),
2275
- ((_V = (_U = layer.visualConfig) == null ? void 0 : _U.icon) == null ? void 0 : _V.enabled) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1 flex-1", children: [
2418
+ ((_X = (_W = layer.visualConfig) == null ? void 0 : _W.icon) == null ? void 0 : _X.enabled) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1 flex-1", children: [
2276
2419
  /* @__PURE__ */ jsxRuntime.jsx(
2277
2420
  IconPicker,
2278
2421
  {
2279
- value: ((_X = (_W = layer.visualConfig) == null ? void 0 : _W.icon) == null ? void 0 : _X.icon) ?? "📍",
2422
+ value: ((_Z = (_Y = layer.visualConfig) == null ? void 0 : _Y.icon) == null ? void 0 : _Z.icon) ?? "📍",
2280
2423
  onChange: (icon) => {
2281
2424
  var _a2, _b2;
2282
2425
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
@@ -2293,7 +2436,7 @@ function LayersPanel({
2293
2436
  /* @__PURE__ */ jsxRuntime.jsx(
2294
2437
  antd.Slider,
2295
2438
  {
2296
- value: ((_Z = (_Y = layer.visualConfig) == null ? void 0 : _Y.icon) == null ? void 0 : _Z.size) ?? 24,
2439
+ value: ((_$ = (__ = layer.visualConfig) == null ? void 0 : __.icon) == null ? void 0 : _$.size) ?? 24,
2297
2440
  min: 12,
2298
2441
  max: 48,
2299
2442
  step: 2,
@@ -2311,7 +2454,7 @@ function LayersPanel({
2311
2454
  }
2312
2455
  }
2313
2456
  ),
2314
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm w-6 text-right", children: ((_$ = (__ = layer.visualConfig) == null ? void 0 : __.icon) == null ? void 0 : _$.size) ?? 24 })
2457
+ /* @__PURE__ */ jsxRuntime.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 })
2315
2458
  ] })
2316
2459
  ] })
2317
2460
  ] })
@@ -2779,7 +2922,7 @@ function RecordFieldsSection({ feature }) {
2779
2922
  );
2780
2923
  }
2781
2924
  let persistedTabPreference = "properties";
2782
- 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 }) {
2925
+ 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 }) {
2783
2926
  var _a, _b, _c, _d, _e;
2784
2927
  const feature = selectedFeatures[0];
2785
2928
  const { toast } = useToast();
@@ -2854,6 +2997,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
2854
2997
  const [endDate, setEndDate] = react.useState("");
2855
2998
  const [customProperties, setCustomProperties] = react.useState([]);
2856
2999
  const [newPropertyKey, setNewPropertyKey] = react.useState("");
3000
+ const headerDotColor = feature && (getFeatureColor == null ? void 0 : getFeatureColor(feature.id)) || (feature == null ? void 0 : feature.properties.stroke) || "#3b82f6";
2857
3001
  const [strokeColor, setStrokeColor] = react.useState("#3b82f6");
2858
3002
  const [strokeWidth, setStrokeWidth] = react.useState(2);
2859
3003
  const [strokeOpacity, setStrokeOpacity] = react.useState(1);
@@ -3971,7 +4115,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3971
4115
  e.currentTarget.style.borderColor = "transparent";
3972
4116
  },
3973
4117
  "data-testid": "button-title-icon-picker",
3974
- children: pointIcon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsxRuntime.jsx(PointColorDot, { color: feature.properties.stroke || "#3b82f6", size: 24 })
4118
+ children: pointIcon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsxRuntime.jsx(PointColorDot, { color: headerDotColor, size: 24 })
3975
4119
  }
3976
4120
  ) }),
3977
4121
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -3988,7 +4132,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3988
4132
  }
3989
4133
  )
3990
4134
  ] }),
3991
- !hasMultipleSelection && feature.geometry.type === "Point" && feature.properties.kind !== "text" && !isEditMode && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shrink-0 w-9 h-9 flex items-center justify-center", children: pointIcon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsxRuntime.jsx(PointColorDot, { color: feature.properties.stroke || "#3b82f6", size: 24 }) }),
4135
+ !hasMultipleSelection && feature.geometry.type === "Point" && feature.properties.kind !== "text" && !isEditMode && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shrink-0 w-9 h-9 flex items-center justify-center", children: pointIcon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsxRuntime.jsx(PointColorDot, { color: headerDotColor, size: 24 }) }),
3992
4136
  !hasMultipleSelection && (feature.geometry.type !== "Point" || feature.properties.kind === "text") && /* @__PURE__ */ jsxRuntime.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") }),
3993
4137
  onDeleteFeatures && /* @__PURE__ */ jsxRuntime.jsx(antd.Tooltip, { title: `Delete ${selectedFeatures.length} feature${selectedFeatures.length > 1 ? "s" : ""}`, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { type: "text", danger: true, icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { className: "w-4 h-4" }), onClick: onDeleteFeatures, className: "!w-6 !h-6 !min-w-0 !p-0", "data-testid": "button-delete-features" }) }),
3994
4138
  /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { type: "text", icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "w-4 h-4" }), onClick: onClose, className: "!w-6 !h-6 !min-w-0 !p-0 shrink-0", "data-testid": "button-close-properties" })
@@ -4101,7 +4245,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
4101
4245
  e.currentTarget.style.borderColor = "transparent";
4102
4246
  },
4103
4247
  "data-testid": "button-title-icon-picker",
4104
- children: pointIcon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsxRuntime.jsx(PointColorDot, { color: feature.properties.stroke || "#3b82f6", size: 24 })
4248
+ children: pointIcon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsxRuntime.jsx(PointColorDot, { color: headerDotColor, size: 24 })
4105
4249
  }
4106
4250
  ) }),
4107
4251
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -4118,7 +4262,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
4118
4262
  }
4119
4263
  )
4120
4264
  ] }),
4121
- feature.geometry.type === "Point" && feature.properties.kind !== "text" && !isEditMode && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shrink-0 w-9 h-9 flex items-center justify-center", children: pointIcon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsxRuntime.jsx(PointColorDot, { color: feature.properties.stroke || "#3b82f6", size: 24 }) }),
4265
+ feature.geometry.type === "Point" && feature.properties.kind !== "text" && !isEditMode && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shrink-0 w-9 h-9 flex items-center justify-center", children: pointIcon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsxRuntime.jsx(PointColorDot, { color: headerDotColor, size: 24 }) }),
4122
4266
  (feature.geometry.type !== "Point" || feature.properties.kind === "text") && /* @__PURE__ */ jsxRuntime.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") }),
4123
4267
  onDeleteFeatures && /* @__PURE__ */ jsxRuntime.jsx(antd.Tooltip, { title: "Delete feature", children: /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { type: "text", danger: true, icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { className: "w-4 h-4" }), onClick: onDeleteFeatures, className: "!w-6 !h-6 !min-w-0 !p-0", "data-testid": "button-delete-features" }) }),
4124
4268
  /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { type: "text", icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "w-4 h-4" }), onClick: onClose, className: "!w-6 !h-6 !min-w-0 !p-0 shrink-0", "data-testid": "button-close-properties" })
@@ -4466,12 +4610,11 @@ function formatDateTime(date) {
4466
4610
  minute: "2-digit"
4467
4611
  });
4468
4612
  }
4469
- function Histogram({ bins, maxCount, selectedBins, colorGroupedBins }) {
4613
+ function Histogram({ bins, maxCount, colorGroupedBins }) {
4470
4614
  const [hoveredBin, setHoveredBin] = react.useState(null);
4471
4615
  const containerRef = react.useRef(null);
4472
4616
  if (bins.length === 0 || maxCount === 0) return null;
4473
4617
  const hasColorGroups = colorGroupedBins && colorGroupedBins.length > 0 && colorGroupedBins.some((group) => group.bins.some((count) => count > 0));
4474
- const hasSelection = !hasColorGroups && selectedBins && selectedBins.length > 0 && selectedBins.some((count) => count > 0);
4475
4618
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative h-16", ref: containerRef, children: [
4476
4619
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-0 flex items-end gap-px", children: bins.map((bin, i) => {
4477
4620
  const height = bin.count / maxCount * 100;
@@ -4511,22 +4654,6 @@ function Histogram({ bins, maxCount, selectedBins, colorGroupedBins }) {
4511
4654
  groupIndex
4512
4655
  );
4513
4656
  }) }),
4514
- hasSelection && /* @__PURE__ */ jsxRuntime.jsx("svg", { className: "absolute inset-0 pointer-events-none w-full h-full", viewBox: "0 0 100 100", preserveAspectRatio: "none", children: /* @__PURE__ */ jsxRuntime.jsx(
4515
- "polyline",
4516
- {
4517
- fill: "none",
4518
- stroke: "hsl(var(--foreground))",
4519
- strokeWidth: "1.5",
4520
- strokeLinejoin: "round",
4521
- strokeLinecap: "round",
4522
- vectorEffect: "non-scaling-stroke",
4523
- points: selectedBins.map((count, i) => {
4524
- const x = (i + 0.5) * (100 / bins.length);
4525
- const y = 100 - count / maxCount * 100;
4526
- return `${x},${y}`;
4527
- }).join(" ")
4528
- }
4529
- ) }),
4530
4657
  hoveredBin !== null && bins[hoveredBin] && /* @__PURE__ */ jsxRuntime.jsxs(
4531
4658
  "div",
4532
4659
  {
@@ -4542,12 +4669,7 @@ function Histogram({ bins, maxCount, selectedBins, colorGroupedBins }) {
4542
4669
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-muted-foreground", children: [
4543
4670
  bins[hoveredBin].count,
4544
4671
  " event",
4545
- bins[hoveredBin].count !== 1 ? "s" : "",
4546
- selectedBins && selectedBins[hoveredBin] > 0 && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "ml-1 text-foreground font-medium", children: [
4547
- "(",
4548
- selectedBins[hoveredBin],
4549
- " selected)"
4550
- ] })
4672
+ bins[hoveredBin].count !== 1 ? "s" : ""
4551
4673
  ] })
4552
4674
  ]
4553
4675
  }
@@ -4579,13 +4701,32 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4579
4701
  rangeStart,
4580
4702
  rangeEnd,
4581
4703
  isPlaying,
4582
- histogramBins,
4704
+ histogramBins: storeHistogramBins,
4583
4705
  setRange,
4584
4706
  setPlaying
4585
4707
  } = useTimelineStore();
4586
- const colorGroupedBins = histogramBins.length > 0 && selectedFeatureIds.length > 0 && selectedFeatureColors && selectedFeatureColors.size > 0 && globalMinDate && globalMaxDate ? (() => {
4708
+ const hasSelection = selectedFeatureIds.length > 0;
4709
+ const selectedTemporalFeatures = react.useMemo(() => {
4710
+ if (!hasSelection) return temporalFeatures;
4587
4711
  const selectedSet = new Set(selectedFeatureIds);
4588
- const selectedTemporalFeatures = temporalFeatures.filter((f) => selectedSet.has(f.id));
4712
+ return temporalFeatures.filter((f) => selectedSet.has(f.id));
4713
+ }, [hasSelection, selectedFeatureIds, temporalFeatures]);
4714
+ const histogramBins = react.useMemo(() => {
4715
+ if (!hasSelection || storeHistogramBins.length === 0) return storeHistogramBins;
4716
+ return storeHistogramBins.map((bin, binIndex) => {
4717
+ const isLastBin = binIndex === storeHistogramBins.length - 1;
4718
+ let count = 0;
4719
+ for (const f of selectedTemporalFeatures) {
4720
+ if (!f.startDate) continue;
4721
+ const t = f.startDate.getTime();
4722
+ if (t >= bin.start.getTime() && (isLastBin ? t <= bin.end.getTime() : t < bin.end.getTime())) {
4723
+ count++;
4724
+ }
4725
+ }
4726
+ return { ...bin, count };
4727
+ });
4728
+ }, [hasSelection, storeHistogramBins, selectedTemporalFeatures]);
4729
+ const colorGroupedBins = histogramBins.length > 0 && hasSelection && selectedFeatureColors && selectedFeatureColors.size > 0 && globalMinDate && globalMaxDate ? (() => {
4589
4730
  if (selectedTemporalFeatures.length === 0) return [];
4590
4731
  const colorGroups = /* @__PURE__ */ new Map();
4591
4732
  selectedTemporalFeatures.forEach((f) => {
@@ -4593,6 +4734,7 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4593
4734
  if (!colorGroups.has(color)) colorGroups.set(color, []);
4594
4735
  colorGroups.get(color).push(f);
4595
4736
  });
4737
+ if (colorGroups.size <= 1) return [];
4596
4738
  const result = [];
4597
4739
  colorGroups.forEach((features, color) => {
4598
4740
  const bins = histogramBins.map((bin, binIndex) => {
@@ -4609,21 +4751,6 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4609
4751
  });
4610
4752
  return result;
4611
4753
  })() : [];
4612
- const selectedBins = histogramBins.length > 0 && selectedFeatureIds.length > 0 && (!selectedFeatureColors || selectedFeatureColors.size === 0) && globalMinDate && globalMaxDate ? (() => {
4613
- const selectedSet = new Set(selectedFeatureIds);
4614
- const selectedTemporalFeatures = temporalFeatures.filter((f) => selectedSet.has(f.id));
4615
- if (selectedTemporalFeatures.length === 0) return [];
4616
- return histogramBins.map((bin, binIndex) => {
4617
- let count = 0;
4618
- const isLastBin = binIndex === histogramBins.length - 1;
4619
- selectedTemporalFeatures.forEach((f) => {
4620
- if (!f.startDate) return;
4621
- const t = f.startDate.getTime();
4622
- if (t >= bin.start.getTime() && (isLastBin ? t <= bin.end.getTime() : t < bin.end.getTime())) count++;
4623
- });
4624
- return count;
4625
- });
4626
- })() : [];
4627
4754
  const animationFrameRef = react.useRef(null);
4628
4755
  const lastFrameTimeRef = react.useRef(0);
4629
4756
  const playbackDuration = 1e4;
@@ -4724,7 +4851,6 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4724
4851
  {
4725
4852
  bins: histogramBins,
4726
4853
  maxCount: maxBinCount,
4727
- selectedBins,
4728
4854
  colorGroupedBins
4729
4855
  }
4730
4856
  ),
@@ -4774,11 +4900,14 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4774
4900
  className: "!h-7 !w-7 !p-0 !min-w-0"
4775
4901
  }
4776
4902
  ),
4777
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-xs text-muted-foreground ml-1", children: [
4778
- temporalFeatures.length,
4779
- " feature",
4780
- temporalFeatures.length !== 1 ? "s" : ""
4781
- ] })
4903
+ /* @__PURE__ */ jsxRuntime.jsx(
4904
+ "span",
4905
+ {
4906
+ className: "text-xs text-muted-foreground ml-1",
4907
+ "data-testid": "text-timeline-feature-count",
4908
+ children: hasSelection ? `${selectedTemporalFeatures.length} of ${temporalFeatures.length} selected` : `${temporalFeatures.length} feature${temporalFeatures.length !== 1 ? "s" : ""}`
4909
+ }
4910
+ )
4782
4911
  ] }),
4783
4912
  timebarExtra,
4784
4913
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-xs text-muted-foreground font-mono", children: [
@@ -4872,6 +5001,12 @@ function MapDropZone({ onDrop, children }) {
4872
5001
  }
4873
5002
  );
4874
5003
  }
5004
+ const OTHER_BUCKET_KEY = "__other__";
5005
+ const OTHER_BUCKET_LABEL = "Other";
5006
+ const OTHER_BUCKET_COLOR = "#9ca3af";
5007
+ function toDisplayName(name) {
5008
+ return name === OTHER_BUCKET_KEY ? OTHER_BUCKET_LABEL : name;
5009
+ }
4875
5010
  function createPieSVG(categories, total, size = 44, onSliceHover) {
4876
5011
  const container = document.createElement("div");
4877
5012
  container.style.width = `${size}px`;
@@ -4890,8 +5025,41 @@ function createPieSVG(categories, total, size = 44, onSliceHover) {
4890
5025
  bgCircle.setAttribute("r", String(radius));
4891
5026
  bgCircle.setAttribute("fill", "white");
4892
5027
  svg.appendChild(bgCircle);
5028
+ const slicesSum = categories.reduce((s, c) => s + c.count, 0);
5029
+ const remainder = Math.max(0, total - slicesSum);
5030
+ const renderList = remainder > 0 ? [...categories, { name: "__remainder__", displayName: "Other", count: remainder, color: OTHER_BUCKET_COLOR }] : categories;
5031
+ const nonZeroSlices = renderList.filter((c) => c.count > 0);
5032
+ const isSingleFullSlice = nonZeroSlices.length === 1 && nonZeroSlices[0].count >= total;
5033
+ if (isSingleFullSlice) {
5034
+ const cat = nonZeroSlices[0];
5035
+ const ring = document.createElementNS("http://www.w3.org/2000/svg", "path");
5036
+ const d = [
5037
+ `M 0 ${radius}`,
5038
+ `a ${radius} ${radius} 0 1 0 ${radius * 2} 0`,
5039
+ `a ${radius} ${radius} 0 1 0 ${-radius * 2} 0`,
5040
+ `M ${radius - innerRadius} ${radius}`,
5041
+ `a ${innerRadius} ${innerRadius} 0 1 1 ${innerRadius * 2} 0`,
5042
+ `a ${innerRadius} ${innerRadius} 0 1 1 ${-innerRadius * 2} 0`,
5043
+ "Z"
5044
+ ].join(" ");
5045
+ ring.setAttribute("d", d);
5046
+ ring.setAttribute("fill-rule", "evenodd");
5047
+ ring.setAttribute("fill", cat.color);
5048
+ ring.setAttribute("stroke", "white");
5049
+ ring.setAttribute("stroke-width", "1");
5050
+ ring.style.transition = "opacity 0.15s";
5051
+ ring.addEventListener("mouseenter", (e) => {
5052
+ ring.style.opacity = "0.8";
5053
+ if (onSliceHover) onSliceHover(cat, e);
5054
+ });
5055
+ ring.addEventListener("mouseleave", (e) => {
5056
+ ring.style.opacity = "1";
5057
+ if (onSliceHover) onSliceHover(null, e);
5058
+ });
5059
+ svg.appendChild(ring);
5060
+ }
4893
5061
  let currentAngle = -90;
4894
- categories.forEach((cat) => {
5062
+ (isSingleFullSlice ? [] : renderList).forEach((cat) => {
4895
5063
  if (cat.count === 0) return;
4896
5064
  const sliceAngle = cat.count / total * 360;
4897
5065
  const startAngle = currentAngle;
@@ -4970,12 +5138,20 @@ function showTooltip(cat, x, y) {
4970
5138
  `;
4971
5139
  document.body.appendChild(tooltipEl);
4972
5140
  }
4973
- tooltipEl.innerHTML = `
4974
- <div style="display: flex; align-items: center; gap: 6px;">
4975
- <span style="width: 10px; height: 10px; border-radius: 2px; background: ${cat.color};"></span>
4976
- <span><strong>${cat.name}</strong>: ${cat.count}</span>
4977
- </div>
4978
- `;
5141
+ while (tooltipEl.firstChild) tooltipEl.removeChild(tooltipEl.firstChild);
5142
+ const row = document.createElement("div");
5143
+ row.style.cssText = "display: flex; align-items: center; gap: 6px;";
5144
+ const swatch = document.createElement("span");
5145
+ swatch.style.cssText = "width: 10px; height: 10px; border-radius: 2px;";
5146
+ swatch.style.backgroundColor = cat.color;
5147
+ row.appendChild(swatch);
5148
+ const label = document.createElement("span");
5149
+ const name = document.createElement("strong");
5150
+ name.textContent = cat.displayName;
5151
+ label.appendChild(name);
5152
+ label.appendChild(document.createTextNode(`: ${cat.count}`));
5153
+ row.appendChild(label);
5154
+ tooltipEl.appendChild(row);
4979
5155
  tooltipEl.style.left = `${x + 12}px`;
4980
5156
  tooltipEl.style.top = `${y - 10}px`;
4981
5157
  tooltipEl.style.display = "block";
@@ -4985,67 +5161,114 @@ function hideTooltip() {
4985
5161
  tooltipEl.style.display = "none";
4986
5162
  }
4987
5163
  }
5164
+ function fingerprintCluster(pointCount, counts, size) {
5165
+ return `${size}|${pointCount}|${counts.join(",")}`;
5166
+ }
5167
+ function buildPieElement(categories, pointCount, size, source, clusterId, map, coords) {
5168
+ const el = createPieSVG(categories, pointCount, size, (cat, event) => {
5169
+ if (cat) {
5170
+ showTooltip(cat, event.clientX, event.clientY);
5171
+ } else {
5172
+ hideTooltip();
5173
+ }
5174
+ });
5175
+ el.addEventListener("click", () => {
5176
+ source.getClusterExpansionZoom(clusterId).then((zoom) => {
5177
+ if (typeof zoom === "number") {
5178
+ map.easeTo({ center: coords, zoom: zoom + 0.5 });
5179
+ }
5180
+ }).catch(() => {
5181
+ });
5182
+ });
5183
+ return el;
5184
+ }
5185
+ function renderClusterPies(map, sourceId, categoryValues, categoryColorMap, markers) {
5186
+ const source = map.getSource(sourceId);
5187
+ if (!source) return;
5188
+ const clusters = map.querySourceFeatures(sourceId, {
5189
+ filter: ["has", "point_count"]
5190
+ });
5191
+ const visibleClusterIds = /* @__PURE__ */ new Set();
5192
+ clusters.forEach((feature) => {
5193
+ var _a, _b;
5194
+ const clusterId = (_a = feature.properties) == null ? void 0 : _a.cluster_id;
5195
+ if (clusterId === void 0) return;
5196
+ const clusterKey = `${clusterId}`;
5197
+ visibleClusterIds.add(clusterKey);
5198
+ const coords = feature.geometry.coordinates;
5199
+ const pointCount = ((_b = feature.properties) == null ? void 0 : _b.point_count) || 0;
5200
+ const allCounts = categoryValues.map((_, i) => {
5201
+ var _a2;
5202
+ return Number(((_a2 = feature.properties) == null ? void 0 : _a2[`cat_${i}`]) || 0);
5203
+ });
5204
+ const categories = categoryValues.map((cat, i) => ({
5205
+ name: cat,
5206
+ displayName: toDisplayName(cat),
5207
+ count: allCounts[i],
5208
+ color: categoryColorMap[cat] || "#3b82f6"
5209
+ })).filter((c) => c.count > 0);
5210
+ const size = pointCount < 100 ? 40 : pointCount < 750 ? 50 : 60;
5211
+ const fingerprint = fingerprintCluster(pointCount, allCounts, size);
5212
+ const existing = markers.get(clusterKey);
5213
+ if (existing && existing.fingerprint === fingerprint) {
5214
+ existing.marker.setLngLat(coords);
5215
+ return;
5216
+ }
5217
+ const el = buildPieElement(categories, pointCount, size, source, clusterId, map, coords);
5218
+ if (existing) {
5219
+ existing.marker.remove();
5220
+ }
5221
+ const marker = new maplibregl.Marker({ element: el }).setLngLat(coords).addTo(map);
5222
+ markers.set(clusterKey, { marker, fingerprint });
5223
+ });
5224
+ markers.forEach((entry, key) => {
5225
+ if (!visibleClusterIds.has(key)) {
5226
+ entry.marker.remove();
5227
+ markers.delete(key);
5228
+ }
5229
+ });
5230
+ }
5231
+ function createClusterPieManager(map, sourceId, categoryValues, categoryColorMap) {
5232
+ const markers = /* @__PURE__ */ new Map();
5233
+ let updateScheduled = false;
5234
+ function scheduleUpdate() {
5235
+ if (updateScheduled) return;
5236
+ updateScheduled = true;
5237
+ requestAnimationFrame(() => {
5238
+ updateScheduled = false;
5239
+ renderClusterPies(map, sourceId, categoryValues, categoryColorMap, markers);
5240
+ });
5241
+ }
5242
+ function onData(e) {
5243
+ if (e.sourceId === sourceId) {
5244
+ scheduleUpdate();
5245
+ }
5246
+ }
5247
+ map.on("moveend", scheduleUpdate);
5248
+ map.on("data", onData);
5249
+ scheduleUpdate();
5250
+ return {
5251
+ update: scheduleUpdate,
5252
+ destroy: () => {
5253
+ map.off("moveend", scheduleUpdate);
5254
+ map.off("data", onData);
5255
+ markers.forEach((entry) => entry.marker.remove());
5256
+ markers.clear();
5257
+ hideTooltip();
5258
+ }
5259
+ };
5260
+ }
4988
5261
  function ClusterPieManager(props) {
4989
- const { map, sourceId, layerId, categoryValues, categoryColorMap, visible } = props;
5262
+ const { map, sourceId, categoryValues, categoryColorMap, visible } = props;
4990
5263
  const markersRef = react.useRef(/* @__PURE__ */ new Map());
4991
5264
  const updateScheduled = react.useRef(false);
4992
5265
  const updateMarkers = react.useCallback(() => {
4993
5266
  if (!map || !visible) {
4994
- markersRef.current.forEach((marker) => marker.remove());
5267
+ markersRef.current.forEach((entry) => entry.marker.remove());
4995
5268
  markersRef.current.clear();
4996
5269
  return;
4997
5270
  }
4998
- const source = map.getSource(sourceId);
4999
- if (!source) return;
5000
- const clusters = map.querySourceFeatures(sourceId, {
5001
- filter: ["has", "point_count"]
5002
- });
5003
- const visibleClusterIds = /* @__PURE__ */ new Set();
5004
- clusters.forEach((feature) => {
5005
- var _a, _b;
5006
- const clusterId = (_a = feature.properties) == null ? void 0 : _a.cluster_id;
5007
- if (clusterId === void 0) return;
5008
- const clusterKey = `${clusterId}`;
5009
- visibleClusterIds.add(clusterKey);
5010
- const coords = feature.geometry.coordinates;
5011
- const pointCount = ((_b = feature.properties) == null ? void 0 : _b.point_count) || 0;
5012
- const categories = categoryValues.map((cat, i) => {
5013
- var _a2;
5014
- return {
5015
- name: cat,
5016
- count: ((_a2 = feature.properties) == null ? void 0 : _a2[`cat_${i}`]) || 0,
5017
- color: categoryColorMap[cat] || "#3b82f6"
5018
- };
5019
- }).filter((c) => c.count > 0);
5020
- const size = pointCount < 100 ? 40 : pointCount < 750 ? 50 : 60;
5021
- const existingMarker = markersRef.current.get(clusterKey);
5022
- if (existingMarker) {
5023
- existingMarker.setLngLat(coords);
5024
- } else {
5025
- const el = createPieSVG(categories, pointCount, size, (cat, event) => {
5026
- if (cat) {
5027
- showTooltip(cat, event.clientX, event.clientY);
5028
- } else {
5029
- hideTooltip();
5030
- }
5031
- });
5032
- el.addEventListener("click", () => {
5033
- source.getClusterExpansionZoom(clusterId, (err, zoom) => {
5034
- if (!err) {
5035
- map.easeTo({ center: coords, zoom: zoom + 0.5 });
5036
- }
5037
- });
5038
- });
5039
- const marker = new maplibregl.Marker({ element: el }).setLngLat(coords).addTo(map);
5040
- markersRef.current.set(clusterKey, marker);
5041
- }
5042
- });
5043
- markersRef.current.forEach((marker, key) => {
5044
- if (!visibleClusterIds.has(key)) {
5045
- marker.remove();
5046
- markersRef.current.delete(key);
5047
- }
5048
- });
5271
+ renderClusterPies(map, sourceId, categoryValues, categoryColorMap, markersRef.current);
5049
5272
  }, [map, sourceId, categoryValues, categoryColorMap, visible]);
5050
5273
  react.useEffect(() => {
5051
5274
  if (!map) return;
@@ -5057,23 +5280,25 @@ function ClusterPieManager(props) {
5057
5280
  updateMarkers();
5058
5281
  });
5059
5282
  };
5060
- scheduleUpdate();
5061
- map.on("moveend", scheduleUpdate);
5062
- map.on("data", (e) => {
5283
+ const onData = (e) => {
5063
5284
  if (e.sourceId === sourceId) {
5064
5285
  scheduleUpdate();
5065
5286
  }
5066
- });
5287
+ };
5288
+ scheduleUpdate();
5289
+ map.on("moveend", scheduleUpdate);
5290
+ map.on("data", onData);
5067
5291
  return () => {
5068
5292
  map.off("moveend", scheduleUpdate);
5069
- markersRef.current.forEach((marker) => marker.remove());
5293
+ map.off("data", onData);
5294
+ markersRef.current.forEach((entry) => entry.marker.remove());
5070
5295
  markersRef.current.clear();
5071
5296
  hideTooltip();
5072
5297
  };
5073
5298
  }, [map, sourceId, updateMarkers]);
5074
5299
  react.useEffect(() => {
5075
5300
  if (!visible) {
5076
- markersRef.current.forEach((marker) => marker.remove());
5301
+ markersRef.current.forEach((entry) => entry.marker.remove());
5077
5302
  markersRef.current.clear();
5078
5303
  hideTooltip();
5079
5304
  } else {
@@ -5082,89 +5307,6 @@ function ClusterPieManager(props) {
5082
5307
  }, [visible, updateMarkers]);
5083
5308
  return null;
5084
5309
  }
5085
- function createClusterPieManager(map, sourceId, categoryValues, categoryColorMap) {
5086
- const markers = /* @__PURE__ */ new Map();
5087
- let updateScheduled = false;
5088
- function update() {
5089
- const source = map.getSource(sourceId);
5090
- if (!source) return;
5091
- const clusters = map.querySourceFeatures(sourceId, {
5092
- filter: ["has", "point_count"]
5093
- });
5094
- const visibleClusterIds = /* @__PURE__ */ new Set();
5095
- clusters.forEach((feature) => {
5096
- var _a, _b;
5097
- const clusterId = (_a = feature.properties) == null ? void 0 : _a.cluster_id;
5098
- if (clusterId === void 0) return;
5099
- const clusterKey = `${clusterId}`;
5100
- visibleClusterIds.add(clusterKey);
5101
- const coords = feature.geometry.coordinates;
5102
- const pointCount = ((_b = feature.properties) == null ? void 0 : _b.point_count) || 0;
5103
- const categories = categoryValues.map((cat, i) => {
5104
- var _a2;
5105
- return {
5106
- name: cat,
5107
- count: ((_a2 = feature.properties) == null ? void 0 : _a2[`cat_${i}`]) || 0,
5108
- color: categoryColorMap[cat] || "#3b82f6"
5109
- };
5110
- }).filter((c) => c.count > 0);
5111
- const size = pointCount < 100 ? 40 : pointCount < 750 ? 50 : 60;
5112
- const existingMarker = markers.get(clusterKey);
5113
- if (existingMarker) {
5114
- existingMarker.setLngLat(coords);
5115
- } else {
5116
- const el = createPieSVG(categories, pointCount, size, (cat, event) => {
5117
- if (cat) {
5118
- showTooltip(cat, event.clientX, event.clientY);
5119
- } else {
5120
- hideTooltip();
5121
- }
5122
- });
5123
- el.addEventListener("click", () => {
5124
- source.getClusterExpansionZoom(clusterId, (err, zoom) => {
5125
- if (!err) {
5126
- map.easeTo({ center: coords, zoom: zoom + 0.5 });
5127
- }
5128
- });
5129
- });
5130
- const marker = new maplibregl.Marker({ element: el }).setLngLat(coords).addTo(map);
5131
- markers.set(clusterKey, marker);
5132
- }
5133
- });
5134
- markers.forEach((marker, key) => {
5135
- if (!visibleClusterIds.has(key)) {
5136
- marker.remove();
5137
- markers.delete(key);
5138
- }
5139
- });
5140
- }
5141
- function scheduleUpdate() {
5142
- if (updateScheduled) return;
5143
- updateScheduled = true;
5144
- requestAnimationFrame(() => {
5145
- updateScheduled = false;
5146
- update();
5147
- });
5148
- }
5149
- function onData(e) {
5150
- if (e.sourceId === sourceId) {
5151
- scheduleUpdate();
5152
- }
5153
- }
5154
- map.on("moveend", scheduleUpdate);
5155
- map.on("data", onData);
5156
- scheduleUpdate();
5157
- return {
5158
- update: scheduleUpdate,
5159
- destroy: () => {
5160
- map.off("moveend", scheduleUpdate);
5161
- map.off("data", onData);
5162
- markers.forEach((marker) => marker.remove());
5163
- markers.clear();
5164
- hideTooltip();
5165
- }
5166
- };
5167
- }
5168
5310
  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");
5169
5311
  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");
5170
5312
  proj4.defs("EPSG:32630", "+proj=utm +zone=30 +datum=WGS84 +units=m +no_defs");
@@ -5829,56 +5971,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
5829
5971
  const timelineVisibleIdsRef = react.useRef(null);
5830
5972
  const syncRef = react.useRef(() => {
5831
5973
  });
5832
- const hashStringToColor = react.useCallback((str) => {
5833
- const palette = [
5834
- "#4e79a7",
5835
- // steel blue
5836
- "#f28e2b",
5837
- // orange
5838
- "#e15759",
5839
- // red
5840
- "#76b7b2",
5841
- // teal
5842
- "#59a14f",
5843
- // green
5844
- "#edc948",
5845
- // yellow
5846
- "#b07aa1",
5847
- // purple
5848
- "#ff9da7",
5849
- // pink
5850
- "#9c755f",
5851
- // brown
5852
- "#bab0ac",
5853
- // gray
5854
- "#5fa2ce",
5855
- // light blue
5856
- "#ffbe7d",
5857
- // light orange
5858
- "#ff9888",
5859
- // salmon
5860
- "#8cd17d",
5861
- // light green
5862
- "#b6992d",
5863
- // olive
5864
- "#f1ce63",
5865
- // gold
5866
- "#d4a6c8",
5867
- // lavender
5868
- "#86bcb6",
5869
- // aqua
5870
- "#d37295",
5871
- // rose
5872
- "#499894"
5873
- // dark teal
5874
- ];
5875
- let hash = 0;
5876
- for (let i = 0; i < str.length; i++) {
5877
- hash = (hash << 5) - hash + str.charCodeAt(i);
5878
- hash = hash & hash;
5879
- }
5880
- return palette[Math.abs(hash) % palette.length];
5881
- }, []);
5974
+ const hashStringToColor$1 = react.useCallback((str) => hashStringToColor(str), []);
5882
5975
  const selectedFeatureColors = react.useMemo(() => {
5883
5976
  if (selectedFeatureIds.length === 0) return /* @__PURE__ */ new Map();
5884
5977
  const colorMap = /* @__PURE__ */ new Map();
@@ -5936,16 +6029,16 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
5936
6029
  if (colorConfig.mode === "fixed" && colorConfig.fixedColor) {
5937
6030
  color = colorConfig.fixedColor;
5938
6031
  } else if (colorConfig.mode === "field" && colorConfig.fieldName && feature.properties) {
5939
- const fieldValue = feature.properties[colorConfig.fieldName];
5940
- if (fieldValue !== void 0 && fieldValue !== null) {
5941
- color = hashStringToColor(String(fieldValue));
6032
+ const key = categoricalKey(feature.properties[colorConfig.fieldName]);
6033
+ if (key !== null) {
6034
+ color = hashStringToColor$1(key);
5942
6035
  }
5943
6036
  }
5944
6037
  }
5945
6038
  colorMap.set(fid, color);
5946
6039
  });
5947
6040
  return colorMap;
5948
- }, [selectedFeatureIds, layers, getAllFeatures, hashStringToColor]);
6041
+ }, [selectedFeatureIds, layers, getAllFeatures, hashStringToColor$1]);
5949
6042
  const isSyncingRef = react.useRef(false);
5950
6043
  const syncFeaturesToCustomLayers = react.useCallback(() => {
5951
6044
  if (!map.current) return;
@@ -6077,9 +6170,9 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
6077
6170
  if (colorConfig.mode === "fixed" && colorConfig.fixedColor) {
6078
6171
  strokeColor = colorConfig.fixedColor;
6079
6172
  } else if (colorConfig.mode === "field" && colorConfig.fieldName && f.properties) {
6080
- const fieldValue = f.properties[colorConfig.fieldName];
6081
- if (fieldValue !== void 0 && fieldValue !== null) {
6082
- strokeColor = hashStringToColor(String(fieldValue));
6173
+ const key = categoricalKey(f.properties[colorConfig.fieldName]);
6174
+ if (key !== null) {
6175
+ strokeColor = hashStringToColor$1(key);
6083
6176
  }
6084
6177
  }
6085
6178
  }
@@ -6169,7 +6262,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
6169
6262
  id: featureId,
6170
6263
  name: labelText,
6171
6264
  isSelected: isFeatureSelected,
6172
- isHiddenByHeatmap: hideByHeatmap ? true : false,
6265
+ isHiddenByHeatmap: hideByHeatmap ? 1 : 0,
6173
6266
  isHiddenByCluster: hideByCluster ? 1 : 0,
6174
6267
  isHiddenByTrace: hideByTrace ? true : false,
6175
6268
  isTracePoint: isTracePoint ? true : false,
@@ -6406,7 +6499,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
6406
6499
  } finally {
6407
6500
  isSyncingRef.current = false;
6408
6501
  }
6409
- }, [layers, hashStringToColor, autoLabelConfig]);
6502
+ }, [layers, hashStringToColor$1, autoLabelConfig]);
6410
6503
  const update3DFlightPaths = react.useCallback(() => {
6411
6504
  if (!map.current || !is3DTerrainEnabled) {
6412
6505
  if (map.current && flightPath3DLayerId.current) {
@@ -6674,6 +6767,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
6674
6767
  0,
6675
6768
  ["==", ["get", "isHiddenByCluster"], 1],
6676
6769
  0,
6770
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6771
+ 0,
6677
6772
  ["!=", ["get", "icon"], ""],
6678
6773
  0,
6679
6774
  ["+", ["coalesce", ["get", "pointRadius"], 5], 1.5]
@@ -6683,6 +6778,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
6683
6778
  "case",
6684
6779
  ["==", ["get", "isHiddenByCluster"], 1],
6685
6780
  0,
6781
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6782
+ 0,
6686
6783
  ["!=", ["get", "icon"], ""],
6687
6784
  0,
6688
6785
  ["coalesce", ["get", "stroke-opacity"], 1]
@@ -6703,6 +6800,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
6703
6800
  0,
6704
6801
  ["==", ["get", "isHiddenByCluster"], 1],
6705
6802
  0,
6803
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6804
+ 0,
6706
6805
  ["!=", ["get", "icon"], ""],
6707
6806
  0,
6708
6807
  ["coalesce", ["get", "pointRadius"], 5]
@@ -6711,6 +6810,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
6711
6810
  "case",
6712
6811
  ["==", ["get", "isHiddenByCluster"], 1],
6713
6812
  0,
6813
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6814
+ 0,
6714
6815
  ["!=", ["get", "icon"], ""],
6715
6816
  0,
6716
6817
  ["coalesce", ["get", "stroke-opacity"], 1]
@@ -6722,6 +6823,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
6722
6823
  0,
6723
6824
  ["==", ["get", "isHiddenByCluster"], 1],
6724
6825
  0,
6826
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6827
+ 0,
6725
6828
  ["!=", ["get", "icon"], ""],
6726
6829
  0,
6727
6830
  ["==", ["get", "isSelected"], 1],
@@ -6732,6 +6835,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
6732
6835
  "case",
6733
6836
  ["==", ["get", "isHiddenByCluster"], 1],
6734
6837
  0,
6838
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6839
+ 0,
6735
6840
  ["!=", ["get", "icon"], ""],
6736
6841
  0,
6737
6842
  1
@@ -6754,6 +6859,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
6754
6859
  "case",
6755
6860
  ["==", ["get", "isHiddenByCluster"], 1],
6756
6861
  0,
6862
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6863
+ 0,
6757
6864
  ["coalesce", ["get", "stroke-opacity"], 1]
6758
6865
  ]
6759
6866
  }
@@ -6762,7 +6869,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
6762
6869
  id: "custom-point-icon-selection",
6763
6870
  type: "circle",
6764
6871
  source: "custom-features",
6765
- filter: ["all", ["==", "$type", "Point"], ["!=", "icon", ""], ["==", "isSelected", 1]],
6872
+ filter: ["all", ["==", "$type", "Point"], ["!=", "icon", ""], ["==", "isSelected", 1], ["!=", "isHiddenByHeatmap", 1]],
6766
6873
  paint: {
6767
6874
  "circle-color": "transparent",
6768
6875
  "circle-radius": ["/", ["coalesce", ["get", "iconSize"], 24], 1.6],
@@ -6804,6 +6911,10 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
6804
6911
  "case",
6805
6912
  ["==", ["get", "isHiddenByTrace"], true],
6806
6913
  "",
6914
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6915
+ "",
6916
+ ["==", ["get", "isHiddenByCluster"], 1],
6917
+ "",
6807
6918
  ["==", ["get", "kind"], "arrow"],
6808
6919
  "",
6809
6920
  // Arrows use custom-arrow-labels layer
@@ -7349,12 +7460,26 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7349
7460
  mapInstance.addLayer(newLayer, beforeLayer);
7350
7461
  addedLayerIds.push(prefixedLayerId);
7351
7462
  } catch (e) {
7463
+ console.warn(
7464
+ `[map-component] failed to add basemap layer ${prefixedLayerId}:`,
7465
+ (e == null ? void 0 : e.message) ?? e
7466
+ );
7352
7467
  }
7353
7468
  }
7354
7469
  }
7355
7470
  }
7356
7471
  basemapLayerIds.current.set(baseMapStyle, addedLayerIds);
7357
7472
  loadedBasemaps.current.add(baseMapStyle);
7473
+ const triggerResize = () => {
7474
+ try {
7475
+ mapInstance.resize();
7476
+ } catch {
7477
+ }
7478
+ };
7479
+ requestAnimationFrame(triggerResize);
7480
+ setTimeout(triggerResize, 200);
7481
+ setTimeout(triggerResize, 600);
7482
+ setTimeout(triggerResize, 1500);
7358
7483
  }).catch((err) => {
7359
7484
  console.error("Failed to load initial basemap:", err);
7360
7485
  });
@@ -7641,7 +7766,19 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7641
7766
  }, 0);
7642
7767
  });
7643
7768
  mapInstance.on("error", (e) => {
7644
- console.error("Map error:", e);
7769
+ var _a, _b;
7770
+ const err = e == null ? void 0 : e.error;
7771
+ const details = {
7772
+ message: err == null ? void 0 : err.message,
7773
+ name: err == null ? void 0 : err.name,
7774
+ stack: err == null ? void 0 : err.stack,
7775
+ status: err == null ? void 0 : err.status,
7776
+ url: err == null ? void 0 : err.url,
7777
+ sourceId: e == null ? void 0 : e.sourceId,
7778
+ 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
7779
+ };
7780
+ for (const k of Object.keys(details)) if (details[k] === void 0) delete details[k];
7781
+ console.error("Map error:", details, e);
7645
7782
  });
7646
7783
  } catch (error) {
7647
7784
  console.error("Failed to initialize map:", error);
@@ -7900,8 +8037,49 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7900
8037
  });
7901
8038
  },
7902
8039
  addFeatures: (layerId, features) => {
8040
+ var _a;
7903
8041
  const layer = layersRef.current.find((l) => l.id === layerId);
7904
- if (!layer || !draw.current || !isMapLoadedRef.current) return [];
8042
+ if (!layer || !isMapLoadedRef.current) return [];
8043
+ if (layer.readOnly) {
8044
+ const existing = readOnlyFeatures.current.get(layerId) || [];
8045
+ let layerHasTemporal = ((_a = layerTemporalCacheRef.current.get(layerId)) == null ? void 0 : _a.hasTemporal) ?? false;
8046
+ const newFeaturesWithIds = features.map((f) => {
8047
+ const id = f.id ? String(f.id) : crypto.randomUUID();
8048
+ const props = f.properties || {};
8049
+ if (!hasAnyTemporalValue(props)) {
8050
+ return { ...f, id };
8051
+ }
8052
+ const { startDate, endDate } = normalizeTemporalProperties(props);
8053
+ if (startDate || endDate) layerHasTemporal = true;
8054
+ return {
8055
+ ...f,
8056
+ id,
8057
+ properties: {
8058
+ ...props,
8059
+ startDate: (startDate == null ? void 0 : startDate.toISOString()) || null,
8060
+ endDate: (endDate == null ? void 0 : endDate.toISOString()) || null
8061
+ }
8062
+ };
8063
+ });
8064
+ const combined = [...existing, ...newFeaturesWithIds];
8065
+ readOnlyFeatures.current.set(layerId, combined);
8066
+ layerTemporalCacheRef.current.set(layerId, { featureCount: combined.length, hasTemporal: layerHasTemporal });
8067
+ const addedIds2 = newFeaturesWithIds.map((f) => String(f.id));
8068
+ const updatedLayers2 = layersRef.current.map(
8069
+ (l) => l.id === layerId ? { ...l, featureIds: [...l.featureIds, ...addedIds2] } : l
8070
+ );
8071
+ layersRef.current = updatedLayers2;
8072
+ setLayers(updatedLayers2);
8073
+ updateFeatureCount();
8074
+ if (layerHasTemporal) {
8075
+ scheduleTimelineUpdate();
8076
+ }
8077
+ requestAnimationFrame(() => {
8078
+ syncRef.current();
8079
+ });
8080
+ return addedIds2;
8081
+ }
8082
+ if (!draw.current) return [];
7905
8083
  const addedIds = [];
7906
8084
  isApiAddingRef.current = true;
7907
8085
  try {
@@ -9572,6 +9750,31 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9572
9750
  });
9573
9751
  return Array.from(fieldsMap.entries()).map(([name, isNumeric]) => ({ name, isNumeric })).sort((a, b) => a.name.localeCompare(b.name));
9574
9752
  }, [layers]);
9753
+ const getFieldValueDistribution = react.useCallback(
9754
+ (layerId, fieldName, maxValues = 50) => {
9755
+ var _a;
9756
+ const layer = layers.find((l) => l.id === layerId);
9757
+ if (!layer) return [];
9758
+ let features = [];
9759
+ if (layer.readOnly) {
9760
+ features = readOnlyFeatures.current.get(layerId) || [];
9761
+ } else if (layer.visible) {
9762
+ features = draw.current ? layer.featureIds.map((id) => draw.current.get(id)) : [];
9763
+ } else {
9764
+ features = hiddenFeatures.current.get(layerId) || [];
9765
+ }
9766
+ const MAX_SAMPLES = 1e4;
9767
+ const sample = features.slice(0, MAX_SAMPLES);
9768
+ const counts = /* @__PURE__ */ new Map();
9769
+ for (const f of sample) {
9770
+ const key = categoricalKey((_a = f == null ? void 0 : f.properties) == null ? void 0 : _a[fieldName]);
9771
+ if (key === null) continue;
9772
+ counts.set(key, (counts.get(key) ?? 0) + 1);
9773
+ }
9774
+ 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 }));
9775
+ },
9776
+ [layers]
9777
+ );
9575
9778
  const handleFitToLayerFeatures = react.useCallback((layerId) => {
9576
9779
  if (!map.current) return;
9577
9780
  const customBounds = fitBoundsProvider == null ? void 0 : fitBoundsProvider(layerId);
@@ -11408,45 +11611,38 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11408
11611
  }
11409
11612
  if (pointFeatures.length === 0) return;
11410
11613
  const groupByField = (_b = layer.clusterConfig) == null ? void 0 : _b.groupByField;
11411
- const categoryColors = [
11412
- "#3b82f6",
11413
- "#ef4444",
11414
- "#22c55e",
11415
- "#f59e0b",
11416
- "#8b5cf6",
11417
- "#ec4899",
11418
- "#06b6d4",
11419
- "#f97316",
11420
- "#84cc16",
11421
- "#6366f1",
11422
- "#14b8a6",
11423
- "#d946ef",
11424
- "#0ea5e9",
11425
- "#a855f7",
11426
- "#10b981"
11427
- ];
11614
+ const OTHER_COLOR = OTHER_BUCKET_COLOR;
11615
+ const MAX_CATEGORIES = 15;
11428
11616
  try {
11429
11617
  const layerColor = ((_d = (_c = layer.visualConfig) == null ? void 0 : _c.color) == null ? void 0 : _d.fixedColor) || "#3b82f6";
11430
11618
  let clusterProperties = {};
11431
11619
  let categoryValues = [];
11432
11620
  let categoryColorMap = {};
11621
+ let hasOtherBucket = false;
11433
11622
  if (groupByField) {
11434
- const uniqueCategories = /* @__PURE__ */ new Set();
11623
+ const counts = /* @__PURE__ */ new Map();
11435
11624
  pointFeatures.forEach((f) => {
11436
11625
  var _a2;
11437
- const val = (_a2 = f.properties) == null ? void 0 : _a2[groupByField];
11438
- if (val !== void 0 && val !== null) {
11439
- uniqueCategories.add(String(val));
11440
- }
11626
+ const key = categoricalKey((_a2 = f.properties) == null ? void 0 : _a2[groupByField]);
11627
+ if (key === null) return;
11628
+ counts.set(key, (counts.get(key) ?? 0) + 1);
11441
11629
  });
11442
- categoryValues = Array.from(uniqueCategories).slice(0, 15);
11443
- categoryValues.forEach((cat, i) => {
11444
- categoryColorMap[cat] = categoryColors[i % categoryColors.length];
11630
+ const sorted = Array.from(counts.entries()).sort((a, b) => b[1] - a[1]);
11631
+ const topKeys = sorted.slice(0, MAX_CATEGORIES).map(([k]) => k);
11632
+ categoryValues = [...topKeys];
11633
+ hasOtherBucket = true;
11634
+ const fieldAsString = ["to-string", ["coalesce", ["get", groupByField], ""]];
11635
+ topKeys.forEach((cat, i) => {
11636
+ categoryColorMap[cat] = hashStringToColor$1(cat);
11445
11637
  clusterProperties[`cat_${i}`] = [
11446
11638
  "+",
11447
- ["case", ["==", ["get", groupByField], cat], 1, 0]
11639
+ ["case", ["==", fieldAsString, cat], 1, 0]
11448
11640
  ];
11449
11641
  });
11642
+ categoryValues.push(OTHER_BUCKET_KEY);
11643
+ categoryColorMap[OTHER_BUCKET_KEY] = OTHER_COLOR;
11644
+ const otherExpr = topKeys.length === 0 ? 1 : ["match", fieldAsString, topKeys, 0, 1];
11645
+ clusterProperties[`cat_${categoryValues.length - 1}`] = ["+", otherExpr];
11450
11646
  }
11451
11647
  const mapStyleMaxZoom = typeof mapInstance.getMaxZoom === "function" ? mapInstance.getMaxZoom() : 24;
11452
11648
  const clusterMaxZoom = Math.min(24, Math.max(1, mapStyleMaxZoom - 1));
@@ -11520,11 +11716,12 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11520
11716
  }
11521
11717
  });
11522
11718
  }
11523
- const unclusteredColor = groupByField ? [
11719
+ const renderableTopKeys = categoryValues.filter((c) => c !== OTHER_BUCKET_KEY);
11720
+ const unclusteredColor = groupByField && renderableTopKeys.length > 0 ? [
11524
11721
  "match",
11525
- ["get", groupByField],
11526
- ...categoryValues.flatMap((cat) => [cat, categoryColorMap[cat] || layerColor]),
11527
- layerColor
11722
+ ["to-string", ["coalesce", ["get", groupByField], ""]],
11723
+ ...renderableTopKeys.flatMap((cat) => [cat, categoryColorMap[cat] || layerColor]),
11724
+ hasOtherBucket ? OTHER_COLOR : layerColor
11528
11725
  ] : layerColor;
11529
11726
  mapInstance.addLayer({
11530
11727
  id: unclusteredLayerId,
@@ -11580,7 +11777,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11580
11777
  } catch {
11581
11778
  }
11582
11779
  };
11583
- }, [isMapLoaded, layers, currentMapStyle]);
11780
+ }, [isMapLoaded, layers, currentMapStyle, hashStringToColor$1]);
11584
11781
  if (mapError) {
11585
11782
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: `flex items-center justify-center h-full bg-muted/30 ${className || ""}`, "data-testid": "map-error", children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Card, { className: "max-w-md", children: [
11586
11783
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4 border-b border-border", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
@@ -11963,6 +12160,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11963
12160
  onMapStyleChange: handleMapStyleChange,
11964
12161
  onUpdateTraceConfig: handleUpdateTraceConfig,
11965
12162
  getAvailableTraceFields,
12163
+ getFieldValueDistribution,
11966
12164
  onUpdateHeatmapConfig: handleUpdateHeatmapConfig,
11967
12165
  onUpdateClusterConfig: handleUpdateClusterConfig,
11968
12166
  hasPointFeatures,
@@ -12021,7 +12219,8 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
12021
12219
  onMoveFeaturesToLayer: handleMoveFeaturesToLayer,
12022
12220
  onCopyFeaturesToLayer: handleCopyFeaturesToLayer,
12023
12221
  onCreateLayerAndMoveFeatures: handleCreateLayerAndMoveFeatures,
12024
- onCreateLayerAndCopyFeatures: handleCreateLayerAndCopyFeatures
12222
+ onCreateLayerAndCopyFeatures: handleCreateLayerAndCopyFeatures,
12223
+ getFeatureColor: (featureId) => selectedFeatureColors.get(featureId)
12025
12224
  }
12026
12225
  );
12027
12226
  })(),