@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.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,
@@ -1693,7 +1816,7 @@ function LayersPanel({
1693
1816
  });
1694
1817
  }, [onRemoveLayer]);
1695
1818
  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, __, _$;
1819
+ 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
1820
  const customCount = featureCountProvider == null ? void 0 : featureCountProvider(layer.id);
1698
1821
  const featureCount = customCount != null ? customCount : getFeatureCount(layer.id);
1699
1822
  const isExpanded = expandedLayers.has(layer.id);
@@ -1888,6 +2011,8 @@ function LayersPanel({
1888
2011
  groupByField: val === "all" ? null : val
1889
2012
  }),
1890
2013
  className: "w-full text-xs",
2014
+ showSearch: true,
2015
+ optionFilterProp: "label",
1891
2016
  options: [
1892
2017
  { value: "all", label: "Connect all points" },
1893
2018
  ...getAvailableTraceFields(layer.id).map((f) => ({ value: f, label: `Group by ${f}` }))
@@ -2000,6 +2125,8 @@ function LayersPanel({
2000
2125
  groupByField: val === "count" ? null : val
2001
2126
  }),
2002
2127
  className: "w-full text-xs",
2128
+ showSearch: true,
2129
+ optionFilterProp: "label",
2003
2130
  options: [
2004
2131
  { value: "count", label: "Simple count" },
2005
2132
  ...getLayerFields(layer.id).filter((f) => !f.isNumeric).map((f) => ({ value: f.name, label: `Pie by ${f.name}` }))
@@ -2101,6 +2228,8 @@ function LayersPanel({
2101
2228
  }),
2102
2229
  className: "w-full text-sm",
2103
2230
  placeholder: "Select field...",
2231
+ showSearch: true,
2232
+ optionFilterProp: "label",
2104
2233
  options: getLayerFields(layer.id).map((f) => ({ value: f.name, label: f.name })),
2105
2234
  "data-testid": `select-label-field-${layer.id}`
2106
2235
  }
@@ -2152,6 +2281,8 @@ function LayersPanel({
2152
2281
  }),
2153
2282
  className: "w-full text-sm",
2154
2283
  placeholder: "Select numeric field...",
2284
+ showSearch: true,
2285
+ optionFilterProp: "label",
2155
2286
  options: getLayerFields(layer.id).filter((f) => f.isNumeric).map((f) => ({ value: f.name, label: f.name })),
2156
2287
  "data-testid": `select-size-field-${layer.id}`
2157
2288
  }
