forked from dvgis/dc-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflying.html
87 lines (79 loc) · 2.92 KB
/
flying.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>dc-example</title>
<script src='/libs/dc-sdk/dc.min.js'></script>
<link href='/libs/dc-sdk/dc.min.css' type='text/css' rel='stylesheet'>
<link href='../index.css' type='text/css' rel='stylesheet'>
</head>
<body>
<div id="viewer-container" class="viewer-container"></div>
<div class="btn-box">
<ul>
<li><input type="checkbox" name="check_loop" /> 是否循环 </li>
<li><button onclick="start()">开始</button></li>
<li><button onclick="pause()">暂停</button></li>
<li><button onclick="restore()">继续</button></li>
</ul>
</div>
<script>
let viewer = undefined
let flying = undefined
function start(){
let checked = document.getElementsByName('check_loop')[0].checked
flying = new DC.Flying(viewer,{
loop: checked,
dwellTime:3,
})
flying.positions = [
{lng: 121.46748793889597, lat: 31.22345700031846, alt: 1082.6691622203975, heading: 0.9161118327237789, pitch: -38.63414039808751},
{lng: 121.49543157056694, lat: 31.219611353179484, alt: 663.5376240776116, heading: 0.9161124649627334, pitch: -38.63418986635751},
{lng: 121.53162234574106, lat: 31.228003869427294, alt: 1891.926162456467, heading: 298.6565902579582, pitch: -33.67285705092492},
{lng: 121.54438164431083, lat: 31.25201585389836, alt: 1441.4625182144541, heading: 298.65660919687264, pitch: -33.6728415156399}
]
flying.start()
}
function pause(){
flying.pause()
}
function restore(){
flying.restore()
}
function initViewer() {
viewer = new DC.Viewer('viewer-container')
let baseLayer = DC.ImageryLayerFactory.createAmapImageryLayer({
style: 'img',
crs:'WGS84'
})
viewer.addBaseLayer( baseLayer,{ brightness : 0.1})
let layer = new DC.TilesetLayer('layer').addTo(viewer)
let tileset = new DC.Tileset(
'//resource.dvgis.cn/data/3dtiles/ljz/tileset.json'
)
let customShader = new DC.CustomShader({
fragmentShaderText:`
void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
vec4 position = czm_inverseModelView * vec4(fsInput.attributes.positionEC,1); // 位置
float glowRange = 100.0; // 光环的移动范围(高度)
vec4 temp = vec4(0.2, 0.5, 1.0, 1.0); // 颜色
temp *= vec4(vec3(position.z / 100.0), 1.0); // 渐变
// 动态光环
float time = fract(czm_frameNumber / 360.0);
time = abs(time - 0.5) * 2.0;
float diff = step(0.005, abs( clamp(position.z / glowRange, 0.0, 1.0) - time));
material.diffuse = vec3(temp.rgb + temp.rgb * (1.0 - diff)) ;
}
`
})
tileset.setCustomShader(customShader)
layer.addOverlay(tileset)
viewer.flyTo(tileset)
}
DC.ready({
baseUrl:'../libs/dc-sdk/resources/'
}).then(initViewer)
</script>
</body>
</html>