-
Notifications
You must be signed in to change notification settings - Fork 53
/
index.html
104 lines (99 loc) · 2.73 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>可视域分析</title>
<link href="src/Cesium/Widgets/widgets.css" rel="stylesheet" />
<script src="src/Cesium/Cesium.js"></script>
<script src="src/cesium-viewshed.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
html,
body,
#viewer-container {
width: 100%;
height: 100%;
overflow: hidden;
}
#btn {
position: absolute;
top: 50px;
left: 50px;
}
</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 = []
}
// init
function initPage() {
// 切换自己的token
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJlYTQ2ZjdjNS1jM2E0LTQ1M2EtOWM0My1mODMzNzY3YjYzY2YiLCJpZCI6MjkzMjcsInNjb3BlcyI6WyJhc3IiLCJnYyJdLCJpYXQiOjE1OTE5NDIzNjB9.RzKlVTVDTQ9r7cqCo-PDydgUh8Frgw0Erul_BVxiS9c';
// 初始化
viewer = new Cesium.Viewer("viewer-container", {
infoBox: false,
shouldAnimate: true,
vrButton: true,
geocoder: false,
homeButton: false,
sceneModePicker: false,
baseLayerPicker: true,
navigationHelpButton: false,
animation: false,
timeline: false,
fullscreenButton: false,
});
// 加载倾斜摄影 大雁塔
var tilesets = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url: 'http://earthsdk.com/v/last/Apps/assets/dayanta/tileset.json'
}));
viewer.flyTo(tilesets)
}
//
window.onload = function () {
initPage()
}
</script>
</body>
</html>