@@ -2195,25 +2326,37 @@ function LayersPanel({
2195
2326
  "data-testid": `select-color-mode-${layer.id}`
2196
2327
  }
2197
2328
  ),
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(
2329
+ ((_K = (_J = layer.visualConfig) == null ? void 0 : _J.color) == null ? void 0 : _K.mode) === "field" && /* @__PURE__ */ jsxs(Fragment, { children: [
2330
+ /* @__PURE__ */ jsx(
2331
+ Select,
2332
+ {
2333
+ size: "small",
2334
+ value: ((_M = (_L = layer.visualConfig) == null ? void 0 : _L.color) == null ? void 0 : _M.fieldName) ?? "",
2335
+ onChange: (val) => onUpdateVisualConfig(layer.id, {
2336
+ ...layer.visualConfig,
2337
+ color: { mode: "field", fieldName: val }
2338
+ }),
2339
+ className: "w-full text-sm",
2340
+ placeholder: "Select field...",
2341
+ showSearch: true,
2342
+ optionFilterProp: "label",
2343
+ options: getLayerFields(layer.id).map((f) => ({ value: f.name, label: f.name })),
2344
+ "data-testid": `select-color-field-${layer.id}`
2345
+ }
2346
+ ),
2347
+ ((_O = (_N = layer.visualConfig) == null ? void 0 : _N.color) == null ? void 0 : _O.fieldName) && getFieldValueDistribution && /* @__PURE__ */ jsx(
2348
+ ColorByFieldLegend,
2349
+ {
2350
+ layerId: layer.id,
2351
+ fieldName: layer.visualConfig.color.fieldName,
2352
+ getFieldValueDistribution
2353
+ }
2354
+ )
2355
+ ] }),
2356
+ ((_Q = (_P = layer.visualConfig) == null ? void 0 : _P.color) == null ? void 0 : _Q.mode) === "fixed" && /* @__PURE__ */ jsx(
2214
2357
  ColorPickerPopover,
2215
2358
  {
2216
- value: ((_Q = (_P = layer.visualConfig) == null ? void 0 : _P.color) == null ? void 0 : _Q.fixedColor) ?? "#3b82f6",
2359
+ value: ((_S = (_R = layer.visualConfig) == null ? void 0 : _R.color) == null ? void 0 : _S.fixedColor) ?? "#3b82f6",
2217
2360
  onChange: (color) => {
2218
2361
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
2219
2362
  ...layer.visualConfig,
@@ -2226,7 +2369,7 @@ function LayersPanel({
2226
2369
  testId: `color-fixed-${layer.id}`
2227
2370
  }
2228
2371
  ),
2229
- (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_R = layer.metadata) == null ? void 0 : _R.hidePointFeatures) && /* @__PURE__ */ jsxs(Fragment, { children: [
2372
+ (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_T = layer.metadata) == null ? void 0 : _T.hidePointFeatures) && /* @__PURE__ */ jsxs(Fragment, { children: [
2230
2373
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 text-sm text-muted-foreground pt-0.5", children: [
2231
2374
  /* @__PURE__ */ jsx(Smile, { className: "w-3.5 h-3.5" }),
2232
2375
  /* @__PURE__ */ jsx("span", { children: "Point Icon" })
@@ -2236,7 +2379,7 @@ function LayersPanel({
2236
2379
  Switch,
2237
2380
  {
2238
2381
  size: "small",
2239
- checked: ((_T = (_S = layer.visualConfig) == null ? void 0 : _S.icon) == null ? void 0 : _T.enabled) ?? false,
2382
+ checked: ((_V = (_U = layer.visualConfig) == null ? void 0 : _U.icon) == null ? void 0 : _V.enabled) ?? false,
2240
2383
  onChange: (checked) => {
2241
2384
  var _a2, _b2, _c2, _d2;
2242
2385
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
@@ -2251,11 +2394,11 @@ function LayersPanel({
2251
2394
  "data-testid": `switch-icon-${layer.id}`
2252
2395
  }
2253
2396
  ),
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: [
2397
+ ((_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
2398
  /* @__PURE__ */ jsx(
2256
2399
  IconPicker,
2257
2400
  {
2258
- value: ((_X = (_W = layer.visualConfig) == null ? void 0 : _W.icon) == null ? void 0 : _X.icon) ?? "📍",
2401
+ value: ((_Z = (_Y = layer.visualConfig) == null ? void 0 : _Y.icon) == null ? void 0 : _Z.icon) ?? "📍",
2259
2402
  onChange: (icon) => {
2260
2403
  var _a2, _b2;
2261
2404
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
@@ -2272,7 +2415,7 @@ function LayersPanel({
2272
2415
  /* @__PURE__ */ jsx(
2273
2416
  Slider,
2274
2417
  {
2275
- value: ((_Z = (_Y = layer.visualConfig) == null ? void 0 : _Y.icon) == null ? void 0 : _Z.size) ?? 24,
2418
+ value: ((_$ = (__ = layer.visualConfig) == null ? void 0 : __.icon) == null ? void 0 : _$.size) ?? 24,
2276
2419
  min: 12,
2277
2420
  max: 48,
2278
2421
  step: 2,
@@ -2290,7 +2433,7 @@ function LayersPanel({
2290
2433
  }
2291
2434
  }
2292
2435
  ),
2293
- /* @__PURE__ */ jsx("span", { className: "text-sm w-6 text-right", children: ((_$ = (__ = layer.visualConfig) == null ? void 0 : __.icon) == null ? void 0 : _$.size) ?? 24 })
2436
+ /* @__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
2437
  ] })
2295
2438
  ] })
2296
2439
  ] })
@@ -2758,7 +2901,7 @@ function RecordFieldsSection({ feature }) {
2758
2901
  );
2759
2902
  }
2760
2903
  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 }) {
2904
+ 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
2905
  var _a, _b, _c, _d, _e;
2763
2906
  const feature = selectedFeatures[0];
2764
2907
  const { toast } = useToast();
@@ -2833,6 +2976,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
2833
2976
  const [endDate, setEndDate] = useState("");
2834
2977
  const [customProperties, setCustomProperties] = useState([]);
2835
2978
  const [newPropertyKey, setNewPropertyKey] = useState("");
2979
+ const headerDotColor = feature && (getFeatureColor == null ? void 0 : getFeatureColor(feature.id)) || (feature == null ? void 0 : feature.properties.stroke) || "#3b82f6";
2836
2980
  const [strokeColor, setStrokeColor] = useState("#3b82f6");
2837
2981
  const [strokeWidth, setStrokeWidth] = useState(2);
2838
2982
  const [strokeOpacity, setStrokeOpacity] = useState(1);
@@ -3950,7 +4094,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3950
4094
  e.currentTarget.style.borderColor = "transparent";
3951
4095
  },
3952
4096
  "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 })
4097
+ children: pointIcon ? /* @__PURE__ */ jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsx(PointColorDot, { color: headerDotColor, size: 24 })
3954
4098
  }
3955
4099
  ) }),
3956
4100
  /* @__PURE__ */ jsx(
@@ -3967,7 +4111,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3967
4111
  }
3968
4112
  )
3969
4113
  ] }),
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 }) }),
4114
+ !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
4115
  !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
4116
  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
4117
  /* @__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" })
@@ -4080,7 +4224,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
4080
4224
  e.currentTarget.style.borderColor = "transparent";
4081
4225
  },
4082
4226
  "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 })
4227
+ children: pointIcon ? /* @__PURE__ */ jsx("span", { className: "text-xl leading-none", children: pointIcon }) : /* @__PURE__ */ jsx(PointColorDot, { color: headerDotColor, size: 24 })
4084
4228
  }
4085
4229
  ) }),
4086
4230
  /* @__PURE__ */ jsx(
@@ -4097,7 +4241,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
4097
4241
  }
4098
4242
  )
4099
4243
  ] }),
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 }) }),
4244
+ 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
4245
  (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
4246
  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
4247
  /* @__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 +4589,11 @@ function formatDateTime(date) {
4445
4589
  minute: "2-digit"
4446
4590
  });
4447
4591
  }
4448
- function Histogram({ bins, maxCount, selectedBins, colorGroupedBins }) {
4592
+ function Histogram({ bins, maxCount, colorGroupedBins }) {
4449
4593
  const [hoveredBin, setHoveredBin] = useState(null);
4450
4594
  const containerRef = useRef(null);
4451
4595
  if (bins.length === 0 || maxCount === 0) return null;
4452
4596
  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
4597
  return /* @__PURE__ */ jsxs("div", { className: "relative h-16", ref: containerRef, children: [
4455
4598
  /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-end gap-px", children: bins.map((bin, i) => {
4456
4599
  const height = bin.count / maxCount * 100;
@@ -4490,22 +4633,6 @@ function Histogram({ bins, maxCount, selectedBins, colorGroupedBins }) {
4490
4633
  groupIndex
4491
4634
  );
4492
4635
  }) }),
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
4636
  hoveredBin !== null && bins[hoveredBin] && /* @__PURE__ */ jsxs(
4510
4637
  "div",
4511
4638
  {
@@ -4521,12 +4648,7 @@ function Histogram({ bins, maxCount, selectedBins, colorGroupedBins }) {
4521
4648
  /* @__PURE__ */ jsxs("div", { className: "text-muted-foreground", children: [
4522
4649
  bins[hoveredBin].count,
4523
4650
  " 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
- ] })
4651
+ bins[hoveredBin].count !== 1 ? "s" : ""
4530
4652
  ] })
