Hello, after my project has been running for some time now, a DeveloperError will occur: “Expected width to be greater than 0, actual value was 0” reported an error. Currently, the computer is Windows 11, Google Chrome version 135.0.7049.115 (official version) (64-bit). I’ll also post the code. The vue framework is being used. I hope this question can be answered. Thank you.
<script setup>
import { onUnmounted, ref, onMounted, reactive, nextTick } from "vue";
import * as Cesium from "cesium";
import { ElCheckbox } from 'element-plus';
import 'ol/ol.css'
import { Map, View } from 'ol'
import TileLayer from 'ol/layer/Tile'
import XYZ from "ol/source/XYZ";
import olcsCamera from "olcs/Camera";
const state = reactive({
isShow3D: false,
element2D: {},
element3D: {},
camera: {},
});
const switchTo = () => {
state.element2D.style.visibility = state.isShow3D
? "hidden"
: "visible";
state.element3D.style.visibility = state.isShow3D
? "visible"
: "hidden";
}
let cesiumViewer
const initmap = () => {
Cesium.Ion.defaultAccessToken = ''
cesiumViewer = new Cesium.Viewer("cesiumContainer", {
infoBox: false,
geocoder: false,
homeButton: false,
sceneModePicker: false,
baseLayerPicker: false,
navigationHelpButton: false,
animation: false,
// creditContainer:"credit",
timeline: false,
maximumScreenSpaceError: 32,
skipLevelOfDetail: true,
immediatelyLoadDesiredLevelOfDetail: true,
contextOptions: {
requestWebgl1: true,
},
fullscreenButton: false
});
const olViewer = new Map({
target: "olContainer",
layers: [
new TileLayer({
source: new XYZ({
url: "",
}),
}),
],
view: new View({
projection: "EPSG:4326",
center: [0, 0],
zoom: 15
})
});
state.element2D = document.getElementById("olContainer");
state.element3D = document.getElementById("cesiumContainer");
state.camera = new olcsCamera(
cesiumViewer.scene,
olViewer
);
state.element3D.style.visibility = "hidden";
}
onMounted(() => {
initmap()
})
</script>
<template>
<div class="main">
<el-checkbox v-model="state.isShow3D" label=" Three-dimensional Earth " size="large" @change="switchTo"
style="position: absolute; z-index: 99; color: white;" /><br />
<div id="olContainer"></div>
<div id="cesiumContainer"></div>
</div>
</template>
<style lang="less" scoped>
.main {
height: 100vh;
width: 100vw;
#cesiumContainer {
position: absolute;
height: 100vh;
width: 100vw;
}
#olContainer {
position: absolute;
height: 100vh;
width: 100vw;
}
}
</style>