huweili-cesium 1.2.42 → 1.2.43
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/js/basis.js +105 -1
- package/package.json +1 -1
package/js/basis.js
CHANGED
|
@@ -721,6 +721,109 @@ export function basicConfig() {
|
|
|
721
721
|
}
|
|
722
722
|
}
|
|
723
723
|
|
|
724
|
+
/**
|
|
725
|
+
* 创建工具栏展开/折叠和拖拽控制器
|
|
726
|
+
* - 单击展开按钮:初始化拖拽能力,不触发展开/折叠
|
|
727
|
+
* - 双击展开按钮:展开/折叠同级工具栏按钮
|
|
728
|
+
* - 拖拽展开按钮:移动整个工具栏按钮组
|
|
729
|
+
*/
|
|
730
|
+
const createToolbarExpandController = () => {
|
|
731
|
+
let isToolbarExpanded = true
|
|
732
|
+
let isToolbarDragging = false
|
|
733
|
+
|
|
734
|
+
const applyToggleExpand = (btn) => {
|
|
735
|
+
const toolbar = btn?.parentElement
|
|
736
|
+
if (!toolbar) return
|
|
737
|
+
|
|
738
|
+
isToolbarExpanded = !isToolbarExpanded
|
|
739
|
+
|
|
740
|
+
Array.from(toolbar.children).forEach((item) => {
|
|
741
|
+
if (item === btn) return
|
|
742
|
+
item.style.display = isToolbarExpanded ? '' : 'none'
|
|
743
|
+
})
|
|
744
|
+
|
|
745
|
+
btn.title = isToolbarExpanded ? '收缩' : '展开'
|
|
746
|
+
btn.setAttribute('aria-expanded', String(isToolbarExpanded))
|
|
747
|
+
btn.classList.toggle('is-collapsed', !isToolbarExpanded)
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
const setupToolbarDrag = (btn) => {
|
|
751
|
+
if (!btn || btn.dataset.toolbarDragReady === 'true') return
|
|
752
|
+
|
|
753
|
+
btn.dataset.toolbarDragReady = 'true'
|
|
754
|
+
btn.style.cursor = 'move'
|
|
755
|
+
|
|
756
|
+
btn.addEventListener('dblclick', (event) => {
|
|
757
|
+
event.preventDefault()
|
|
758
|
+
event.stopPropagation()
|
|
759
|
+
if (isToolbarDragging) return
|
|
760
|
+
applyToggleExpand(btn)
|
|
761
|
+
})
|
|
762
|
+
|
|
763
|
+
btn.addEventListener('pointerdown', (event) => {
|
|
764
|
+
const toolbar = btn.parentElement
|
|
765
|
+
if (!toolbar) return
|
|
766
|
+
|
|
767
|
+
const startX = event.clientX
|
|
768
|
+
const startY = event.clientY
|
|
769
|
+
const rect = toolbar.getBoundingClientRect()
|
|
770
|
+
const startLeft = rect.left
|
|
771
|
+
const startTop = rect.top
|
|
772
|
+
let hasMoved = false
|
|
773
|
+
|
|
774
|
+
toolbar.style.position = 'fixed'
|
|
775
|
+
toolbar.style.left = `${startLeft}px`
|
|
776
|
+
toolbar.style.top = `${startTop}px`
|
|
777
|
+
toolbar.style.right = 'auto'
|
|
778
|
+
toolbar.style.bottom = 'auto'
|
|
779
|
+
toolbar.style.zIndex = toolbar.style.zIndex || '9999'
|
|
780
|
+
toolbar.style.margin = '0'
|
|
781
|
+
|
|
782
|
+
const moveToolbar = (moveEvent) => {
|
|
783
|
+
const deltaX = moveEvent.clientX - startX
|
|
784
|
+
const deltaY = moveEvent.clientY - startY
|
|
785
|
+
|
|
786
|
+
if (Math.abs(deltaX) > 3 || Math.abs(deltaY) > 3) {
|
|
787
|
+
hasMoved = true
|
|
788
|
+
isToolbarDragging = true
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
const maxLeft = window.innerWidth - toolbar.offsetWidth
|
|
792
|
+
const maxTop = window.innerHeight - toolbar.offsetHeight
|
|
793
|
+
const nextLeft = Math.min(Math.max(startLeft + deltaX, 0), Math.max(maxLeft, 0))
|
|
794
|
+
const nextTop = Math.min(Math.max(startTop + deltaY, 0), Math.max(maxTop, 0))
|
|
795
|
+
|
|
796
|
+
toolbar.style.left = `${nextLeft}px`
|
|
797
|
+
toolbar.style.top = `${nextTop}px`
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
const stopDrag = () => {
|
|
801
|
+
window.removeEventListener('pointermove', moveToolbar)
|
|
802
|
+
window.removeEventListener('pointerup', stopDrag)
|
|
803
|
+
window.removeEventListener('pointercancel', stopDrag)
|
|
804
|
+
|
|
805
|
+
if (hasMoved) {
|
|
806
|
+
window.setTimeout(() => {
|
|
807
|
+
isToolbarDragging = false
|
|
808
|
+
}, 0)
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
window.addEventListener('pointermove', moveToolbar)
|
|
813
|
+
window.addEventListener('pointerup', stopDrag)
|
|
814
|
+
window.addEventListener('pointercancel', stopDrag)
|
|
815
|
+
})
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
return {
|
|
819
|
+
toggleExpand: (_viewer, btn) => {
|
|
820
|
+
setupToolbarDrag(btn)
|
|
821
|
+
},
|
|
822
|
+
setupToolbarDrag,
|
|
823
|
+
applyToggleExpand,
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
|
|
724
827
|
/**
|
|
725
828
|
* 以当前视口中心点为锚点,在 2D 俯视 / 3D 斜视之间切换(不依赖 RTK)
|
|
726
829
|
* @param {string=} mapId 地图实例ID
|
|
@@ -781,8 +884,9 @@ export function basicConfig() {
|
|
|
781
884
|
applyOrthographicFrustum,
|
|
782
885
|
restorePerspectiveFrustum,
|
|
783
886
|
setInitialCameraView,
|
|
887
|
+
createToolbarExpandController,
|
|
784
888
|
syncCameraInteractionMode: (map, mapId, sceneMode) =>
|
|
785
|
-
|
|
889
|
+
syncCameraInteractionMode(map, mapId, sceneMode, orthoViewHelpers()),
|
|
786
890
|
}
|
|
787
891
|
}
|
|
788
892
|
|