huweili-cesium 1.2.47 → 1.2.49

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.
Files changed (2) hide show
  1. package/js/basis.js +94 -4
  2. package/package.json +1 -1
package/js/basis.js CHANGED
@@ -760,12 +760,60 @@ export function basicConfig() {
760
760
  zoomOutDefault(mapId, factor)
761
761
  }
762
762
 
763
+ const defaultVisibleTitles = ['指北针', '2D/3D视角切换', '降低视角', '抬升视角', '更多']
764
+ let isMoreExpanded = false
765
+
766
+ const isDefaultVisibleToolbarItem = (item) => {
767
+ const title = item?.getAttribute?.('title') || item?.title || item?.textContent?.trim()
768
+ return defaultVisibleTitles.includes(title)
769
+ }
770
+
771
+ const applyMoreVisible = (toolbar, expanded) => {
772
+ if (!toolbar) return
773
+
774
+ Array.from(toolbar.children).forEach((item) => {
775
+ const isDefaultVisible = isDefaultVisibleToolbarItem(item)
776
+ item.style.display = expanded || isDefaultVisible ? '' : 'none'
777
+ })
778
+ }
779
+
780
+ const setupDefaultMoreVisible = (retryCount = 0) => {
781
+ if (typeof window === 'undefined' || typeof document === 'undefined') return
782
+
783
+ const moreBtn = document.querySelector('[title="更多"]')
784
+ const toolbar = moreBtn?.parentElement
785
+
786
+ if (toolbar) {
787
+ applyMoreVisible(toolbar, isMoreExpanded)
788
+ return
789
+ }
790
+
791
+ if (retryCount < 20) {
792
+ window.setTimeout(() => setupDefaultMoreVisible(retryCount + 1), 100)
793
+ }
794
+ }
795
+
796
+ if (typeof window !== 'undefined') {
797
+ window.requestAnimationFrame(() => setupDefaultMoreVisible())
798
+ }
799
+
800
+ const toggleMoreButtons = (_viewer, btn) => {
801
+ const toolbar = btn?.parentElement
802
+ if (!toolbar) return
803
+
804
+ isMoreExpanded = !isMoreExpanded
805
+ applyMoreVisible(toolbar, isMoreExpanded)
806
+ btn.title = isMoreExpanded ? '收起更多' : '更多'
807
+ btn.setAttribute('aria-expanded', String(isMoreExpanded))
808
+ }
809
+
763
810
  return [
764
811
  {
765
812
  index: 0,
766
813
  title: '指北针',
767
814
  text: 'N',
768
815
  isCompass: true,
816
+ isDefaultVisible: true,
769
817
  onClick: () => resetCompassDirection(),
770
818
  },
771
819
  {
@@ -792,9 +840,10 @@ export function basicConfig() {
792
840
  },
793
841
  },
794
842
  {
795
- index: 3,
843
+ index: 4,
796
844
  title: '2D/3D视角切换',
797
845
  text: '2D',
846
+ isDefaultVisible: true,
798
847
  onClick: (_v, btn) => {
799
848
  const result = toggleViewAtViewportCenter(mapId, {
800
849
  distance2D,
@@ -806,23 +855,33 @@ export function basicConfig() {
806
855
  },
807
856
  },
808
857
  {
809
- index: 4,
858
+ index: 5,
810
859
  title: '降低视角',
811
860
  iconSrc: `${baseUrl}/images/new/jia.svg`,
861
+ isDefaultVisible: true,
812
862
  onClick: () => zoomIn(),
813
863
  },
814
864
  {
815
- index: 5,
865
+ index: 6,
816
866
  title: '抬升视角',
817
867
  iconSrc: `${baseUrl}/images/new/jian.svg`,
868
+ isDefaultVisible: true,
818
869
  onClick: () => zoomOut(),
819
870
  },
820
871
  {
821
- index: 6,
872
+ index: 7,
822
873
  title: '切换底图',
823
874
  iconSrc: `${baseUrl}/images/new/map.svg`,
824
875
  onClick: (v, btn) => toggleBasemapPickerPanel(v, btn || null),
825
876
  },
877
+ {
878
+ index: 1000,
879
+ title: '更多',
880
+ text: '更多',
881
+ isDefaultVisible: true,
882
+ isMoreToggle: true,
883
+ onClick: (v, btn) => toggleMoreButtons(v, btn),
884
+ },
826
885
  ]
827
886
  }
828
887
 
@@ -834,6 +893,8 @@ export function basicConfig() {
834
893
  */
835
894
  const createToolbarExpandController = ({
836
895
  storageKey = 'huweili-cesium-toolbar-position',
896
+ toggleIconSrc = '',
897
+ autoRestore = true,
837
898
  } = {}) => {
838
899
  let isToolbarExpanded = true
839
900
  let isToolbarDragging = false
@@ -995,12 +1056,41 @@ export function basicConfig() {
995
1056
  })
996
1057
  }
997
1058
 
1059
+ const findExpandButtonByIcon = () => {
1060
+ if (!toggleIconSrc || typeof document === 'undefined') return null
1061
+
1062
+ const images = Array.from(document.querySelectorAll('img'))
1063
+ const icon = images.find((img) => img.src?.includes(toggleIconSrc) || img.getAttribute('src')?.includes(toggleIconSrc))
1064
+ if (!icon) return null
1065
+
1066
+ return icon.closest('button') || icon.parentElement
1067
+ }
1068
+
1069
+ const autoRestoreToolbarPosition = (retryCount = 0) => {
1070
+ if (!autoRestore || typeof window === 'undefined') return
1071
+
1072
+ const btn = findExpandButtonByIcon()
1073
+ if (btn) {
1074
+ setupToolbarDrag(btn)
1075
+ return
1076
+ }
1077
+
1078
+ if (retryCount < 20) {
1079
+ window.setTimeout(() => autoRestoreToolbarPosition(retryCount + 1), 100)
1080
+ }
1081
+ }
1082
+
1083
+ if (autoRestore && typeof window !== 'undefined') {
1084
+ window.requestAnimationFrame(() => autoRestoreToolbarPosition())
1085
+ }
1086
+
998
1087
  return {
999
1088
  toggleExpand: (_viewer, btn) => {
1000
1089
  if (btn) setupToolbarDrag(btn)
1001
1090
  },
1002
1091
  setupToolbarDrag,
1003
1092
  applyToggleExpand,
1093
+ restoreToolbarPosition,
1004
1094
  }
1005
1095
  }
1006
1096
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "huweili-cesium",
3
- "version": "1.2.47",
3
+ "version": "1.2.49",
4
4
  "description": "基于 Cesium 的地图工具库(无人机态势、轨迹、围栏、工具栏等)",
5
5
  "type": "module",
6
6
  "main": "./index.js",