@octostar/map-component 0.4.0 → 0.4.2

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
@@ -836,6 +836,59 @@ function buildCustomLabelPaint(opts) {
836
836
  "text-opacity": (opts == null ? void 0 : opts.hideSelected) ? ["case", TIMELINE_HIDDEN, 0, SELECTED, 0, visibleOpacity] : visibleOpacity
837
837
  };
838
838
  }
839
+ const DEFAULT_FEATURE_COLOR = "#3b82f6";
840
+ const LAYER_COLOR_PALETTE = [
841
+ "#3FB37F",
842
+ // green
843
+ "#E5A000",
844
+ // amber
845
+ "#D14FA0",
846
+ // magenta
847
+ "#FF4F30",
848
+ // orange
849
+ "#2F4858",
850
+ // slate
851
+ "#8C564B",
852
+ // brown
853
+ "#BCBD22"
854
+ // olive
855
+ ];
856
+ function pickLayerColor(layers) {
857
+ var _a;
858
+ const visibleUses = /* @__PURE__ */ new Map();
859
+ const hiddenUses = /* @__PURE__ */ new Map();
860
+ for (const l of layers) {
861
+ const color = (_a = l.visualConfig) == null ? void 0 : _a.color;
862
+ if ((color == null ? void 0 : color.mode) !== "fixed" || !color.fixedColor) continue;
863
+ const uses = l.visible ? visibleUses : hiddenUses;
864
+ const key = color.fixedColor.toLowerCase();
865
+ uses.set(key, (uses.get(key) ?? 0) + 1);
866
+ }
867
+ const score = (c) => (visibleUses.get(c.toLowerCase()) ?? 0) * (layers.length + 1) + (hiddenUses.get(c.toLowerCase()) ?? 0);
868
+ let best = LAYER_COLOR_PALETTE[0];
869
+ let bestScore = Infinity;
870
+ for (const candidate of LAYER_COLOR_PALETTE) {
871
+ const s = score(candidate);
872
+ if (s < bestScore) {
873
+ best = candidate;
874
+ bestScore = s;
875
+ }
876
+ }
877
+ return best;
878
+ }
879
+ function carriesOwnColor(feature) {
880
+ var _a;
881
+ const stroke = (_a = feature.properties) == null ? void 0 : _a.stroke;
882
+ return typeof stroke === "string" && stroke !== "" && stroke.toLowerCase() !== DEFAULT_FEATURE_COLOR;
883
+ }
884
+ function withAutoLayerColor(layer, features, existing) {
885
+ var _a;
886
+ if (((_a = layer.visualConfig) == null ? void 0 : _a.color) || features.some(carriesOwnColor)) return layer;
887
+ return {
888
+ ...layer,
889
+ visualConfig: { ...layer.visualConfig, color: { mode: "fixed", fixedColor: pickLayerColor(existing) } }
890
+ };
891
+ }
839
892
  const CUSTOM_LAYER_ROLES = [
840
893
  "polygon-fill",
841
894
  "polygon-stroke",
@@ -991,7 +1044,7 @@ function buildLayer(role, sourceId, opts) {
991
1044
  source: sourceId,
992
1045
  filter: ["==", "$type", "Point"],
993
1046
  paint: {
994
- "circle-color": ["coalesce", ["get", "stroke"], "#3b82f6"],
1047
+ "circle-color": ["coalesce", ["get", "stroke"], DEFAULT_FEATURE_COLOR],
995
1048
  "circle-radius": [
996
1049
  "case",
997
1050
  TIMELINE_HIDDEN,
@@ -1969,7 +2022,7 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
1969
2022
  const featureId = String(f.id);
1970
2023
  const visualConfig = layer == null ? void 0 : layer.visualConfig;
1971
2024
  const baseOpacity = ((_a = f.properties) == null ? void 0 : _a["stroke-opacity"]) ?? DEFAULT_VISIBLE_STROKE_OPACITY;
1972
- let strokeColor = ((_b = f.properties) == null ? void 0 : _b.stroke) || "#3b82f6";
2025
+ let strokeColor = ((_b = f.properties) == null ? void 0 : _b.stroke) || DEFAULT_FEATURE_COLOR;
1973
2026
  const colorConfig = visualConfig == null ? void 0 : visualConfig.color;
1974
2027
  if (colorConfig) {
1975
2028
  strokeColor = resolveFeatureColor(
@@ -4352,7 +4405,7 @@ function LayersPanel({
4352
4405
  });
4353
4406
  }, [onRemoveLayer]);
4354
4407
  const renderLayerItem = (layer) => {
4355
- 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;
4408
+ 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, _ea, _fa;
4356
4409
  const customCount = featureCountProvider == null ? void 0 : featureCountProvider(layer.id);
4357
4410
  const featureCount = customCount != null ? customCount : getFeatureCount(layer.id);
4358
4411
  const isExpanded = expandedLayers.has(layer.id);
@@ -4426,6 +4479,14 @@ function LayersPanel({
4426
4479
  "data-testid": `input-edit-layer-${layer.id}`
4427
4480
  }
4428
4481
  ) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 flex-1 min-w-0", children: [
4482
+ ((_b = (_a = layer.visualConfig) == null ? void 0 : _a.color) == null ? void 0 : _b.mode) === "fixed" && layer.visualConfig.color.fixedColor && /* @__PURE__ */ jsx(
4483
+ "span",
4484
+ {
4485
+ className: "w-2.5 h-2.5 rounded-full shrink-0",
4486
+ style: { backgroundColor: layer.visualConfig.color.fixedColor },
4487
+ "data-testid": `layer-color-${layer.id}`
4488
+ }
4489
+ ),
4429
4490
  /* @__PURE__ */ jsx(Tooltip, { title: layer.name, children: /* @__PURE__ */ jsx(
4430
4491
  "button",
4431
4492
  {
@@ -4481,8 +4542,8 @@ function LayersPanel({
4481
4542
  Switch,
4482
4543
  {
4483
4544
  size: "small",
4484
- disabled: (_b = (_a = layer.visualConfig) == null ? void 0 : _a.label) == null ? void 0 : _b.hidden,
4485
- checked: !!((_d = (_c = layer.visualConfig) == null ? void 0 : _c.label) == null ? void 0 : _d.neverHide),
4545
+ disabled: (_d = (_c = layer.visualConfig) == null ? void 0 : _c.label) == null ? void 0 : _d.hidden,
4546
+ checked: !!((_f = (_e = layer.visualConfig) == null ? void 0 : _e.label) == null ? void 0 : _f.neverHide),
4486
4547
  onChange: (checked) => {
4487
4548
  var _a2, _b2, _c2;
4488
4549
  return onUpdateVisualConfig(layer.id, {
@@ -4498,7 +4559,7 @@ function LayersPanel({
4498
4559
  }
4499
4560
  )
4500
4561
  ] }),
4501
- /* @__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" })
4562
+ /* @__PURE__ */ jsx("div", { className: "text-xs text-muted-foreground mt-1", children: ((_h = (_g = layer.visualConfig) == null ? void 0 : _g.label) == null ? void 0 : _h.hidden) ? "Labels are turned off for this layer" : "Show every label even when the map is crowded" })
4502
4563
  ] })
4503
4564
  }
4504
4565
  ] : [],
@@ -4554,14 +4615,14 @@ function LayersPanel({
4554
4615
  ]
4555
4616
  }
4556
4617
  ),
4557
- (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: [
4618
+ (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_i = layer.metadata) == null ? void 0 : _i.hidePointFeatures) && /* @__PURE__ */ jsxs("div", { className: "space-y-1 p-1.5 bg-muted/30 rounded-md", children: [
4558
4619
  /* @__PURE__ */ jsx("div", { className: "flex items-center gap-1.5 text-xs font-medium", children: /* @__PURE__ */ jsx("span", { children: "Point Features" }) }),
4559
4620
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
4560
4621
  /* @__PURE__ */ jsx(
4561
4622
  Switch,
4562
4623
  {
4563
4624
  size: "small",
4564
- checked: ((_h = layer.traceConfig) == null ? void 0 : _h.enabled) ?? false,
4625
+ checked: ((_j = layer.traceConfig) == null ? void 0 : _j.enabled) ?? false,
4565
4626
  onChange: (checked) => onUpdateTraceConfig(layer.id, {
4566
4627
  enabled: checked,
4567
4628
  // A layer that has never had trace settings starts grouped; a
@@ -4573,7 +4634,7 @@ function LayersPanel({
4573
4634
  ),
4574
4635
  /* @__PURE__ */ jsx("span", { className: "text-xs", children: "Trace Lines" })
4575
4636
  ] }),
4576
- ((_i = layer.traceConfig) == null ? void 0 : _i.enabled) && /* @__PURE__ */ jsx(
4637
+ ((_k = layer.traceConfig) == null ? void 0 : _k.enabled) && /* @__PURE__ */ jsx(
4577
4638
  Select,
4578
4639
  {
4579
4640
  size: "small",
@@ -4599,7 +4660,7 @@ function LayersPanel({
4599
4660
  Switch,
4600
4661
  {
4601
4662
  size: "small",
4602
- checked: ((_j = layer.heatmapConfig) == null ? void 0 : _j.enabled) ?? false,
4663
+ checked: ((_l = layer.heatmapConfig) == null ? void 0 : _l.enabled) ?? false,
4603
4664
  onChange: (checked) => {
4604
4665
  var _a2, _b2;
4605
4666
  return onUpdateHeatmapConfig(layer.id, {
@@ -4613,7 +4674,7 @@ function LayersPanel({
4613
4674
  ),
4614
4675
  /* @__PURE__ */ jsx("span", { className: "text-xs", children: "Heatmap" })
4615
4676
  ] }),
4616
- ((_k = layer.heatmapConfig) == null ? void 0 : _k.enabled) && /* @__PURE__ */ jsxs("div", { className: "space-y-1 pl-4", children: [
4677
+ ((_m = layer.heatmapConfig) == null ? void 0 : _m.enabled) && /* @__PURE__ */ jsxs("div", { className: "space-y-1 pl-4", children: [
4617
4678
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
4618
4679
  /* @__PURE__ */ jsx("span", { className: "text-[10px] w-12", children: "Intensity" }),
4619
4680
  /* @__PURE__ */ jsx(
@@ -4657,7 +4718,7 @@ function LayersPanel({
4657
4718
  Switch,
4658
4719
  {
4659
4720
  size: "small",
4660
- checked: ((_l = layer.clusterConfig) == null ? void 0 : _l.enabled) ?? false,
4721
+ checked: ((_n = layer.clusterConfig) == null ? void 0 : _n.enabled) ?? false,
4661
4722
  onChange: (checked) => {
4662
4723
  var _a2, _b2;
4663
4724
  return onUpdateClusterConfig(layer.id, {
@@ -4672,7 +4733,7 @@ function LayersPanel({
4672
4733
  ),
4673
4734
  /* @__PURE__ */ jsx("span", { className: "text-xs", children: "Clustering" })
4674
4735
  ] }),
4675
- ((_m = layer.clusterConfig) == null ? void 0 : _m.enabled) && getLayerFields && /* @__PURE__ */ jsxs("div", { className: "space-y-1 pl-4", children: [
4736
+ ((_o = layer.clusterConfig) == null ? void 0 : _o.enabled) && getLayerFields && /* @__PURE__ */ jsxs("div", { className: "space-y-1 pl-4", children: [
4676
4737
  /* @__PURE__ */ jsx(
4677
4738
  Select,
4678
4739
  {
@@ -4788,7 +4849,7 @@ function LayersPanel({
4788
4849
  Switch,
4789
4850
  {
4790
4851
  size: "small",
4791
- checked: !((_o = (_n = layer.visualConfig) == null ? void 0 : _n.label) == null ? void 0 : _o.hidden),
4852
+ checked: !((_q = (_p = layer.visualConfig) == null ? void 0 : _p.label) == null ? void 0 : _q.hidden),
4792
4853
  onChange: (checked) => {
4793
4854
  var _a2, _b2, _c2;
4794
4855
  return onUpdateVisualConfig(layer.id, {
@@ -4804,8 +4865,8 @@ function LayersPanel({
4804
4865
  Select,
4805
4866
  {
4806
4867
  size: "small",
4807
- disabled: (_q = (_p = layer.visualConfig) == null ? void 0 : _p.label) == null ? void 0 : _q.hidden,
4808
- value: ((_s = (_r = layer.visualConfig) == null ? void 0 : _r.label) == null ? void 0 : _s.mode) ?? "standard",
4868
+ disabled: (_s = (_r = layer.visualConfig) == null ? void 0 : _r.label) == null ? void 0 : _s.hidden,
4869
+ value: ((_u = (_t = layer.visualConfig) == null ? void 0 : _t.label) == null ? void 0 : _u.mode) ?? "standard",
4809
4870
  onChange: (val) => {
4810
4871
  var _a2;
4811
4872
  return onUpdateVisualConfig(layer.id, {
@@ -4822,11 +4883,11 @@ function LayersPanel({
4822
4883
  "data-testid": `select-label-mode-${layer.id}`
4823
4884
  }
4824
4885
  ),
4825
- ((_u = (_t = layer.visualConfig) == null ? void 0 : _t.label) == null ? void 0 : _u.mode) === "field" && /* @__PURE__ */ jsx(
4886
+ ((_w = (_v = layer.visualConfig) == null ? void 0 : _v.label) == null ? void 0 : _w.mode) === "field" && /* @__PURE__ */ jsx(
4826
4887
  Select,
4827
4888
  {
4828
4889
  size: "small",
4829
- value: ((_w = (_v = layer.visualConfig) == null ? void 0 : _v.label) == null ? void 0 : _w.fieldName) ?? "",
4890
+ value: ((_y = (_x = layer.visualConfig) == null ? void 0 : _x.label) == null ? void 0 : _y.fieldName) ?? "",
4830
4891
  onChange: (val) => {
4831
4892
  var _a2;
4832
4893
  return onUpdateVisualConfig(layer.id, {
@@ -4842,11 +4903,11 @@ function LayersPanel({
4842
4903
  "data-testid": `select-label-field-${layer.id}`
4843
4904
  }
4844
4905
  ),
4845
- ((_y = (_x = layer.visualConfig) == null ? void 0 : _x.label) == null ? void 0 : _y.mode) === "fixed" && /* @__PURE__ */ jsx(
4906
+ ((_A = (_z = layer.visualConfig) == null ? void 0 : _z.label) == null ? void 0 : _A.mode) === "fixed" && /* @__PURE__ */ jsx(
4846
4907
  Input,
4847
4908
  {
4848
4909
  size: "small",
4849
- value: ((_A = (_z = layer.visualConfig) == null ? void 0 : _z.label) == null ? void 0 : _A.fixedText) ?? "",
4910
+ value: ((_C = (_B = layer.visualConfig) == null ? void 0 : _B.label) == null ? void 0 : _C.fixedText) ?? "",
4850
4911
  onChange: (e) => {
4851
4912
  var _a2;
4852
4913
  return onUpdateVisualConfig(layer.id, {
@@ -4867,7 +4928,7 @@ function LayersPanel({
4867
4928
  Select,
4868
4929
  {
4869
4930
  size: "small",
4870
- value: ((_C = (_B = layer.visualConfig) == null ? void 0 : _B.size) == null ? void 0 : _C.mode) ?? "standard",
4931
+ value: ((_E = (_D = layer.visualConfig) == null ? void 0 : _D.size) == null ? void 0 : _E.mode) ?? "standard",
4871
4932
  onChange: (val) => onUpdateVisualConfig(layer.id, {
4872
4933
  ...layer.visualConfig,
4873
4934
  size: { mode: val }
@@ -4881,11 +4942,11 @@ function LayersPanel({
4881
4942
  "data-testid": `select-size-mode-${layer.id}`
4882
4943
  }
4883
4944
  ),
4884
- ((_E = (_D = layer.visualConfig) == null ? void 0 : _D.size) == null ? void 0 : _E.mode) === "field" && /* @__PURE__ */ jsx(
4945
+ ((_G = (_F = layer.visualConfig) == null ? void 0 : _F.size) == null ? void 0 : _G.mode) === "field" && /* @__PURE__ */ jsx(
4885
4946
  Select,
4886
4947
  {
4887
4948
  size: "small",
4888
- value: ((_G = (_F = layer.visualConfig) == null ? void 0 : _F.size) == null ? void 0 : _G.fieldName) ?? "",
4949
+ value: ((_I = (_H = layer.visualConfig) == null ? void 0 : _H.size) == null ? void 0 : _I.fieldName) ?? "",
4889
4950
  onChange: (val) => onUpdateVisualConfig(layer.id, {
4890
4951
  ...layer.visualConfig,
4891
4952
  size: { mode: "field", fieldName: val }
@@ -4898,11 +4959,11 @@ function LayersPanel({
4898
4959
  "data-testid": `select-size-field-${layer.id}`
4899
4960
  }
4900
4961
  ),
4901
- ((_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: [
4962
+ ((_K = (_J = layer.visualConfig) == null ? void 0 : _J.size) == null ? void 0 : _K.mode) === "override" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
4902
4963
  /* @__PURE__ */ jsx(
4903
4964
  Slider,
4904
4965
  {
4905
- value: ((_K = (_J = layer.visualConfig) == null ? void 0 : _J.size) == null ? void 0 : _K.overrideValue) ?? 5,
4966
+ value: ((_M = (_L = layer.visualConfig) == null ? void 0 : _L.size) == null ? void 0 : _M.overrideValue) ?? 5,
4906
4967
  min: 1,
4907
4968
  max: 10,
4908
4969
  step: 1,
@@ -4913,7 +4974,7 @@ function LayersPanel({
4913
4974
  })
4914
4975
  }
4915
4976
  ),
4916
- /* @__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 })
4977
+ /* @__PURE__ */ jsx("span", { className: "text-sm w-4 text-right", children: ((_O = (_N = layer.visualConfig) == null ? void 0 : _N.size) == null ? void 0 : _O.overrideValue) ?? 5 })
4917
4978
  ] }),
4918
4979
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 text-sm text-muted-foreground pt-0.5", children: [
4919
4980
  /* @__PURE__ */ jsx("span", { className: "w-3.5 h-3.5 rounded-full bg-current" }),
@@ -4923,7 +4984,7 @@ function LayersPanel({
4923
4984
  Select,
4924
4985
  {
4925
4986
  size: "small",
4926
- value: ((_O = (_N = layer.visualConfig) == null ? void 0 : _N.color) == null ? void 0 : _O.mode) ?? "standard",
4987
+ value: ((_Q = (_P = layer.visualConfig) == null ? void 0 : _P.color) == null ? void 0 : _Q.mode) ?? "standard",
4927
4988
  onChange: (val) => onUpdateVisualConfig(layer.id, {
4928
4989
  ...layer.visualConfig,
4929
4990
  color: { mode: val }
@@ -4937,7 +4998,7 @@ function LayersPanel({
4937
4998
  "data-testid": `select-color-mode-${layer.id}`
4938
4999
  }
4939
5000
  ),
4940
- ((_Q = (_P = layer.visualConfig) == null ? void 0 : _P.color) == null ? void 0 : _Q.mode) === "field" && (() => {
5001
+ ((_S = (_R = layer.visualConfig) == null ? void 0 : _R.color) == null ? void 0 : _S.mode) === "field" && (() => {
4941
5002
  var _a2, _b2, _c2, _d2;
4942
5003
  const fields = getLayerFields(layer.id);
4943
5004
  const colorField = (_b2 = (_a2 = layer.visualConfig) == null ? void 0 : _a2.color) == null ? void 0 : _b2.fieldName;
@@ -5004,10 +5065,10 @@ function LayersPanel({
5004
5065
  )
5005
5066
  ] });
5006
5067
  })(),
5007
- ((_S = (_R = layer.visualConfig) == null ? void 0 : _R.color) == null ? void 0 : _S.mode) === "fixed" && /* @__PURE__ */ jsx(
5068
+ ((_U = (_T = layer.visualConfig) == null ? void 0 : _T.color) == null ? void 0 : _U.mode) === "fixed" && /* @__PURE__ */ jsx(
5008
5069
  ColorPickerPopover,
5009
5070
  {
5010
- value: ((_U = (_T = layer.visualConfig) == null ? void 0 : _T.color) == null ? void 0 : _U.fixedColor) ?? "#3b82f6",
5071
+ value: ((_W = (_V = layer.visualConfig) == null ? void 0 : _V.color) == null ? void 0 : _W.fixedColor) ?? "#3b82f6",
5011
5072
  onChange: (color) => {
5012
5073
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
5013
5074
  ...layer.visualConfig,
@@ -5020,7 +5081,7 @@ function LayersPanel({
5020
5081
  testId: `color-fixed-${layer.id}`
5021
5082
  }
5022
5083
  ),
5023
- (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_V = layer.metadata) == null ? void 0 : _V.hidePointFeatures) && /* @__PURE__ */ jsxs(Fragment, { children: [
5084
+ (hasPointFeatures == null ? void 0 : hasPointFeatures(layer.id)) && !((_X = layer.metadata) == null ? void 0 : _X.hidePointFeatures) && /* @__PURE__ */ jsxs(Fragment, { children: [
5024
5085
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 text-sm text-muted-foreground pt-0.5", children: [
5025
5086
  /* @__PURE__ */ jsx(Smile, { className: "w-3.5 h-3.5" }),
5026
5087
  /* @__PURE__ */ jsx("span", { children: "Point Icon" })
@@ -5030,7 +5091,7 @@ function LayersPanel({
5030
5091
  Switch,
5031
5092
  {
5032
5093
  size: "small",
5033
- checked: ((_X = (_W = layer.visualConfig) == null ? void 0 : _W.icon) == null ? void 0 : _X.enabled) ?? false,
5094
+ checked: ((_Z = (_Y = layer.visualConfig) == null ? void 0 : _Y.icon) == null ? void 0 : _Z.enabled) ?? false,
5034
5095
  onChange: (checked) => {
5035
5096
  var _a2, _b2, _c2, _d2;
5036
5097
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
@@ -5045,11 +5106,11 @@ function LayersPanel({
5045
5106
  "data-testid": `switch-icon-${layer.id}`
5046
5107
  }
5047
5108
  ),
5048
- ((_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: [
5109
+ ((_$ = (__ = layer.visualConfig) == null ? void 0 : __.icon) == null ? void 0 : _$.enabled) && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 flex-1", children: [
5049
5110
  /* @__PURE__ */ jsx(
5050
5111
  IconPicker,
5051
5112
  {
5052
- value: ((_$ = (__ = layer.visualConfig) == null ? void 0 : __.icon) == null ? void 0 : _$.icon) ?? "📍",
5113
+ value: ((_ba = (_aa = layer.visualConfig) == null ? void 0 : _aa.icon) == null ? void 0 : _ba.icon) ?? "📍",
5053
5114
  onChange: (icon) => {
5054
5115
  var _a2, _b2;
5055
5116
  onUpdateVisualConfig == null ? void 0 : onUpdateVisualConfig(layer.id, {
@@ -5066,7 +5127,7 @@ function LayersPanel({
5066
5127
  /* @__PURE__ */ jsx(
5067
5128
  Slider,
5068
5129
  {
5069
- value: ((_ba = (_aa = layer.visualConfig) == null ? void 0 : _aa.icon) == null ? void 0 : _ba.size) ?? 24,
5130
+ value: ((_da = (_ca = layer.visualConfig) == null ? void 0 : _ca.icon) == null ? void 0 : _da.size) ?? 24,
5070
5131
  min: 12,
5071
5132
  max: 48,
5072
5133
  step: 2,
@@ -5084,7 +5145,7 @@ function LayersPanel({
5084
5145
  }
5085
5146
  }
5086
5147
  ),
5087
- /* @__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 })
5148
+ /* @__PURE__ */ jsx("span", { className: "text-sm w-6 text-right", children: ((_fa = (_ea = layer.visualConfig) == null ? void 0 : _ea.icon) == null ? void 0 : _fa.size) ?? 24 })
5088
5149
  ] })
5089
5150
  ] })
5090
5151
  ] })
@@ -9620,7 +9681,7 @@ function extract3DFlightPaths(features) {
9620
9681
  paths.push({
9621
9682
  id: feature.id || `path-${paths.length}`,
9622
9683
  coordinates: feature.geometry.coordinates,
9623
- color: ((_a = feature.properties) == null ? void 0 : _a.stroke) || "#3b82f6",
9684
+ color: ((_a = feature.properties) == null ? void 0 : _a.stroke) || DEFAULT_FEATURE_COLOR,
9624
9685
  lineWidth: ((_b = feature.properties) == null ? void 0 : _b["stroke-width"]) || 3
9625
9686
  });
9626
9687
  } else if (feature.geometry.type === "MultiLineString") {
@@ -9631,7 +9692,7 @@ function extract3DFlightPaths(features) {
9631
9692
  paths.push({
9632
9693
  id: `${feature.id || "path"}-${idx}`,
9633
9694
  coordinates: line,
9634
- color: ((_a2 = feature.properties) == null ? void 0 : _a2.stroke) || "#3b82f6",
9695
+ color: ((_a2 = feature.properties) == null ? void 0 : _a2.stroke) || DEFAULT_FEATURE_COLOR,
9635
9696
  lineWidth: ((_b2 = feature.properties) == null ? void 0 : _b2["stroke-width"]) || 3
9636
9697
  });
9637
9698
  }
@@ -9750,6 +9811,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9750
9811
  toastProvider,
9751
9812
  maxFeaturesPerLayer,
9752
9813
  readOnlyShardSize,
9814
+ autoColorNewLayers = false,
9753
9815
  onFeaturesTruncated,
9754
9816
  customGlobalMenuItems,
9755
9817
  extraLayerToolbarButtons,
@@ -9887,6 +9949,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9887
9949
  const shardSize = useMemo(() => resolveShardSize(readOnlyShardSize), [readOnlyShardSize]);
9888
9950
  const shardSizeRef = useRef(shardSize);
9889
9951
  shardSizeRef.current = shardSize;
9952
+ const autoColorNewLayersRef = useRef(autoColorNewLayers);
9953
+ autoColorNewLayersRef.current = autoColorNewLayers;
9954
+ const withAutoColor = useCallback(
9955
+ (layer, features, existing) => autoColorNewLayersRef.current ? withAutoLayerColor(layer, features, existing) : layer,
9956
+ []
9957
+ );
9890
9958
  const capNoticeRef = useRef(/* @__PURE__ */ new Map());
9891
9959
  const notifyFeatureCap = useCallback((info) => {
9892
9960
  if (onFeaturesTruncated) {
@@ -10253,7 +10321,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10253
10321
  colorMap.set(fid, tracePointColors.get(fid));
10254
10322
  return;
10255
10323
  }
10256
- const fallback = ((_a = feature == null ? void 0 : feature.properties) == null ? void 0 : _a.stroke) || "#3b82f6";
10324
+ const fallback = ((_a = feature == null ? void 0 : feature.properties) == null ? void 0 : _a.stroke) || DEFAULT_FEATURE_COLOR;
10257
10325
  let color = fallback;
10258
10326
  const colorConfig = visualConfig == null ? void 0 : visualConfig.color;
10259
10327
  if (colorConfig && feature) {
@@ -11221,7 +11289,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11221
11289
  type: "fill",
11222
11290
  source: "arrow-heads",
11223
11291
  paint: {
11224
- "fill-color": ["coalesce", ["get", "stroke"], "#3b82f6"],
11292
+ "fill-color": ["coalesce", ["get", "stroke"], DEFAULT_FEATURE_COLOR],
11225
11293
  "fill-opacity": ["coalesce", ["get", "stroke-opacity"], 1]
11226
11294
  }
11227
11295
  });
@@ -11249,7 +11317,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
11249
11317
  "text-font": ["Montserrat Medium", "Noto Sans Regular"]
11250
11318
  },
11251
11319
  paint: {
11252
- "text-color": ["coalesce", ["get", "stroke"], "#3b82f6"],
11320
+ "text-color": ["coalesce", ["get", "stroke"], DEFAULT_FEATURE_COLOR],
11253
11321
  "text-halo-color": "#ffffff",
11254
11322
  "text-halo-width": 1.5,
11255
11323
  "text-opacity": ["coalesce", ["get", "stroke-opacity"], 1]
@@ -12422,7 +12490,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12422
12490
  });
12423
12491
  newLayer.featureIds = [];
12424
12492
  }
12425
- const updatedLayers = [...layersRef.current, newLayer];
12493
+ const placedLayer = (options == null ? void 0 : options.autoColor) ? withAutoColor(newLayer, addedFeatures, layersRef.current) : newLayer;
12494
+ const updatedLayers = [...layersRef.current, placedLayer];
12426
12495
  layersRef.current = updatedLayers;
12427
12496
  setLayers(updatedLayers);
12428
12497
  updateFeatureCount();
@@ -13626,9 +13695,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13626
13695
  visible: true,
13627
13696
  featureIds: []
13628
13697
  };
13629
- setLayers((prev) => [...prev, newLayer]);
13698
+ setLayers((prev) => [...prev, withAutoColor(newLayer, [], prev)]);
13630
13699
  setActiveEditingLayerId(newLayer.id);
13631
- }, []);
13700
+ }, [withAutoColor]);
13632
13701
  const handleRemoveLayer = useCallback((layerId) => {
13633
13702
  if (layers.length <= 1) return;
13634
13703
  const layer = layers.find((l) => l.id === layerId);
@@ -13790,17 +13859,20 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13790
13859
  const idSet = new Set(featureIds);
13791
13860
  saveStateForUndo();
13792
13861
  const movedIds = [];
13862
+ const movedFeatures = [];
13793
13863
  featureIds.forEach((id) => {
13794
13864
  var _a;
13795
13865
  const inDraw = (_a = draw.current) == null ? void 0 : _a.get(id);
13796
13866
  if (inDraw) {
13797
13867
  movedIds.push(id);
13868
+ movedFeatures.push(inDraw);
13798
13869
  } else {
13799
13870
  const roFeature = findFeatureById(id);
13800
13871
  if (roFeature) {
13801
13872
  const copy = { ...roFeature, id: void 0, properties: { ...roFeature.properties } };
13802
13873
  const added = draw.current.add(copy);
13803
13874
  movedIds.push(added[0]);
13875
+ movedFeatures.push(copy);
13804
13876
  }
13805
13877
  }
13806
13878
  });
@@ -13814,38 +13886,39 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13814
13886
  } else readOnlyFeatures.current.set(layerId, filtered);
13815
13887
  }
13816
13888
  });
13817
- setLayers((prev) => [
13818
- ...prev.map((l) => {
13889
+ setLayers((prev) => {
13890
+ const remainingLayers = prev.map((l) => {
13819
13891
  const remaining = l.featureIds.filter((id) => !idSet.has(id));
13820
13892
  return remaining.length !== l.featureIds.length ? { ...l, featureIds: remaining } : l;
13821
- }),
13822
- { id: newLayerId, name: layerName, visible: true, featureIds: movedIds }
13823
- ]);
13893
+ });
13894
+ const newLayer = { id: newLayerId, name: layerName, visible: true, featureIds: movedIds };
13895
+ return [...remainingLayers, withAutoColor(newLayer, movedFeatures, remainingLayers)];
13896
+ });
13824
13897
  scheduleSync();
13825
13898
  updateFeatureCount();
13826
13899
  }
13827
- }, [saveStateForUndo, findFeatureById, updateFeatureCount, scheduleSync]);
13900
+ }, [saveStateForUndo, findFeatureById, updateFeatureCount, scheduleSync, withAutoColor]);
13828
13901
  const handleCreateLayerAndCopyFeatures = useCallback((featureIds, layerName) => {
13829
13902
  if (!draw.current) return;
13830
13903
  saveStateForUndo();
13831
13904
  const newIds = [];
13905
+ const copiedFeatures = [];
13832
13906
  featureIds.forEach((id) => {
13833
13907
  const feature = findFeatureById(id);
13834
13908
  if (feature) {
13835
13909
  const copy = { ...feature, id: void 0, properties: { ...feature.properties } };
13836
13910
  const added = draw.current.add(copy);
13837
13911
  newIds.push(added[0]);
13912
+ copiedFeatures.push(copy);
13838
13913
  }
13839
13914
  });
13840
13915
  if (newIds.length > 0) {
13841
13916
  const newLayerId = `layer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
13842
- setLayers((prev) => [
13843
- ...prev,
13844
- { id: newLayerId, name: layerName, visible: true, featureIds: newIds }
13845
- ]);
13917
+ const newLayer = { id: newLayerId, name: layerName, visible: true, featureIds: newIds };
13918
+ setLayers((prev) => [...prev, withAutoColor(newLayer, copiedFeatures, prev)]);
13846
13919
  updateFeatureCount();
13847
13920
  }
13848
- }, [saveStateForUndo, updateFeatureCount, findFeatureById]);
13921
+ }, [saveStateForUndo, updateFeatureCount, findFeatureById, withAutoColor]);
13849
13922
  const getFeatureCountForLayer = useCallback((layerId) => {
13850
13923
  var _a;
13851
13924
  const layer = layers.find((l) => l.id === layerId);
@@ -15552,7 +15625,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15552
15625
  visible: true,
15553
15626
  featureIds: addedIds
15554
15627
  };
15555
- layersRef.current = [...layersRef.current, newLayer];
15628
+ layersRef.current = [...layersRef.current, withAutoColor(newLayer, capped.features, layersRef.current)];
15556
15629
  setLayers(layersRef.current);
15557
15630
  setActiveEditingLayerId(newLayerId);
15558
15631
  targetLayerId = newLayerId;
@@ -15585,7 +15658,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15585
15658
  variant: "destructive"
15586
15659
  });
15587
15660
  }
15588
- }, [onSearchEngineRequest, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, toast, notifyFeatureCap]);
15661
+ }, [onSearchEngineRequest, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, toast, notifyFeatureCap, withAutoColor]);
15589
15662
  const restoreEnrichedGeoJSON = useCallback((enriched) => {
15590
15663
  var _a;
15591
15664
  const mapState = enriched["octostar:map"];
@@ -15731,7 +15804,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15731
15804
  featureIds: prepared.featureIds,
15732
15805
  readOnly: true
15733
15806
  };
15734
- setLayers((prev) => [...prev, newLayer]);
15807
+ setLayers((prev) => [...prev, withAutoColor(newLayer, prepared.features, prev)]);
15735
15808
  updateFeatureCount();
15736
15809
  scheduleTimelineUpdate();
15737
15810
  scheduleSync();
@@ -15746,7 +15819,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15746
15819
  variant: "destructive"
15747
15820
  });
15748
15821
  }
15749
- }, [onWorkspaceLoad, saveStateForUndo, restoreEnrichedGeoJSON, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, toast]);
15822
+ }, [onWorkspaceLoad, saveStateForUndo, restoreEnrichedGeoJSON, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, toast, withAutoColor]);
15750
15823
  const handleWorkspaceSave = useCallback(async () => {
15751
15824
  if (!onWorkspaceSave) return;
15752
15825
  const geojson = buildEnrichedGeoJSON();
@@ -15921,7 +15994,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
15921
15994
  })
15922
15995
  );
15923
15996
  }
15924
- setLayers((prev) => [...prev, newLayer]);
15997
+ setLayers((prev) => [...prev, withAutoColor(newLayer, normalizedFeatures, prev)]);
15925
15998
  updateFeatureCount();
15926
15999
  scheduleTimelineUpdate();
15927
16000
  scheduleSync();
@@ -16027,7 +16100,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
16027
16100
  title: "GeoJSON loaded",
16028
16101
  description: `Added ${appendFeatures.length} features${reprojectMsg}${!(targetLayer == null ? void 0 : targetLayer.visible) ? " (layer hidden)" : ""}`
16029
16102
  });
16030
- }, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad, ingestWithProgress, notifyFeatureCap]);
16103
+ }, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad, ingestWithProgress, notifyFeatureCap, withAutoColor]);
16031
16104
  const handleFileChange = useCallback((e) => {
16032
16105
  var _a;
16033
16106
  const file = (_a = e.target.files) == null ? void 0 : _a[0];
@@ -16099,7 +16172,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
16099
16172
  })
16100
16173
  );
16101
16174
  }
16102
- const nextLayers = [...layersRef.current, newLayer];
16175
+ const nextLayers = [...layersRef.current, withAutoColor(newLayer, normalizedFeatures, layersRef.current)];
16103
16176
  layersRef.current = nextLayers;
16104
16177
  setLayers(nextLayers);
16105
16178
  updateFeatureCount();
@@ -16121,7 +16194,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
16121
16194
  title: "Layer added",
16122
16195
  description: `Created "${newLayer.name}" with ${addedIds.length} features${reprojectMsg} (high-performance)`
16123
16196
  });
16124
- }, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad, ingestWithProgress, notifyFeatureCap]);
16197
+ }, [saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, scheduleSync, restoreEnrichedGeoJSON, toast, interceptGeoJSONFileLoad, ingestWithProgress, notifyFeatureCap, withAutoColor]);
16125
16198
  const handleDropGeoJSON = useCallback((name, data) => {
16126
16199
  void ingestDroppedLayer(name, data);
16127
16200
  }, [ingestDroppedLayer]);