@octostar/map-component 0.2.14 → 0.2.15

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
@@ -5,7 +5,7 @@ import MapboxDraw from "@mapbox/mapbox-gl-draw";
5
5
  import * as turf from "@turf/turf";
6
6
  import * as THREE from "three";
7
7
  import proj4 from "proj4";
8
- import { Button, Modal, Input, App, message, Tooltip, Dropdown, Divider, Popover, Switch, Slider, Tag, Select, Collapse, ColorPicker, Tabs, Card, Table, DatePicker } from "antd";
8
+ import { Button, Modal, Input, App, message, Tooltip, Dropdown, Divider, Popover, Switch, Slider, Tag, Select, Segmented, Collapse, ColorPicker, Tabs, Card, Table, DatePicker } from "antd";
9
9
  import { clsx } from "clsx";
10
10
  import { twMerge } from "tailwind-merge";
11
11
  import { MousePointer2, Square, Hexagon, Circle, MoreVertical, ChevronDown, Filter, X, Move, Ruler, Search, Scan, Pencil, Database, MapPin, Minus, Pentagon, Type, MoveRight, Undo2, Redo2, Trash2, Navigation, Loader2, Map as Map$1, Satellite, FolderOpen, Upload, Download, MoreHorizontal, Focus, Box, Layers, Plus, ChevronRight, Eye, EyeOff, Lock, Smile, Package, Copy, FolderInput, Save, Calendar, Palette, Blend, RefreshCw, ExternalLink, Info, SkipBack, Pause, Play, Clock, AlertTriangle, TestTube, Users, GripVertical, Plane, FileJson, Check, Phone, Car, AlertCircle } from "lucide-react";
@@ -2316,6 +2316,85 @@ function hashStringToColor(str) {
2316
2316
  const light = 45 + (hash >>> 16) % 18;
2317
2317
  return hslToHex(hue, sat, light);
2318
2318
  }
2319
+ const GRADIENT_RAMP = [
2320
+ "#fee5d9",
2321
+ "#fcae91",
2322
+ "#fb6a4a",
2323
+ "#de2d26",
2324
+ "#a50f15"
2325
+ ];
2326
+ const GRADIENT_FALLBACK_COLOR = "#9ca3af";
2327
+ const NUMERIC_FIELD_RATIO_THRESHOLD = 0.8;
2328
+ const NUMERIC_FIELD_COVERAGE_FLOOR = 0.3;
2329
+ function coerceFiniteNumber(raw) {
2330
+ if (typeof raw === "number") return Number.isFinite(raw) ? raw : null;
2331
+ if (typeof raw === "string" && raw.trim() !== "") {
2332
+ const n = Number(raw);
2333
+ return Number.isFinite(n) ? n : null;
2334
+ }
2335
+ return null;
2336
+ }
2337
+ function parseHexColor(hex) {
2338
+ return [
2339
+ parseInt(hex.slice(1, 3), 16),
2340
+ parseInt(hex.slice(3, 5), 16),
2341
+ parseInt(hex.slice(5, 7), 16)
2342
+ ];
2343
+ }
2344
+ function gradientColor(t, ramp = GRADIENT_RAMP) {
2345
+ const clamped = Math.max(0, Math.min(1, Number.isFinite(t) ? t : 0.5));
2346
+ const scaled = clamped * (ramp.length - 1);
2347
+ const i = Math.min(Math.floor(scaled), ramp.length - 2);
2348
+ const frac = scaled - i;
2349
+ const [r1, g1, b1] = parseHexColor(ramp[i]);
2350
+ const [r2, g2, b2] = parseHexColor(ramp[i + 1]);
2351
+ const channel = (a, b) => Math.round(a + (b - a) * frac).toString(16).padStart(2, "0");
2352
+ return `#${channel(r1, r2)}${channel(g1, g2)}${channel(b1, b2)}`;
2353
+ }
2354
+ function defaultColorScaleForField(field) {
2355
+ if (!field) return "categorical";
2356
+ return (field.numericRatio ?? 0) >= NUMERIC_FIELD_RATIO_THRESHOLD && (field.coverage ?? 0) >= NUMERIC_FIELD_COVERAGE_FLOOR ? "gradient" : "categorical";
2357
+ }
2358
+ function computeNumericRange(featureIds, getProperties, fieldName) {
2359
+ var _a;
2360
+ let min = Infinity;
2361
+ let max = -Infinity;
2362
+ for (const id of featureIds) {
2363
+ const v = coerceFiniteNumber((_a = getProperties(id)) == null ? void 0 : _a[fieldName]);
2364
+ if (v === null) continue;
2365
+ if (v < min) min = v;
2366
+ if (v > max) max = v;
2367
+ }
2368
+ return isFinite(min) ? { min, max } : null;
2369
+ }
2370
+ function resolveFeatureColor(colorConfig, properties, fallback, gradientRange) {
2371
+ if (!colorConfig) return fallback;
2372
+ if (colorConfig.mode === "fixed" && colorConfig.fixedColor) return colorConfig.fixedColor;
2373
+ if (colorConfig.mode === "field" && colorConfig.fieldName) {
2374
+ if (colorConfig.scale === "gradient") {
2375
+ const value = coerceFiniteNumber(properties == null ? void 0 : properties[colorConfig.fieldName]);
2376
+ if (value === null || !gradientRange) return GRADIENT_FALLBACK_COLOR;
2377
+ const t = gradientRange.max > gradientRange.min ? (value - gradientRange.min) / (gradientRange.max - gradientRange.min) : 0.5;
2378
+ return gradientColor(t);
2379
+ }
2380
+ if (properties) {
2381
+ const key = categoricalKey(properties[colorConfig.fieldName]);
2382
+ if (key !== null) return hashStringToColor(key);
2383
+ }
2384
+ }
2385
+ return fallback;
2386
+ }
2387
+ function formatGradientStop(value) {
2388
+ if (!Number.isFinite(value)) return "";
2389
+ const abs = Math.abs(value);
2390
+ if (abs >= 1e4) {
2391
+ return new Intl.NumberFormat("en-US", { notation: "compact", maximumFractionDigits: 1 }).format(value);
2392
+ }
2393
+ if (abs > 0 && abs < 1) {
2394
+ return new Intl.NumberFormat("en-US", { maximumSignificantDigits: 3 }).format(value);
2395
+ }
2396
+ return new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 }).format(value);
2397
+ }
2319
2398
  const MAP_STYLES = [
2320
2399
  { id: "streets", name: "Streets", icon: Map$1 },
2321
2400
  { id: "satellite", name: "Satellite", icon: Satellite },
@@ -2404,6 +2483,38 @@ function ColorByFieldLegend({
2404
2483
  }
2405
2484
  );
2406
2485
  }
2486
+ function ColorGradientLegend({
2487
+ layerId,
2488
+ min,
2489
+ max,
2490
+ sampled
2491
+ }) {
2492
+ const degenerate = min === max;
2493
+ return /* @__PURE__ */ jsxs(
2494
+ "div",
2495
+ {
2496
+ className: "mt-1 rounded border border-border/50 bg-background/40 p-1.5",
2497
+ "data-testid": `legend-gradient-${layerId}`,
2498
+ children: [
2499
+ /* @__PURE__ */ jsxs("div", { className: "text-[10px] uppercase tracking-wide text-muted-foreground mb-1", children: [
2500
+ "Legend",
2501
+ sampled ? " (sampled)" : ""
2502
+ ] }),
2503
+ /* @__PURE__ */ jsx(
2504
+ "div",
2505
+ {
2506
+ className: "h-2.5 rounded-sm border border-black/10",
2507
+ style: { background: degenerate ? gradientColor(0.5) : `linear-gradient(to right, ${GRADIENT_RAMP.join(", ")})` }
2508
+ }
2509
+ ),
2510
+ /* @__PURE__ */ jsx("div", { className: "flex justify-between text-[11px] text-muted-foreground tabular-nums mt-0.5", children: degenerate ? /* @__PURE__ */ jsx("span", { className: "mx-auto", children: formatGradientStop(min) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2511
+ /* @__PURE__ */ jsx("span", { children: formatGradientStop(min) }),
2512
+ /* @__PURE__ */ jsx("span", { children: formatGradientStop(max) })
2513
+ ] }) })
2514
+ ]
2515
+ }
2516
+ );
2517
+ }
2407
2518
  function LayersPanel({
2408
2519
  layers,
2409
2520
  onAddLayer,
@@ -2542,7 +2653,7 @@ function LayersPanel({
2542
2653
  });
2543
2654
  }, [onRemoveLayer]);
