huweili-cesium 1.2.42 → 1.2.44
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 +211 -1
- package/package.json +1 -1
package/js/basis.js
CHANGED
|
@@ -15,6 +15,13 @@ import {
|
|
|
15
15
|
teardownOrthographicWheelZoom,
|
|
16
16
|
restorePerspectiveControllerState,
|
|
17
17
|
} from './utils/cameraInteraction.js'
|
|
18
|
+
import { getMapCenterPosition } from './utils/getMapCenterPosition.js'
|
|
19
|
+
import { resetCompassDirection } from './toolbar/compass.js'
|
|
20
|
+
import { createBasemapSwitcher } from './utils/basemapSwitcher.js'
|
|
21
|
+
import { createZoomController } from './toolbar/zoomController.js'
|
|
22
|
+
import { useEventBus } from './utils/useEventBus.js'
|
|
23
|
+
import { applyOrthographicZoomFactor } from './utils/orthographicCameraZoom.js'
|
|
24
|
+
import { measureDistance } from './measureDistance.js'
|
|
18
25
|
|
|
19
26
|
export function basicConfig() {
|
|
20
27
|
|
|
@@ -721,6 +728,207 @@ export function basicConfig() {
|
|
|
721
728
|
}
|
|
722
729
|
}
|
|
723
730
|
|
|
731
|
+
/**
|
|
732
|
+
* 创建默认首页地图工具栏按钮
|
|
733
|
+
* @param {Object} options
|
|
734
|
+
* @param {string} options.mapId 地图实例 ID
|
|
735
|
+
* @param {string} [options.baseUrl='/'] 静态资源基础路径
|
|
736
|
+
* @param {number} [options.distance2D=8000] 2D 视角距离
|
|
737
|
+
* @param {number} [options.distance3D=15000] 3D 视角距离
|
|
738
|
+
* @returns {Object[]} 默认工具栏按钮配置
|
|
739
|
+
*/
|
|
740
|
+
const createDefaultHomeToolbarButtons = ({
|
|
741
|
+
mapId,
|
|
742
|
+
baseUrl = '/',
|
|
743
|
+
distance2D = 8000,
|
|
744
|
+
distance3D = 15000,
|
|
745
|
+
} = {}) => {
|
|
746
|
+
const { zoomIn: zoomInDefault, zoomOut: zoomOutDefault } = createZoomController()
|
|
747
|
+
const { toggleBasemapPickerPanel } = createBasemapSwitcher()
|
|
748
|
+
const { startMeasure } = measureDistance()
|
|
749
|
+
const { emit } = useEventBus()
|
|
750
|
+
|
|
751
|
+
const zoomIn = (factor = 0.8) => {
|
|
752
|
+
const map = mapStore.getMap(mapId)
|
|
753
|
+
if (map && applyOrthographicZoomFactor(map, mapId, factor)) return
|
|
754
|
+
zoomInDefault(mapId, factor)
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
const zoomOut = (factor = 1.25) => {
|
|
758
|
+
const map = mapStore.getMap(mapId)
|
|
759
|
+
if (map && applyOrthographicZoomFactor(map, mapId, factor)) return
|
|
760
|
+
zoomOutDefault(mapId, factor)
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
return [
|
|
764
|
+
{
|
|
765
|
+
index: 0,
|
|
766
|
+
title: '指北针',
|
|
767
|
+
text: 'N',
|
|
768
|
+
isCompass: true,
|
|
769
|
+
onClick: () => resetCompassDirection(),
|
|
770
|
+
},
|
|
771
|
+
{
|
|
772
|
+
index: 1,
|
|
773
|
+
title: '测距',
|
|
774
|
+
iconSrc: `${baseUrl}/images/new/ceju.svg`,
|
|
775
|
+
onClick: () => {
|
|
776
|
+
const measureId = `home_measure_${Date.now()}`
|
|
777
|
+
startMeasure({
|
|
778
|
+
id: measureId,
|
|
779
|
+
mapId,
|
|
780
|
+
color: '#00ffff',
|
|
781
|
+
width: 3,
|
|
782
|
+
})
|
|
783
|
+
},
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
index: 2,
|
|
787
|
+
title: '返回初始点位',
|
|
788
|
+
iconSrc: `${baseUrl}/images/new/home.svg`,
|
|
789
|
+
onClick: (v) => {
|
|
790
|
+
const { lng, lat } = getMapCenterPosition({ mapInstanceId: mapId })
|
|
791
|
+
setCesiumCenter({ lng, lat, map: v, mapId })
|
|
792
|
+
},
|
|
793
|
+
},
|
|
794
|
+
{
|
|
795
|
+
index: 3,
|
|
796
|
+
title: '2D/3D视角切换',
|
|
797
|
+
text: '2D',
|
|
798
|
+
onClick: (_v, btn) => {
|
|
799
|
+
const result = toggleViewAtViewportCenter(mapId, {
|
|
800
|
+
distance2D,
|
|
801
|
+
distance3D,
|
|
802
|
+
})
|
|
803
|
+
if (result.success && btn) btn.innerText = result.currentMode
|
|
804
|
+
mapStore.setSceneMode(result.currentMode, mapId)
|
|
805
|
+
emit('map-scene-mode-changed', { mapId, sceneMode: result.currentMode })
|
|
806
|
+
},
|
|
807
|
+
},
|
|
808
|
+
{
|
|
809
|
+
index: 4,
|
|
810
|
+
title: '降低视角',
|
|
811
|
+
iconSrc: `${baseUrl}/images/new/jia.svg`,
|
|
812
|
+
onClick: () => zoomIn(),
|
|
813
|
+
},
|
|
814
|
+
{
|
|
815
|
+
index: 5,
|
|
816
|
+
title: '抬升视角',
|
|
817
|
+
iconSrc: `${baseUrl}/images/new/jian.svg`,
|
|
818
|
+
onClick: () => zoomOut(),
|
|
819
|
+
},
|
|
820
|
+
{
|
|
821
|
+
index: 6,
|
|
822
|
+
title: '切换底图',
|
|
823
|
+
iconSrc: `${baseUrl}/images/new/map.svg`,
|
|
824
|
+
onClick: (v, btn) => toggleBasemapPickerPanel(v, btn || null),
|
|
825
|
+
},
|
|
826
|
+
]
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* 创建工具栏展开/折叠和拖拽控制器
|
|
831
|
+
* - 单击展开按钮:初始化拖拽能力,不触发展开/折叠
|
|
832
|
+
* - 双击展开按钮:展开/折叠同级工具栏按钮
|
|
833
|
+
* - 拖拽展开按钮:移动整个工具栏按钮组
|
|
834
|
+
*/
|
|
835
|
+
const createToolbarExpandController = () => {
|
|
836
|
+
let isToolbarExpanded = true
|
|
837
|
+
let isToolbarDragging = false
|
|
838
|
+
|
|
839
|
+
const applyToggleExpand = (btn) => {
|
|
840
|
+
const toolbar = btn?.parentElement
|
|
841
|
+
if (!toolbar) return
|
|
842
|
+
|
|
843
|
+
isToolbarExpanded = !isToolbarExpanded
|
|
844
|
+
|
|
845
|
+
Array.from(toolbar.children).forEach((item) => {
|
|
846
|
+
if (item === btn) return
|
|
847
|
+
item.style.display = isToolbarExpanded ? '' : 'none'
|
|
848
|
+
})
|
|
849
|
+
|
|
850
|
+
btn.title = isToolbarExpanded ? '收缩' : '展开'
|
|
851
|
+
btn.setAttribute('aria-expanded', String(isToolbarExpanded))
|
|
852
|
+
btn.classList.toggle('is-collapsed', !isToolbarExpanded)
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
const setupToolbarDrag = (btn) => {
|
|
856
|
+
if (!btn || btn.dataset.toolbarDragReady === 'true') return
|
|
857
|
+
|
|
858
|
+
btn.dataset.toolbarDragReady = 'true'
|
|
859
|
+
btn.style.cursor = 'move'
|
|
860
|
+
|
|
861
|
+
btn.addEventListener('dblclick', (event) => {
|
|
862
|
+
event.preventDefault()
|
|
863
|
+
event.stopPropagation()
|
|
864
|
+
if (isToolbarDragging) return
|
|
865
|
+
applyToggleExpand(btn)
|
|
866
|
+
})
|
|
867
|
+
|
|
868
|
+
btn.addEventListener('pointerdown', (event) => {
|
|
869
|
+
const toolbar = btn.parentElement
|
|
870
|
+
if (!toolbar) return
|
|
871
|
+
|
|
872
|
+
const startX = event.clientX
|
|
873
|
+
const startY = event.clientY
|
|
874
|
+
const rect = toolbar.getBoundingClientRect()
|
|
875
|
+
const startLeft = rect.left
|
|
876
|
+
const startTop = rect.top
|
|
877
|
+
let hasMoved = false
|
|
878
|
+
|
|
879
|
+
toolbar.style.position = 'fixed'
|
|
880
|
+
toolbar.style.left = `${startLeft}px`
|
|
881
|
+
toolbar.style.top = `${startTop}px`
|
|
882
|
+
toolbar.style.right = 'auto'
|
|
883
|
+
toolbar.style.bottom = 'auto'
|
|
884
|
+
toolbar.style.zIndex = toolbar.style.zIndex || '9999'
|
|
885
|
+
toolbar.style.margin = '0'
|
|
886
|
+
|
|
887
|
+
const moveToolbar = (moveEvent) => {
|
|
888
|
+
const deltaX = moveEvent.clientX - startX
|
|
889
|
+
const deltaY = moveEvent.clientY - startY
|
|
890
|
+
|
|
891
|
+
if (Math.abs(deltaX) > 3 || Math.abs(deltaY) > 3) {
|
|
892
|
+
hasMoved = true
|
|
893
|
+
isToolbarDragging = true
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
const maxLeft = window.innerWidth - toolbar.offsetWidth
|
|
897
|
+
const maxTop = window.innerHeight - toolbar.offsetHeight
|
|
898
|
+
const nextLeft = Math.min(Math.max(startLeft + deltaX, 0), Math.max(maxLeft, 0))
|
|
899
|
+
const nextTop = Math.min(Math.max(startTop + deltaY, 0), Math.max(maxTop, 0))
|
|
900
|
+
|
|
901
|
+
toolbar.style.left = `${nextLeft}px`
|
|
902
|
+
toolbar.style.top = `${nextTop}px`
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
const stopDrag = () => {
|
|
906
|
+
window.removeEventListener('pointermove', moveToolbar)
|
|
907
|
+
window.removeEventListener('pointerup', stopDrag)
|
|
908
|
+
window.removeEventListener('pointercancel', stopDrag)
|
|
909
|
+
|
|
910
|
+
if (hasMoved) {
|
|
911
|
+
window.setTimeout(() => {
|
|
912
|
+
isToolbarDragging = false
|
|
913
|
+
}, 0)
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
window.addEventListener('pointermove', moveToolbar)
|
|
918
|
+
window.addEventListener('pointerup', stopDrag)
|
|
919
|
+
window.addEventListener('pointercancel', stopDrag)
|
|
920
|
+
})
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
return {
|
|
924
|
+
toggleExpand: (_viewer, btn) => {
|
|
925
|
+
setupToolbarDrag(btn)
|
|
926
|
+
},
|
|
927
|
+
setupToolbarDrag,
|
|
928
|
+
applyToggleExpand,
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
|
|
724
932
|
/**
|
|
725
933
|
* 以当前视口中心点为锚点,在 2D 俯视 / 3D 斜视之间切换(不依赖 RTK)
|
|
726
934
|
* @param {string=} mapId 地图实例ID
|
|
@@ -781,8 +989,10 @@ export function basicConfig() {
|
|
|
781
989
|
applyOrthographicFrustum,
|
|
782
990
|
restorePerspectiveFrustum,
|
|
783
991
|
setInitialCameraView,
|
|
992
|
+
createDefaultHomeToolbarButtons,
|
|
993
|
+
createToolbarExpandController,
|
|
784
994
|
syncCameraInteractionMode: (map, mapId, sceneMode) =>
|
|
785
|
-
|
|
995
|
+
syncCameraInteractionMode(map, mapId, sceneMode, orthoViewHelpers()),
|
|
786
996
|
}
|
|
787
997
|
}
|
|
788
998
|
|