4531
4653
  ]
4532
4654
  }
@@ -4558,13 +4680,32 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4558
4680
  rangeStart,
4559
4681
  rangeEnd,
4560
4682
  isPlaying,
4561
- histogramBins,
4683
+ histogramBins: storeHistogramBins,
4562
4684
  setRange,
4563
4685
  setPlaying
4564
4686
  } = useTimelineStore();
4565
- const colorGroupedBins = histogramBins.length > 0 && selectedFeatureIds.length > 0 && selectedFeatureColors && selectedFeatureColors.size > 0 && globalMinDate && globalMaxDate ? (() => {
4687
+ const hasSelection = selectedFeatureIds.length > 0;
4688
+ const selectedTemporalFeatures = useMemo(() => {
4689
+ if (!hasSelection) return temporalFeatures;
4566
4690
  const selectedSet = new Set(selectedFeatureIds);
4567
- const selectedTemporalFeatures = temporalFeatures.filter((f) => selectedSet.has(f.id));
4691
+ return temporalFeatures.filter((f) => selectedSet.has(f.id));
4692
+ }, [hasSelection, selectedFeatureIds, temporalFeatures]);
4693
+ const histogramBins = useMemo(() => {
4694
+ if (!hasSelection || storeHistogramBins.length === 0) return storeHistogramBins;
4695
+ return storeHistogramBins.map((bin, binIndex) => {
4696
+ const isLastBin = binIndex === storeHistogramBins.length - 1;
4697
+ let count = 0;
4698
+ for (const f of selectedTemporalFeatures) {
4699
+ if (!f.startDate) continue;
4700
+ const t = f.startDate.getTime();
4701
+ if (t >= bin.start.getTime() && (isLastBin ? t <= bin.end.getTime() : t < bin.end.getTime())) {
4702
+ count++;
4703
+ }
4704
+ }
4705
+ return { ...bin, count };
4706
+ });
4707
+ }, [hasSelection, storeHistogramBins, selectedTemporalFeatures]);
4708
+ const colorGroupedBins = histogramBins.length > 0 && hasSelection && selectedFeatureColors && selectedFeatureColors.size > 0 && globalMinDate && globalMaxDate ? (() => {
4568
4709
  if (selectedTemporalFeatures.length === 0) return [];
4569
4710
  const colorGroups = /* @__PURE__ */ new Map();
4570
4711
  selectedTemporalFeatures.forEach((f) => {
@@ -4572,6 +4713,7 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4572
4713
  if (!colorGroups.has(color)) colorGroups.set(color, []);
4573
4714
  colorGroups.get(color).push(f);
4574
4715
  });
4716
+ if (colorGroups.size <= 1) return [];
4575
4717
  const result = [];
4576
4718
  colorGroups.forEach((features, color) => {
4577
4719
  const bins = histogramBins.map((bin, binIndex) => {
@@ -4588,21 +4730,6 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4588
4730
  });
4589
4731
  return result;
4590
4732
  })() : [];
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
4733
  const animationFrameRef = useRef(null);
4607
4734
  const lastFrameTimeRef = useRef(0);
4608
4735
  const playbackDuration = 1e4;
@@ -4703,7 +4830,6 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4703
4830
  {
4704
4831
  bins: histogramBins,
4705
4832
  maxCount: maxBinCount,
4706
- selectedBins,
4707
4833
  colorGroupedBins
4708
4834
  }
4709
4835
  ),
@@ -4753,11 +4879,14 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4753
4879
  className: "!h-7 !w-7 !p-0 !min-w-0"
4754
4880
  }
4755
4881
  ),
4756
- /* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground ml-1", children: [
4757
- temporalFeatures.length,
4758
- " feature",
4759
- temporalFeatures.length !== 1 ? "s" : ""
4760
- ] })
4882
+ /* @__PURE__ */ jsx(
4883
+ "span",
4884
+ {
4885
+ className: "text-xs text-muted-foreground ml-1",
4886
+ "data-testid": "text-timeline-feature-count",
4887
+ children: hasSelection ? `${selectedTemporalFeatures.length} of ${temporalFeatures.length} selected` : `${temporalFeatures.length} feature${temporalFeatures.length !== 1 ? "s" : ""}`
4888
+ }
4889
+ )
4761
4890
  ] }),
4762
4891
  timebarExtra,
4763
4892
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-xs text-muted-foreground font-mono", children: [
@@ -4851,6 +4980,12 @@ function MapDropZone({ onDrop, children }) {
4851
4980
  }
4852
4981
  );
4853
4982
  }
