fix: 谷歌地图资源的展示

This commit is contained in:
hawk86104 2025-03-27 08:46:50 +08:00
parent 551339e9fd
commit 1718b54f64
2 changed files with 55 additions and 49 deletions

View File

@ -4,7 +4,7 @@
* @Autor: 地虎降天龙 * @Autor: 地虎降天龙
* @Date: 2024-03-13 17:14:11 * @Date: 2024-03-13 17:14:11
* @LastEditors: 地虎降天龙 * @LastEditors: 地虎降天龙
* @LastEditTime: 2024-08-12 11:06:13 * @LastEditTime: 2025-03-27 08:42:47
--> -->
<template> <template>
<div class="container circle" v-if="!hasFinishLoading"> <div class="container circle" v-if="!hasFinishLoading">
@ -29,6 +29,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { hasPlugin } from '@/common/utils' import { hasPlugin } from '@/common/utils'
import { useProgress } from '@tresjs/cientos' import { useProgress } from '@tresjs/cientos'
import { Resource } from 'PLS/resourceManager'
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
@ -48,8 +49,8 @@ let hasFinishLoading = null as any
if (props.useResourceManager) { if (props.useResourceManager) {
if (hasPlugin('resourceManager', '资源管理器插件')) { if (hasPlugin('resourceManager', '资源管理器插件')) {
const modules = import.meta.glob('/src/plugins/resourceManager/index.js') // const modules = import.meta.glob('/src/plugins/resourceManager/index.js')
const { Resource } = await modules['/src/plugins/resourceManager/index.js']() // const { Resource } = await modules['/src/plugins/resourceManager/index.js']()
progress = Resource.progress progress = Resource.progress
hasFinishLoading = Resource.hasAllFinished hasFinishLoading = Resource.hasAllFinished
} }

View File

@ -1,82 +1,87 @@
<!--
* @Description:
* @Version: 1.668
* @Autor: 地虎降天龙
* @Date: 2025-03-25 09:49:51
* @LastEditors: 地虎降天龙
* @LastEditTime: 2025-03-27 08:45:36
-->
<template> <template>
<TresGroup> <TresGroup>
<primitive :object="tiles.group" /> <primitive :object="tiles.group" />
</TresGroup> </TresGroup>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { watchEffect, toRaw } from 'vue'
import * as THREE from 'three'
import { useTresContext, useRenderLoop } from '@tresjs/core' import { useTresContext, useRenderLoop } from '@tresjs/core'
import { WGS84_ELLIPSOID, CAMERA_FRAME, GeoUtils, CameraTransitionManager, TilesRenderer, GlobeControls } from '3d-tiles-renderer' import { CameraTransitionManager, TilesRenderer, GlobeControls } from '3d-tiles-renderer'
import { import {
TilesFadePlugin, TilesFadePlugin,
UpdateOnChangePlugin, UpdateOnChangePlugin,
TileCompressionPlugin, TileCompressionPlugin,
UnloadTilesPlugin, UnloadTilesPlugin,
GLTFExtensionsPlugin, GLTFExtensionsPlugin,
BatchedTilesPlugin, CesiumIonAuthPlugin,
CesiumIonAuthPlugin,
} from '3d-tiles-renderer/plugins' } from '3d-tiles-renderer/plugins'
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js' import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js'
const assetId = '2275207' const assetId = '2275207'
const accessToken = const accessToken =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJhM2RlZDE0YS03NWNlLTQ2ZmItODFmZi0zMDQyZGMxZjdjNzQiLCJpZCI6NDYzMzQsImlhdCI6MTYxNjA1MjY2Nn0.3BRsxy7UmJgW0LemXo6cMsD7xwe7YvUDITeQ3RLxOHI' 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJhM2RlZDE0YS03NWNlLTQ2ZmItODFmZi0zMDQyZGMxZjdjNzQiLCJpZCI6NDYzMzQsImlhdCI6MTYxNjA1MjY2Nn0.3BRsxy7UmJgW0LemXo6cMsD7xwe7YvUDITeQ3RLxOHI'
const { camera, renderer, sizes, scene } = useTresContext() const { camera, renderer, sizes, scene } = useTresContext() as any
let transition = null as any let transition = null as any
let tiles = null as TilesRenderer let tiles = null as unknown as TilesRenderer
let globeControls = null as any let globeControls = null as any
function reinstantiateTiles() { function reinstantiateTiles() {
tiles = new TilesRenderer() tiles = new TilesRenderer()
tiles.registerPlugin( tiles.registerPlugin(
new CesiumIonAuthPlugin({ new CesiumIonAuthPlugin({
apiToken: accessToken, apiToken: accessToken,
assetId: assetId, assetId: assetId,
autoRefreshToken: true, autoRefreshToken: true,
}), }),
) )
tiles.registerPlugin(new TileCompressionPlugin()) tiles.registerPlugin(new TileCompressionPlugin())
tiles.registerPlugin(new UpdateOnChangePlugin()) tiles.registerPlugin(new UpdateOnChangePlugin())
tiles.registerPlugin(new UnloadTilesPlugin()) tiles.registerPlugin(new UnloadTilesPlugin())
tiles.registerPlugin(new TilesFadePlugin()) tiles.registerPlugin(new TilesFadePlugin())
tiles.registerPlugin( tiles.registerPlugin(
new GLTFExtensionsPlugin({ new GLTFExtensionsPlugin({
dracoLoader: new DRACOLoader().setDecoderPath('./draco/'), dracoLoader: new DRACOLoader().setDecoderPath('./draco/'),
}), }),
) )
tiles.group.rotation.x = -Math.PI / 2 tiles.group.rotation.x = -Math.PI / 2
} }
reinstantiateTiles() reinstantiateTiles()
tiles.setCamera(camera.value) tiles.setCamera(camera.value)
tiles.setResolutionFromRenderer(camera.value, renderer.value) tiles.setResolutionFromRenderer(camera.value, renderer.value)
transition = new CameraTransitionManager(camera.value, null) transition = new CameraTransitionManager(camera.value, undefined)
transition.perspectiveCamera.position.set(-3960140, 3689031, -3364162) transition.perspectiveCamera.position.set(-3960140, 3689031, -3364162)
transition.perspectiveCamera.lookAt(0, 0, 0) transition.perspectiveCamera.lookAt(0, 0, 0)
transition.autoSync = false transition.autoSync = false
transition.orthographicPositionalZoom = false transition.orthographicPositionalZoom = false
globeControls = new GlobeControls(scene.value, transition.camera, renderer.value.domElement, null) globeControls = new GlobeControls(scene.value, transition.camera, renderer.value.domElement, undefined)
globeControls.enableDamping = true globeControls.enableDamping = true
globeControls.setTilesRenderer(tiles) globeControls.setTilesRenderer(tiles)
const { onBeforeLoop } = useRenderLoop() const { onBeforeLoop } = useRenderLoop()
onBeforeLoop(() => { onBeforeLoop(() => {
if (camera.value && sizes.width.value && tiles) { if (camera.value && sizes.width.value && tiles) {
globeControls.enabled = !transition.animating globeControls.enabled = !transition.animating
globeControls.update() globeControls.update()
transition.update() transition.update()
const camerac = transition.camera const camerac = transition.camera
tiles.setResolutionFromRenderer(camerac, renderer.value) tiles.setResolutionFromRenderer(camerac, renderer.value)
tiles.setCamera(camerac) tiles.setCamera(camerac)
camerac.updateMatrixWorld() camerac.updateMatrixWorld()
tiles.update() tiles.update()
} }
}) })
</script> </script>