huweili-cesium 1.2.4 → 1.2.6

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.
@@ -21,7 +21,7 @@
21
21
  * - 收到无人机数据时绿色高亮闪烁(.active)
22
22
  */
23
23
  import { ref, computed, onMounted, onUnmounted, nextTick } from 'vue'
24
- import { useEventBus } from '../../js/utils/useEventBus'
24
+ import { useEventBus } from '../../js/utils/useEventBus.js'
25
25
 
26
26
  const { on, off } = useEventBus()
27
27
 
package/index.vue CHANGED
@@ -1,385 +1,765 @@
1
- <template>
2
- <div class="cesium-map-wrapper" @pointerdown="handleMapPointerDown">
3
- <div class="cesium-container" ref="cesiumContainer" />
4
- <WsIndicator />
5
- </div>
6
- </template>
7
-
8
- <script setup>
9
- import * as Cesium from 'cesium'
10
- import { ref, watch, onMounted, onUnmounted, onActivated, onDeactivated, nextTick, toRaw } from 'vue'
11
- import { MapConfig, DroneConfig } from './config'
12
- import WsIndicator from './components/wsIndicator/wsIndicator.vue'
13
- import { objectUtils } from './utils/cesium/object'
14
- import { basicConfig, teardownOrthographicWheelZoom } from './basis'
15
- import { useMapStore, MapLoadStatus } from './stores/mapStore'
16
- import { useEventBus } from './utils/useEventBus'
17
- import { processMapConfigColors } from './tileProviders'
18
- import { applyImageryLayers, resolveOnlineBasemap } from './utils/mapImagery'
19
- import { createCustomToolbarButtons } from './customToolbarButtons'
20
- import { ensureMapFocus } from './utils/cameraInteraction'
21
-
22
- const { merge } = objectUtils()
23
- const { mouseController, setInitialCameraView, syncCameraInteractionMode } = basicConfig()
24
-
25
- const {
26
- addToolbarButton,
27
- addToolbarButtons,
28
- removeToolbarButtons,
29
- createDefaultToolbarButtons,
30
- } = createCustomToolbarButtons()
31
-
32
- const mapStore = useMapStore()
33
- const { on: onEvent, off: offEvent } = useEventBus()
34
-
35
- const emit = defineEmits(['onload'])
36
-
37
- const props = defineProps({
38
- options: {
39
- type: Object,
40
- default: undefined,
41
- },
42
- mapId: {
43
- type: String,
44
- default: 'default',
45
- },
46
- showDefaultToolbar: {
47
- type: Boolean,
48
- default: true,
49
- },
50
- toolbarButtons: {
51
- type: Array,
52
- default: undefined,
53
- },
54
- extraToolbarButtons: {
55
- type: Array,
56
- default: () => [],
57
- },
58
- })
59
-
60
- function resolveToolbarButtonConfigs() {
61
- if (props.toolbarButtons?.length) {
62
- return props.toolbarButtons
63
- }
64
- const configs = []
65
- if (props.showDefaultToolbar) {
66
- configs.push(...createDefaultToolbarButtons({ mapId: props.mapId }))
67
- }
68
- if (props.extraToolbarButtons?.length) {
69
- configs.push(...props.extraToolbarButtons)
70
- }
71
- return configs
72
- }
73
-
74
- const handleSceneModeChange = ({ mapId, sceneMode }) => {
75
- if (mapId !== props.mapId || !map || map.isDestroyed?.()) return
76
- syncCameraInteractionMode(map, mapId, sceneMode)
77
- }
78
-
79
- const handleMapPointerDown = () => {
80
- if (map && !map.isDestroyed?.()) {
81
- ensureMapFocus(map)
82
- }
83
- }
84
-
85
- const cesiumContainer = ref(null)
86
- let map = null
87
- let customButtons = []
88
- let isMapActive = true
89
-
90
- function mountToolbarButtons(viewer) {
91
- if (!viewer || viewer.isDestroyed?.()) return
92
- removeToolbarButtons(customButtons)
93
- customButtons = []
94
- const toolbarConfigs = resolveToolbarButtonConfigs()
95
- if (toolbarConfigs.length) {
96
- customButtons = addToolbarButtons(viewer, toolbarConfigs)
97
- }
98
- }
99
-
100
- const initCesium = async () => {
101
- if (!cesiumContainer.value) return
102
- mapStore.setMapLoadSta(MapLoadStatus.LOADING, props.mapId)
103
-
104
- let mapOptions
105
- if (MapConfig) {
106
- mapOptions = MapConfig
107
- }
108
-
109
- if (DroneConfig) {
110
- mapStore.setTrailTime(DroneConfig.trailTime, props.mapId)
111
- }
112
-
113
- if (props.options) {
114
- let exOptions
115
- if (props.options.then) {
116
- exOptions = toRaw(await props.options)
117
- } else {
118
- exOptions = toRaw(props.options)
119
- }
120
-
121
- if (mapOptions) {
122
- mapOptions = merge(mapOptions, exOptions)
123
- } else {
124
- mapOptions = exOptions
125
- }
126
- }
127
-
128
- if (mapOptions) {
129
- mapOptions = processMapConfigColors(mapOptions)
130
- }
131
-
132
- try {
133
- const viewerOptions = {
134
- sceneMode: Cesium.SceneMode.SCENE3D,
135
- useDefaultRenderLoop: false,
136
- baseLayer: mapOptions.control.imageryProvider === false ? false : undefined,
137
- baseLayerPicker: mapOptions.control.baseLayerPicker,
138
- geocoder: mapOptions.control.geocoder,
139
- homeButton: mapOptions.control.homeButton,
140
- sceneModePicker: mapOptions.control.sceneModePicker,
141
- navigationHelpButton: mapOptions.control.navigationHelpButton,
142
- animation: mapOptions.control.animation,
143
- timeline: mapOptions.control.timeline,
144
- infoBox: mapOptions.control.infoBox,
145
- fullscreenButton: mapOptions.control.fullscreenButton,
146
- vrButton: mapOptions.control.vrButton,
147
- terrainProvider: mapOptions.terrain.show
148
- ? await Cesium.CesiumTerrainProvider.fromUrl(mapOptions.terrain.url, {
149
- requestWaterMask: mapOptions.terrain.coastlineData,
150
- requestVertexNormals: mapOptions.terrain.lightingData,
151
- })
152
- : undefined,
153
- terrainShadows: Cesium.ShadowMode.RECEIVE_ONLY,
154
- creditContainer: document.createElement('div'),
155
- }
156
-
157
- const contextOptions = {
158
- webgl: {
159
- alpha: false,
160
- depth: true,
161
- stencil: false,
162
- antialias: true,
163
- premultipliedAlpha: true,
164
- preserveDrawingBuffer: false,
165
- failIfMajorPerformanceCaveat: false,
166
- },
167
- requestWebGl2: true,
168
- powerPreference: 'high-performance',
169
- }
170
-
171
- const sceneRenderOptions = {
172
- debugShowFramesPerSecond: mapOptions.scene.debugShowFramesPerSecond,
173
- enableLighting: mapOptions.scene.globe.enableLighting,
174
- depthTestAgainstTerrain: mapOptions.scene.globe.depthTestAgainstTerrain,
175
- fogEnabled: mapOptions.scene.fog.enabled,
176
- skyAtmosphereShow: mapOptions.scene.skyAtmosphere.show,
177
- dynamicAtmosphereLighting: mapOptions.scene.globe.dynamicAtmosphereLighting,
178
- dynamicAtmosphereLightingFromSun: mapOptions.scene.globe.dynamicAtmosphereLightingFromSun,
179
- }
180
-
181
- map = new Cesium.Viewer(cesiumContainer.value, {
182
- ...viewerOptions,
183
- contextOptions,
184
- })
185
-
186
- map.scene.debugShowFramesPerSecond = sceneRenderOptions.debugShowFramesPerSecond
187
- map.scene.globe.enableLighting = sceneRenderOptions.enableLighting
188
- map.scene.globe.depthTestAgainstTerrain = sceneRenderOptions.depthTestAgainstTerrain
189
- map.scene.fog.enabled = sceneRenderOptions.fogEnabled
190
- map.scene.skyAtmosphere.show = sceneRenderOptions.skyAtmosphereShow
191
- map.scene.globe.dynamicAtmosphereLighting = sceneRenderOptions.dynamicAtmosphereLighting
192
- map.scene.globe.dynamicAtmosphereLightingFromSun =
193
- sceneRenderOptions.dynamicAtmosphereLightingFromSun
194
-
195
- const sceneMode = mapOptions.scene.sceneMode || '3D'
196
-
197
- const activeBasemap = resolveOnlineBasemap(mapOptions)
198
- if (activeBasemap) {
199
- applyImageryLayers(map, mapOptions, activeBasemap)
200
- console.log(`加载在线底图:${activeBasemap.name},URL:${activeBasemap.url}`)
201
- window._currentBasemapId = activeBasemap.id
202
- } else {
203
- console.warn('未找到可用底图,Cesium 将使用默认底图或空底图显示')
204
- }
205
-
206
- if (map.screenSpaceEventHandler && mapOptions.control.disableDoubleClick) {
207
- map.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)
208
- }
209
-
210
- if (mapOptions.control.disableEntityClick) {
211
- map.selectedEntityChanged.addEventListener(() => {
212
- map.selectedEntity = undefined
213
- })
214
- }
215
-
216
- mouseController(map, props.mapId)
217
-
218
- mapStore.setMapInfo(
219
- 'center',
220
- {
221
- lng: mapOptions.scene.center.lng,
222
- lat: mapOptions.scene.center.lat,
223
- heading: mapOptions.scene.center.heading,
224
- pitch: mapOptions.scene.center.pitch,
225
- roll: mapOptions.scene.center.roll,
226
- duration: mapOptions.scene.center.duration,
227
- alt: mapOptions.scene.center.alt,
228
- },
229
- props.mapId,
230
- )
231
- mapStore.setMap(map, props.mapId)
232
- mapStore.setSceneMode(sceneMode, props.mapId)
233
-
234
- const center = mapOptions.scene.center || {}
235
-
236
- mountToolbarButtons(map)
237
- mapStore.setMapLoadSta(MapLoadStatus.LOADED, props.mapId)
238
-
239
- console.log(`Cesium 地图加载成功,mapId: ${props.mapId}`)
240
- emit('onload', {
241
- map,
242
- center,
243
- mapId: props.mapId,
244
- toolbar: {
245
- addToolbarButton: (opt) => addToolbarButton(map, opt),
246
- addToolbarButtons: (opts) => addToolbarButtons(map, opts),
247
- removeToolbarButtons,
248
- },
249
- syncCameraInteractionMode: (mode) => syncCameraInteractionMode(map, props.mapId, mode),
250
- })
251
-
252
- map.resize()
253
- setInitialCameraView(map, mapOptions.scene.center, sceneMode, props.mapId)
254
- map.render()
255
-
256
- if (sceneMode === '2D') {
257
- nextTick(() => {
258
- if (!map || map.isDestroyed?.()) return
259
- syncCameraInteractionMode(map, props.mapId, '2D')
260
- })
261
- }
262
-
263
- startContinuousRendering(map)
264
- } catch (error) {
265
- mapStore.setMapLoadSta(MapLoadStatus.FAILED, props.mapId)
266
- console.error('Cesium 地图加载失败:', error)
267
- }
268
- }
269
-
270
- let animationId = null
271
- let lastActiveTime = Date.now()
272
- const IDLE_TIMEOUT = 30000
273
-
274
- function startContinuousRendering(viewer) {
275
- if (animationId) return
276
- function animate() {
277
- const now = Date.now()
278
- if (
279
- isMapActive &&
280
- !document.hidden &&
281
- map &&
282
- !map.isDestroyed?.() &&
283
- now - lastActiveTime < IDLE_TIMEOUT
284
- ) {
285
- viewer.render()
286
- }
287
- animationId = requestAnimationFrame(animate)
288
- }
289
- animate()
290
- }
291
-
292
- function stopRenderLoop() {
293
- if (animationId) {
294
- cancelAnimationFrame(animationId)
295
- animationId = null
296
- }
297
- }
298
-
299
- function setupActivityListeners() {
300
- const activities = ['mousemove', 'keydown', 'touchmove', 'wheel', 'click']
301
- activities.forEach((event) => {
302
- document.addEventListener(event, () => {
303
- lastActiveTime = Date.now()
304
- })
305
- })
306
- }
307
-
308
- function resumeMapAfterCache() {
309
- if (!map || map.isDestroyed?.()) return
310
- mapStore.setCurrentMapId(props.mapId)
311
- isMapActive = true
312
- lastActiveTime = Date.now()
313
- nextTick(() => {
314
- if (!map || map.isDestroyed?.()) return
315
- map.resize()
316
- const mode = mapStore.getSceneMode(props.mapId)
317
- syncCameraInteractionMode(map, props.mapId, mode === '2D' ? '2D' : '3D')
318
- map.render()
319
- if (!animationId) startContinuousRendering(map)
320
- })
321
- }
322
-
323
- watch(
324
- () => props.toolbarButtons,
325
- () => {
326
- if (map && !map.isDestroyed?.()) {
327
- mountToolbarButtons(map)
328
- }
329
- },
330
- { deep: true },
331
- )
332
-
333
- onMounted(() => {
334
- mapStore.setCurrentMapId(props.mapId)
335
- setupActivityListeners()
336
- onEvent('map-scene-mode-changed', handleSceneModeChange)
337
- initCesium()
338
- })
339
-
340
- onActivated(() => {
341
- mapStore.setCurrentMapId(props.mapId)
342
- if (!map || map.isDestroyed?.()) {
343
- isMapActive = true
344
- initCesium()
345
- return
346
- }
347
- resumeMapAfterCache()
348
- })
349
-
350
- onDeactivated(() => {
351
- isMapActive = false
352
- stopRenderLoop()
353
- })
354
-
355
- onUnmounted(() => {
356
- isMapActive = false
357
- stopRenderLoop()
358
- offEvent('map-scene-mode-changed', handleSceneModeChange)
359
- if (map) {
360
- teardownOrthographicWheelZoom(map)
361
- }
362
- removeToolbarButtons(customButtons)
363
- customButtons = []
364
- if (map) {
365
- map.destroy()
366
- map = null
367
- }
368
- mapStore.removeMapInstance(props.mapId)
369
- })
370
- </script>
371
-
372
- <style scoped lang="less">
373
- .cesium-map-wrapper {
374
- width: 100%;
375
- height: 100%;
376
- position: relative;
377
- }
378
-
379
- .cesium-container {
380
- width: 100%;
381
- height: 100%;
382
- position: relative;
383
- }
384
- </style>
385
-
1
+ <template>
2
+
3
+ <div class="cesium-map-wrapper" @pointerdown="handleMapPointerDown">
4
+
5
+ <div class="cesium-container" ref="cesiumContainer" />
6
+
7
+ <WsIndicator />
8
+
9
+ </div>
10
+
11
+ </template>
12
+
13
+
14
+
15
+ <script setup>
16
+
17
+ import * as Cesium from 'cesium'
18
+
19
+ import { ref, watch, onMounted, onUnmounted, onActivated, onDeactivated, nextTick, toRaw } from 'vue'
20
+
21
+ import { MapConfig, DroneConfig } from './js/config/index.js'
22
+
23
+ import WsIndicator from './components/wsIndicator/wsIndicator.vue'
24
+
25
+ import { objectUtils } from './js/utils/cesium/object.js'
26
+
27
+ import { basicConfig, teardownOrthographicWheelZoom } from './js/basis.js'
28
+
29
+ import { useMapStore, MapLoadStatus } from './js/stores/mapStore.js'
30
+
31
+ import { useEventBus } from './js/utils/useEventBus.js'
32
+
33
+ import { processMapConfigColors } from './js/tileProviders.js'
34
+
35
+ import { applyImageryLayers, resolveOnlineBasemap } from './js/utils/mapImagery.js'
36
+
37
+ import { createCustomToolbarButtons } from './js/customToolbarButtons.js'
38
+
39
+ import { ensureMapFocus } from './js/utils/cameraInteraction.js'
40
+
41
+
42
+
43
+ const { merge } = objectUtils()
44
+
45
+ const { mouseController, setInitialCameraView, syncCameraInteractionMode } = basicConfig()
46
+
47
+
48
+
49
+ const {
50
+
51
+ addToolbarButton,
52
+
53
+ addToolbarButtons,
54
+
55
+ removeToolbarButtons,
56
+
57
+ createDefaultToolbarButtons,
58
+
59
+ } = createCustomToolbarButtons()
60
+
61
+
62
+
63
+ const mapStore = useMapStore()
64
+
65
+ const { on: onEvent, off: offEvent } = useEventBus()
66
+
67
+
68
+
69
+ const emit = defineEmits(['onload'])
70
+
71
+
72
+
73
+ const props = defineProps({
74
+
75
+ options: {
76
+
77
+ type: Object,
78
+
79
+ default: undefined,
80
+
81
+ },
82
+
83
+ mapId: {
84
+
85
+ type: String,
86
+
87
+ default: 'default',
88
+
89
+ },
90
+
91
+ showDefaultToolbar: {
92
+
93
+ type: Boolean,
94
+
95
+ default: true,
96
+
97
+ },
98
+
99
+ toolbarButtons: {
100
+
101
+ type: Array,
102
+
103
+ default: undefined,
104
+
105
+ },
106
+
107
+ extraToolbarButtons: {
108
+
109
+ type: Array,
110
+
111
+ default: () => [],
112
+
113
+ },
114
+
115
+ })
116
+
117
+
118
+
119
+ function resolveToolbarButtonConfigs() {
120
+
121
+ if (props.toolbarButtons?.length) {
122
+
123
+ return props.toolbarButtons
124
+
125
+ }
126
+
127
+ const configs = []
128
+
129
+ if (props.showDefaultToolbar) {
130
+
131
+ configs.push(...createDefaultToolbarButtons({ mapId: props.mapId }))
132
+
133
+ }
134
+
135
+ if (props.extraToolbarButtons?.length) {
136
+
137
+ configs.push(...props.extraToolbarButtons)
138
+
139
+ }
140
+
141
+ return configs
142
+
143
+ }
144
+
145
+
146
+
147
+ const handleSceneModeChange = ({ mapId, sceneMode }) => {
148
+
149
+ if (mapId !== props.mapId || !map || map.isDestroyed?.()) return
150
+
151
+ syncCameraInteractionMode(map, mapId, sceneMode)
152
+
153
+ }
154
+
155
+
156
+
157
+ const handleMapPointerDown = () => {
158
+
159
+ if (map && !map.isDestroyed?.()) {
160
+
161
+ ensureMapFocus(map)
162
+
163
+ }
164
+
165
+ }
166
+
167
+
168
+
169
+ const cesiumContainer = ref(null)
170
+
171
+ let map = null
172
+
173
+ let customButtons = []
174
+
175
+ let isMapActive = true
176
+
177
+
178
+
179
+ function mountToolbarButtons(viewer) {
180
+
181
+ if (!viewer || viewer.isDestroyed?.()) return
182
+
183
+ removeToolbarButtons(customButtons)
184
+
185
+ customButtons = []
186
+
187
+ const toolbarConfigs = resolveToolbarButtonConfigs()
188
+
189
+ if (toolbarConfigs.length) {
190
+
191
+ customButtons = addToolbarButtons(viewer, toolbarConfigs)
192
+
193
+ }
194
+
195
+ }
196
+
197
+
198
+
199
+ const initCesium = async () => {
200
+
201
+ if (!cesiumContainer.value) return
202
+
203
+ mapStore.setMapLoadSta(MapLoadStatus.LOADING, props.mapId)
204
+
205
+
206
+
207
+ let mapOptions
208
+
209
+ if (MapConfig) {
210
+
211
+ mapOptions = MapConfig
212
+
213
+ }
214
+
215
+
216
+
217
+ if (DroneConfig) {
218
+
219
+ mapStore.setTrailTime(DroneConfig.trailTime, props.mapId)
220
+
221
+ }
222
+
223
+
224
+
225
+ if (props.options) {
226
+
227
+ let exOptions
228
+
229
+ if (props.options.then) {
230
+
231
+ exOptions = toRaw(await props.options)
232
+
233
+ } else {
234
+
235
+ exOptions = toRaw(props.options)
236
+
237
+ }
238
+
239
+
240
+
241
+ if (mapOptions) {
242
+
243
+ mapOptions = merge(mapOptions, exOptions)
244
+
245
+ } else {
246
+
247
+ mapOptions = exOptions
248
+
249
+ }
250
+
251
+ }
252
+
253
+
254
+
255
+ if (mapOptions) {
256
+
257
+ mapOptions = processMapConfigColors(mapOptions)
258
+
259
+ }
260
+
261
+
262
+
263
+ try {
264
+
265
+ const viewerOptions = {
266
+
267
+ sceneMode: Cesium.SceneMode.SCENE3D,
268
+
269
+ useDefaultRenderLoop: false,
270
+
271
+ baseLayer: mapOptions.control.imageryProvider === false ? false : undefined,
272
+
273
+ baseLayerPicker: mapOptions.control.baseLayerPicker,
274
+
275
+ geocoder: mapOptions.control.geocoder,
276
+
277
+ homeButton: mapOptions.control.homeButton,
278
+
279
+ sceneModePicker: mapOptions.control.sceneModePicker,
280
+
281
+ navigationHelpButton: mapOptions.control.navigationHelpButton,
282
+
283
+ animation: mapOptions.control.animation,
284
+
285
+ timeline: mapOptions.control.timeline,
286
+
287
+ infoBox: mapOptions.control.infoBox,
288
+
289
+ fullscreenButton: mapOptions.control.fullscreenButton,
290
+
291
+ vrButton: mapOptions.control.vrButton,
292
+
293
+ terrainProvider: mapOptions.terrain.show
294
+
295
+ ? await Cesium.CesiumTerrainProvider.fromUrl(mapOptions.terrain.url, {
296
+
297
+ requestWaterMask: mapOptions.terrain.coastlineData,
298
+
299
+ requestVertexNormals: mapOptions.terrain.lightingData,
300
+
301
+ })
302
+
303
+ : undefined,
304
+
305
+ terrainShadows: Cesium.ShadowMode.RECEIVE_ONLY,
306
+
307
+ creditContainer: document.createElement('div'),
308
+
309
+ }
310
+
311
+
312
+
313
+ const contextOptions = {
314
+
315
+ webgl: {
316
+
317
+ alpha: false,
318
+
319
+ depth: true,
320
+
321
+ stencil: false,
322
+
323
+ antialias: true,
324
+
325
+ premultipliedAlpha: true,
326
+
327
+ preserveDrawingBuffer: false,
328
+
329
+ failIfMajorPerformanceCaveat: false,
330
+
331
+ },
332
+
333
+ requestWebGl2: true,
334
+
335
+ powerPreference: 'high-performance',
336
+
337
+ }
338
+
339
+
340
+
341
+ const sceneRenderOptions = {
342
+
343
+ debugShowFramesPerSecond: mapOptions.scene.debugShowFramesPerSecond,
344
+
345
+ enableLighting: mapOptions.scene.globe.enableLighting,
346
+
347
+ depthTestAgainstTerrain: mapOptions.scene.globe.depthTestAgainstTerrain,
348
+
349
+ fogEnabled: mapOptions.scene.fog.enabled,
350
+
351
+ skyAtmosphereShow: mapOptions.scene.skyAtmosphere.show,
352
+
353
+ dynamicAtmosphereLighting: mapOptions.scene.globe.dynamicAtmosphereLighting,
354
+
355
+ dynamicAtmosphereLightingFromSun: mapOptions.scene.globe.dynamicAtmosphereLightingFromSun,
356
+
357
+ }
358
+
359
+
360
+
361
+ map = new Cesium.Viewer(cesiumContainer.value, {
362
+
363
+ ...viewerOptions,
364
+
365
+ contextOptions,
366
+
367
+ })
368
+
369
+
370
+
371
+ map.scene.debugShowFramesPerSecond = sceneRenderOptions.debugShowFramesPerSecond
372
+
373
+ map.scene.globe.enableLighting = sceneRenderOptions.enableLighting
374
+
375
+ map.scene.globe.depthTestAgainstTerrain = sceneRenderOptions.depthTestAgainstTerrain
376
+
377
+ map.scene.fog.enabled = sceneRenderOptions.fogEnabled
378
+
379
+ map.scene.skyAtmosphere.show = sceneRenderOptions.skyAtmosphereShow
380
+
381
+ map.scene.globe.dynamicAtmosphereLighting = sceneRenderOptions.dynamicAtmosphereLighting
382
+
383
+ map.scene.globe.dynamicAtmosphereLightingFromSun =
384
+
385
+ sceneRenderOptions.dynamicAtmosphereLightingFromSun
386
+
387
+
388
+
389
+ const sceneMode = mapOptions.scene.sceneMode || '3D'
390
+
391
+
392
+
393
+ const activeBasemap = resolveOnlineBasemap(mapOptions)
394
+
395
+ if (activeBasemap) {
396
+
397
+ applyImageryLayers(map, mapOptions, activeBasemap)
398
+
399
+ console.log(`加载在线底图:${activeBasemap.name},URL:${activeBasemap.url}`)
400
+
401
+ window._currentBasemapId = activeBasemap.id
402
+
403
+ } else {
404
+
405
+ console.warn('未找到可用底图,Cesium 将使用默认底图或空底图显示')
406
+
407
+ }
408
+
409
+
410
+
411
+ if (map.screenSpaceEventHandler && mapOptions.control.disableDoubleClick) {
412
+
413
+ map.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)
414
+
415
+ }
416
+
417
+
418
+
419
+ if (mapOptions.control.disableEntityClick) {
420
+
421
+ map.selectedEntityChanged.addEventListener(() => {
422
+
423
+ map.selectedEntity = undefined
424
+
425
+ })
426
+
427
+ }
428
+
429
+
430
+
431
+ mouseController(map, props.mapId)
432
+
433
+
434
+
435
+ mapStore.setMapInfo(
436
+
437
+ 'center',
438
+
439
+ {
440
+
441
+ lng: mapOptions.scene.center.lng,
442
+
443
+ lat: mapOptions.scene.center.lat,
444
+
445
+ heading: mapOptions.scene.center.heading,
446
+
447
+ pitch: mapOptions.scene.center.pitch,
448
+
449
+ roll: mapOptions.scene.center.roll,
450
+
451
+ duration: mapOptions.scene.center.duration,
452
+
453
+ alt: mapOptions.scene.center.alt,
454
+
455
+ },
456
+
457
+ props.mapId,
458
+
459
+ )
460
+
461
+ mapStore.setMap(map, props.mapId)
462
+
463
+ mapStore.setSceneMode(sceneMode, props.mapId)
464
+
465
+
466
+
467
+ const center = mapOptions.scene.center || {}
468
+
469
+
470
+
471
+ mountToolbarButtons(map)
472
+
473
+ mapStore.setMapLoadSta(MapLoadStatus.LOADED, props.mapId)
474
+
475
+
476
+
477
+ console.log(`Cesium 地图加载成功,mapId: ${props.mapId}`)
478
+
479
+ emit('onload', {
480
+
481
+ map,
482
+
483
+ center,
484
+
485
+ mapId: props.mapId,
486
+
487
+ toolbar: {
488
+
489
+ addToolbarButton: (opt) => addToolbarButton(map, opt),
490
+
491
+ addToolbarButtons: (opts) => addToolbarButtons(map, opts),
492
+
493
+ removeToolbarButtons,
494
+
495
+ },
496
+
497
+ syncCameraInteractionMode: (mode) => syncCameraInteractionMode(map, props.mapId, mode),
498
+
499
+ })
500
+
501
+
502
+
503
+ map.resize()
504
+
505
+ setInitialCameraView(map, mapOptions.scene.center, sceneMode, props.mapId)
506
+
507
+ map.render()
508
+
509
+
510
+
511
+ if (sceneMode === '2D') {
512
+
513
+ nextTick(() => {
514
+
515
+ if (!map || map.isDestroyed?.()) return
516
+
517
+ syncCameraInteractionMode(map, props.mapId, '2D')
518
+
519
+ })
520
+
521
+ }
522
+
523
+
524
+
525
+ startContinuousRendering(map)
526
+
527
+ } catch (error) {
528
+
529
+ mapStore.setMapLoadSta(MapLoadStatus.FAILED, props.mapId)
530
+
531
+ console.error('Cesium 地图加载失败:', error)
532
+
533
+ }
534
+
535
+ }
536
+
537
+
538
+
539
+ let animationId = null
540
+
541
+ let lastActiveTime = Date.now()
542
+
543
+ const IDLE_TIMEOUT = 30000
544
+
545
+
546
+
547
+ function startContinuousRendering(viewer) {
548
+
549
+ if (animationId) return
550
+
551
+ function animate() {
552
+
553
+ const now = Date.now()
554
+
555
+ if (
556
+
557
+ isMapActive &&
558
+
559
+ !document.hidden &&
560
+
561
+ map &&
562
+
563
+ !map.isDestroyed?.() &&
564
+
565
+ now - lastActiveTime < IDLE_TIMEOUT
566
+
567
+ ) {
568
+
569
+ viewer.render()
570
+
571
+ }
572
+
573
+ animationId = requestAnimationFrame(animate)
574
+
575
+ }
576
+
577
+ animate()
578
+
579
+ }
580
+
581
+
582
+
583
+ function stopRenderLoop() {
584
+
585
+ if (animationId) {
586
+
587
+ cancelAnimationFrame(animationId)
588
+
589
+ animationId = null
590
+
591
+ }
592
+
593
+ }
594
+
595
+
596
+
597
+ function setupActivityListeners() {
598
+
599
+ const activities = ['mousemove', 'keydown', 'touchmove', 'wheel', 'click']
600
+
601
+ activities.forEach((event) => {
602
+
603
+ document.addEventListener(event, () => {
604
+
605
+ lastActiveTime = Date.now()
606
+
607
+ })
608
+
609
+ })
610
+
611
+ }
612
+
613
+
614
+
615
+ function resumeMapAfterCache() {
616
+
617
+ if (!map || map.isDestroyed?.()) return
618
+
619
+ mapStore.setCurrentMapId(props.mapId)
620
+
621
+ isMapActive = true
622
+
623
+ lastActiveTime = Date.now()
624
+
625
+ nextTick(() => {
626
+
627
+ if (!map || map.isDestroyed?.()) return
628
+
629
+ map.resize()
630
+
631
+ const mode = mapStore.getSceneMode(props.mapId)
632
+
633
+ syncCameraInteractionMode(map, props.mapId, mode === '2D' ? '2D' : '3D')
634
+
635
+ map.render()
636
+
637
+ if (!animationId) startContinuousRendering(map)
638
+
639
+ })
640
+
641
+ }
642
+
643
+
644
+
645
+ watch(
646
+
647
+ () => props.toolbarButtons,
648
+
649
+ () => {
650
+
651
+ if (map && !map.isDestroyed?.()) {
652
+
653
+ mountToolbarButtons(map)
654
+
655
+ }
656
+
657
+ },
658
+
659
+ { deep: true },
660
+
661
+ )
662
+
663
+
664
+
665
+ onMounted(() => {
666
+
667
+ mapStore.setCurrentMapId(props.mapId)
668
+
669
+ setupActivityListeners()
670
+
671
+ onEvent('map-scene-mode-changed', handleSceneModeChange)
672
+
673
+ initCesium()
674
+
675
+ })
676
+
677
+
678
+
679
+ onActivated(() => {
680
+
681
+ mapStore.setCurrentMapId(props.mapId)
682
+
683
+ if (!map || map.isDestroyed?.()) {
684
+
685
+ isMapActive = true
686
+
687
+ initCesium()
688
+
689
+ return
690
+
691
+ }
692
+
693
+ resumeMapAfterCache()
694
+
695
+ })
696
+
697
+
698
+
699
+ onDeactivated(() => {
700
+
701
+ isMapActive = false
702
+
703
+ stopRenderLoop()
704
+
705
+ })
706
+
707
+
708
+
709
+ onUnmounted(() => {
710
+
711
+ isMapActive = false
712
+
713
+ stopRenderLoop()
714
+
715
+ offEvent('map-scene-mode-changed', handleSceneModeChange)
716
+
717
+ if (map) {
718
+
719
+ teardownOrthographicWheelZoom(map)
720
+
721
+ }
722
+
723
+ removeToolbarButtons(customButtons)
724
+
725
+ customButtons = []
726
+
727
+ if (map) {
728
+
729
+ map.destroy()
730
+
731
+ map = null
732
+
733
+ }
734
+
735
+ mapStore.removeMapInstance(props.mapId)
736
+
737
+ })
738
+
739
+ </script>
740
+
741
+
742
+
743
+ <style scoped lang="less">
744
+ .cesium-map-wrapper {
745
+
746
+ width: 100%;
747
+
748
+ height: 100%;
749
+
750
+ position: relative;
751
+
752
+ }
753
+
754
+
755
+
756
+ .cesium-container {
757
+
758
+ width: 100%;
759
+
760
+ height: 100%;
761
+
762
+ position: relative;
763
+
764
+ }
765
+ </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "huweili-cesium",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "基于 Cesium 的地图工具库(无人机态势、轨迹、围栏、工具栏等)",
5
5
  "type": "module",
6
6
  "main": "./index.js",