4983
+ const OTHER_BUCKET_KEY = "__other__";
4984
+ const OTHER_BUCKET_LABEL = "Other";
4985
+ const OTHER_BUCKET_COLOR = "#9ca3af";
4986
+ function toDisplayName(name) {
4987
+ return name === OTHER_BUCKET_KEY ? OTHER_BUCKET_LABEL : name;
4988
+ }
4854
4989
  function createPieSVG(categories, total, size = 44, onSliceHover) {
4855
4990
  const container = document.createElement("div");
4856
4991
  container.style.width = `${size}px`;
@@ -4869,8 +5004,41 @@ function createPieSVG(categories, total, size = 44, onSliceHover) {
4869
5004
  bgCircle.setAttribute("r", String(radius));
4870
5005
  bgCircle.setAttribute("fill", "white");
4871
5006
  svg.appendChild(bgCircle);
5007
+ const slicesSum = categories.reduce((s, c) => s + c.count, 0);
5008
+ const remainder = Math.max(0, total - slicesSum);
5009
+ const renderList = remainder > 0 ? [...categories, { name: "__remainder__", displayName: "Other", count: remainder, color: OTHER_BUCKET_COLOR }] : categories;
5010
+ const nonZeroSlices = renderList.filter((c) => c.count > 0);
5011
+ const isSingleFullSlice = nonZeroSlices.length === 1 && nonZeroSlices[0].count >= total;
5012
+ if (isSingleFullSlice) {
5013
+ const cat = nonZeroSlices[0];
5014
+ const ring = document.createElementNS("http://www.w3.org/2000/svg", "path");
5015
+ const d = [
5016
+ `M 0 ${radius}`,
5017
+ `a ${radius} ${radius} 0 1 0 ${radius * 2} 0`,
5018
+ `a ${radius} ${radius} 0 1 0 ${-radius * 2} 0`,
5019
+ `M ${radius - innerRadius} ${radius}`,
5020
+ `a ${innerRadius} ${innerRadius} 0 1 1 ${innerRadius * 2} 0`,
5021
+ `a ${innerRadius} ${innerRadius} 0 1 1 ${-innerRadius * 2} 0`,
5022
+ "Z"
5023
+ ].join(" ");
5024
+ ring.setAttribute("d", d);
5025
+ ring.setAttribute("fill-rule", "evenodd");
5026
+ ring.setAttribute("fill", cat.color);
5027
+ ring.setAttribute("stroke", "white");
5028
+ ring.setAttribute("stroke-width", "1");
5029
+ ring.style.transition = "opacity 0.15s";
5030
+ ring.addEventListener("mouseenter", (e) => {
5031
+ ring.style.opacity = "0.8";
5032
+ if (onSliceHover) onSliceHover(cat, e);
5033
+ });
5034
+ ring.addEventListener("mouseleave", (e) => {
5035
+ ring.style.opacity = "1";
5036
+ if (onSliceHover) onSliceHover(null, e);
5037
+ });
5038
+ svg.appendChild(ring);
5039
+ }
4872
5040
  let currentAngle = -90;
4873
- categories.forEach((cat) => {
5041
+ (isSingleFullSlice ? [] : renderList).forEach((cat) => {
4874
5042
  if (cat.count === 0) return;
4875
5043
  const sliceAngle = cat.count / total * 360;
4876
5044
  const startAngle = currentAngle;
@@ -4949,12 +5117,20 @@ function showTooltip(cat, x, y) {
4949
5117
  `;
4950
5118
  document.body.appendChild(tooltipEl);
4951
5119
  }
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
- `;
5120
+ while (tooltipEl.firstChild) tooltipEl.removeChild(tooltipEl.firstChild);
5121
+ const row = document.createElement("div");
5122
+ row.style.cssText = "display: flex; align-items: center; gap: 6px;";
5123
+ const swatch = document.createElement("span");
5124
+ swatch.style.cssText = "width: 10px; height: 10px; border-radius: 2px;";
5125
+ swatch.style.backgroundColor = cat.color;
5126
+ row.appendChild(swatch);
5127
+ const label = document.createElement("span");
5128
+ const name = document.createElement("strong");
5129
+ name.textContent = cat.displayName;
5130
+ label.appendChild(name);
5131
+ label.appendChild(document.createTextNode(`: ${cat.count}`));
5132
+ row.appendChild(label);
5133
+ tooltipEl.appendChild(row);
4958
5134
  tooltipEl.style.left = `${x + 12}px`;
4959
5135
  tooltipEl.style.top = `${y - 10}px`;
4960
5136
  tooltipEl.style.display = "block";
@@ -4964,67 +5140,114 @@ function hideTooltip() {
4964
5140
  tooltipEl.style.display = "none";
4965
5141
  }
4966
5142
  }
5143
+ function fingerprintCluster(pointCount, counts, size) {
5144
+ return `${size}|${pointCount}|${counts.join(",")}`;
5145
+ }
5146
+ function buildPieElement(categories, pointCount, size, source, clusterId, map, coords) {
5147
+ const el = createPieSVG(categories, pointCount, size, (cat, event) => {
5148
+ if (cat) {
5149
+ showTooltip(cat, event.clientX, event.clientY);
5150
+ } else {
5151
+ hideTooltip();
5152
+ }
5153
+ });
5154
+ el.addEventListener("click", () => {
5155
+ source.getClusterExpansionZoom(clusterId).then((zoom) => {
5156
+ if (typeof zoom === "number") {
5157
+ map.easeTo({ center: coords, zoom: zoom + 0.5 });
5158
+ }
5159
+ }).catch(() => {
5160
+ });
5161
+ });
5162
+ return el;
5163
+ }
5164
+ function renderClusterPies(map, sourceId, categoryValues, categoryColorMap, markers) {
5165
+ const source = map.getSource(sourceId);
5166
+ if (!source) return;
5167
+ const clusters = map.querySourceFeatures(sourceId, {
5168
+ filter: ["has", "point_count"]
5169
+ });
5170
+ const visibleClusterIds = /* @__PURE__ */ new Set();
5171
+ clusters.forEach((feature) => {
5172
+ var _a, _b;
5173
+ const clusterId = (_a = feature.properties) == null ? void 0 : _a.cluster_id;
5174
+ if (clusterId === void 0) return;
5175
+ const clusterKey = `${clusterId}`;
5176
+ visibleClusterIds.add(clusterKey);
5177
+ const coords = feature.geometry.coordinates;
5178
+ const pointCount = ((_b = feature.properties) == null ? void 0 : _b.point_count) || 0;
5179
+ const allCounts = categoryValues.map((_, i) => {
5180
+ var _a2;
5181
+ return Number(((_a2 = feature.properties) == null ? void 0 : _a2[`cat_${i}`]) || 0);
5182
+ });
5183
+ const categories = categoryValues.map((cat, i) => ({
5184
+ name: cat,
5185
+ displayName: toDisplayName(cat),
5186
+ count: allCounts[i],
5187
+ color: categoryColorMap[cat] || "#3b82f6"
5188
+ })).filter((c) => c.count > 0);
5189
+ const size = pointCount < 100 ? 40 : pointCount < 750 ? 50 : 60;
5190
+ const fingerprint = fingerprintCluster(pointCount, allCounts, size);
5191
+ const existing = markers.get(clusterKey);
5192
+ if (existing && existing.fingerprint === fingerprint) {
5193
+ existing.marker.setLngLat(coords);
5194
+ return;
5195
+ }
5196
+ const el = buildPieElement(categories, pointCount, size, source, clusterId, map, coords);
5197
+ if (existing) {
5198
+ existing.marker.remove();
5199
+ }
5200
+ const marker = new maplibregl.Marker({ element: el }).setLngLat(coords).addTo(map);
5201
+ markers.set(clusterKey, { marker, fingerprint });
5202
+ });
5203
+ markers.forEach((entry, key) => {
5204
+ if (!visibleClusterIds.has(key)) {
5205
+ entry.marker.remove();
5206
+ markers.delete(key);
5207
+ }
5208
+ });
5209
+ }
5210
+ function createClusterPieManager(map, sourceId, categoryValues, categoryColorMap) {
5211
+ const markers = /* @__PURE__ */ new Map();
5212
+ let updateScheduled = false;
5213
+ function scheduleUpdate() {
5214
+ if (updateScheduled) return;
5215
+ updateScheduled = true;
5216
+ requestAnimationFrame(() => {
5217
+ updateScheduled = false;
5218
+ renderClusterPies(map, sourceId, categoryValues, categoryColorMap, markers);
5219
+ });
5220
+ }
5221
+ function onData(e) {
5222
+ if (e.sourceId === sourceId) {
5223
+ scheduleUpdate();
5224
+ }
5225
+ }
5226
+ map.on("moveend", scheduleUpdate);
5227
+ map.on("data", onData);
5228
+ scheduleUpdate();
5229
+ return {
5230
+ update: scheduleUpdate,
5231
+ destroy: () => {
5232
+ map.off("moveend", scheduleUpdate);
5233
+ map.off("data", onData);
5234
+ markers.forEach((entry) => entry.marker.remove());
5235
+ markers.clear();
5236
+ hideTooltip();
5237
+ }
5238
+ };
5239
+ }
4967
5240
  function ClusterPieManager(props) {
4968
- const { map, sourceId, layerId, categoryValues, categoryColorMap, visible } = props;
5241
+ const { map, sourceId, categoryValues, categoryColorMap, visible } = props;
4969
5242
  const markersRef = useRef(/* @__PURE__ */ new Map());
4970
5243
  const updateScheduled = useRef(false);
4971
5244
  const updateMarkers = useCallback(() => {
4972
5245
  if (!map || !visible) {
4973
- markersRef.current.forEach((marker) => marker.remove());
5246
+ markersRef.current.forEach((entry) => entry.marker.remove());
4974
5247
  markersRef.current.clear();
4975
5248
  return;
4976
5249
  }
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
- });
5250
+ renderClusterPies(map, sourceId, categoryValues, categoryColorMap, markersRef.current);
5028
5251
  }, [map, sourceId, categoryValues, categoryColorMap, visible]);
5029
5252
  useEffect(() => {
5030
5253
  if (!map) return;
@@ -5036,23 +5259,25 @@ function ClusterPieManager(props) {
5036
5259
  updateMarkers();
5037
5260
  });
5038
5261
  };
5039
- scheduleUpdate();
5040
- map.on("moveend", scheduleUpdate);
5041
- map.on("data", (e) => {
5262
+ const onData = (e) => {
5042
5263
  if (e.sourceId === sourceId) {
5043
5264
  scheduleUpdate();
5044
5265
  }
5045
- });
5266
+ };
5267
+ scheduleUpdate();
5268
+ map.on("moveend", scheduleUpdate);
5269
+ map.on("data", onData);
5046
5270
  return () => {
5047
5271
  map.off("moveend", scheduleUpdate);
5048
- markersRef.current.forEach((marker) => marker.remove());
5272
+ map.off("data", onData);
5273
+ markersRef.current.forEach((entry) => entry.marker.remove());
5049
5274
  markersRef.current.clear();
5050
5275
  hideTooltip();
5051
5276
  };
5052
5277
  }, [map, sourceId, updateMarkers]);
5053
5278
  useEffect(() => {
5054
5279
  if (!visible) {
5055
- markersRef.current.forEach((marker) => marker.remove());
5280
+ markersRef.current.forEach((entry) => entry.marker.remove());
5056
5281
  markersRef.current.clear();
5057
5282
  hideTooltip();
5058
5283
  } else {
@@ -5061,89 +5286,6 @@ function ClusterPieManager(props) {
5061
5286
  }, [visible, updateMarkers]);
5062
5287
  return null;
5063
5288
  }
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
5289
  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
5290
  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
5291
  proj4.defs("EPSG:32630", "+proj=utm +zone=30 +datum=WGS84 +units=m +no_defs");
@@ -5808,56 +5950,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
5808
5950
  const timelineVisibleIdsRef = useRef(null);
5809
5951
  const syncRef = useRef(() => {
5810
5952
  });
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
- }, []);
5953
+ const hashStringToColor$1 = useCallback((str) => hashStringToColor(str), []);
5861
5954
  const selectedFeatureColors = useMemo(() => {
5862
5955
  if (selectedFeatureIds.length === 0) return /* @__PURE__ */ new Map();
5863
5956
  const colorMap = /* @__PURE__ */ new Map();
@@ -5915,16 +6008,16 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
5915
6008
  if (colorConfig.mode === "fixed" && colorConfig.fixedColor) {
5916
6009
  color = colorConfig.fixedColor;
5917
6010
  } 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));
6011
+ const key = categoricalKey(feature.properties[colorConfig.fieldName]);
6012
+ if (key !== null) {
6013
+ color = hashStringToColor$1(key);
5921
6014
  }
5922
6015
  }
5923
6016
  }
