1+ <!DOCTYPE html>
2+ < html xmlns ="http://www.w3.org/1999/xhtml ">
3+
4+ < head >
5+ < meta charset ='utf-8 ' />
6+ < meta name ='viewport ' content ='initial-scale=1,maximum-scale=1,user-scalable=no ' />
7+ < title > 动画漫游</ title >
8+ <!--引入第三方的jquery脚本库-->
9+ < script include ="jquery " src ="./static/libs/include-lib-local.js "> </ script >
10+ < script src ="./static/libs/include-cesium-local.js "> </ script >
11+ <!--当前示例页面样式表引用-->
12+ < link rel ="stylesheet " href ="./static/demo/cesium/style.css " />
13+ < script >
14+ 'use strict' ;
15+
16+ //定义三维视图的主要类
17+ var webGlobe ;
18+ //定义动画漫游对象、路径;
19+ var animation , positions ;
20+
21+ //地图初始化函数
22+ function init ( ) {
23+ //构造三维视图类(视图容器div的id,三维视图设置参数)
24+ webGlobe = new Cesium . WebSceneControl ( 'GlobeView' , {
25+ terrainExaggeration : 1 ,
26+ } ) ;
27+
28+ //构造第三方图层对象
29+ var thirdPartyLayer = new CesiumZondy . Layer . ThirdPartyLayer ( {
30+ viewer : webGlobe . viewer
31+ } ) ;
32+ //添加Google地图
33+ thirdPartyLayer . appendGoogleMapExt ( {
34+ //m-全地图(含矢量与道路)、r-矢量地图、h-道路地图、s-卫星影像地图、t-地形图
35+ ptype : 's'
36+ } ) ;
37+
38+ //视点跳转(经度,纬度,视角高度,方位角,俯仰角,翻滚角)
39+ webGlobe . flyToEx ( 117.213063 , 31.812956 , {
40+ height : 200 ,
41+ heading : 90 ,
42+ pitch : 0 ,
43+ roll : 0
44+ } ) ;
45+
46+ //显示鼠标位置控件
47+ webGlobe . showPosition ( 'coordinate_location' ) ;
48+ //显示导航控件(罗盘、比例尺、场景导航)
49+ webGlobe . createNavigationTool ( {
50+ enableCompass : true ,
51+ enableZoomControls : true ,
52+ enableDistanceLegend : true
53+ } ) ;
54+
55+ var viewer = webGlobe . viewer ;
56+ var scene = webGlobe . scene ;
57+ //避免穿透地形
58+ var controller = scene . screenSpaceCameraController ;
59+ controller . minimumZoomDistance = 3000 ;
60+ scene . camera . enableTerrainAdjustmentWhenLoading = true ; //避免穿透地形
61+
62+ //漫游路径
63+ positions = Cesium . Cartesian3 . fromDegreesArray ( [
64+ 117.213063 , 31.812956 , 117.213162 , 31.812389 , 117.212929 , 31.812056 , 117.213275 , 31.811582 ,
65+ 117.21348 , 31.811513 , 117.214141 , 31.811682 , 117.21497 , 31.811691 , 117.216318 , 31.811454 ,
66+ 117.216962 , 31.812037 , 117.217893 , 31.812298 , 117.218607 , 31.811488 , 117.219466 , 31.810935 ,
67+ 117.224439 , 31.810929 , 117.225266 , 31.811119 , 117.225308 , 31.81131 , 117.224819 , 31.811724 ,
68+ 117.225189 , 31.811928 , 117.225676 , 31.811624 , 117.225843 , 31.811943 , 117.22625 , 31.812183 ,
69+ 117.226292 , 31.81281 , 117.225888 , 31.813287 , 117.226093 , 31.814059 , 117.22564 , 31.814582 ,
70+ 117.225953 , 31.814731 , 117.225611 , 31.814954 , 117.22576 , 31.815233 , 117.224073 , 31.816329 ,
71+ 117.223694 , 31.81627 , 117.222769 , 31.817007 , 117.222259 , 31.816871 , 117.221922 , 31.816707 ,
72+ 117.221653 , 31.816788 , 117.22151 , 31.817002 , 117.221039 , 31.816891 , 117.220395 , 31.816352 ,
73+ 117.220166 , 31.815734 , 117.219804 , 31.815607 , 117.219461 , 31.815122 , 117.21878 , 31.814846 ,
74+ 117.218297 , 31.815275 , 117.217975 , 31.815172 , 117.217142 , 31.815229 , 117.216753 , 31.815124 ,
75+ 117.216652 , 31.814308 , 117.215726 , 31.814049 , 117.214769 , 31.813517 , 117.214111 , 31.813717 ,
76+ 117.213552 , 31.814099 , 117.213024 , 31.813954 , 117.212897 , 31.813892 , 117.213224 , 31.813681 ,
77+ 117.212788 , 31.813147 , 117.212928 , 31.813018 , 117.213063 , 31.812956
78+ ] ) ;
79+
80+ //初始化高级分析功能管理类
81+ var advancedAnalysisManager = new CesiumZondy . Manager . AdvancedAnalysisManager ( {
82+ viewer : webGlobe . viewer
83+ } ) ;
84+ //创建动画漫游对象
85+ animation = advancedAnalysisManager . createAnimation ( {
86+ exHeight : 9 ,
87+ isLoop : false ,
88+ //漫游模型url
89+ modelUrl : './static/data/model/WuRenJi.glb' ,
90+ //完成动画漫游回调函数
91+ complete : function ( ) {
92+ alert ( '完毕' ) ;
93+ }
94+ } ) ;
95+
96+ //设置路径
97+ animation . positions = positions ;
98+ //漫游方式:1-跟随、2-锁定第一视角、3-上帝视角
99+ animation . animationType = 2 ;
100+ //漫游速度
101+ animation . speed = 1 ;
102+
103+ //设置动画漫游参数
104+ var viewModel = {
105+ pitch : 0 , //俯仰角
106+ heading : 90 , //方位角
107+ range : 0 , //距离
108+ speed : 1 //速度
109+ } ;
110+ Cesium . knockout . track ( viewModel ) ;
111+ //与界面UI绑定
112+ var toolbar = document . getElementById ( 'toolbar' ) ;
113+ Cesium . knockout . applyBindings ( viewModel , toolbar ) ;
114+
115+ function subscribeParameter ( name ) {
116+ Cesium . knockout . getObservable ( viewModel , name ) . subscribe (
117+ function ( newValue ) {
118+ if ( name === 'pitch' ) {
119+ //animation.offsetZ = newValue;
120+ //animation.pitch = Cesium.Math.toRadians(parseInt(newValue));
121+ animation . pitch = Cesium . Math . toRadians ( parseInt ( newValue ) ) ; //俯仰角
122+ } else if ( name === 'range' ) {
123+ animation . range = parseFloat ( newValue ) ; //距离
124+
125+ } else if ( name === 'heading' ) {
126+ animation . heading = Cesium . Math . toRadians ( parseInt ( newValue ) ) ; //方位角
127+ } else if ( name === 'speed' ) {
128+ animation . speedupFactor = parseFloat ( newValue ) ; //速度
129+ }
130+ }
131+ ) ;
132+ }
133+ subscribeParameter ( 'pitch' ) ;
134+ subscribeParameter ( 'heading' ) ;
135+ subscribeParameter ( 'range' ) ;
136+ subscribeParameter ( 'speed' ) ;
137+
138+ /*
139+ function callBack(arg) {
140+ //绘制路径点
141+ positions = arg._points;
142+ //设置漫游路径
143+ animation.positions = positions;
144+ //显示路径
145+ animation.animationModel.path.show._value = !animation.animationModel.path.show._value;
146+ //开始漫游
147+ animation.start();
148+ //漫游速度
149+ animation.speed = 1;
150+ //漫游方式:1-跟随、2-锁定第一视角、3-上帝视角
151+ animation.animationType = 2;
152+
153+ }
154+ //创建交互绘制工具
155+ var drawPolygon = new Cesium.DrawPolygonTool(webGlobe.viewer, callBack);
156+ drawPolygon.activeTool();
157+ */
158+ }
159+
160+ function start ( ) {
161+ //开始漫游
162+ animation . start ( ) ;
163+ //显示路径
164+ animation . _animationModel . _path . _show . _value = true ;
165+ }
166+
167+ function pause ( ) {
168+ //暂停漫游
169+ animation . pause = true ;
170+ }
171+
172+ function stop ( ) {
173+ //停止漫游
174+ animation . stop ( ) ;
175+ }
176+
177+ function changeType ( ) {
178+ var aType = document . getElementsByName ( "animationType" )
179+ for ( var i = 0 ; i < aType . length ; i ++ ) {
180+ if ( aType [ i ] . checked ) {
181+ if ( Number ( aType [ i ] . value ) == 2 ) {
182+ document . getElementById ( "pitch" ) . style . display = "" ;
183+ document . getElementById ( "heading" ) . style . display = "" ;
184+ } else {
185+ document . getElementById ( "pitch" ) . style . display = 'none' ;
186+ document . getElementById ( "heading" ) . style . display = 'none' ;
187+ }
188+ //设置漫游方式:1-跟随、2-锁定第一视角、3-上帝视角
189+ animation . animationType = Number ( aType [ i ] . value ) ;
190+ }
191+ }
192+ }
193+ </ script >
194+ </ head >
195+
196+ < body onload ="init() ">
197+ < div id ="GlobeView ">
198+ < div class ="message ">
199+ < button id ="start " onclick ="start() "> 开始漫游</ button >
200+ < button id ="pause " onclick ="pause() "> 暂停漫游</ button >
201+ < button id ="stop " onclick ="stop() "> 结束漫游</ button >
202+ </ div >
203+ </ div >
204+ <!--坐标容器-->
205+ < div id ="coordinateDiv " class ="coordinateClass ">
206+ < label id ="coordinate_location "> </ label >
207+ < label id ="coordinate_height "> </ label >
208+ </ div >
209+
210+ < div class ="message " id ="toolbar " style ="left: unset; top: 40px; ">
211+ < table >
212+ < tbody >
213+ < tr >
214+ < td > 漫游方式</ td >
215+ < td >
216+ < label > < input style ="float:unset; width:unset; " name ="animationType " type ="radio " value ="1 "
217+ onclick ="changeType() " /> 跟随</ label >
218+ < label > < input style ="float:unset; width:unset; " name ="animationType " type ="radio " checked
219+ value ="2 " onclick ="changeType() " /> 锁定第一视角</ label >
220+ < label > < input style ="float:unset; width:unset; " name ="animationType " type ="radio " value ="3 "
221+ onclick ="changeType() " /> 上帝视角</ label >
222+
223+ </ td >
224+ </ tr >
225+ < tr >
226+ < td > </ td >
227+ </ tr >
228+ < tr id ="pitch " style ="display:'' ">
229+ < td > 俯仰角</ td >
230+ < td >
231+ < input type ="range " min ="-180 " max ="180 " value ="0 " step ="1 "
232+ data-bind ="value: pitch, valueUpdate: 'input' " size ="20 ">
233+ < input type ="number " size ="2 " data-bind ="value: pitch ">
234+ </ td >
235+ </ tr >
236+ < tr id ="heading " style ="display:'' ">
237+ < td > 方位角</ td >
238+ < td >
239+ < input type ="range " min ="-180 " max ="180 " value ="90 " step ="1 "
240+ data-bind ="value: heading, valueUpdate: 'input' ">
241+ < input type ="number " size ="2 " data-bind ="value: heading ">
242+ </ td >
243+ </ tr >
244+ < tr >
245+ < td > 距离</ td >
246+ < td >
247+ < input type ="range " min ="0.1 " max ="200 " step ="1 " data-bind ="value: range, valueUpdate: 'input' ">
248+ < input type ="number " size ="2 " data-bind ="value: range ">
249+ </ td >
250+ </ tr >
251+ < tr >
252+ < td > 播放速度</ td >
253+ < td >
254+ < input type ="range " min ="1 " max ="10 " step ="1 " data-bind ="value: speed, valueUpdate: 'input' ">
255+ < input type ="number " size ="2 " data-bind ="value: speed ">
256+ </ td >
257+ </ tr >
258+ </ tbody >
259+ </ table >
260+ </ div >
261+
262+ </ body >
263+
264+ </ html >
0 commit comments