|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { Viewer } from 'cesium' |
| 3 | +import { useGLTF } from '#imports' |
| 4 | +import { Cartesian3, Color, HeightReference, Math, PolygonHierarchy } from 'cesium' |
| 5 | +
|
| 6 | +const cesiumContainerRef = useTemplateRef('cesiumContainer') |
| 7 | +
|
| 8 | +let viewer: Viewer |
| 9 | +
|
| 10 | +onMounted(() => { |
| 11 | + if (!cesiumContainerRef.value) |
| 12 | + return |
| 13 | +
|
| 14 | + viewer = useViewer(cesiumContainerRef.value) |
| 15 | +
|
| 16 | + // 加载泰山区宿舍的GeoJSON数据 |
| 17 | + const data = loadGeoJson('/data/泰山区宿舍.geojson', { |
| 18 | + stroke: Color.fromCssColorString('#aaaa9d'), |
| 19 | + fill: Color.fromCssColorString('#aaaa9d').withAlpha(0.5), |
| 20 | + strokeWidth: 3, |
| 21 | + clampToGround: true, |
| 22 | + }) |
| 23 | + viewer.dataSources.add(data) |
| 24 | +
|
| 25 | + geoJsonToBuildingModel('/data/泰山区宿舍1-4.geojson').then((positions) => { |
| 26 | + positions.forEach((position) => { |
| 27 | + viewer.entities.add({ |
| 28 | + polygon: { |
| 29 | + hierarchy: new PolygonHierarchy(position), // 底面形状 |
| 30 | + height: 0, // 底部高度(从地面0开始) |
| 31 | + heightReference: HeightReference.CLAMP_TO_TERRAIN, |
| 32 | + extrudedHeight: 30, // 顶部高度(总高度100米,可调整) |
| 33 | + material: Color.WHITE, // 填充材质(半透明红色) |
| 34 | + outline: true, // 显示轮廓 |
| 35 | + outlineColor: Color.BLACK, // 轮廓颜色 |
| 36 | + outlineWidth: 2, // 轮廓宽度 |
| 37 | + }, |
| 38 | + }) |
| 39 | + }) |
| 40 | + }) |
| 41 | +
|
| 42 | + useGLTF('/data/Air.glb', { position: Cartesian3.fromDegrees(113.36629986763, 23.15732289356693, 3) }) |
| 43 | +
|
| 44 | + viewer.camera.flyTo({ |
| 45 | + destination: Cartesian3.fromDegrees(113.36629986763, 23.15732289356693, 70), |
| 46 | + orientation: { |
| 47 | + heading: Math.toRadians(-90), |
| 48 | + pitch: 0, |
| 49 | + }, |
| 50 | + }) |
| 51 | +}) |
| 52 | +
|
| 53 | +onUnmounted(() => { |
| 54 | + if (viewer) { |
| 55 | + viewer.destroy() |
| 56 | + } |
| 57 | +}) |
| 58 | +</script> |
| 59 | + |
| 60 | +<template> |
| 61 | + <div> |
| 62 | + <div ref="cesiumContainer" style="width: 100%;height: 100vh;" /> |
| 63 | + </div> |
| 64 | +</template> |
| 65 | + |
| 66 | +<style scoped> |
| 67 | +
|
| 68 | +</style> |
0 commit comments