huweili-cesium 1.2.45 → 1.2.47
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 +64 -47
- package/package.json +1 -1
package/js/basis.js
CHANGED
|
@@ -874,10 +874,17 @@ export function basicConfig() {
|
|
|
874
874
|
}
|
|
875
875
|
|
|
876
876
|
const applyToolbarPosition = (toolbar, left, top) => {
|
|
877
|
-
if (!toolbar) return
|
|
877
|
+
if (!toolbar) return false
|
|
878
|
+
|
|
879
|
+
const toolbarWidth = toolbar.offsetWidth
|
|
880
|
+
const toolbarHeight = toolbar.offsetHeight
|
|
881
|
+
const viewportWidth = window.innerWidth
|
|
882
|
+
const viewportHeight = window.innerHeight
|
|
878
883
|
|
|
879
|
-
|
|
880
|
-
|
|
884
|
+
if (!toolbarWidth || !toolbarHeight || !viewportWidth || !viewportHeight) return false
|
|
885
|
+
|
|
886
|
+
const maxLeft = viewportWidth - toolbarWidth
|
|
887
|
+
const maxTop = viewportHeight - toolbarHeight
|
|
881
888
|
const nextLeft = Math.min(Math.max(left, 0), Math.max(maxLeft, 0))
|
|
882
889
|
const nextTop = Math.min(Math.max(top, 0), Math.max(maxTop, 0))
|
|
883
890
|
|
|
@@ -888,6 +895,7 @@ export function basicConfig() {
|
|
|
888
895
|
toolbar.style.bottom = 'auto'
|
|
889
896
|
toolbar.style.zIndex = toolbar.style.zIndex || '9999'
|
|
890
897
|
toolbar.style.margin = '0'
|
|
898
|
+
return true
|
|
891
899
|
}
|
|
892
900
|
|
|
893
901
|
const restoreToolbarPosition = (btn) => {
|
|
@@ -898,7 +906,12 @@ export function basicConfig() {
|
|
|
898
906
|
if (!position) return
|
|
899
907
|
|
|
900
908
|
window.requestAnimationFrame(() => {
|
|
901
|
-
applyToolbarPosition(toolbar, position.left, position.top)
|
|
909
|
+
const restored = applyToolbarPosition(toolbar, position.left, position.top)
|
|
910
|
+
if (!restored) {
|
|
911
|
+
window.setTimeout(() => {
|
|
912
|
+
applyToolbarPosition(toolbar, position.left, position.top)
|
|
913
|
+
}, 100)
|
|
914
|
+
}
|
|
902
915
|
})
|
|
903
916
|
}
|
|
904
917
|
|
|
@@ -918,6 +931,51 @@ export function basicConfig() {
|
|
|
918
931
|
btn.classList.toggle('is-collapsed', !isToolbarExpanded)
|
|
919
932
|
}
|
|
920
933
|
|
|
934
|
+
const startToolbarDrag = (event, btn) => {
|
|
935
|
+
const toolbar = btn?.parentElement
|
|
936
|
+
if (!toolbar) return
|
|
937
|
+
|
|
938
|
+
const startX = event.clientX
|
|
939
|
+
const startY = event.clientY
|
|
940
|
+
const rect = toolbar.getBoundingClientRect()
|
|
941
|
+
const startLeft = rect.left
|
|
942
|
+
const startTop = rect.top
|
|
943
|
+
let hasMoved = false
|
|
944
|
+
|
|
945
|
+
applyToolbarPosition(toolbar, startLeft, startTop)
|
|
946
|
+
|
|
947
|
+
const moveToolbar = (moveEvent) => {
|
|
948
|
+
const deltaX = moveEvent.clientX - startX
|
|
949
|
+
const deltaY = moveEvent.clientY - startY
|
|
950
|
+
|
|
951
|
+
if (Math.abs(deltaX) > 3 || Math.abs(deltaY) > 3) {
|
|
952
|
+
hasMoved = true
|
|
953
|
+
isToolbarDragging = true
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
applyToolbarPosition(toolbar, startLeft + deltaX, startTop + deltaY)
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
const stopDrag = () => {
|
|
960
|
+
window.removeEventListener('pointermove', moveToolbar)
|
|
961
|
+
window.removeEventListener('pointerup', stopDrag)
|
|
962
|
+
window.removeEventListener('pointercancel', stopDrag)
|
|
963
|
+
|
|
964
|
+
if (hasMoved) {
|
|
965
|
+
const currentRect = toolbar.getBoundingClientRect()
|
|
966
|
+
saveToolbarPosition(currentRect.left, currentRect.top)
|
|
967
|
+
|
|
968
|
+
window.setTimeout(() => {
|
|
969
|
+
isToolbarDragging = false
|
|
970
|
+
}, 0)
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
window.addEventListener('pointermove', moveToolbar)
|
|
975
|
+
window.addEventListener('pointerup', stopDrag)
|
|
976
|
+
window.addEventListener('pointercancel', stopDrag)
|
|
977
|
+
}
|
|
978
|
+
|
|
921
979
|
const setupToolbarDrag = (btn) => {
|
|
922
980
|
if (!btn || btn.dataset.toolbarDragReady === 'true') return
|
|
923
981
|
|
|
@@ -933,54 +991,13 @@ export function basicConfig() {
|
|
|
933
991
|
})
|
|
934
992
|
|
|
935
993
|
btn.addEventListener('pointerdown', (event) => {
|
|
936
|
-
|
|
937
|
-
if (!toolbar) return
|
|
938
|
-
|
|
939
|
-
const startX = event.clientX
|
|
940
|
-
const startY = event.clientY
|
|
941
|
-
const rect = toolbar.getBoundingClientRect()
|
|
942
|
-
const startLeft = rect.left
|
|
943
|
-
const startTop = rect.top
|
|
944
|
-
let hasMoved = false
|
|
945
|
-
|
|
946
|
-
applyToolbarPosition(toolbar, startLeft, startTop)
|
|
947
|
-
|
|
948
|
-
const moveToolbar = (moveEvent) => {
|
|
949
|
-
const deltaX = moveEvent.clientX - startX
|
|
950
|
-
const deltaY = moveEvent.clientY - startY
|
|
951
|
-
|
|
952
|
-
if (Math.abs(deltaX) > 3 || Math.abs(deltaY) > 3) {
|
|
953
|
-
hasMoved = true
|
|
954
|
-
isToolbarDragging = true
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
applyToolbarPosition(toolbar, startLeft + deltaX, startTop + deltaY)
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
const stopDrag = () => {
|
|
961
|
-
window.removeEventListener('pointermove', moveToolbar)
|
|
962
|
-
window.removeEventListener('pointerup', stopDrag)
|
|
963
|
-
window.removeEventListener('pointercancel', stopDrag)
|
|
964
|
-
|
|
965
|
-
if (hasMoved) {
|
|
966
|
-
const currentRect = toolbar.getBoundingClientRect()
|
|
967
|
-
saveToolbarPosition(currentRect.left, currentRect.top)
|
|
968
|
-
|
|
969
|
-
window.setTimeout(() => {
|
|
970
|
-
isToolbarDragging = false
|
|
971
|
-
}, 0)
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
window.addEventListener('pointermove', moveToolbar)
|
|
976
|
-
window.addEventListener('pointerup', stopDrag)
|
|
977
|
-
window.addEventListener('pointercancel', stopDrag)
|
|
994
|
+
startToolbarDrag(event, btn)
|
|
978
995
|
})
|
|
979
996
|
}
|
|
980
997
|
|
|
981
998
|
return {
|
|
982
999
|
toggleExpand: (_viewer, btn) => {
|
|
983
|
-
setupToolbarDrag(btn)
|
|
1000
|
+
if (btn) setupToolbarDrag(btn)
|
|
984
1001
|
},
|
|
985
1002
|
setupToolbarDrag,
|
|
986
1003
|
applyToggleExpand,
|