2544
2655
  const renderLayerItem = (layer) => {
2545
- 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;
2656
+ 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, _ca, _da;
2546
2657
  const customCount = featureCountProvider == null ? void 0 : featureCountProvider(layer.id);
2547
2658
  const featureCount = customCount != null ? customCount : getFeatureCount(layer.id);
2548
2659
  const isExpanded = expandedLayers.has(layer.id);
@@ -2655,6 +2766,41 @@ function LayersPanel({
2655
2766
  label: "Save GeoJSON to desktop",
2656
2767
  onClick: () => onSaveLayerGeoJSON(layer.id)
2657
2768
  },
2769
+ ...onUpdateVisualConfig ? [
2770
+ { type: "divider" },
2771
+ {
2772
+ key: "never-hide-labels",
2773
+ label: /* @__PURE__ */ jsxs("div", { className: "px-1.5 py-1", onClick: (e) => e.stopPropagation(), children: [
2774
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
2775
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
2776
+ /* @__PURE__ */ jsx(Type, { className: "w-[18px] h-[18px]" }),
2777
+ /* @__PURE__ */ jsx("span", { className: "text-sm", children: "Never hide labels" })
2778
+ ] }),
2779
+ /* @__PURE__ */ jsx(
2780
+ Switch,
2781
+ {
2782
+ size: "small",
2783
+ disabled: (_b = (_a = layer.visualConfig) == null ? void 0 : _a.label) == null ? void 0 : _b.hidden,
2784
+ checked: !!((_d = (_c = layer.visualConfig) == null ? void 0 : _c.label) == null ? void 0 : _d.neverHide),
2785
+ onChange: (checked) => {
2786
+ var _a2, _b2, _c2;
2787
+ return onUpdateVisualConfig(layer.id, {
2788
+ ...layer.visualConfig,
2789
+ label: {
2790
+ ...(_a2 = layer.visualConfig) == null ? void 0 : _a2.label,
2791
+ mode: ((_c2 = (_b2 = layer.visualConfig) == null ? void 0 : _b2.label) == null ? void 0 : _c2.mode) ?? "standard",
2792
+ neverHide: checked
2793
+ }
2794
+ });
2795
+ },
2796
+ "data-testid": `switch-never-hide-labels-${layer.id}`
2797
+ }
2798
+ )
2799
+ ] }),
2800
+ /* @__PURE__ */ jsx("div", { className: "text-xs text-muted-foreground mt-1", children: ((_f = (_e = layer.visualConfig) == null ? void 0 : _e.label) == null ? void 0 : _f.hidden) ? "Labels are turned off for this layer" : "Show every label even when the map is crowded" })
2801
+ ] })
2802
+ }
2803
+ ] : [],
2658
2804
  ...onFitToLayerFeatures && (typeof featureCount === "string" ? featureCount.length > 0 : featureCount > 0) ? [
2659
2805
  { type: "divider" },
2660
2806
  {
@@ -2707,14 +2853,14 @@ function LayersPanel({
2707
2853
  ]
2708
2854
  }
2709
2855
  ),
2710
- (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_a = layer.metadata) == null ? void 0 : _a.hidePointFeatures) && /* @__PURE__ */ jsxs("div", { className: "space-y-1 p-1.5 bg-muted/30 rounded-md", children: [
2856
+ (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_g = layer.metadata) == null ? void 0 : _g.hidePointFeatures) && /* @__PURE__ */ jsxs("div", { className: "space-y-1 p-1.5 bg-muted/30 rounded-md", children: [
2711
2857
  /* @__PURE__ */ jsx("div", { className: "flex items-center gap-1.5 text-xs font-medium", children: /* @__PURE__ */ jsx("span", { children: "Point Features" }) }),
2712
2858
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
2713
2859
  /* @__PURE__ */ jsx(
2714
2860
  Switch,
2715
2861
  {
2716
2862
  size: "small",
2717
- checked: ((_b = layer.traceConfig) == null ? void 0 : _b.enabled) ?? false,
2863
+ checked: ((_h = layer.traceConfig) == null ? void 0 : _h.enabled) ?? false,
2718
2864
  onChange: (checked) => {
2719
2865
  var _a2;
2720
2866
  return onUpdateTraceConfig(layer.id, {
@@ -2727,7 +2873,7 @@ function LayersPanel({
2727
2873
  ),
2728
2874
  /* @__PURE__ */ jsx("span", { className: "text-xs", children: "Trace Lines" })
2729
2875
  ] }),
2730
- ((_c = layer.traceConfig) == null ? void 0 : _c.enabled) && /* @__PURE__ */ jsx(
2876
+ ((_i = layer.traceConfig) == null ? void 0 : _i.enabled) && /* @__PURE__ */ jsx(
2731
2877
  Select,
2732
2878
  {
2733
2879
  size: "small",
@@ -2753,7 +2899,7 @@ function LayersPanel({
2753
2899
  Switch,
2754
2900
  {
2755
2901
  size: "small",
2756
- checked: ((_d = layer.heatmapConfig) == null ? void 0 : _d.enabled) ?? false,
2902
+ checked: ((_j = layer.heatmapConfig) == null ? void 0 : _j.enabled) ?? false,
2757
2903
  onChange: (checked) => {
2758
2904
  var _a2, _b2;
2759
2905
  return onUpdateHeatmapConfig(layer.id, {
@@ -2767,7 +2913,7 @@ function LayersPanel({
2767
2913
  ),
2768
2914
  /* @__PURE__ */ jsx("span", { className: "text-xs", children: "Heatmap" })
2769
2915
  ] }),
2770
- ((_e = layer.heatmapConfig) == null ? void 0 : _e.enabled) && /* @__PURE__ */ jsxs("div", { className: "space-y-1 pl-4", children: [
2916
+ ((_k = layer.heatmapConfig) == null ? void 0 : _k.enabled) && /* @__PURE__ */ jsxs("div", { className: "space-y-1 pl-4", children: [
2771
2917
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
2772
2918
  /* @__PURE__ */ jsx("span", { className: "text-[10px] w-12", children: "Intensity" }),
2773
2919
  /* @__PURE__ */ jsx(
@@ -2811,10 +2957,11 @@ function LayersPanel({
2811
2957
  Switch,
2812
2958
  {
2813
2959
  size: "small",
2814
- checked: ((_f = layer.clusterConfig) == null ? void 0 : _f.enabled) ?? false,
2960
+ checked: ((_l = layer.clusterConfig) == null ? void 0 : _l.enabled) ?? false,
2815
2961
  onChange: (checked) => {
2816
2962
  var _a2, _b2;
2817
2963
  return onUpdateClusterConfig(layer.id, {
2964
+ ...layer.clusterConfig,
2818
2965
  enabled: checked,
2819
2966
  groupByField: ((_a2 = layer.clusterConfig) == null ? void 0 : _a2.groupByField) ?? null,
2820
2967
  showPointDots: ((_b2 = layer.clusterConfig) == null ? void 0 : _b2.showPointDots) ?? false
@@ -2825,7 +2972,7 @@ function LayersPanel({
2825
2972
  ),
2826
2973
  /* @__PURE__ */ jsx("span", { className: "text-xs", children: "Clustering" })
2827
2974
  ] }),
2828
- ((_g = layer.clusterConfig) == null ? void 0 : _g.enabled) && getLayerFields && /* @__PURE__ */ jsxs("div", { className: "space-y-1 pl-4", children: [
2975
+ ((_m = layer.clusterConfig) == null ? void 0 : _m.enabled) && getLayerFields && /* @__PURE__ */ jsxs("div", { className: "space-y-1 pl-4", children: [
2829
2976
  /* @__PURE__ */ jsx(
2830
2977
  Select,
2831
2978
  {
@@ -2858,6 +3005,53 @@ function LayersPanel({
2858
3005
  }
2859
3006
  ),
2860
3007
  /* @__PURE__ */ jsx("span", { className: "text-[10px]", children: "Show point dots" })
3008
+ ] }),
3009
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
3010
+ /* @__PURE__ */ jsx(
3011
+ Switch,
3012
+ {
3013
+ size: "small",
3014
+ checked: layer.clusterConfig.countByFieldEnabled ?? false,
3015
+ onChange: (checked) => onUpdateClusterConfig(layer.id, {
3016
+ ...layer.clusterConfig,
3017
+ countByFieldEnabled: checked
3018
+ }),
3019
+ "data-testid": `switch-cluster-count-by-${layer.id}`
3020
+ }
3021
+ ),
3022
+ /* @__PURE__ */ jsx("span", { className: "text-[10px]", children: "Count by field" })
3023
+ ] }),
3024
+ layer.clusterConfig.countByFieldEnabled && /* @__PURE__ */ jsx(
3025
+ Select,
3026
+ {
3027
+ size: "small",
3028
+ value: layer.clusterConfig.countByField ?? void 0,
3029
+ onChange: (val) => onUpdateClusterConfig(layer.id, {
3030
+ ...layer.clusterConfig,
3031
+ countByField: val
3032
+ }),
3033
+ className: "w-full text-xs",
3034
+ placeholder: "Select numeric field...",
3035
+ showSearch: true,
3036
+ optionFilterProp: "label",
3037
+ options: getLayerFields(layer.id).filter((f) => f.isNumeric).map((f) => ({ value: f.name, label: f.name })),
3038
+ "data-testid": `select-cluster-count-field-${layer.id}`
3039
+ }
3040
+ ),
3041
+ !layer.clusterConfig.groupByField && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
3042
+ /* @__PURE__ */ jsx(
3043
+ Switch,
3044
+ {
3045
+ size: "small",
3046
+ checked: layer.clusterConfig.bubbleGradient ?? false,
3047
+ onChange: (checked) => onUpdateClusterConfig(layer.id, {
3048
+ ...layer.clusterConfig,
3049
+ bubbleGradient: checked
3050
+ }),
3051
+ "data-testid": `switch-cluster-gradient-${layer.id}`
3052
+ }
3053
+ ),
3054
+ /* @__PURE__ */ jsx("span", { className: "text-[10px]", children: "Color bubbles by value" })
2861
3055
  ] })
2862
3056
  ] })
2863
3057
  ] })
@@ -2894,7 +3088,7 @@ function LayersPanel({
2894
3088
  Switch,
2895
3089
  {
2896
3090
  size: "small",
2897
- checked: !((_i = (_h = layer.visualConfig) == null ? void 0 : _h.label) == null ? void 0 : _i.hidden),
3091
+ checked: !((_o = (_n = layer.visualConfig) == null ? void 0 : _n.label) == null ? void 0 : _o.hidden),
2898
3092
  onChange: (checked) => {
2899
3093
  var _a2, _b2, _c2;
2900
3094
  return onUpdateVisualConfig(layer.id, {
@@ -2910,8 +3104,8 @@ function LayersPanel({
2910
3104
  Select,
2911
3105
  {
2912
3106
  size: "small",
2913
- disabled: (_k = (_j = layer.visualConfig) == null ? void 0 : _j.label) == null ? void 0 : _k.hidden,
2914
- value: ((_m = (_l = layer.visualConfig) == null ? void 0 : _l.label) == null ? void 0 : _m.mode) ?? "standard",
3107
+ disabled: (_q = (_p = layer.visualConfig) == null ? void 0 : _p.label) == null ? void 0 : _q.hidden,
3108
+ value: ((_s = (_r = layer.visualConfig) == null ? void 0 : _r.label) == null ? void 0 : _s.mode) ?? "standard",
2915
3109
  onChange: (val) => {
2916
3110
  var _a2;
2917
3111
  return onUpdateVisualConfig(layer.id, {
@@ -2928,15 +3122,18 @@ function LayersPanel({
2928
3122
  "data-testid": `select-label-mode-${layer.id}`
2929
3123
  }
2930
3124
  ),
2931
- ((_o = (_n = layer.visualConfig) == null ? void 0 : _n.label) == null ? void 0 : _o.mode) === "field" && /* @__PURE__ */ jsx(
3125
+ ((_u = (_t = layer.visualConfig) == null ? void 0 : _t.label) == null ? void 0 : _u.mode) === "field" && /* @__PURE__ */ jsx(
2932
3126
  Select,
2933
3127
  {
2934
3128
  size: "small",
2935
- value: ((_q = (_p = layer.visualConfig) == null ? void 0 : _p.label) == null ? void 0 : _q.fieldName) ?? "",
2936
- onChange: (val) => onUpdateVisualConfig(layer.id, {
2937
- ...layer.visualConfig,
2938
- label: { mode: "field", fieldName: val }
2939
- }),
3129
+ value: ((_w = (_v = layer.visualConfig) == null ? void 0 : _v.label) == null ? void 0 : _w.fieldName) ?? "",
3130
+ onChange: (val) => {
3131
+ var _a2;
3132
+ return onUpdateVisualConfig(layer.id, {
3133
+ ...layer.visualConfig,
3134
+ label: { ...(_a2 = layer.visualConfig) == null ? void 0 : _a2.label, mode: "field", fieldName: val }
3135
+ });
3136
+ },
2940
3137
  className: "w-full text-sm",
2941
3138
  placeholder: "Select field...",
2942
3139
  showSearch: true,
@@ -2945,15 +3142,18 @@ function LayersPanel({
2945
3142
  "data-testid": `select-label-field-${layer.id}`
2946
3143
  }
2947
3144
  ),
2948
- ((_s = (_r = layer.visualConfig) == null ? void 0 : _r.label) == null ? void 0 : _s.mode) === "fixed" && /* @__PURE__ */ jsx(
3145
+ ((_y = (_x = layer.visualConfig) == null ? void 0 : _x.label) == null ? void 0 : _y.mode) === "fixed" && /* @__PURE__ */ jsx(
2949
3146
  Input,
2950
3147
  {
2951
3148
  size: "small",
2952
- value: ((_u = (_t = layer.visualConfig) == null ? void 0 : _t.label) == null ? void 0 : _u.fixedText) ?? "",
2953
- onChange: (e) => onUpdateVisualConfig(layer.id, {
2954
- ...layer.visualConfig,
2955
- label: { mode: "fixed", fixedText: e.target.value }
2956
- }),
3149
+ value: ((_A = (_z = layer.visualConfig) == null ? void 0 : _z.label) == null ? void 0 : _A.fixedText) ?? "",
3150
+ onChange: (e) => {
3151
+ var _a2;
3152
+ return onUpdateVisualConfig(layer.id, {
3153
+ ...layer.visualConfig,
3154
+ label: { ...(_a2 = layer.visualConfig) == null ? void 0 : _a2.label, mode: "fixed", fixedText: e.target.value }
3155
+ });
3156
+ },
2957
3157
  placeholder: "Enter label text...",
2958
3158
  className: "text-sm",
2959
3159
  "data-testid": `input-label-text-${layer.id}`
@@ -2967,7 +3167,7 @@ function LayersPanel({
2967
3167
  Select,
2968
3168
  {
2969
3169
  size: "small",
2970
- value: ((_w = (_v = layer.visualConfig) == null ? void 0 : _v.size) == null ? void 0 : _w.mode) ?? "standard",
3170
+ value: ((_C = (_B = layer.visualConfig) == null ? void 0 : _B.size) == null ? void 0 : _C.mode) ?? "standard",
2971
3171
  onChange: (val) => onUpdateVisualConfig(layer.id, {
2972
3172
  ...layer.visualConfig,
2973
3173
  size: { mode: val }
@@ -2981,11 +3181,11 @@ function LayersPanel({
2981
3181
  "data-testid": `select-size-mode-${layer.id}`
2982
3182
  }
2983
3183
  ),
2984
- ((_y = (_x = layer.visualConfig) == null ? void 0 : _x.size) == null ? void 0 : _y.mode) === "field" && /* @__PURE__ */ jsx(
3184
+ ((_E = (_D = layer.visualConfig) == null ? void 0 : _D.size) == null ? void 0 : _E.mode) === "field" && /* @__PURE__ */ jsx(
2985
3185
  Select,
2986
3186
  {
2987
3187
  size: "small",
2988
- value: ((_A = (_z = layer.visualConfig) == null ? void 0 : _z.size) == null ? void 0 : _A.fieldName) ?? "",
3188
+ value: ((_G = (_F = layer.visualConfig) == null ? void 0 : _F.size) == null ? void 0 : _G.fieldName) ?? "",
2989
3189
  onChange: (val) => onUpdateVisualConfig(layer.id, {
2990
3190
  ...layer.visualConfig,
2991
3191
  size: { mode: "field", fieldName: val }
@@ -2998,11 +3198,11 @@ function LayersPanel({
2998
3198
  "data-testid": `select-size-field-${layer.id}`
2999
3199
  }
3000
3200
  ),
3001
- ((_C = (_B = layer.visualConfig) == null ? void 0 : _B.size) == null ? void 0 : _C.mode) === "override" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
3201
+ ((_I = (_H = layer.visualConfig) == null ? void 0 : _H.size) == null ? void 0 : _I.mode) === "override" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
3002
3202
  /* @__PURE__ */ jsx(
3003
3203
  Slider,
3004
3204
  {
3005
- value: ((_E = (_D = layer.visualConfig) == null ? void 0 : _D.size) == null ? void 0 : _E.overrideValue) ?? 5,
3205
+ value: ((_K = (_J = layer.visualConfig) == null ? void 0 : _J.size) == null ? void 0 : _K.overrideValue) ?? 5,
3006
3206
  min: 1,
3007
3207
  max: 10,
3008
3208
  step: 1,
@@ -3013,7 +3213,7 @@ function LayersPanel({
3013
3213
  })
3014
3214
  }
3015
3215
  ),
3016
- /* @__PURE__ */ jsx("span", { className: "text-sm w-4 text-right", children: ((_G = (_F = layer.visualConfig) == null ? void 0 : _F.size) == null ? void 0 : _G.overrideValue) ?? 5 })
3216
+ /* @__PURE__ */ jsx("span", { className: "text-sm w-4 text-right", children: ((_M = (_L = layer.visualConfig) == null ? void 0 : _L.size) == null ? void 0 : _M.overrideValue) ?? 5 })
3017
3217
  ] }),
3018
3218
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 text-sm text-muted-foreground pt-0.5", children: [
3019
3219
  /* @__PURE__ */ jsx("span", { className: "w-3.5 h-3.5 rounded-full bg-current" }),
@@ -3023,7 +3223,7 @@ function LayersPanel({
3023
3223
  Select,
3024
3224
  {
3025
3225
  size: "small",
3026
- value: ((_I = (_H = layer.visualConfig) == null ? void 0 : _H.color) == null ? void 0 : _I.mode) ?? "standard",
3226
+ value: ((_O = (_N = layer.visualConfig) == null ? void 0 : _N.color) == null ? void 0 : _O.mode) ?? "standard",
3027
3227
  onChange: (val) => onUpdateVisualConfig(layer.id, {
3028
3228
  ...layer.visualConfig,
3029
3229
  color: { mode: val }
@@ -3037,37 +3237,77 @@ function LayersPanel({
3037
3237
  "data-testid": `select-color-mode-${layer.id}`
3038
3238
  }
3039
3239
  ),
3040
- ((_K = (_J = layer.visualConfig) == null ? void 0 : _J.color) == null ? void 0 : _K.mode) === "field" && /* @__PURE__ */ jsxs(Fragment, { children: [
3041
- /* @__PURE__ */ jsx(
3042
- Select,
3043
- {
3044
- size: "small",
3045
- value: ((_M = (_L = layer.visualConfig) == null ? void 0 : _L.color) == null ? void 0 : _M.fieldName) ?? "",
3046
- onChange: (val) => onUpdateVisualConfig(layer.id, {
3047
- ...layer.visualConfig,
3048
- color: { mode: "field", fieldName: val }
3049
- }),
3050
- className: "w-full text-sm",
3051
- placeholder: "Select field...",
3052
- showSearch: true,
3053
- optionFilterProp: "label",
3054
- options: getLayerFields(layer.id).map((f) => ({ value: f.name, label: f.name })),
3055
- "data-testid": `select-color-field-${layer.id}`
3056
- }
3057
- ),
3058
- ((_O = (_N = layer.visualConfig) == null ? void 0 : _N.color) == null ? void 0 : _O.fieldName) && getFieldValueDistribution && /* @__PURE__ */ jsx(
3059
- ColorByFieldLegend,
3060
- {
3061
- layerId: layer.id,
3062
- fieldName: layer.visualConfig.color.fieldName,
3063
- getFieldValueDistribution
3064
- }
3065
- )
3066
- ] }),
3067
- ((_Q = (_P = layer.visualConfig) == null ? void 0 : _P.color) == null ? void 0 : _Q.mode) === "fixed" && /* @__PURE__ */ jsx(
3240
+ ((_Q = (_P = layer.visualConfig) == null ? void 0 : _P.color) == null ? void 0 : _Q.mode) === "field" && (() => {
3241
+ var _a2, _b2, _c2, _d2;
3242
+ const fields = getLayerFields(layer.id);
3243
+ const colorField = (_b2 = (_a2 = layer.visualConfig) == null ? void 0 : _a2.color) == null ? void 0 : _b2.fieldName;
3244
+ const fieldStats = colorField ? fields.find((f) => f.name === colorField) : void 0;
3245
+ const fieldHasNumeric = (fieldStats == null ? void 0 : fieldStats.min) !== void 0;
3246
+ const scale = ((_d2 = (_c2 = layer.visualConfig) == null ? void 0 : _c2.color) == null ? void 0 : _d2.scale) ?? "categorical";
3247
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
3248
+ /* @__PURE__ */ jsx(
3249
+ Select,
3250
+ {
3251
+ size: "small",
3252
+ value: colorField ?? "",
3253
+ onChange: (val) => onUpdateVisualConfig(layer.id, {
3254
+ ...layer.visualConfig,
3255
+ // The scale default is decided once, at pick time, and
3256
+ // stored — never re-inferred at render, so data drifting
3257
+ // later can't silently flip a user's choice.
3258
+ color: { mode: "field", fieldName: val, scale: defaultColorScaleForField(fields.find((f) => f.name === val)) }
3259
+ }),
3260
+ className: "w-full text-sm",
3261
+ placeholder: "Select field...",
3262
+ showSearch: true,
3263
+ optionFilterProp: "label",
3264
+ options: fields.map((f) => ({ value: f.name, label: f.name })),
3265
+ "data-testid": `select-color-field-${layer.id}`
3266
+ }
3267
+ ),
3268
+ colorField && /* @__PURE__ */ jsx(
3269
+ Segmented,
3270
+ {
3271
+ size: "small",
3272
+ block: true,
3273
+ value: scale,
3274
+ onChange: (val) => {
3275
+ var _a3;
3276
+ return onUpdateVisualConfig(layer.id, {
3277
+ ...layer.visualConfig,
3278
+ color: { ...(_a3 = layer.visualConfig) == null ? void 0 : _a3.color, mode: "field", scale: val }
3279
+ });
3280
+ },
3281
+ options: [
3282
+ { label: "Categories", value: "categorical" },
3283
+ { label: "Gradient", value: "gradient", disabled: !fieldHasNumeric && scale !== "gradient" }
3284
+ ],
3285
+ "data-testid": `segmented-color-scale-${layer.id}`
3286
+ }
3287
+ ),
3288
+ colorField && scale === "gradient" && fieldStats && fieldStats.min !== void 0 && fieldStats.max !== void 0 && /* @__PURE__ */ jsx(
3289
+ ColorGradientLegend,
3290
+ {
3291
+ layerId: layer.id,
3292
+ min: fieldStats.min,
3293
+ max: fieldStats.max,
3294
+ sampled: fieldStats.sampled
3295
+ }
3296
+ ),
3297
+ colorField && scale !== "gradient" && getFieldValueDistribution && /* @__PURE__ */ jsx(
3298
+ ColorByFieldLegend,
3299
+ {
3300
+ layerId: layer.id,
3301
+ fieldName: colorField,
3302
+ getFieldValueDistribution
3303
+ }
3304
+ )
3305
+ ] });
3306
+ })(),
3307
+ ((_S = (_R = layer.visualConfig) == null ? void 0 : _R.color) == null ? void 0 : _S.mode) === "fixed" && /* @__PURE__ */ jsx(
3068
3308
  ColorPickerPopover,
3069
3309
  {
3070
- value: ((_S = (_R = layer.visualConfig) == null ? void 0 : _R.color) == null ? void 0 : _S.fixedColor) ?? "#3b82f6",
3310
+ value: ((_U = (_T = layer.visualConfig) == null ? void 0 : _T.color) == null ? void 0 : _U.fixedColor) ?? "#3b82f6",
3071
3311
  onChange: (color) => {
3072
3312
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
3073
3313
  ...layer.visualConfig,
@@ -3080,7 +3320,7 @@ function LayersPanel({
3080
3320
  testId: `color-fixed-${layer.id}`
3081
3321
  }
3082
3322
  ),
3083
- (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_T = layer.metadata) == null ? void 0 : _T.hidePointFeatures) && /* @__PURE__ */ jsxs(Fragment, { children: [
3323
+ (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_V = layer.metadata) == null ? void 0 : _V.hidePointFeatures) && /* @__PURE__ */ jsxs(Fragment, { children: [
3084
3324
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 text-sm text-muted-foreground pt-0.5", children: [
3085
3325
  /* @__PURE__ */ jsx(Smile, { className: "w-3.5 h-3.5" }),
3086
3326
  /* @__PURE__ */ jsx("span", { children: "Point Icon" })
@@ -3090,7 +3330,7 @@ function LayersPanel({
3090
3330
  Switch,
3091
3331
  {
3092
3332
  size: "small",
3093
- checked: ((_V = (_U = layer.visualConfig) == null ? void 0 : _U.icon) == null ? void 0 : _V.enabled) ?? false,
3333
+ checked: ((_X = (_W = layer.visualConfig) == null ? void 0 : _W.icon) == null ? void 0 : _X.enabled) ?? false,
3094
3334
  onChange: (checked) => {
3095
3335
  var _a2, _b2, _c2, _d2;
3096
3336
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
@@ -3105,11 +3345,11 @@ function LayersPanel({
3105
3345
  "data-testid": `switch-icon-${layer.id}`
3106
3346
  }
3107
3347
  ),
3108
- ((_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: [
3348
+ ((_Z = (_Y = layer.visualConfig) == null ? void 0 : _Y.icon) == null ? void 0 : _Z.enabled) && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 flex-1", children: [
3109
3349
  /* @__PURE__ */ jsx(
3110
3350
  IconPicker,
3111
3351
  {
3112
- value: ((_Z = (_Y = layer.visualConfig) == null ? void 0 : _Y.icon) == null ? void 0 : _Z.icon) ?? "📍",
3352
+ value: ((_$ = (__ = layer.visualConfig) == null ? void 0 : __.icon) == null ? void 0 : _$.icon) ?? "📍",
3113
3353
  onChange: (icon) => {
3114
3354
  var _a2, _b2;
3115
3355
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
@@ -3126,7 +3366,7 @@ function LayersPanel({
3126
3366
  /* @__PURE__ */ jsx(
3127
3367
  Slider,
3128
3368
  {
3129
- value: ((_$ = (__ = layer.visualConfig) == null ? void 0 : __.icon) == null ? void 0 : _$.size) ?? 24,
3369
+ value: ((_ba = (_aa = layer.visualConfig) == null ? void 0 : _aa.icon) == null ? void 0 : _ba.size) ?? 24,
3130
3370
  min: 12,
3131
3371
  max: 48,
3132
3372
  step: 2,
@@ -3144,7 +3384,7 @@ function LayersPanel({
3144
3384
  }
3145
3385
  }
3146
3386
  ),
3147
- /* @__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 })
3387
+ /* @__PURE__ */ jsx("span", { className: "text-sm w-6 text-right", children: ((_da = (_ca = layer.visualConfig) == null ? void 0 : _ca.icon) == null ? void 0 : _da.size) ?? 24 })
3148
3388
  ] })
3149
3389
  ] })
3150
3390
  ] })
@@ -6477,13 +6717,282 @@ function hitTestSelection(featureGroups, selectionPolygon, options) {
6477
6717
  mapPerfLog("hit-test", "selection gesture", { visited, total, selected: selectedIds.length });
6478
6718
  return selectedIds;
6479
6719
  }
6720
+ const CLUSTER_COUNT_VALUE_PROP = "__cluster_count_value";
6721
+ const CLUSTER_SUM_PROP = "value_sum";
6722
+ const CLUSTER_MEMBER_ID_PROP = "__cluster_fid";
6723
+ function clusterCountValue(raw) {
6724
+ if (typeof raw === "number") return Number.isFinite(raw) ? raw : 1;
6725
+ if (typeof raw === "string" && raw.trim() !== "") {
6726
+ const n = Number(raw);
6727
+ if (Number.isFinite(n)) return n;
6728
+ }
6729
+ return 1;
6730
+ }
6731
+ function injectClusterCountValues(features, fieldName) {
6732
+ return features.map((f) => {
6733
+ var _a;
6734
+ return {
6735
+ ...f,
6736
+ properties: {
6737
+ ...f.properties,
6738
+ [CLUSTER_COUNT_VALUE_PROP]: clusterCountValue((_a = f.properties) == null ? void 0 : _a[fieldName]),
6739
+ ...f.id != null ? { [CLUSTER_MEMBER_ID_PROP]: String(f.id) } : {}
6740
+ }
6741
+ };
6742
+ });
6743
+ }
6744
+ function roundHalfAwayFromZero1(n) {
6745
+ return Math.sign(n) * Math.round(Math.abs(n) * 10) / 10;
6746
+ }
6747
+ function formatClusterBadge(value) {
6748
+ if (value >= 1e6) return `${roundHalfAwayFromZero1(value / 1e6)}M`;
6749
+ if (value >= 1e3) return `${roundHalfAwayFromZero1(value / 1e3)}k`;
6750
+ return String(roundHalfAwayFromZero1(value));
6751
+ }
6752
+ function clusterBadgeTextField(prop) {
6753
+ const value = ["get", prop];
6754
+ const round1 = (expr) => ["/", ["round", ["*", expr, 10]], 10];
6755
+ return [
6756
+ "step",
6757
+ value,
6758
+ ["to-string", round1(value)],
6759
+ 1e3,
6760
+ ["concat", ["to-string", round1(["/", value, 1e3])], "k"],
6761
+ 1e6,
6762
+ ["concat", ["to-string", round1(["/", value, 1e6])], "M"]
6763
+ ];
6764
+ }
6765
+ const INTERNAL_PROPERTY_KEYS = /* @__PURE__ */ new Set([
6766
+ "fill",
6767
+ "fill-opacity",
6768
+ "pointRadius",
6769
+ "pointIcon",
6770
+ "pointIconSize",
6771
+ "circleCenter",
6772
+ "circleRadius",
6773
+ "icon",
6774
+ "iconSize",
6775
+ "fontSize",
6776
+ "fontColor",
6777
+ "fontWeight",
6778
+ "arrowSize",
6779
+ "label",
6780
+ "entityType",
6781
+ "kind",
6782
+ "meta:type",
6783
+ "stroke",
6784
+ "stroke-width",
6785
+ "stroke-opacity",
6786
+ CLUSTER_COUNT_VALUE_PROP,
6787
+ CLUSTER_MEMBER_ID_PROP
6788
+ ]);
6789
+ const STYLING_PROPERTY_KEYS = [
6790
+ "stroke",
6791
+ "stroke-width",
6792
+ "stroke-opacity",
6793
+ "fill",
6794
+ "fill-opacity",
6795
+ "pointRadius",
6796
+ "pointIcon",
6797
+ "pointIconSize",
6798
+ "icon",
6799
+ "iconSize",
6800
+ "circleCenter",
6801
+ "circleRadius",
6802
+ "fontSize",
6803
+ "fontColor",
6804
+ "fontWeight",
6805
+ "arrowSize"
6806
+ ];
6807
+ const INTERNAL_PROPERTY_PREFIXES = [
6808
+ "IsHiddenBy",
6809
+ "isHidden",
6810
+ "isSelected",
6811
+ "isTrace",
6812
+ "isTimeline",
6813
+ "trace"
6814
+ ];
6815
+ function isInternalProperty(key) {
6816
+ if (INTERNAL_PROPERTY_KEYS.has(key)) return true;
6817
+ return INTERNAL_PROPERTY_PREFIXES.some((prefix) => key.startsWith(prefix));
6818
+ }
6819
+ function computeBubbleDomain(values) {
6820
+ let min = Infinity;
6821
+ let max = -Infinity;
6822
+ for (const v of values) {
6823
+ if (!Number.isFinite(v)) continue;
6824
+ if (v < min) min = v;
6825
+ if (v > max) max = v;
6826
+ }
6827
+ return isFinite(min) ? { min, max } : null;
6828
+ }
6829
+ function bubbleGradientColorExpression(prop, min, max) {
6830
+ if (!(max > min)) return gradientColor(0.5);
6831
+ const expr = ["interpolate", ["linear"], ["get", prop]];
6832
+ const span = max - min;
6833
+ GRADIENT_RAMP.forEach((color, i) => {
6834
+ expr.push(min + span * i / (GRADIENT_RAMP.length - 1), color);
6835
+ });
6836
+ return expr;
6837
+ }
6838
+ function createClusterGradientManager(map, sourceId, options) {
6839
+ const clusterProp = options.valueProp ?? "point_count";
6840
+ let scheduled = false;
6841
+ let lastDomainKey = "";
6842
+ let reportedFailure = false;
6843
+ function reportFailure(stage, error) {
6844
+ if (reportedFailure) return;
6845
+ reportedFailure = true;
6846
+ console.error(`[map-component] cluster gradient ${stage} failed; bubbles keep their current colors:`, error);
6847
+ }
6848
+ function apply() {
6849
+ scheduled = false;
6850
+ let values;
6851
+ try {
6852
+ if (!map.getSource(sourceId)) return;
6853
+ values = map.querySourceFeatures(sourceId, { filter: ["has", "point_count"] }).map((f) => {
6854
+ var _a;
6855
+ return Number((_a = f.properties) == null ? void 0 : _a[clusterProp]);
6856
+ });
6857
+ if (options.singleLayerId) {
6858
+ const singles = map.querySourceFeatures(sourceId, {
6859
+ filter: ["all", ["!", ["has", "point_count"]], [">", ["get", CLUSTER_COUNT_VALUE_PROP], 1]]
6860
+ });
6861
+ values.push(...singles.map((f) => {
6862
+ var _a;
6863
+ return Number((_a = f.properties) == null ? void 0 : _a[CLUSTER_COUNT_VALUE_PROP]);
6864
+ }));
6865
+ }
6866
+ } catch (error) {
6867
+ reportFailure("domain query", error);
6868
+ return;
6869
+ }
6870
+ const domain = computeBubbleDomain(values);
6871
+ if (!domain) return;
6872
+ const key = `${domain.min}|${domain.max}`;
6873
+ if (key === lastDomainKey) return;
6874
+ lastDomainKey = key;
6875
+ try {
6876
+ if (map.getLayer(options.clustersLayerId)) {
6877
+ map.setPaintProperty(
6878
+ options.clustersLayerId,
6879
+ "circle-color",
6880
+ bubbleGradientColorExpression(clusterProp, domain.min, domain.max)
6881
+ );
6882
+ }
6883
+ if (options.singleLayerId && map.getLayer(options.singleLayerId)) {
6884
+ map.setPaintProperty(
6885
+ options.singleLayerId,
6886
+ "circle-color",
6887
+ bubbleGradientColorExpression(CLUSTER_COUNT_VALUE_PROP, domain.min, domain.max)
6888
+ );
6889
+ }
6890
+ } catch (error) {
6891
+ reportFailure("paint update", error);
6892
+ lastDomainKey = "";
6893
+ }
6894
+ }
6895
+ function schedule() {
6896
+ if (scheduled) return;
6897
+ scheduled = true;
6898
+ requestAnimationFrame(apply);
6899
+ }
6900
+ function onData(e) {
6901
+ if (e.sourceId === sourceId) schedule();
6902
+ }
6903
+ map.on("moveend", schedule);
6904
+ map.on("data", onData);
6905
+ schedule();
6906
+ return {
6907
+ destroy: () => {
6908
+ map.off("moveend", schedule);
6909
+ map.off("data", onData);
6910
+ }
6911
+ };
6912
+ }
6913
+ const LABEL_NEVER_HIDE_PROP = "_labelNeverHide";
6914
+ const PINNED_LABEL_FILTER = ["==", ["get", LABEL_NEVER_HIDE_PROP], 1];
6915
+ const UNPINNED_LABEL_FILTER = ["!=", ["get", LABEL_NEVER_HIDE_PROP], 1];
6916
+ function computeLabelNeverHide(label) {
6917
+ return (label == null ? void 0 : label.neverHide) && !label.hidden ? 1 : 0;
6918
+ }
6919
+ function buildCustomLabelLayout() {
6920
+ return {
6921
+ // Hide labels for trace points (except last point which has isTraceLabel),
6922
+ // arrows handled by the custom-arrow-labels layer. Features blanked by
6923
+ // heatmap/cluster/trace modes stay blank in BOTH layers: "never hide"
6924
+ // exempts labels from collision and density culling, it does not resurrect
6925
+ // labels other mode choices explicitly blank.
6926
+ "text-field": [
6927
+ "case",
6928
+ ["==", ["get", "isHiddenByTrace"], true],
6929
+ "",
6930
+ ["==", ["get", "isHiddenByHeatmap"], 1],
6931
+ "",
6932
+ ["==", ["get", "isHiddenByCluster"], 1],
6933
+ "",
6934
+ ["==", ["get", "kind"], "arrow"],
6935
+ "",
6936
+ // Trace points: only show label if isTraceLabel is true (last point in group)
6937
+ ["all", ["==", ["get", "isTracePoint"], true], ["!=", ["get", "isTraceLabel"], true]],
6938
+ "",
6939
+ ["==", ["get", "kind"], "text"],
6940
+ ["coalesce", ["get", "label"], ["get", "text"], "New Label"],
6941
+ ["coalesce", ["get", "name"], ""]
6942
+ ],
6943
+ // Text features use their fontSize property; trace labels 14px; others 12px
6944
+ "text-size": [
6945
+ "case",
6946
+ ["==", ["get", "kind"], "text"],
6947
+ ["coalesce", ["get", "fontSize"], 14],
6948
+ ["==", ["get", "isTraceLabel"], true],
6949
+ 14,
6950
+ 12
6951
+ ],
6952
+ // Text features: center anchor; others: top anchor
6953
+ "text-anchor": ["case", ["==", ["get", "kind"], "text"], "center", "top"],
6954
+ "text-offset": ["case", ["==", ["get", "kind"], "text"], ["literal", [0, 0]], ["literal", [0, 0.8]]],
6955
+ "text-padding": 2,
6956
+ // Bold font for text features with fontWeight=bold, trace labels, others regular
6957
+ "text-font": [
6958
+ "case",
6959
+ ["all", ["==", ["get", "kind"], "text"], ["==", ["get", "fontWeight"], "bold"]],
6960
+ ["literal", ["Montserrat SemiBold", "Noto Sans Regular"]],
6961
+ ["==", ["get", "isTraceLabel"], true],
6962
+ ["literal", ["Montserrat Medium", "Noto Sans Regular"]],
6963
+ ["literal", ["Montserrat Regular", "Noto Sans Regular"]]
6964
+ ]
6965
+ };
6966
+ }
6967
+ function buildCustomLabelPaint() {
6968
+ return {
6969
+ // Text features use fontColor; others use default
6970
+ "text-color": [
6971
+ "case",
6972
+ ["==", ["get", "kind"], "text"],
6973
+ ["coalesce", ["get", "fontColor"], "#000000"],
6974
+ "#1f2937"
6975
+ ],
6976
+ "text-halo-color": "#ffffff",
6977
+ // Thicker halo for trace labels and text features
6978
+ "text-halo-width": [
6979
+ "case",
6980
+ ["==", ["get", "kind"], "text"],
6981
+ 2,
6982
+ ["==", ["get", "isTraceLabel"], true],
6983
+ 2,
6984
+ 1.5
6985
+ ],
6986
+ "text-opacity": ["*", 0.9, ["get", "stroke-opacity"]]
6987
+ };
6988
+ }
6480
6989
  const OTHER_BUCKET_KEY = "__other__";
6481
6990
  const OTHER_BUCKET_LABEL = "Other";
6482
6991
  const OTHER_BUCKET_COLOR = "#9ca3af";
6483
6992
  function toDisplayName(name) {
6484
6993
  return name === OTHER_BUCKET_KEY ? OTHER_BUCKET_LABEL : name;
6485
6994
  }
6486
- function createPieSVG(categories, total, size = 44, onSliceHover) {
6995
+ function createPieSVG(categories, total, size = 44, onSliceHover, badgeValue) {
6487
6996
  const container = document.createElement("div");
6488
6997
  container.style.width = `${size}px`;
6489
6998
  container.style.height = `${size}px`;
@@ -6581,16 +7090,17 @@ function createPieSVG(categories, total, size = 44, onSliceHover) {
6581
7090
  centerCircle.setAttribute("r", String(innerRadius - 2));
6582
7091
  centerCircle.setAttribute("fill", "#1f2937");
6583
7092
  svg.appendChild(centerCircle);
7093
+ const badgeText = formatClusterBadge(badgeValue ?? total);
6584
7094
  const text = document.createElementNS("http://www.w3.org/2000/svg", "text");
6585
7095
  text.setAttribute("x", String(radius));
6586
7096
  text.setAttribute("y", String(radius));
6587
7097
  text.setAttribute("text-anchor", "middle");
6588
7098
  text.setAttribute("dominant-baseline", "central");
6589
7099
  text.setAttribute("fill", "white");
6590
- text.setAttribute("font-size", total >= 1e3 ? "9" : total >= 100 ? "10" : "11");
7100
+ text.setAttribute("font-size", badgeText.length >= 6 ? "8" : badgeText.length >= 4 ? "9" : badgeText.length >= 3 ? "10" : "11");
6591
7101
  text.setAttribute("font-weight", "bold");
6592
7102
  text.setAttribute("font-family", "system-ui, sans-serif");
6593
- text.textContent = total >= 1e3 ? `${(total / 1e3).toFixed(1)}k` : String(total);
7103
+ text.textContent = badgeText;
6594
7104
  svg.appendChild(text);
6595
7105
  container.appendChild(svg);
6596
7106
  return container;
@@ -6637,17 +7147,17 @@ function hideTooltip() {
6637
7147
  tooltipEl.style.display = "none";
6638
7148
  }
6639
7149
  }
6640
- function fingerprintCluster(pointCount, counts, size) {
6641
- return `${size}|${pointCount}|${counts.join(",")}`;
7150
+ function fingerprintCluster(pointCount, counts, size, badgeValue) {
7151
+ return `${size}|${pointCount}|${badgeValue ?? ""}|${counts.join(",")}`;
6642
7152
  }
6643
- function buildPieElement(categories, pointCount, size, source, clusterId, map, coords) {
7153
+ function buildPieElement(categories, pointCount, size, source, clusterId, map, coords, badgeValue) {
6644
7154
  const el = createPieSVG(categories, pointCount, size, (cat, event) => {
6645
7155
  if (cat) {
6646
7156
  showTooltip(cat, event.clientX, event.clientY);
6647
7157
  } else {
6648
7158
  hideTooltip();
6649
7159
  }
6650
- });
7160
+ }, badgeValue);
6651
7161
  el.addEventListener("click", () => {
6652
7162
  source.getClusterExpansionZoom(clusterId).then((zoom) => {
6653
7163
  if (typeof zoom === "number") {
@@ -6666,13 +7176,16 @@ function renderClusterPies(map, sourceId, categoryValues, categoryColorMap, mark
6666
7176
  });
6667
7177
  const visibleClusterIds = /* @__PURE__ */ new Set();
6668
7178
  clusters.forEach((feature) => {
6669
- var _a, _b;
7179
+ var _a, _b, _c;
6670
7180
  const clusterId = (_a = feature.properties) == null ? void 0 : _a.cluster_id;
6671
7181
  if (clusterId === void 0) return;
6672
7182
  const clusterKey = `${clusterId}`;
6673
7183
  visibleClusterIds.add(clusterKey);
6674
7184
  const coords = feature.geometry.coordinates;
6675
7185
  const pointCount = ((_b = feature.properties) == null ? void 0 : _b.point_count) || 0;
7186
+ const sumRaw = (_c = feature.properties) == null ? void 0 : _c[CLUSTER_SUM_PROP];
7187
+ const sumNum = typeof sumRaw === "number" ? sumRaw : sumRaw != null ? Number(sumRaw) : NaN;
7188
+ const badgeValue = Number.isFinite(sumNum) ? sumNum : void 0;
6676
7189
  const allCounts = categoryValues.map((_, i) => {
6677
7190
  var _a2;
6678
7191
  return Number(((_a2 = feature.properties) == null ? void 0 : _a2[`cat_${i}`]) || 0);
@@ -6684,13 +7197,13 @@ function renderClusterPies(map, sourceId, categoryValues, categoryColorMap, mark
6684
7197
  color: categoryColorMap[cat] || "#3b82f6"
6685
7198
  })).filter((c) => c.count > 0);
6686
7199
  const size = pointCount < 100 ? 40 : pointCount < 750 ? 50 : 60;
6687
- const fingerprint = fingerprintCluster(pointCount, allCounts, size);
7200
+ const fingerprint = fingerprintCluster(pointCount, allCounts, size, badgeValue);
6688
7201
  const existing = markers.get(clusterKey);
6689
7202
  if (existing && existing.fingerprint === fingerprint) {
6690
7203
  existing.marker.setLngLat(coords);
6691
7204
  return;
6692
7205
  }
6693
- const el = buildPieElement(categories, pointCount, size, source, clusterId, map, coords);
7206
+ const el = buildPieElement(categories, pointCount, size, source, clusterId, map, coords, badgeValue);
6694
7207
  if (existing) {
6695
7208
  existing.marker.remove();
6696
7209
  }
@@ -7131,6 +7644,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7131
7644
  const loadingBasemaps = useRef(/* @__PURE__ */ new Set());
7132
7645
  const customBasemapRegistry = useRef(/* @__PURE__ */ new Map());
7133
7646
  const clusterPieManagers = useRef(/* @__PURE__ */ new Map());
7647
+ const clusterGradientManagers = useRef(/* @__PURE__ */ new Map());
7648
+ const clusterLayerHandlers = useRef(/* @__PURE__ */ new Map());
7134
7649
  const handleMapStyleChangeRef = useRef(null);
7135
7650
  const flightPath3DLayerId = useRef(null);
7136
7651
  const update3DFlightPathsRef = useRef(null);
@@ -7145,6 +7660,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7145
7660
  const [selectedFeatureIds, setSelectedFeatureIds] = useState([]);
7146
7661
  const [featureCount, setFeatureCount] = useState(0);
7147
7662
  const [featureUpdateCounter, setFeatureUpdateCounter] = useState(0);
7663
+ const [clusterDataVersion, setClusterDataVersion] = useState(0);
7148
7664
  const [showProperties, setShowProperties] = useState(false);
7149
7665
  const [autoFocusLabel, setAutoFocusLabel] = useState(false);
7150
7666
  const [showLayers, setShowLayers] = useState(false);
@@ -7476,6 +7992,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7476
7992
  });
7477
7993
  });
7478
7994
  });
7995
+ const layerGradientRanges = /* @__PURE__ */ new Map();
7479
7996
  selectedFeatureIds.forEach((fid) => {
7480
7997
  var _a;
7481
7998
  const feature = featById.get(fid);
@@ -7485,22 +8002,29 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7485
8002
  colorMap.set(fid, tracePointColors.get(fid));
7486
8003
  return;
7487
8004
  }
7488
- let color = ((_a = feature == null ? void 0 : feature.properties) == null ? void 0 : _a.stroke) || "#3b82f6";
8005
+ const fallback = ((_a = feature == null ? void 0 : feature.properties) == null ? void 0 : _a.stroke) || "#3b82f6";
8006
+ let color = fallback;
7489
8007
  const colorConfig = visualConfig == null ? void 0 : visualConfig.color;
7490
8008
  if (colorConfig && feature) {
7491
- if (colorConfig.mode === "fixed" && colorConfig.fixedColor) {
7492
- color = colorConfig.fixedColor;
7493
- } else if (colorConfig.mode === "field" && colorConfig.fieldName && feature.properties) {
7494
- const key = categoricalKey(feature.properties[colorConfig.fieldName]);
7495
- if (key !== null) {
7496
- color = hashStringToColor$1(key);
8009
+ let range;
8010
+ if (layer && colorConfig.mode === "field" && colorConfig.scale === "gradient" && colorConfig.fieldName) {
8011
+ const cached = layerGradientRanges.get(layer.id);
8012
+ if (cached === void 0) {
8013
+ range = computeNumericRange(layer.featureIds, (id) => {
8014
+ var _a2;
8015
+ return (_a2 = featById.get(id)) == null ? void 0 : _a2.properties;
8016
+ }, colorConfig.fieldName);
8017
+ layerGradientRanges.set(layer.id, range);
8018
+ } else {
8019
+ range = cached;
7497
8020
  }
7498
8021
  }
8022
+ color = resolveFeatureColor(colorConfig, feature.properties, fallback, range);
7499
8023
  }
7500
8024
  colorMap.set(fid, color);
7501
8025
  });
7502
8026
  return colorMap;
7503
- }, [selectedFeatureIds, layers, getAllFeatures, hashStringToColor$1]);
8027
+ }, [selectedFeatureIds, layers, getAllFeatures]);
7504
8028
  const countVisibleFeatures = useCallback((threshold) => {
7505
8029
  const m = map.current;
7506
8030
  if (!m) return 0;
@@ -7651,27 +8175,38 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7651
8175
  layer.featureIds.forEach((fid) => featureToLayer.set(fid, layer));
7652
8176
  });
7653
8177
  const sizeFieldRanges = /* @__PURE__ */ new Map();
8178
+ const colorFieldRanges = /* @__PURE__ */ new Map();
7654
8179
  currentLayers.forEach((layer) => {
7655
- var _a;
8180
+ var _a, _b;
7656
8181
  if (!layer.visible) return;
7657
8182
  const sizeConfig = (_a = layer.visualConfig) == null ? void 0 : _a.size;
7658
- if ((sizeConfig == null ? void 0 : sizeConfig.mode) === "field" && sizeConfig.fieldName) {
7659
- let min = Infinity, max = -Infinity;
7660
- layer.featureIds.forEach((fid) => {
7661
- const feature = featureById.get(fid);
7662
- if (feature == null ? void 0 : feature.properties) {
7663
- const rawVal = feature.properties[sizeConfig.fieldName];
7664
- const val = typeof rawVal === "number" ? rawVal : typeof rawVal === "string" && rawVal.trim() !== "" ? Number(rawVal) : NaN;
7665
- if (isFinite(val)) {
7666
- min = Math.min(min, val);
7667
- max = Math.max(max, val);
7668
- }
8183
+ const colorConfig = (_b = layer.visualConfig) == null ? void 0 : _b.color;
8184
+ const sizeField = (sizeConfig == null ? void 0 : sizeConfig.mode) === "field" && sizeConfig.fieldName ? sizeConfig.fieldName : null;
8185
+ const colorField = (colorConfig == null ? void 0 : colorConfig.mode) === "field" && colorConfig.scale === "gradient" && colorConfig.fieldName ? colorConfig.fieldName : null;
8186
+ if (!sizeField && !colorField) return;
8187
+ let sMin = Infinity, sMax = -Infinity;
8188
+ let cMin = Infinity, cMax = -Infinity;
8189
+ layer.featureIds.forEach((fid) => {
8190
+ var _a2;
8191
+ const props = (_a2 = featureById.get(fid)) == null ? void 0 : _a2.properties;
8192
+ if (!props) return;
8193
+ if (sizeField) {
8194
+ const v = coerceFiniteNumber(props[sizeField]);
8195
+ if (v !== null) {
8196
+ if (v < sMin) sMin = v;
8197
+ if (v > sMax) sMax = v;
7669
8198
  }
7670
- });
7671
- if (isFinite(min) && isFinite(max)) {
7672
- sizeFieldRanges.set(layer.id, { min, max });
7673
8199
  }
7674
- }
8200
+ if (colorField) {
8201
+ const v = coerceFiniteNumber(props[colorField]);
8202
+ if (v !== null) {
8203
+ if (v < cMin) cMin = v;
8204
+ if (v > cMax) cMax = v;
8205
+ }
8206
+ }
8207
+ });
8208
+ if (sizeField && isFinite(sMin)) sizeFieldRanges.set(layer.id, { min: sMin, max: sMax });
8209
+ if (colorField && isFinite(cMin)) colorFieldRanges.set(layer.id, { min: cMin, max: cMax });
7675
8210
  });
7676
8211
  const lastTracePointIds = /* @__PURE__ */ new Set();
7677
8212
  const tracePointColors = /* @__PURE__ */ new Map();
@@ -7736,7 +8271,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7736
8271
  const sourceData = {
7737
8272
  type: "FeatureCollection",
7738
8273
  features: allFeatures.map((f) => {
7739
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
8274
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
7740
8275
  const featureId = String(f.id);
7741
8276
  const layer = featureToLayer.get(featureId);
7742
8277
  const visualConfig = layer == null ? void 0 : layer.visualConfig;
@@ -7745,14 +8280,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7745
8280
  let strokeColor = ((_b = f.properties) == null ? void 0 : _b.stroke) || "#3b82f6";
7746
8281
  const colorConfig = visualConfig == null ? void 0 : visualConfig.color;
7747
8282
  if (colorConfig) {
7748
- if (colorConfig.mode === "fixed" && colorConfig.fixedColor) {
7749
- strokeColor = colorConfig.fixedColor;
7750
- } else if (colorConfig.mode === "field" && colorConfig.fieldName && f.properties) {
7751
- const key = categoricalKey(f.properties[colorConfig.fieldName]);
7752
- if (key !== null) {
7753
- strokeColor = hashStringToColor$1(key);
7754
- }
7755
- }
8283
+ strokeColor = resolveFeatureColor(
8284
+ colorConfig,
8285
+ f.properties,
8286
+ strokeColor,
8287
+ layer ? colorFieldRanges.get(layer.id) : void 0
8288
+ );
7756
8289
  }
7757
8290
  let strokeWidth = ((_c = f.properties) == null ? void 0 : _c["stroke-width"]) || 2;
7758
8291
  let pointRadius = Math.round(3 + strokeWidth);
@@ -7880,7 +8413,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7880
8413
  pointRadius,
7881
8414
  isHiddenFor3DOnly: hideFlatFor3DOnly ? 1 : 0,
7882
8415
  isTimelineHidden: isTimelineVisible ? 0 : 1,
7883
- _labelPriority: labelPriority
8416
+ _labelPriority: labelPriority,
8417
+ [LABEL_NEVER_HIDE_PROP]: computeLabelNeverHide((_o = layer == null ? void 0 : layer.visualConfig) == null ? void 0 : _o.label)
7884
8418
  }
7885
8419
  };
7886
8420
  })
@@ -8194,6 +8728,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
8194
8728
  clusterPieManagers.current.delete(layerId);
8195
8729
  }
8196
8730
  });
8731
+ clusterGradientManagers.current.forEach((mgr, layerId) => {
8732
+ if (!liveLayerIds.has(layerId)) {
8733
+ try {
8734
+ mgr.destroy();
8735
+ } catch {
8736
+ }
8737
+ clusterGradientManagers.current.delete(layerId);
8738
+ }
8739
+ });
8197
8740
  const m = map.current;
8198
8741
  if (!m) return;
8199
8742
  let style;
@@ -8202,7 +8745,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
8202
8745
  } catch {
8203
8746
  return;
8204
8747
  }
8205
- const layerPrefixes = ["heatmap-layer-", "cluster-count-", "clusters-", "unclustered-point-"];
8748
+ const layerPrefixes = ["heatmap-layer-", "cluster-count-", "cluster-single-count-", "cluster-single-", "clusters-", "unclustered-point-"];
8206
8749
  const sourcePrefixes = ["heatmap-source-", "cluster-source-"];
8207
8750
  ((style == null ? void 0 : style.layers) ?? []).forEach((sl) => {
8208
8751
  const prefix = layerPrefixes.find((p) => sl.id.startsWith(p));
@@ -8652,39 +9195,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
8652
9195
  id: "custom-labels",
8653
9196
  type: "symbol",
8654
9197
  source: "custom-features",
9198
+ filter: UNPINNED_LABEL_FILTER,
8655
9199
  layout: {
9200
+ ...buildCustomLabelLayout(),
8656
9201
  "visibility": "none",
8657
- // Hide labels for trace points (except last point which has isTraceLabel), arrows handled separately
8658
- "text-field": [
8659
- "case",
8660
- ["==", ["get", "isHiddenByTrace"], true],
8661
- "",
8662
- ["==", ["get", "isHiddenByHeatmap"], 1],
8663
- "",
8664
- ["==", ["get", "isHiddenByCluster"], 1],
8665
- "",
8666
- ["==", ["get", "kind"], "arrow"],
8667
- "",
8668
- // Arrows use custom-arrow-labels layer
8669
- // Trace points: only show label if isTraceLabel is true (last point in group)
8670
- ["all", ["==", ["get", "isTracePoint"], true], ["!=", ["get", "isTraceLabel"], true]],
8671
- "",
8672
- ["==", ["get", "kind"], "text"],
8673
- ["coalesce", ["get", "label"], ["get", "text"], "New Label"],
8674
- ["coalesce", ["get", "name"], ""]
8675
- ],
8676
- // Text features use their fontSize property; trace labels 14px; others 12px
8677
- "text-size": [
8678
- "case",
8679
- ["==", ["get", "kind"], "text"],
8680
- ["coalesce", ["get", "fontSize"], 14],
8681
- ["==", ["get", "isTraceLabel"], true],
8682
- 14,
8683
- 12
8684
- ],
8685
- // Text features: center anchor; others: top anchor
8686
- "text-anchor": ["case", ["==", ["get", "kind"], "text"], "center", "top"],
8687
- "text-offset": ["case", ["==", ["get", "kind"], "text"], ["literal", [0, 0]], ["literal", [0, 0.8]]],
8688
9202
  // Native collision-based de-overlap.
8689
9203
  //
8690
9204
  // History: a prior PR turned collision off (`text-allow-overlap: true`)
@@ -8711,40 +9225,28 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
8711
9225
  "text-allow-overlap": false,
8712
9226
  "text-ignore-placement": false,
8713
9227
  "text-optional": true,
8714
- "text-padding": 2,
8715
9228
  // Lower value = higher collision priority (placed first).
8716
9229
  // Computed per-feature in syncFeaturesToCustomLayers.
8717
- "symbol-sort-key": ["coalesce", ["get", "_labelPriority"], 100],
8718
- // Bold font for text features with fontWeight=bold, trace labels, others regular
8719
- "text-font": [
8720
- "case",
8721
- ["all", ["==", ["get", "kind"], "text"], ["==", ["get", "fontWeight"], "bold"]],
8722
- ["literal", ["Montserrat SemiBold", "Noto Sans Regular"]],
8723
- ["==", ["get", "isTraceLabel"], true],
8724
- ["literal", ["Montserrat Medium", "Noto Sans Regular"]],
8725
- ["literal", ["Montserrat Regular", "Noto Sans Regular"]]
8726
- ]
9230
+ "symbol-sort-key": ["coalesce", ["get", "_labelPriority"], 100]
8727
9231
  },
8728
- paint: {
8729
- // Text features use fontColor; others use default
8730
- "text-color": [
8731
- "case",
8732
- ["==", ["get", "kind"], "text"],
8733
- ["coalesce", ["get", "fontColor"], "#000000"],
8734
- "#1f2937"
8735
- ],
8736
- "text-halo-color": "#ffffff",
8737
- // Thicker halo for trace labels and text features
8738
- "text-halo-width": [
8739
- "case",
8740
- ["==", ["get", "kind"], "text"],
8741
- 2,
8742
- ["==", ["get", "isTraceLabel"], true],
8743
- 2,
8744
- 1.5
8745
- ],
8746
- "text-opacity": ["*", 0.9, ["get", "stroke-opacity"]]
8747
- }
9232
+ paint: buildCustomLabelPaint()
9233
+ });
9234
+ mapInstance.addLayer({
9235
+ id: "custom-labels-pinned",
9236
+ type: "symbol",
9237
+ source: "custom-features",
9238
+ filter: PINNED_LABEL_FILTER,
9239
+ layout: {
9240
+ ...buildCustomLabelLayout(),
9241
+ "visibility": "visible",
9242
+ "text-allow-overlap": true,
9243
+ "text-ignore-placement": true,
9244
+ // With allow-overlap the collision pass is gone and the key only
9245
+ // orders painting, where HIGHER paints on top — negate so important
9246
+ // (low-priority-value) labels draw over their neighbours' halos.
9247
+ "symbol-sort-key": ["*", -1, ["coalesce", ["get", "_labelPriority"], 100]]
9248
+ },
9249
+ paint: buildCustomLabelPaint()
8748
9250
  });
8749
9251
  mapInstance.addSource("arrow-heads", {
8750
9252
  type: "geojson",
@@ -9570,7 +10072,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9570
10072
  scheduleSync();
9571
10073
  });
9572
10074
  mapInstance.on("click", (e) => {
9573
- var _a;
10075
+ var _a, _b;
9574
10076
  if (!enableSelectionRef.current) return;
9575
10077
  if (e.originalEvent.button !== 0) return;
9576
10078
  if (contextMenuFiredRef.current) return;
@@ -9579,14 +10081,24 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9579
10081
  const features = mapInstance.queryRenderedFeatures(e.point, {
9580
10082
  layers: ["custom-polygon-fill", "custom-line", "custom-point"]
9581
10083
  });
10084
+ let clusteredFeatureId = null;
9582
10085
  if (features.length === 0) {
9583
- if (selectedFeatureIdsRef.current.length > 0 && !isModifierKey) {
9584
- applySelectionState([]);
10086
+ const clusterOverlayIds = layersRef.current.filter((l) => {
10087
+ var _a2;
10088
+ return (_a2 = l.clusterConfig) == null ? void 0 : _a2.enabled;
10089
+ }).flatMap((l) => [`clusters-${l.id}`, `cluster-single-${l.id}`, `cluster-single-count-${l.id}`, `unclustered-point-${l.id}`]).filter((id) => mapInstance.getLayer(id));
10090
+ const clusterHit = clusterOverlayIds.length > 0 ? mapInstance.queryRenderedFeatures(e.point, { layers: clusterOverlayIds })[0] : void 0;
10091
+ if (!clusterHit) {
10092
+ if (selectedFeatureIdsRef.current.length > 0 && !isModifierKey) {
10093
+ applySelectionState([]);
10094
+ }
10095
+ return;
9585
10096
  }
9586
- return;
10097
+ const memberId = (_a = clusterHit.properties) == null ? void 0 : _a[CLUSTER_MEMBER_ID_PROP];
10098
+ if (memberId == null || memberId === "") return;
10099
+ clusteredFeatureId = String(memberId);
9587
10100
  }
9588
- const hitFeature = features[0];
9589
- const featureId = (_a = hitFeature.properties) == null ? void 0 : _a.id;
10101
+ const featureId = clusteredFeatureId ?? ((_b = features[0].properties) == null ? void 0 : _b.id);
9590
10102
  if (!featureId) return;
9591
10103
  let isReadOnly = false;
9592
10104
  readOnlyFeatures.current.forEach((layerFeatures) => {
@@ -10887,10 +11399,17 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10887
11399
  scheduleSync();
10888
11400
  scheduleTimelineUpdate();
10889
11401
  setFeatureUpdateCounter((c) => c + 1);
11402
+ if (hasRealChange && !(options == null ? void 0 : options.fromRefresh) && layersRef.current.some((l) => {
11403
+ var _a2;
11404
+ return (_a2 = l.clusterConfig) == null ? void 0 : _a2.enabled;
11405
+ })) {
11406
+ setClusterDataVersion((c) => c + 1);
11407
+ }
10890
11408
  const updated = draw.current.get(featureId);
10891
11409
  if (updated) onFeatureUpdate == null ? void 0 : onFeatureUpdate(updated);
10892
11410
  } else {
10893
11411
  let updatedFeature;
11412
+ let anyRealChange = false;
10894
11413
  readOnlyFeatures.current.forEach((features, layerId) => {
10895
11414
  var _a2;
10896
11415
  const idx = features.findIndex((f) => String(f.id) === featureId);
@@ -10902,6 +11421,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10902
11421
  const oldVal = (_a3 = f.properties) == null ? void 0 : _a3[key];
10903
11422
  if (JSON.stringify(oldVal) !== JSON.stringify(value)) hasRealChange = true;
10904
11423
  });
11424
+ if (hasRealChange) anyRealChange = true;
10905
11425
  const currentUnsaved = (_a2 = f.properties) == null ? void 0 : _a2._unsaved;
10906
11426
  const nextProperties = { ...f.properties, ...normalizedProperties };
10907
11427
  if (!externalPersistence && hasRealChange && currentUnsaved !== false && !(options == null ? void 0 : options.fromRefresh)) {
@@ -10922,6 +11442,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10922
11442
  scheduleSync();
10923
11443
  scheduleTimelineUpdate();
10924
11444
  setFeatureUpdateCounter((c) => c + 1);
11445
+ if (anyRealChange && !(options == null ? void 0 : options.fromRefresh) && layersRef.current.some((l) => {
11446
+ var _a2;
11447
+ return (_a2 = l.clusterConfig) == null ? void 0 : _a2.enabled;
11448
+ })) {
11449
+ setClusterDataVersion((c) => c + 1);
11450
+ }
10925
11451
  onFeatureUpdate == null ? void 0 : onFeatureUpdate(updatedFeature);
10926
11452
  }
10927
11453
  }
@@ -10949,6 +11475,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10949
11475
  draw.current.changeMode("simple_select", { featureIds: [featureId] });
10950
11476
  scheduleSync();
10951
11477
  setFeatureUpdateCounter((c) => c + 1);
11478
+ if (layersRef.current.some((l) => {
11479
+ var _a;
11480
+ return (_a = l.clusterConfig) == null ? void 0 : _a.enabled;
11481
+ })) {
11482
+ setClusterDataVersion((c) => c + 1);
11483
+ }
10952
11484
  const updated = draw.current.get(featureId);
10953
11485
  if (updated) {
10954
11486
  onFeatureUpdate == null ? void 0 : onFeatureUpdate(updated);
@@ -11303,11 +11835,17 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11303
11835
  try {
11304
11836
  if (firstVisibleBasemapSymbol) {
11305
11837
  m.moveLayer("custom-labels", firstVisibleBasemapSymbol.id);
11838
+ if (m.getLayer("custom-labels-pinned")) {
11839
+ m.moveLayer("custom-labels-pinned", firstVisibleBasemapSymbol.id);
11840
+ }
11306
11841
  if (m.getLayer("custom-arrow-labels")) {
11307
11842
  m.moveLayer("custom-arrow-labels", firstVisibleBasemapSymbol.id);
11308
11843
  }
11309
11844
  } else {
11310
11845
  m.moveLayer("custom-labels");
11846
+ if (m.getLayer("custom-labels-pinned")) {
11847
+ m.moveLayer("custom-labels-pinned");
11848
+ }
11311
11849
  if (m.getLayer("custom-arrow-labels")) {
11312
11850
  m.moveLayer("custom-arrow-labels");
11313
11851
  }
@@ -11612,7 +12150,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11612
12150
  const layer = layers.find((l) => l.id === layerId);
11613
12151
  if (!layer) return [];
11614
12152
  const fieldsMap = /* @__PURE__ */ new Map();
11615
- const excludedFields = /* @__PURE__ */ new Set(["name", "startDate", "endDate", "opacity"]);
12153
+ const excludedFields = /* @__PURE__ */ new Set(["name", "startDate", "endDate", "opacity", ...STYLING_PROPERTY_KEYS]);
11616
12154
  const MAX_SAMPLES = 1e4;
11617
12155
  let features = [];
11618
12156
  if (layer.readOnly) {
@@ -11622,22 +12160,41 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11622
12160
  } else {
11623
12161
  features = hiddenFeatures.current.get(layerId) || [];
11624
12162
  }
11625
- const sampleFeatures = features.slice(0, MAX_SAMPLES);
12163
+ const sampled = !layer.readOnly && features.length > MAX_SAMPLES;
12164
+ const sampleFeatures = layer.readOnly ? features : features.slice(0, MAX_SAMPLES);
11626
12165
  sampleFeatures.forEach((f) => {
11627
12166
  if (f && f.properties) {
11628
12167
  Object.entries(f.properties).forEach(([key, value]) => {
11629
- if (!excludedFields.has(key)) {
11630
- const isNumeric = typeof value === "number" || typeof value === "string" && value.trim() !== "" && !isNaN(Number(value));
11631
- if (!fieldsMap.has(key)) {
11632
- fieldsMap.set(key, isNumeric);
11633
- } else if (isNumeric && !fieldsMap.get(key)) {
11634
- fieldsMap.set(key, true);
11635
- }
12168
+ if (excludedFields.has(key)) return;
12169
+ let acc = fieldsMap.get(key);
12170
+ if (!acc) {
12171
+ acc = { isNumeric: false, numericCount: 0, nonEmptyCount: 0, min: Infinity, max: -Infinity };
12172
+ fieldsMap.set(key, acc);
12173
+ }
12174
+ if (typeof value === "number" || typeof value === "string" && value.trim() !== "" && !isNaN(Number(value))) {
12175
+ acc.isNumeric = true;
12176
+ }
12177
+ if (!(value == null || typeof value === "string" && value.trim() === "")) {
12178
+ acc.nonEmptyCount++;
12179
+ }
12180
+ const num = coerceFiniteNumber(value);
12181
+ if (num !== null) {
12182
+ acc.numericCount++;
12183
+ if (num < acc.min) acc.min = num;
12184
+ if (num > acc.max) acc.max = num;
11636
12185
  }
11637
12186
  });
11638
12187
  }
11639
12188
  });
11640
- return Array.from(fieldsMap.entries()).map(([name, isNumeric]) => ({ name, isNumeric })).sort((a, b) => a.name.localeCompare(b.name));
12189
+ const sampledFeatureCount = sampleFeatures.length;
12190
+ return Array.from(fieldsMap.entries()).map(([name, acc]) => ({
12191
+ name,
12192
+ isNumeric: acc.isNumeric,
12193
+ numericRatio: acc.nonEmptyCount > 0 ? acc.numericCount / acc.nonEmptyCount : 0,
12194
+ coverage: sampledFeatureCount > 0 ? acc.nonEmptyCount / sampledFeatureCount : 0,
12195
+ sampled,
12196
+ ...acc.numericCount > 0 ? { min: acc.min, max: acc.max } : {}
12197
+ })).sort((a, b) => a.name.localeCompare(b.name));
11641
12198
  }, [layers]);
11642
12199
  const getFieldValueDistribution = useCallback(
11643
12200
  (layerId, fieldName, maxValues = 50) => {
@@ -13385,16 +13942,33 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13385
13942
  mapInstance.once("idle", rebuildClusters);
13386
13943
  return;
13387
13944
  }
13945
+ clusterLayerHandlers.current.forEach((handlers, layerId) => {
13946
+ const clustersLayerId = `clusters-${layerId}`;
13947
+ try {
13948
+ mapInstance.off("click", clustersLayerId, handlers.click);
13949
+ mapInstance.off("mouseenter", clustersLayerId, handlers.enter);
13950
+ mapInstance.off("mouseleave", clustersLayerId, handlers.leave);
13951
+ } catch {
13952
+ }
13953
+ });
13954
+ clusterLayerHandlers.current.clear();
13388
13955
  layers.forEach((layer) => {
13389
13956
  const sourceId = `cluster-source-${layer.id}`;
13390
13957
  const clustersLayerId = `clusters-${layer.id}`;
13391
13958
  const clusterCountLayerId = `cluster-count-${layer.id}`;
13392
13959
  const unclusteredLayerId = `unclustered-point-${layer.id}`;
13960
+ const singleValueLayerId = `cluster-single-${layer.id}`;
13961
+ const singleValueCountLayerId = `cluster-single-count-${layer.id}`;
13393
13962
  const existingPieManager = clusterPieManagers.current.get(layer.id);
13394
13963
  if (existingPieManager) {
13395
13964
  existingPieManager.destroy();
13396
13965
  clusterPieManagers.current.delete(layer.id);
13397
13966
  }
13967
+ const existingGradientManager = clusterGradientManagers.current.get(layer.id);
13968
+ if (existingGradientManager) {
13969
+ existingGradientManager.destroy();
13970
+ clusterGradientManagers.current.delete(layer.id);
13971
+ }
13398
13972
  try {
13399
13973
  if (mapInstance.getLayer(clusterCountLayerId)) {
13400
13974
  mapInstance.removeLayer(clusterCountLayerId);
@@ -13402,6 +13976,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13402
13976
  if (mapInstance.getLayer(clustersLayerId)) {
13403
13977
  mapInstance.removeLayer(clustersLayerId);
13404
13978
  }
13979
+ if (mapInstance.getLayer(singleValueCountLayerId)) {
13980
+ mapInstance.removeLayer(singleValueCountLayerId);
13981
+ }
13982
+ if (mapInstance.getLayer(singleValueLayerId)) {
13983
+ mapInstance.removeLayer(singleValueLayerId);
13984
+ }
13405
13985
  if (mapInstance.getLayer(unclusteredLayerId)) {
13406
13986
  mapInstance.removeLayer(unclusteredLayerId);
13407
13987
  }
@@ -13412,12 +13992,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13412
13992
  }
13413
13993
  });
13414
13994
  layers.forEach((layer) => {
13415
- var _a, _b, _c, _d;
13995
+ var _a, _b, _c, _d, _e, _f, _g;
13416
13996
  if (!((_a = layer.clusterConfig) == null ? void 0 : _a.enabled) || !layer.visible) return;
13417
13997
  const sourceId = `cluster-source-${layer.id}`;
13418
13998
  const clustersLayerId = `clusters-${layer.id}`;
13419
13999
  const clusterCountLayerId = `cluster-count-${layer.id}`;
13420
14000
  const unclusteredLayerId = `unclustered-point-${layer.id}`;
14001
+ const singleValueLayerId = `cluster-single-${layer.id}`;
14002
+ const singleValueCountLayerId = `cluster-single-count-${layer.id}`;
13421
14003
  let pointFeatures = [];
13422
14004
  if (layer.visible) {
13423
14005
  if (layer.readOnly) {
@@ -13444,10 +14026,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13444
14026
  }
13445
14027
  if (pointFeatures.length === 0) return;
13446
14028
  const groupByField = (_b = layer.clusterConfig) == null ? void 0 : _b.groupByField;
14029
+ const countByField = ((_c = layer.clusterConfig) == null ? void 0 : _c.countByFieldEnabled) && ((_d = layer.clusterConfig) == null ? void 0 : _d.countByField) || null;
14030
+ const bubbleGradient = !!((_e = layer.clusterConfig) == null ? void 0 : _e.bubbleGradient) && !groupByField;
13447
14031
  const OTHER_COLOR = OTHER_BUCKET_COLOR;
13448
14032
  const MAX_CATEGORIES = 15;
13449
14033
  try {
13450
- const layerColor = ((_d = (_c = layer.visualConfig) == null ? void 0 : _c.color) == null ? void 0 : _d.fixedColor) || "#3b82f6";
14034
+ const layerColor = ((_g = (_f = layer.visualConfig) == null ? void 0 : _f.color) == null ? void 0 : _g.fixedColor) || "#3b82f6";
13451
14035
  let clusterProperties = {};
13452
14036
  let categoryValues = [];
13453
14037
  let categoryColorMap = {};
@@ -13477,12 +14061,16 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13477
14061
  const otherExpr = topKeys.length === 0 ? 1 : ["match", fieldAsString, topKeys, 0, 1];
13478
14062
  clusterProperties[`cat_${categoryValues.length - 1}`] = ["+", otherExpr];
13479
14063
  }
14064
+ if (countByField) {
14065
+ clusterProperties[CLUSTER_SUM_PROP] = ["+", ["get", CLUSTER_COUNT_VALUE_PROP]];
14066
+ }
14067
+ const sourceFeatures = countByField ? injectClusterCountValues(pointFeatures, countByField) : pointFeatures;
13480
14068
  const mapStyleMaxZoom = typeof mapInstance.getMaxZoom === "function" ? mapInstance.getMaxZoom() : 24;
13481
14069
  const clusterMaxZoom = Math.min(24, Math.max(1, mapStyleMaxZoom - 1));
13482
14070
  const geojsonSourceMaxZoom = Math.min(24, Math.max(clusterMaxZoom + 1, mapStyleMaxZoom));
13483
14071
  mapInstance.addSource(sourceId, {
13484
14072
  type: "geojson",
13485
- data: { type: "FeatureCollection", features: pointFeatures },
14073
+ data: { type: "FeatureCollection", features: sourceFeatures },
13486
14074
  maxzoom: geojsonSourceMaxZoom,
13487
14075
  cluster: true,
13488
14076
  clusterMaxZoom,
@@ -13540,12 +14128,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13540
14128
  source: sourceId,
13541
14129
  filter: ["has", "point_count"],
13542
14130
  layout: {
13543
- "text-field": ["get", "point_count_abbreviated"],
14131
+ "text-field": countByField ? clusterBadgeTextField(CLUSTER_SUM_PROP) : ["get", "point_count_abbreviated"],
13544
14132
  "text-font": ["Open Sans Bold", "Arial Unicode MS Bold"],
13545
14133
  "text-size": 12
13546
14134
  },
13547
14135
  paint: {
13548
- "text-color": "#ffffff"
14136
+ "text-color": "#ffffff",
14137
+ // The gradient's pale end needs a dark halo for the white
14138
+ // badge text to stay readable at every ramp stop.
14139
+ ...bubbleGradient ? { "text-halo-color": "#111827", "text-halo-width": 1.1 } : {}
13549
14140
  }
13550
14141
  });
13551
14142
  }
@@ -13560,7 +14151,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13560
14151
  id: unclusteredLayerId,
13561
14152
  type: "circle",
13562
14153
  source: sourceId,
13563
- filter: ["!", ["has", "point_count"]],
14154
+ // With count-by-field on, points whose value exceeds 1 render as
14155
+ // value bubbles below instead of plain dots.
14156
+ filter: countByField ? ["all", ["!", ["has", "point_count"]], ["<=", ["get", CLUSTER_COUNT_VALUE_PROP], 1]] : ["!", ["has", "point_count"]],
13564
14157
  paint: {
13565
14158
  "circle-color": unclusteredColor,
13566
14159
  "circle-radius": 6,
@@ -13568,7 +14161,50 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13568
14161
  "circle-stroke-color": "#ffffff"
13569
14162
  }
13570
14163
  });
13571
- mapInstance.on("click", clustersLayerId, async (e) => {
14164
+ if (countByField) {
14165
+ const singleValueFilter = ["all", ["!", ["has", "point_count"]], [">", ["get", CLUSTER_COUNT_VALUE_PROP], 1]];
14166
+ mapInstance.addLayer({
14167
+ id: singleValueLayerId,
14168
+ type: "circle",
14169
+ source: sourceId,
14170
+ filter: singleValueFilter,
14171
+ paint: {
14172
+ "circle-color": unclusteredColor,
14173
+ "circle-radius": 14,
14174
+ "circle-stroke-width": 2,
14175
+ "circle-stroke-color": "#ffffff"
14176
+ }
14177
+ });
14178
+ mapInstance.addLayer({
14179
+ id: singleValueCountLayerId,
14180
+ type: "symbol",
14181
+ source: sourceId,
14182
+ filter: singleValueFilter,
14183
+ layout: {
14184
+ "text-field": clusterBadgeTextField(CLUSTER_COUNT_VALUE_PROP),
14185
+ "text-font": ["Open Sans Bold", "Arial Unicode MS Bold"],
14186
+ "text-size": 11,
14187
+ // A bubble without its number reads as broken - never cull.
14188
+ "text-allow-overlap": true,
14189
+ "text-ignore-placement": true
14190
+ },
14191
+ paint: {
14192
+ "text-color": "#ffffff",
14193
+ ...bubbleGradient ? { "text-halo-color": "#111827", "text-halo-width": 1.1 } : {}
14194
+ }
14195
+ });
14196
+ }
14197
+ if (bubbleGradient) {
14198
+ clusterGradientManagers.current.set(
14199
+ layer.id,
14200
+ createClusterGradientManager(mapInstance, sourceId, {
14201
+ clustersLayerId,
14202
+ valueProp: countByField ? CLUSTER_SUM_PROP : null,
14203
+ ...countByField ? { singleLayerId: singleValueLayerId } : {}
14204
+ })
14205
+ );
14206
+ }
14207
+ const handleClusterClick = async (e) => {
13572
14208
  var _a2;
13573
14209
  const features = mapInstance.queryRenderedFeatures(e.point, {
13574
14210
  layers: [clustersLayerId]
@@ -13587,12 +14223,20 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13587
14223
  }
13588
14224
  } catch {
13589
14225
  }
13590
- });
13591
- mapInstance.on("mouseenter", clustersLayerId, () => {
14226
+ };
14227
+ const handleClusterMouseEnter = () => {
13592
14228
  mapInstance.getCanvas().style.cursor = "pointer";
13593
- });
13594
- mapInstance.on("mouseleave", clustersLayerId, () => {
14229
+ };
14230
+ const handleClusterMouseLeave = () => {
13595
14231
  mapInstance.getCanvas().style.cursor = "";
14232
+ };
14233
+ mapInstance.on("click", clustersLayerId, handleClusterClick);
14234
+ mapInstance.on("mouseenter", clustersLayerId, handleClusterMouseEnter);
14235
+ mapInstance.on("mouseleave", clustersLayerId, handleClusterMouseLeave);
14236
+ clusterLayerHandlers.current.set(layer.id, {
14237
+ click: handleClusterClick,
14238
+ enter: handleClusterMouseEnter,
14239
+ leave: handleClusterMouseLeave
13596
14240
  });
13597
14241
  } catch (e) {
13598
14242
  console.warn("Error creating cluster layer:", e);
@@ -13610,7 +14254,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13610
14254
  } catch {
13611
14255
  }
13612
14256
  };
13613
- }, [isMapLoaded, layers, currentMapStyle, hashStringToColor$1]);
14257
+ }, [isMapLoaded, layers, currentMapStyle, hashStringToColor$1, clusterDataVersion]);
13614
14258
  if (mapError) {
13615
14259
  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: [
13616
14260
  /* @__PURE__ */ jsx("div", { className: "p-4 border-b border-border", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
@@ -15130,40 +15774,6 @@ function DebugSidebar({ onAddRandomPoints, onImportKML, onAddDomMarkers, onRemov
15130
15774
  }
15131
15775
  );
15132
15776
  }
15133
- const INTERNAL_PROPERTY_KEYS = /* @__PURE__ */ new Set([
15134
- "fill",
15135
- "fill-opacity",
15136
- "pointRadius",
15137
- "pointIcon",
15138
- "pointIconSize",
15139
- "circleCenter",
15140
- "circleRadius",
15141
- "icon",
15142
- "iconSize",
15143
- "fontSize",
15144
- "fontColor",
15145
- "fontWeight",
15146
- "arrowSize",
15147
- "label",
15148
- "entityType",
15149
- "kind",
15150
- "meta:type",
15151
- "stroke",
15152
- "stroke-width",
15153
- "stroke-opacity"
15154
- ]);
15155
- const INTERNAL_PROPERTY_PREFIXES = [
15156
- "IsHiddenBy",
15157
- "isHidden",
15158
- "isSelected",
15159
- "isTrace",
15160
- "isTimeline",
15161
- "trace"
15162
- ];
15163
- function isInternalProperty(key) {
15164
- if (INTERNAL_PROPERTY_KEYS.has(key)) return true;
15165
- return INTERNAL_PROPERTY_PREFIXES.some((prefix) => key.startsWith(prefix));
15166
- }
15167
15777
  export {
15168
15778
  ActionPanel,
15169
15779
  ClusterPieManager,