5924
6017
  colorMap.set(fid, color);
5925
6018
  });
5926
6019
  return colorMap;
5927
- }, [selectedFeatureIds, layers, getAllFeatures, hashStringToColor]);
6020
+ }, [selectedFeatureIds, layers, getAllFeatures, hashStringToColor$1]);
5928
6021
  const isSyncingRef = useRef(false);
5929
6022
  const syncFeaturesToCustomLayers = useCallback(() => {
5930
6023
  if (!map.current) return;
@@ -6056,9 +6149,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6056
6149
  if (colorConfig.mode === "fixed" && colorConfig.fixedColor) {
6057
6150
  strokeColor = colorConfig.fixedColor;
6058
6151
  } 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));
6152
+ const key = categoricalKey(f.properties[colorConfig.fieldName]);
6153
+ if (key !== null) {
6154
+ strokeColor = hashStringToColor$1(key);
6062
6155
  }
6063
6156
  }
6064
6157
  }
@@ -6148,7 +6241,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6148
6241
  id: featureId,
6149
6242
  name: labelText,
6150
6243
  isSelected: isFeatureSelected,
6151
- isHiddenByHeatmap: hideByHeatmap ? true : false,
6244
+ isHiddenByHeatmap: hideByHeatmap ? 1 : 0,
6152
6245
  isHiddenByCluster: hideByCluster ? 1 : 0,
