|
@@ -15,6 +15,7 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
|
+import CesiumPreloader from '@/utils/cesiumPreloader';
|
|
|
const Cesium = window.Cesium;
|
|
const Cesium = window.Cesium;
|
|
|
|
|
|
|
|
function createOuterRingTexture(color) {
|
|
function createOuterRingTexture(color) {
|
|
@@ -112,12 +113,15 @@ export default {
|
|
|
|
|
|
|
|
this._coords = { start: [-15.0, 35.86, 45000000], china: [104.19, 35.86, 14000000] };
|
|
this._coords = { start: [-15.0, 35.86, 45000000], china: [104.19, 35.86, 14000000] };
|
|
|
|
|
|
|
|
- this.$nextTick(() => {
|
|
|
|
|
|
|
+ this.$nextTick(async () => {
|
|
|
if (!this.$refs.cesiumContainer) return;
|
|
if (!this.$refs.cesiumContainer) return;
|
|
|
- this.initCesium();
|
|
|
|
|
- this.waitForGlobeReady().then(() => {
|
|
|
|
|
- if (!this._destroyed) this.startTransition();
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // 尝试复用预加载的 Viewer
|
|
|
|
|
+ const preloaded = await CesiumPreloader.acquire(this.$refs.cesiumContainer);
|
|
|
|
|
+ this.initCesium(preloaded);
|
|
|
|
|
+ if (!preloaded) {
|
|
|
|
|
+ await this.waitForGlobeReady();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!this._destroyed) this.startTransition();
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
beforeDestroy() {
|
|
beforeDestroy() {
|
|
@@ -135,9 +139,11 @@ export default {
|
|
|
methods: {
|
|
methods: {
|
|
|
waitForGlobeReady() {
|
|
waitForGlobeReady() {
|
|
|
return new Promise(resolve => {
|
|
return new Promise(resolve => {
|
|
|
|
|
+ const startTime = Date.now();
|
|
|
|
|
+ const maxWait = 3000; // 最多等待3秒,避免卡住
|
|
|
const check = () => {
|
|
const check = () => {
|
|
|
if (this._destroyed) { resolve(); return; }
|
|
if (this._destroyed) { resolve(); return; }
|
|
|
- if (this._viewer && this._viewer.scene.globe.tilesLoaded) {
|
|
|
|
|
|
|
+ if ((this._viewer && this._viewer.scene.globe.tilesLoaded) || (Date.now() - startTime > maxWait)) {
|
|
|
resolve();
|
|
resolve();
|
|
|
} else {
|
|
} else {
|
|
|
requestAnimationFrame(check);
|
|
requestAnimationFrame(check);
|
|
@@ -147,7 +153,7 @@ export default {
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- initCesium() {
|
|
|
|
|
|
|
+ initCesium(preloadedViewer) {
|
|
|
this._baseGold = Cesium.Color.GOLD;
|
|
this._baseGold = Cesium.Color.GOLD;
|
|
|
this._baseWhite = Cesium.Color.WHITE;
|
|
this._baseWhite = Cesium.Color.WHITE;
|
|
|
this._baseBlack = Cesium.Color.BLACK;
|
|
this._baseBlack = Cesium.Color.BLACK;
|
|
@@ -164,15 +170,38 @@ export default {
|
|
|
color: Cesium.Color.fromCssColorString(r.color)
|
|
color: Cesium.Color.fromCssColorString(r.color)
|
|
|
}));
|
|
}));
|
|
|
|
|
|
|
|
- this._viewer = new Cesium.Viewer(this.$refs.cesiumContainer, {
|
|
|
|
|
- animation: false, timeline: false, baseLayerPicker: false, geocoder: false,
|
|
|
|
|
- homeButton: false, sceneModePicker: false, navigationHelpButton: false, infoBox: false,
|
|
|
|
|
- fullscreenButton: false, selectionIndicator: false,
|
|
|
|
|
- imageryProvider: new Cesium.UrlTemplateImageryProvider({
|
|
|
|
|
- url: './tiles/{z}/{y}/{x}.jpg',
|
|
|
|
|
- maximumLevel: 12
|
|
|
|
|
- })
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (preloadedViewer) {
|
|
|
|
|
+ // 复用预加载的 Viewer(瓦片已渲染好)
|
|
|
|
|
+ this._viewer = preloadedViewer;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 降级:从头创建
|
|
|
|
|
+ this._viewer = new Cesium.Viewer(this.$refs.cesiumContainer, {
|
|
|
|
|
+ animation: false, timeline: false, baseLayerPicker: false, geocoder: false,
|
|
|
|
|
+ homeButton: false, sceneModePicker: false, navigationHelpButton: false, infoBox: false,
|
|
|
|
|
+ fullscreenButton: false, selectionIndicator: false, shadows: false, shouldAnimate: false,
|
|
|
|
|
+ requestRenderMode: false,
|
|
|
|
|
+ imageryProvider: new Cesium.UrlTemplateImageryProvider({
|
|
|
|
|
+ url: './tiles/{z}/{y}/{x}.jpg',
|
|
|
|
|
+ maximumLevel: 12
|
|
|
|
|
+ })
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ this._viewer.cesiumWidget.creditContainer.style.display = "none";
|
|
|
|
|
+
|
|
|
|
|
+ const scene = this._viewer.scene;
|
|
|
|
|
+ scene.fog.enabled = false;
|
|
|
|
|
+ scene.skyAtmosphere.show = false;
|
|
|
|
|
+ scene.globe.showGroundAtmosphere = false;
|
|
|
|
|
+ scene.globe.enableLighting = true;
|
|
|
|
|
+ scene.globe.tileCacheSize = 300;
|
|
|
|
|
+ scene.globe.maximumScreenSpaceError = 1.5;
|
|
|
|
|
+
|
|
|
|
|
+ this._viewer.clock.currentTime = Cesium.JulianDate.fromDate(new Date('2024-01-01T23:30:00Z'));
|
|
|
|
|
+ this._viewer.clock.shouldAnimate = false;
|
|
|
|
|
+
|
|
|
|
|
+ const baseLayer = this._viewer.imageryLayers.get(0);
|
|
|
|
|
+ if (baseLayer) { baseLayer.brightness = 0.45; baseLayer.contrast = 1.3; }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
const cam = this._viewer.scene.screenSpaceCameraController;
|
|
const cam = this._viewer.scene.screenSpaceCameraController;
|
|
|
cam.enableRotate = false;
|
|
cam.enableRotate = false;
|
|
@@ -181,14 +210,6 @@ export default {
|
|
|
cam.enableTilt = false;
|
|
cam.enableTilt = false;
|
|
|
cam.enableLook = false;
|
|
cam.enableLook = false;
|
|
|
|
|
|
|
|
- this._viewer.cesiumWidget.creditContainer.style.display = "none";
|
|
|
|
|
- this._viewer.scene.globe.enableLighting = true;
|
|
|
|
|
- this._viewer.clock.currentTime = Cesium.JulianDate.fromDate(new Date('2024-01-01T23:30:00Z'));
|
|
|
|
|
- this._viewer.clock.shouldAnimate = false;
|
|
|
|
|
-
|
|
|
|
|
- const baseLayer = this._viewer.imageryLayers.get(0);
|
|
|
|
|
- if (baseLayer) { baseLayer.brightness = 0.45; baseLayer.contrast = 1.3; }
|
|
|
|
|
-
|
|
|
|
|
// 微观区域高清卫星底图
|
|
// 微观区域高清卫星底图
|
|
|
if (this.satelliteImage && this.satelliteImage.url) {
|
|
if (this.satelliteImage && this.satelliteImage.url) {
|
|
|
const b = this.satelliteImage.bounds;
|
|
const b = this.satelliteImage.bounds;
|
|
@@ -420,12 +441,6 @@ export default {
|
|
|
this._microEffectsSource.show = true;
|
|
this._microEffectsSource.show = true;
|
|
|
if (this.poi && this.$refs.poiLabel) this.$refs.poiLabel.style.opacity = 1;
|
|
if (this.poi && this.$refs.poiLabel) this.$refs.poiLabel.style.opacity = 1;
|
|
|
|
|
|
|
|
- // 阶段4: 路网生长
|
|
|
|
|
- await this._safeDelay(300);
|
|
|
|
|
- if (this._destroyed) return;
|
|
|
|
|
- const roadPromises = this._majorRoads.map((road, i) => this.animatePathGrowing(road, i * 150));
|
|
|
|
|
- await Promise.all(roadPromises);
|
|
|
|
|
- if (this._destroyed) return;
|
|
|
|
|
await this._safeDelay(1000);
|
|
await this._safeDelay(1000);
|
|
|
if (this._destroyed) return;
|
|
if (this._destroyed) return;
|
|
|
this.$emit('complete');
|
|
this.$emit('complete');
|