@octostar/map-component 0.7.0 → 0.7.1

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
@@ -10,7 +10,7 @@ import proj4 from "proj4";
10
10
  import { Button, Modal, Input, App, message, ConfigProvider, Tooltip, Dropdown, Divider, Popover, Switch, Slider, Tag, Select, Segmented, DatePicker, Collapse, ColorPicker, Tabs, Card, Table } from "antd";
11
11
  import { clsx } from "clsx";
12
12
  import { twMerge } from "tailwind-merge";
13
- 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, ChevronLeft, SkipBack, Pause, Play, Clock, AlertTriangle, TestTube, Users, GripVertical, Plane, FileJson, Check, Phone, Car, AlertCircle } from "lucide-react";
13
+ 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, RotateCcw, RefreshCw, ExternalLink, Info, ChevronLeft, SkipBack, Pause, Play, Clock, AlertTriangle, TestTube, Users, GripVertical, Plane, FileJson, Check, Phone, Car, AlertCircle } from "lucide-react";
14
14
  import { createPortal } from "react-dom";
15
15
  import dayjs from "dayjs";
16
16
  import { createStore, useStore } from "zustand";
@@ -902,6 +902,116 @@ function buildHostLabelLayout() {
902
902
  function buildHostLabelPaint() {
903
903
  return { ...buildCustomLabelPaint(), "text-color": ["coalesce", ["get", "fontColor"], "#1f2937"] };
904
904
  }
905
+ const CLUSTER_COUNT_VALUE_PROP = "__cluster_count_value";
906
+ const CLUSTER_SUM_PROP = "value_sum";
907
+ const CLUSTER_MEMBER_ID_PROP = "__cluster_fid";
908
+ function clusterCountValue(raw) {
909
+ if (typeof raw === "number") return Number.isFinite(raw) ? raw : 1;
910
+ if (typeof raw === "string" && raw.trim() !== "") {
911
+ const n = Number(raw);
912
+ if (Number.isFinite(n)) return n;
913
+ }
914
+ return 1;
915
+ }
916
+ function injectClusterCountValues(features, fieldName) {
917
+ return features.map((f) => {
918
+ var _a;
919
+ return {
920
+ ...f,
921
+ properties: {
922
+ ...f.properties,
923
+ [CLUSTER_COUNT_VALUE_PROP]: clusterCountValue((_a = f.properties) == null ? void 0 : _a[fieldName]),
924
+ ...f.id != null ? { [CLUSTER_MEMBER_ID_PROP]: String(f.id) } : {}
925
+ }
926
+ };
927
+ });
928
+ }
929
+ function roundHalfAwayFromZero1(n) {
930
+ return Math.sign(n) * Math.round(Math.abs(n) * 10) / 10;
931
+ }
932
+ function formatClusterBadge(value) {
933
+ if (value >= 1e6) return `${roundHalfAwayFromZero1(value / 1e6)}M`;
934
+ if (value >= 1e3) return `${roundHalfAwayFromZero1(value / 1e3)}k`;
935
+ return String(roundHalfAwayFromZero1(value));
936
+ }
937
+ function clusterBadgeTextField(prop) {
938
+ const value = ["get", prop];
939
+ const round1 = (expr) => ["/", ["round", ["*", expr, 10]], 10];
940
+ return [
941
+ "step",
942
+ value,
943
+ ["to-string", round1(value)],
944
+ 1e3,
945
+ ["concat", ["to-string", round1(["/", value, 1e3])], "k"],
946
+ 1e6,
947
+ ["concat", ["to-string", round1(["/", value, 1e6])], "M"]
948
+ ];
949
+ }
950
+ const FILL_PICKED_PROP = "fillPicked";
951
+ const INTERNAL_PROPERTY_KEYS = /* @__PURE__ */ new Set([
952
+ "fill",
953
+ "fill-opacity",
954
+ "pointRadius",
955
+ "pointIcon",
956
+ "pointIconSize",
957
+ "circleCenter",
958
+ "circleRadius",
959
+ "icon",
960
+ "iconSize",
961
+ "fontSize",
962
+ "fontColor",
963
+ "fontWeight",
964
+ "arrowSize",
965
+ "arrowInset",
966
+ "iconFullZoom",
967
+ "iconMinZoom",
968
+ "iconMinScale",
969
+ "label",
970
+ "entityType",
971
+ "kind",
972
+ "meta:type",
973
+ "stroke",
974
+ "stroke-width",
975
+ "stroke-opacity",
976
+ FILL_PICKED_PROP,
977
+ CLUSTER_COUNT_VALUE_PROP,
978
+ CLUSTER_MEMBER_ID_PROP
979
+ ]);
980
+ const STYLING_PROPERTY_KEYS = [
981
+ "stroke",
982
+ "stroke-width",
983
+ "stroke-opacity",
984
+ "fill",
985
+ "fill-opacity",
986
+ FILL_PICKED_PROP,
987
+ "pointRadius",
988
+ "pointIcon",
989
+ "pointIconSize",
990
+ "icon",
991
+ "iconSize",
992
+ "circleCenter",
993
+ "circleRadius",
994
+ "fontSize",
995
+ "fontColor",
996
+ "fontWeight",
997
+ "arrowSize",
998
+ "arrowInset",
999
+ "iconFullZoom",
1000
+ "iconMinZoom",
1001
+ "iconMinScale"
1002
+ ];
1003
+ const INTERNAL_PROPERTY_PREFIXES = [
1004
+ "IsHiddenBy",
1005
+ "isHidden",
1006
+ "isSelected",
1007
+ "isTrace",
1008
+ "isTimeline",
1009
+ "trace"
1010
+ ];
1011
+ function isInternalProperty(key) {
1012
+ if (INTERNAL_PROPERTY_KEYS.has(key)) return true;
1013
+ return INTERNAL_PROPERTY_PREFIXES.some((prefix) => key.startsWith(prefix));
1014
+ }
905
1015
  const DEFAULT_FEATURE_COLOR = "#3b82f6";
906
1016
  const LAYER_COLOR_PALETTE = [
907
1017
  "#3FB37F",
@@ -942,10 +1052,14 @@ function pickLayerColor(layers) {
942
1052
  }
943
1053
  return best;
944
1054
  }
1055
+ function ownFill(properties) {
1056
+ const fill = properties == null ? void 0 : properties.fill;
1057
+ return (properties == null ? void 0 : properties[FILL_PICKED_PROP]) === true && typeof fill === "string" && fill !== "" ? fill : void 0;
1058
+ }
1059
+ const isOwnColor = (color) => typeof color === "string" && color !== "" && color.toLowerCase() !== DEFAULT_FEATURE_COLOR;
945
1060
  function carriesOwnColor(feature) {
946
1061
  var _a;
947
- const stroke = (_a = feature.properties) == null ? void 0 : _a.stroke;
948
- return typeof stroke === "string" && stroke !== "" && stroke.toLowerCase() !== DEFAULT_FEATURE_COLOR;
1062
+ return isOwnColor((_a = feature.properties) == null ? void 0 : _a.stroke) || isOwnColor(ownFill(feature.properties));
949
1063
  }
950
1064
  function withAutoLayerColor(layer, features, existing) {
951
1065
  var _a;
@@ -2387,16 +2501,9 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2387
2501
  const featureId = String(f.id);
2388
2502
  const visualConfig = layer == null ? void 0 : layer.visualConfig;
2389
2503
  const baseOpacity = ((_a = f.properties) == null ? void 0 : _a["stroke-opacity"]) ?? DEFAULT_VISIBLE_STROKE_OPACITY;
2390
- let strokeColor = ((_b = f.properties) == null ? void 0 : _b.stroke) || DEFAULT_FEATURE_COLOR;
2391
2504
  const colorConfig = visualConfig == null ? void 0 : visualConfig.color;
2392
- if (colorConfig) {
2393
- strokeColor = resolveFeatureColor(
2394
- colorConfig,
2395
- f.properties,
2396
- strokeColor,
2397
- layer ? ctx.colorFieldRanges.get(layer.id) : void 0
2398
- );
2399
- }
2505
+ const layerColor = colorConfig ? resolveFeatureColor(colorConfig, f.properties, "", layer ? ctx.colorFieldRanges.get(layer.id) : void 0) : "";
2506
+ let strokeColor = layerColor || ((_b = f.properties) == null ? void 0 : _b.stroke) || DEFAULT_FEATURE_COLOR;
2400
2507
  let strokeWidth = ((_c = f.properties) == null ? void 0 : _c["stroke-width"]) || 2;
2401
2508
  let pointRadius = Math.round(3 + strokeWidth);
2402
2509
  const sizeConfig = visualConfig == null ? void 0 : visualConfig.size;
@@ -2506,7 +2613,7 @@ function styleFeatureForPaint(f, layer, ctx, slim) {
2506
2613
  stroke: strokeColor,
2507
2614
  "stroke-width": strokeWidth,
2508
2615
  "stroke-opacity": visibleStrokeOpacity,
2509
- fill: strokeColor,
2616
+ fill: layerColor ? strokeColor : ownFill(f.properties) ?? strokeColor,
2510
2617
  "fill-opacity": visibleFillOpacity,
2511
2618
  pointRadius,
2512
2619
  _labelPriority: labelPriority2,
@@ -6594,7 +6701,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
6594
6701
  setStrokeColor(feature.properties.stroke || "#3b82f6");
6595
6702
  setStrokeWidth(feature.properties["stroke-width"] || 2);
6596
6703
  setStrokeOpacity(feature.properties["stroke-opacity"] ?? 1);
6597
- setFillColor(feature.properties.fill || "#3b82f6");
6704
+ setFillColor(ownFill(feature.properties) ?? (feature.properties.stroke || "#3b82f6"));
6598
6705
  setFillOpacity(feature.properties["fill-opacity"] ?? 0.2);
6599
6706
  setFontSize(feature.properties.fontSize || 14);
6600
6707
  setFontColor(feature.properties.fontColor || "#000000");
@@ -6652,7 +6759,8 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
6652
6759
  "longitude",
6653
6760
  // The marker color is shown via the colored dot in the panel header,
6654
6761
  // so we don't repeat it as an editable property row.
6655
- "color"
6762
+ "color",
6763
+ FILL_PICKED_PROP
6656
6764
  ]);
6657
6765
  const isReservedKey = buildKeyExclusionPredicate(reserved);
6658
6766
  const custom = [];
@@ -6703,9 +6811,15 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
6703
6811
  "stroke": (overrides == null ? void 0 : overrides.strokeColor) ?? strokeColor,
6704
6812
  "stroke-width": (overrides == null ? void 0 : overrides.strokeWidth) ?? strokeWidth,
6705
6813
  "stroke-opacity": (overrides == null ? void 0 : overrides.strokeOpacity) ?? strokeOpacity,
6706
- "fill": (overrides == null ? void 0 : overrides.fillColor) ?? fillColor,
6707
6814
  "fill-opacity": (overrides == null ? void 0 : overrides.fillOpacity) ?? fillOpacity
6708
6815
  };