6153
6246
  isHiddenByTrace: hideByTrace ? true : false,
6154
6247
  isTracePoint: isTracePoint ? true : false,
@@ -6385,7 +6478,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6385
6478
  } finally {
6386
6479
  isSyncingRef.current = false;
6387
6480
  }
6388
- }, [layers, hashStringToColor, autoLabelConfig]);
6481
+ }, [layers, hashStringToColor$1, autoLabelConfig]);
6389
6482
  const update3DFlightPaths = useCallback(() => {
6390
6483
  if (!map.current || !is3DTerrainEnabled) {
6391
6484
  if (map.current && flightPath3DLayerId.current) {
@@ -6653,6 +6746,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6653
6746
  0,
6654
6747
  ["==", ["get", "isHiddenByCluster"], 1],
6655
6748
  0,
6749
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6750
+ 0,
6656
6751
  ["!=", ["get", "icon"], ""],
6657
6752
  0,
6658
6753
  ["+", ["coalesce", ["get", "pointRadius"], 5], 1.5]
@@ -6662,6 +6757,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6662
6757
  "case",
6663
6758
  ["==", ["get", "isHiddenByCluster"], 1],
6664
6759
  0,
6760
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6761
+ 0,
6665
6762
  ["!=", ["get", "icon"], ""],
6666
6763
  0,
6667
6764
  ["coalesce", ["get", "stroke-opacity"], 1]
@@ -6682,6 +6779,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6682
6779
  0,
6683
6780
  ["==", ["get", "isHiddenByCluster"], 1],
6684
6781
  0,
6782
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6783
+ 0,
6685
6784
  ["!=", ["get", "icon"], ""],
6686
6785
  0,
6687
6786
  ["coalesce", ["get", "pointRadius"], 5]
@@ -6690,6 +6789,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6690
6789
  "case",
6691
6790
  ["==", ["get", "isHiddenByCluster"], 1],
6692
6791
  0,
6792
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6793
+ 0,
6693
6794
  ["!=", ["get", "icon"], ""],
6694
6795
  0,
6695
6796
  ["coalesce", ["get", "stroke-opacity"], 1]
@@ -6701,6 +6802,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6701
6802
  0,
6702
6803
  ["==", ["get", "isHiddenByCluster"], 1],
6703
6804
  0,
6805
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6806
+ 0,
6704
6807
  ["!=", ["get", "icon"], ""],
6705
6808
  0,
6706
6809
  ["==", ["get", "isSelected"], 1],
@@ -6711,6 +6814,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6711
6814
  "case",
6712
6815
  ["==", ["get", "isHiddenByCluster"], 1],
6713
6816
  0,
6817
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6818
+ 0,
6714
6819
  ["!=", ["get", "icon"], ""],
6715
6820
  0,
6716
6821
  1
@@ -6733,6 +6838,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6733
6838
  "case",
6734
6839
  ["==", ["get", "isHiddenByCluster"], 1],
6735
6840
  0,
6841
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6842
+ 0,
6736
6843
  ["coalesce", ["get", "stroke-opacity"], 1]
6737
6844
  ]
6738
6845
  }
@@ -6741,7 +6848,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6741
6848
  id: "custom-point-icon-selection",
6742
6849
  type: "circle",
6743
6850
  source: "custom-features",
6744
- filter: ["all", ["==", "$type", "Point"], ["!=", "icon", ""], ["==", "isSelected", 1]],
6851
+ filter: ["all", ["==", "$type", "Point"], ["!=", "icon", ""], ["==", "isSelected", 1], ["!=", "isHiddenByHeatmap", 1]],
6745
6852
  paint: {
6746
6853
  "circle-color": "transparent",
6747
6854
  "circle-radius": ["/", ["coalesce", ["get", "iconSize"], 24], 1.6],
@@ -6783,6 +6890,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6783
6890
  "case",
6784
6891
  ["==", ["get", "isHiddenByTrace"], true],
6785
6892
  "",
6893
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6894
+ "",
6895
+ ["==", ["get", "isHiddenByCluster"], 1],
6896
+ "",
6786
6897
  ["==", ["get", "kind"], "arrow"],
6787
6898
  "",
6788
6899
  // Arrows use custom-arrow-labels layer
@@ -7328,12 +7439,26 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7328
7439
  mapInstance.addLayer(newLayer, beforeLayer);
7329
7440
  addedLayerIds.push(prefixedLayerId);
7330
7441
  } catch (e) {
7442
+ console.warn(
7443
+ `[map-component] failed to add basemap layer ${prefixedLayerId}:`,
7444
+ (e == null ? void 0 : e.message) ?? e
7445
+ );
7331
7446
  }
7332
7447
  }
7333
7448
  }
7334
7449
  }
7335
7450
  basemapLayerIds.current.set(baseMapStyle, addedLayerIds);
7336
7451
  loadedBasemaps.current.add(baseMapStyle);
