huweili-cesium 1.2.89 → 1.2.91

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.
@@ -54,6 +54,9 @@ export function createBasemapSwitcher() {
54
54
  if (!viewer?.container) return
55
55
 
56
56
  const PANEL_ID = 'cesium-basemap-picker-panel'
57
+ /** 水平工具栏时,面板相对锚点的微调 */
58
+ const PANEL_POSITION_OFFSET = { top: -26, left: -2 }
59
+ const PANEL_GAP = 8
57
60
  let panel = document.getElementById(PANEL_ID)
58
61
 
59
62
  const syncPanelViewport = () => {
@@ -65,13 +68,42 @@ export function createBasemapSwitcher() {
65
68
  const panelRect = panel.getBoundingClientRect()
66
69
  const toolbar = document.querySelector('.cesium-viewer-toolbar')
67
70
  const toolbarRect = toolbar?.getBoundingClientRect()
68
-
69
- let left = (toolbarRect?.left || 0) + (toolbarRect?.width || 0)
70
- let top = buttonRect.bottom - panelRect.height
71
-
72
- if (top < 0) top = margin
73
- if (top + panelRect.height > window.innerHeight) {
74
- top = window.innerHeight - panelRect.height - margin
71
+ const isHorizontalToolbar = toolbar
72
+ ? getComputedStyle(toolbar).flexDirection === 'row'
73
+ : false
74
+
75
+ let left
76
+ let top
77
+
78
+ if (isHorizontalToolbar) {
79
+ // 水平工具栏:面板在触发按钮左上方展开,并钳制在视口内
80
+ left = buttonRect.left - panelRect.width - PANEL_GAP
81
+ top = buttonRect.top - panelRect.height
82
+
83
+ if (left < margin) {
84
+ left = buttonRect.right + PANEL_GAP
85
+ }
86
+
87
+ if (top < margin) top = margin
88
+ if (top + panelRect.height > window.innerHeight - margin) {
89
+ top = window.innerHeight - panelRect.height - margin
90
+ }
91
+ if (left + panelRect.width > window.innerWidth - margin) {
92
+ left = window.innerWidth - panelRect.width - margin
93
+ }
94
+ if (left < margin) left = margin
95
+
96
+ left += PANEL_POSITION_OFFSET.left
97
+ top += PANEL_POSITION_OFFSET.top
98
+ } else {
99
+ // 竖直工具栏:保持原逻辑,面板在工具栏右侧
100
+ left = (toolbarRect?.left || 0) + (toolbarRect?.width || 0)
101
+ top = buttonRect.bottom - panelRect.height
102
+
103
+ if (top < 0) top = margin
104
+ if (top + panelRect.height > window.innerHeight) {
105
+ top = window.innerHeight - panelRect.height - margin
106
+ }
75
107
  }
76
108
 
77
109
  panel.style.position = 'fixed'
@@ -53,6 +53,9 @@ export function createBasemapSwitcher() {
53
53
  if (!viewer?.container) return
54
54
 
55
55
  const PANEL_ID = 'cesium-basemap-picker-panel'
56
+ /** 水平工具栏时,面板相对锚点的微调 */
57
+ const PANEL_POSITION_OFFSET = { top: -26, left: -2 }
58
+ const PANEL_GAP = 8
56
59
  let panel = document.getElementById(PANEL_ID)
57
60
 
58
61
  const syncPanelViewport = () => {
@@ -64,13 +67,42 @@ export function createBasemapSwitcher() {
64
67
  const panelRect = panel.getBoundingClientRect()
65
68
  const toolbar = document.querySelector('.cesium-viewer-toolbar')
66
69
  const toolbarRect = toolbar?.getBoundingClientRect()
67
-
68
- let left = (toolbarRect?.left || 0) + (toolbarRect?.width || 0)
69
- let top = buttonRect.bottom - panelRect.height
70
-
71
- if (top < 0) top = margin
72
- if (top + panelRect.height > window.innerHeight) {
73
- top = window.innerHeight - panelRect.height - margin
70
+ const isHorizontalToolbar = toolbar
71
+ ? getComputedStyle(toolbar).flexDirection === 'row'
72
+ : false
73
+
74
+ let left
75
+ let top
76
+
77
+ if (isHorizontalToolbar) {
78
+ // 水平工具栏:面板在触发按钮左上方展开,并钳制在视口内
79
+ left = buttonRect.left - panelRect.width - PANEL_GAP
80
+ top = buttonRect.top - panelRect.height
81
+
82
+ if (left < margin) {
83
+ left = buttonRect.right + PANEL_GAP
84
+ }
85
+
86
+ if (top < margin) top = margin
87
+ if (top + panelRect.height > window.innerHeight - margin) {
88
+ top = window.innerHeight - panelRect.height - margin
89
+ }
90
+ if (left + panelRect.width > window.innerWidth - margin) {
91
+ left = window.innerWidth - panelRect.width - margin
92
+ }
93
+ if (left < margin) left = margin
94
+
95
+ left += PANEL_POSITION_OFFSET.left
96
+ top += PANEL_POSITION_OFFSET.top
97
+ } else {
98
+ // 竖直工具栏:保持原逻辑,面板在工具栏右侧
99
+ left = (toolbarRect?.left || 0) + (toolbarRect?.width || 0)
100
+ top = buttonRect.bottom - panelRect.height
101
+
102
+ if (top < 0) top = margin
103
+ if (top + panelRect.height > window.innerHeight) {
104
+ top = window.innerHeight - panelRect.height - margin
105
+ }
74
106
  }
75
107
 
76
108
  panel.style.position = 'fixed'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "huweili-cesium",
3
- "version": "1.2.89",
3
+ "version": "1.2.91",
4
4
  "description": "基于 Cesium 的地图工具库(无人机态势、轨迹、围栏、工具栏等)",
5
5
  "type": "module",
6
6
  "main": "./index.js",