I have a task which
I want to change the scene mode in Cesium every 1 mins.
For example, let say be default the scene mode is 3D. after 1 mins, it will change to 2D mode and then anohter. I used refresh feature to change the scene mode. Here is my code below.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Use correct character set. -->
<meta charset="utf-8">
<!-- Tell IE to use the latest, best version. -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Make the application on mobile take up the full browser screen and disable user scaling. -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<title>Hello World!</title>
<script src="../Build/Cesium/Cesium.js"></script>
<style>
@import url(../Build/Cesium/Widgets/widgets.css);
html, body, #cesiumContainer {
width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
}
</style>
</head>
<body>
<div id="cesiumContainer"></div>
<script type="text/javascript">
var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;
scene.mode= Cesium.SceneMode.SCENE3D;
var scenename = "3D";
console.log("Scene Mode 3D");
//updateFromServer();
var intervalID = window.setInterval(updateFromServer, 6000);
function updateFromServer() {
if (scenename = "3D")
{
var scene = viewer.scene;
scene.mode= Cesium.SceneMode.SCENE2D;
//document.cookie = "SceneMode=2D;";
scenename = "2D";
console.log("Scene Mode 2D");
}
else
{
var scene = viewer.scene;
scene.mode= Cesium.SceneMode.SCENE3D;
scenename = "3D";
console.log("Scene Mode 3D");
}
}
</script>
</body>
</html>
It does not work except my console.log.
Can you help me?
Best Answer
You're using a single '=' sign in the condition which assigns scenename to"3D". Instead, in your if statement use '===' to compare the value of scenemane . Use
p.s. you also don't need to re-declare scene
var scene = viewer.scene;
inside the updateFromServer() function.