7452
+ const triggerResize = () => {
7453
+ try {
7454
+ mapInstance.resize();
7455
+ } catch {
7456
+ }
7457
+ };
7458
+ requestAnimationFrame(triggerResize);
7459
+ setTimeout(triggerResize, 200);
7460
+ setTimeout(triggerResize, 600);
7461
+ setTimeout(triggerResize, 1500);
7337
7462
  }).catch((err) => {
7338
7463
  console.error("Failed to load initial basemap:", err);
7339
7464
  });
@@ -7620,7 +7745,19 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7620
7745
  }, 0);
7621
7746
  });
7622
7747
  mapInstance.on("error", (e) => {
7623
- console.error("Map error:", e);
7748
+ var _a, _b;
7749
+ const err = e == null ? void 0 : e.error;
7750
+ const details = {
7751
+ message: err == null ? void 0 : err.message,
7752
+ name: err == null ? void 0 : err.name,
7753
+ stack: err == null ? void 0 : err.stack,
7754
+ status: err == null ? void 0 : err.status,
7755
+ url: err == null ? void 0 : err.url,
7756
+ sourceId: e == null ? void 0 : e.sourceId,
7757
+ 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
7758
+ };
7759
+ for (const k of Object.keys(details)) if (details[k] === void 0) delete details[k];
7760
+ console.error("Map error:", details, e);
7624
7761
  });
7625
7762
  } catch (error) {
7626
7763
  console.error("Failed to initialize map:", error);
@@ -7879,8 +8016,49 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7879
8016
  });
7880
8017
  },
7881
8018
  addFeatures: (layerId, features) => {
8019
+ var _a;
7882
8020
  const layer = layersRef.current.find((l) => l.id === layerId);
7883
- if (!layer || !draw.current || !isMapLoadedRef.current) return [];
8021
+ if (!layer || !isMapLoadedRef.current) return [];
8022
+ if (layer.readOnly) {
8023
+ const existing = readOnlyFeatures.current.get(layerId) || [];
8024
+ let layerHasTemporal = ((_a = layerTemporalCacheRef.current.get(layerId)) == null ? void 0 : _a.hasTemporal) ?? false;
8025
+ const newFeaturesWithIds = features.map((f) => {
8026
+ const id = f.id ? String(f.id) : crypto.randomUUID();
8027
+ const props = f.properties || {};
8028
+ if (!hasAnyTemporalValue(props)) {
8029
+ return { ...f, id };
8030
+ }
8031
+ const { startDate, endDate } = normalizeTemporalProperties(props);
8032
+ if (startDate || endDate) layerHasTemporal = true;
8033
+ return {
8034
+ ...f,
8035
+ id,
8036
+ properties: {
8037
+ ...props,
8038
+ startDate: (startDate == null ? void 0 : startDate.toISOString()) || null,
8039
+ endDate: (endDate == null ? void 0 : endDate.toISOString()) || null
8040
+ }
8041
+ };
8042
+ });
8043
+ const combined = [...existing, ...newFeaturesWithIds];
8044
+ readOnlyFeatures.current.set(layerId, combined);
8045
+ layerTemporalCacheRef.current.set(layerId, { featureCount: combined.length, hasTemporal: layerHasTemporal });
8046
+ const addedIds2 = newFeaturesWithIds.map((f) => String(f.id));
8047
+ const updatedLayers2 = layersRef.current.map(
8048
+ (l) => l.id === layerId ? { ...l, featureIds: [...l.featureIds, ...addedIds2] } : l
8049
+ );
8050
+ layersRef.current = updatedLayers2;
8051
+ setLayers(updatedLayers2);
8052
+ updateFeatureCount();
8053
+ if (layerHasTemporal) {
8054
+ scheduleTimelineUpdate();
8055
+ }
8056
+ requestAnimationFrame(() => {
8057
+ syncRef.current();
8058
+ });
8059
+ return addedIds2;
8060
+ }
8061
+ if (!draw.current) return [];
7884
8062
  const addedIds = [];
7885
8063
  isApiAddingRef.current = true;
7886
8064
  try {
@@ -9551,6 +9729,31 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9551
9729
  });
9552
9730
  return Array.from(fieldsMap.entries()).map(([name, isNumeric]) => ({ name, isNumeric })).sort((a, b) => a.name.localeCompare(b.name));
9553
9731
  }, [layers]);
