huweili-cesium 1.2.43 → 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 +106 -0
- 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,104 @@ 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
|
+
|
|
724
829
|
/**
|
|
725
830
|
* 创建工具栏展开/折叠和拖拽控制器
|
|
726
831
|
* - 单击展开按钮:初始化拖拽能力,不触发展开/折叠
|
|
@@ -884,6 +989,7 @@ export function basicConfig() {
|
|
|
884
989
|
applyOrthographicFrustum,
|
|
885
990
|
restorePerspectiveFrustum,
|
|
886
991
|
setInitialCameraView,
|
|
992
|
+
createDefaultHomeToolbarButtons,
|
|
887
993
|
createToolbarExpandController,
|
|
888
994
|
syncCameraInteractionMode: (map, mapId, sceneMode) =>
|
|
889
995
|
syncCameraInteractionMode(map, mapId, sceneMode, orthoViewHelpers()),
|