SceneModePicker
是一个CesiumJS
的小部件,用于切换场景模式(2D、3D、垂直)。
将cesium.js
文件下载到本地,然后在HTML文件中按以下方式引用:
<script src="./cesium/Cesium.js"></script>
要使用SceneModePicker,请按照以下步骤操作:
Cesium.Viewer
对象:let viewer = new Cesium.Viewer('cesiumContainer');
SceneModePicker
添加到 viewer
上:let sceneModePicker = new Cesium.SceneModePicker(document.getElementById("sceneModePickerContainer"), viewer);
/* CSS */
#sceneModePickerContainer {
position: absolute;
top: 20px;
left: 20px;
}
/* 或者直接修改默认样式 */
.cesium-sceneModePicker-wrapper {
/*添加自己的样式*/
}
SceneModePicker
有一些方法和属性可供使用。
销毁 SceneModePicker
。
sceneModePicker.destroy();
SceneModePicker
的 DOM 容器。
let container = sceneModePicker.container;
SceneModePicker
的ViewModel
属性。
let viewModel = sceneModePicker.viewModel;
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="./cesium/Widgets/widgets.css" type="text/css">
<style>
#sceneModePickerContainer {
position: absolute;
top: 20px;
left: 20px;
}
.cesium-sceneModePicker-wrapper {
width: 35px;
margin: 5px;
}
</style>
<title>Test Scene</title>
</head>
<body>
<div id="cesiumContainer" style="height:500px;"></div>
<div id="sceneModePickerContainer"></div>
<script src="./cesium/Cesium.js"></script>
<script>
let viewer = new Cesium.Viewer('cesiumContainer');
let sceneModePicker = new Cesium.SceneModePicker(document.getElementById("sceneModePickerContainer"), viewer);
</script>
</body>
</html>