6816
+ if ((overrides == null ? void 0 : overrides.fillColor) === null) {
6817
+ properties.fill = void 0;
6818
+ properties[FILL_PICKED_PROP] = void 0;
6819
+ } else if ((overrides == null ? void 0 : overrides.fillColor) !== void 0) {
6820
+ properties.fill = overrides.fillColor;
6821
+ properties[FILL_PICKED_PROP] = true;
6822
+ }
6709
6823
  if ((overrides == null ? void 0 : overrides.entityType) !== void 0) {
6710
6824
  properties.entityType = overrides.entityType;
6711
6825
  } else if (entityType !== void 0) {
@@ -6742,7 +6856,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
6742
6856
  }
6743
6857
  });
6744
6858
  onUpdateProperties(feature.id, properties);
6745
- }, [feature, name, description, startDate, endDate, strokeColor, strokeWidth, strokeOpacity, fillColor, fillOpacity, fontSize, fontColor, fontWeight, arrowSize, pointIcon, pointIconSize, entityType, customProperties, onUpdateProperties, isEditMode]);
6859
+ }, [feature, name, description, startDate, endDate, strokeColor, strokeWidth, strokeOpacity, fillOpacity, fontSize, fontColor, fontWeight, arrowSize, pointIcon, pointIconSize, entityType, customProperties, onUpdateProperties, isEditMode]);
6746
6860
  const handleAddProperty = useCallback(() => {
6747
6861
  if (!newPropertyKey.trim() || !isEditMode) return;
6748
6862
  setCustomProperties((prev) => [...prev, { key: newPropertyKey.trim(), value: "" }]);
@@ -7209,6 +7323,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
7209
7323
  onChange: (color) => {
7210
7324
  const hex = color.toHexString();
7211
7325
  setStrokeColor(hex);
7326
+ if (!ownFill(feature.properties)) setFillColor(hex);
7212
7327
  handleSave({ strokeColor: hex });
7213
7328
  },
7214
7329
  disabled: !isEditMode,
@@ -7295,6 +7410,20 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
7295
7410
  "data-testid": "color-picker-fill"
7296
7411
  }
7297
7412
  ) }) }),