9732
+ const getFieldValueDistribution = useCallback(
9733
+ (layerId, fieldName, maxValues = 50) => {
9734
+ var _a;
9735
+ const layer = layers.find((l) => l.id === layerId);
9736
+ if (!layer) return [];
9737
+ let features = [];
9738
+ if (layer.readOnly) {
9739
+ features = readOnlyFeatures.current.get(layerId) || [];
9740
+ } else if (layer.visible) {
9741
+ features = draw.current ? layer.featureIds.map((id) => draw.current.get(id)) : [];
9742
+ } else {
9743
+ features = hiddenFeatures.current.get(layerId) || [];
9744
+ }
9745
+ const MAX_SAMPLES = 1e4;
9746
+ const sample = features.slice(0, MAX_SAMPLES);
9747
+ const counts = /* @__PURE__ */ new Map();
9748
+ for (const f of sample) {
9749
+ const key = categoricalKey((_a = f == null ? void 0 : f.properties) == null ? void 0 : _a[fieldName]);
9750
+ if (key === null) continue;
9751
+ counts.set(key, (counts.get(key) ?? 0) + 1);
9752
+ }
9753
+ 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 }));
9754
+ },
9755
+ [layers]
9756
+ );
9554
9757
  const handleFitToLayerFeatures = useCallback((layerId) => {
9555
9758
  if (!map.current) return;
9556
9759
  const customBounds = fitBoundsProvider == null ? void 0 : fitBoundsProvider(layerId);
@@ -11387,45 +11590,38 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11387
11590
  }
11388
11591
  if (pointFeatures.length === 0) return;
11389
11592
  const groupByField = (_b = layer.clusterConfig) == null ? void 0 : _b.groupByField;
11390
- const categoryColors = [
11391
- "#3b82f6",
11392
- "#ef4444",
11393
- "#22c55e",
11394
- "#f59e0b",
11395
- "#8b5cf6",
11396
- "#ec4899",
11397
- "#06b6d4",
11398
- "#f97316",
11399
- "#84cc16",
11400
- "#6366f1",
11401
- "#14b8a6",
11402
- "#d946ef",
11403
- "#0ea5e9",
11404
- "#a855f7",
11405
- "#10b981"
11406
- ];
11593
+ const OTHER_COLOR = OTHER_BUCKET_COLOR;
11594
+ const MAX_CATEGORIES = 15;
11407
11595
  try {
11408
11596
  const layerColor = ((_d = (_c = layer.visualConfig) == null ? void 0 : _c.color) == null ? void 0 : _d.fixedColor) || "#3b82f6";
11409
11597
  let clusterProperties = {};
11410
11598
  let categoryValues = [];
11411
11599
  let categoryColorMap = {};
11600
+ let hasOtherBucket = false;
11412
11601
  if (groupByField) {
11413
- const uniqueCategories = /* @__PURE__ */ new Set();
11602
+ const counts = /* @__PURE__ */ new Map();
11414
11603
  pointFeatures.forEach((f) => {
11415
11604
  var _a2;
11416
- const val = (_a2 = f.properties) == null ? void 0 : _a2[groupByField];
11417
- if (val !== void 0 && val !== null) {
11418
- uniqueCategories.add(String(val));
11419
- }
11605
+ const key = categoricalKey((_a2 = f.properties) == null ? void 0 : _a2[groupByField]);
11606
+ if (key === null) return;
11607
+ counts.set(key, (counts.get(key) ?? 0) + 1);
11420
11608
  });
11421
- categoryValues = Array.from(uniqueCategories).slice(0, 15);
11422
- categoryValues.forEach((cat, i) => {
11423
- categoryColorMap[cat] = categoryColors[i % categoryColors.length];
11609
+ const sorted = Array.from(counts.entries()).sort((a, b) => b[1] - a[1]);
11610
+ const topKeys = sorted.slice(0, MAX_CATEGORIES).map(([k]) => k);
11611
+ categoryValues = [...topKeys];
11612
+ hasOtherBucket = true;
11613
+ const fieldAsString = ["to-string", ["coalesce", ["get", groupByField], ""]];
11614
+ topKeys.forEach((cat, i) => {
11615
+ categoryColorMap[cat] = hashStringToColor$1(cat);
11424
11616
  clusterProperties[`cat_${i}`] = [
11425
11617
  "+",
11426
- ["case", ["==", ["get", groupByField], cat], 1, 0]
11618
+ ["case", ["==", fieldAsString, cat], 1, 0]
11427
11619
  ];
11428
11620
  });
11621
+ categoryValues.push(OTHER_BUCKET_KEY);
11622
+ categoryColorMap[OTHER_BUCKET_KEY] = OTHER_COLOR;
11623
+ const otherExpr = topKeys.length === 0 ? 1 : ["match", fieldAsString, topKeys, 0, 1];
11624
+ clusterProperties[`cat_${categoryValues.length - 1}`] = ["+", otherExpr];
11429
11625
  }
11430
11626
  const mapStyleMaxZoom = typeof mapInstance.getMaxZoom === "function" ? mapInstance.getMaxZoom() : 24;
11431
11627
  const clusterMaxZoom = Math.min(24, Math.max(1, mapStyleMaxZoom - 1));
@@ -11499,11 +11695,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11499
11695
  }
11500
11696
  });
11501
11697
  }
11502
- const unclusteredColor = groupByField ? [
11698
+ const renderableTopKeys = categoryValues.filter((c) => c !== OTHER_BUCKET_KEY);
11699
+ const unclusteredColor = groupByField && renderableTopKeys.length > 0 ? [
11503
11700
  "match",
11504
- ["get", groupByField],
11505
- ...categoryValues.flatMap((cat) => [cat, categoryColorMap[cat] || layerColor]),
11506
- layerColor
11701
+ ["to-string", ["coalesce", ["get", groupByField], ""]],
11702
+ ...renderableTopKeys.flatMap((cat) => [cat, categoryColorMap[cat] || layerColor]),
11703
+ hasOtherBucket ? OTHER_COLOR : layerColor
11507
11704
  ] : layerColor;
11508
11705
  mapInstance.addLayer({
11509
11706
  id: unclusteredLayerId,
@@ -11559,7 +11756,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11559
11756
  } catch {
11560
11757
  }
11561
11758
  };
11562
- }, [isMapLoaded, layers, currentMapStyle]);
11759
+ }, [isMapLoaded, layers, currentMapStyle, hashStringToColor$1]);
11563
11760
  if (mapError) {
11564
11761
  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: [
11565
11762
  /* @__PURE__ */ jsx("div", { className: "p-4 border-b border-border", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
@@ -11942,6 +12139,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11942
12139
  onMapStyleChange: handleMapStyleChange,
11943
12140
  onUpdateTraceConfig: handleUpdateTraceConfig,
11944
12141
  getAvailableTraceFields,
12142
+ getFieldValueDistribution,
11945
12143
  onUpdateHeatmapConfig: handleUpdateHeatmapConfig,
11946
12144
  onUpdateClusterConfig: handleUpdateClusterConfig,
11947
12145
  hasPointFeatures,
@@ -12000,7 +12198,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12000
12198
  onMoveFeaturesToLayer: handleMoveFeaturesToLayer,
12001
12199
  onCopyFeaturesToLayer: handleCopyFeaturesToLayer,
12002
12200
  onCreateLayerAndMoveFeatures: handleCreateLayerAndMoveFeatures,
12003
- onCreateLayerAndCopyFeatures: handleCreateLayerAndCopyFeatures
12201
+ onCreateLayerAndCopyFeatures: handleCreateLayerAndCopyFeatures,
12202
+ getFeatureColor: (featureId) => selectedFeatureColors.get(featureId)
12004
12203
  }
12005
12204
  );
12006
12205
  })(),