本文主要是介绍cesium 添加可视域,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
引入cesium-viewshed.js 下载地址https://download.csdn.net/download/qq_34200979/14894299
<!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/CesiumUnminified/Cesium.js"></script><script src="cesium-viewshed.js"></script><style>@import url(../Build/CesiumUnminified/Widgets/widgets.css);</style></head><body><div id="viewer-container"></div><div id="btn"><button onclick="setvisible('add')">添加可视域</button><button onclick="setvisible('remove')">删除可视域</button></div><script>var viewer = null;var arrViewField = [];var viewModel = {verticalAngle: 90,horizontalAngle: 120,distance: 10};// 开关function setvisible(value) {switch (value) {case 'add':addViewField();break;case 'remove':clearAllViewField();break;}}// 添加可视域function addViewField() {var e = new Cesium.ViewShed3D(viewer, {horizontalAngle: Number(viewModel.horizontalAngle),verticalAngle: Number(viewModel.verticalAngle),distance: Number(viewModel.distance),calback: function() {viewModel.distance = e.distance}});arrViewField.push(e)}// 清除可视域function clearAllViewField() {for (var e = 0, i = arrViewField.length; e < i; e++) {arrViewField[e].destroy()}arrViewField = []}// initfunction initPage() {viewer = new Cesium.Viewer("viewer-container", {});var tilesets = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({url: 'xian/tileset.json'}));viewer.flyTo(tilesets)}// window.onload = function() {initPage()}</script></body></html>
这篇关于cesium 添加可视域的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!