7413
+ isEditMode && ownFill(feature.properties) && /* @__PURE__ */ jsx(Tooltip, { title: "Reset fill to the stroke colour", children: /* @__PURE__ */ jsx(
7414
+ Button,
7415
+ {
7416
+ size: "small",
7417
+ type: "text",
7418
+ icon: /* @__PURE__ */ jsx(RotateCcw, { className: "w-3 h-3" }),
7419
+ "aria-label": "Reset fill to the stroke colour",
7420
+ onClick: () => {
7421
+ setFillColor(strokeColor);
7422
+ handleSave({ fillColor: null });
7423
+ },
7424
+ "data-testid": "button-reset-fill"
7425
+ }
7426
+ ) }),
7298
7427
  /* @__PURE__ */ jsx(Tooltip, { title: "Fill Opacity", children: /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1", children: [
7299
7428
  /* @__PURE__ */ jsx(Blend, { className: "w-3 h-3 text-muted-foreground" }),
7300
7429
  /* @__PURE__ */ jsx(
@@ -9630,113 +9759,6 @@ function buildSelectionOverlayData(ids, styleFor) {
9630
9759
  });
9631
9760
  return { type: "FeatureCollection", features };
9632
9761
  }
9633
- const CLUSTER_COUNT_VALUE_PROP = "__cluster_count_value";
9634
- const CLUSTER_SUM_PROP = "value_sum";
9635
- const CLUSTER_MEMBER_ID_PROP = "__cluster_fid";
9636
- function clusterCountValue(raw) {
9637
- if (typeof raw === "number") return Number.isFinite(raw) ? raw : 1;
9638
- if (typeof raw === "string" && raw.trim() !== "") {
9639
- const n = Number(raw);
9640
- if (Number.isFinite(n)) return n;
9641
- }
9642
- return 1;
9643
- }
9644
- function injectClusterCountValues(features, fieldName) {
9645
- return features.map((f) => {
9646
- var _a;
9647
- return {
9648
- ...f,
9649
- properties: {
9650
- ...f.properties,
9651
- [CLUSTER_COUNT_VALUE_PROP]: clusterCountValue((_a = f.properties) == null ? void 0 : _a[fieldName]),
9652
- ...f.id != null ? { [CLUSTER_MEMBER_ID_PROP]: String(f.id) } : {}
9653
- }
9654
- };
9655
- });
9656
- }
9657
- function roundHalfAwayFromZero1(n) {
9658
- return Math.sign(n) * Math.round(Math.abs(n) * 10) / 10;
9659
- }
9660
- function formatClusterBadge(value) {
9661
- if (value >= 1e6) return `${roundHalfAwayFromZero1(value / 1e6)}M`;
9662
- if (value >= 1e3) return `${roundHalfAwayFromZero1(value / 1e3)}k`;
9663
- return String(roundHalfAwayFromZero1(value));
9664
- }
9665
- function clusterBadgeTextField(prop) {
9666
- const value = ["get", prop];
9667
- const round1 = (expr) => ["/", ["round", ["*", expr, 10]], 10];
9668
- return [
9669
- "step",
9670
- value,
9671
- ["to-string", round1(value)],
9672
- 1e3,
9673
- ["concat", ["to-string", round1(["/", value, 1e3])], "k"],
9674
- 1e6,
9675
- ["concat", ["to-string", round1(["/", value, 1e6])], "M"]
9676
- ];
9677
- }
9678
- const INTERNAL_PROPERTY_KEYS = /* @__PURE__ */ new Set([
9679
- "fill",
9680
- "fill-opacity",
9681
- "pointRadius",
9682
- "pointIcon",
9683
- "pointIconSize",
9684
- "circleCenter",
9685
- "circleRadius",
9686
- "icon",
9687
- "iconSize",
9688
- "fontSize",
9689
- "fontColor",
9690
- "fontWeight",
9691
- "arrowSize",
9692
- "arrowInset",
9693
- "iconFullZoom",
9694
- "iconMinZoom",
9695
- "iconMinScale",
9696
- "label",
9697
- "entityType",
9698
- "kind",
9699
- "meta:type",
9700
- "stroke",
9701
- "stroke-width",
9702
- "stroke-opacity",
9703
- CLUSTER_COUNT_VALUE_PROP,
9704
- CLUSTER_MEMBER_ID_PROP
9705
- ]);
9706
- const STYLING_PROPERTY_KEYS = [
9707
- "stroke",
9708
- "stroke-width",
9709
- "stroke-opacity",
9710
- "fill",
9711
- "fill-opacity",
9712
- "pointRadius",
9713
- "pointIcon",
9714
- "pointIconSize",
9715
- "icon",
9716
- "iconSize",
9717
- "circleCenter",
9718
- "circleRadius",
9719
- "fontSize",
9720
- "fontColor",
9721
- "fontWeight",
9722
- "arrowSize",
9723
- "arrowInset",
9724
- "iconFullZoom",
9725
- "iconMinZoom",
9726
- "iconMinScale"
9727
- ];
9728
- const INTERNAL_PROPERTY_PREFIXES = [
9729
- "IsHiddenBy",
9730
- "isHidden",
9731
- "isSelected",
9732
- "isTrace",
9733
- "isTimeline",
9734
- "trace"
9735
- ];
9736
- function isInternalProperty(key) {
9737
- if (INTERNAL_PROPERTY_KEYS.has(key)) return true;
9738
- return INTERNAL_PROPERTY_PREFIXES.some((prefix) => key.startsWith(prefix));
9739
- }
9740
9762
  function computeBubbleDomain(values) {
9741
9763
  let min = Infinity;
9742
9764
  let max = -Infinity;