当前位置:   article > 正文

[cesium] 自定义无人机轨迹 和 无人机探测效果_cesium高性能轨迹回放

cesium高性能轨迹回放

效果

实现

  1. /**
  2. * 飞行路径封装类
  3. */
  4. import Camera from './camera.js'
  5. import CVTools from './cvTool.js';
  6. import Entitys from './entitys.js';
  7. import entityFactory from './entityFactory.js';
  8. import Handler from './handler.js';
  9. import mouseManager from './mouseManager.js';
  10. import {Components} from '../BaseUI/component.js';
  11. import ModelManager from './modelManager.js';
  12. export default class FlyPath{
  13. constructor(v){
  14. //核心类
  15. this.CoreV = v;
  16. //时钟对象
  17. this.flyClock = v.clock;
  18. /**
  19. * mouseManager
  20. * 坐标转换
  21. */
  22. this.mouseManager = new mouseManager(v);
  23. //默认飞行路线
  24. this.mFlyPath = [
  25. {longitude:116.538799, dimension:39.9948, height:0, time:0},
  26. {longitude:116.130034, dimension:38.291387, height:5000, time:120},
  27. {longitude:116.415192, dimension:34.841955, height:5000, time:240},
  28. {longitude:117.261468, dimension:31.831171, height:5000, time:360},
  29. {longitude:115.881671, dimension:28.70164, height:5000, time:480},
  30. {longitude:116.120835, dimension:24.308311, height:5000, time:600},
  31. {longitude:113.269254, dimension:23.13956, height:0, time:720}
  32. ]
  33. //相机对象
  34. this.ccc = new Camera(v);
  35. //工具对象
  36. this.Tools = new CVTools();
  37. //实体对象
  38. this.entitys = new Entitys(v);
  39. //时间速率
  40. this.flySpeed = 10;
  41. //飞行时间间隔
  42. this.flyInterval = 120;
  43. //飞行高度
  44. this.flyHeight = 5000;
  45. //自定义画线
  46. this.positions = [];
  47. //自定义位置点信息
  48. this.lnglatPositions = [];
  49. //自定义线实体
  50. this.polyLine = null;
  51. //飞机实体
  52. this.pickedFeature = null;
  53. //模型管理
  54. this.ModelManager = new ModelManager(v);
  55. }
  56. /**
  57. * 准备飞行
  58. */
  59. initFly(){
  60. this.startTime = new Cesium.JulianDate(); //当前时间
  61. this.stopTime = Cesium.JulianDate.addSeconds(this.startTime, (this.mFlyPath.length-1)*120,new Cesium.JulianDate()); //结束时间
  62. this.flyClock.startTime = this.startTime.clone(); // 设置始时钟始时间
  63. this.flyClock.currentTime = this.startTime.clone(); // 设置时钟当前时间
  64. this.flyClock.stopTime = this.stopTime.clone(); // 设置始终停止时间
  65. this.flyClock.multiplier = this.flySpeed; // 时间速率,数字越大时间过的越快
  66. this.flyClock.clockRange = Cesium.ClockRange.LOOP_STOP;// 循环执行
  67. this.run(); //run方法
  68. this.toView(); //切换视野
  69. this.flyInfo(); //飞行信息
  70. this.addModel(); //添加模型
  71. }
  72. //相机视野
  73. toView(){
  74. this.ccc.toView(Cesium.Cartesian3.fromDegrees(this.mFlyPath[0].longitude , this.mFlyPath[0].dimension , 100000));
  75. }
  76. /**
  77. * 飞行
  78. */
  79. run(){
  80. let _self = this;
  81. let property = new Cesium.SampledPositionProperty(); //属性
  82. _self.Tools.arrForEach(_self.mFlyPath,function(vue,index){ //value index
  83. let time = Cesium.JulianDate.addSeconds(_self.startTime, vue.time, new Cesium.JulianDate());
  84. let position = Cesium.Cartesian3.fromDegrees(vue.longitude, vue.dimension, vue.height);
  85. property.addSample(time, position); // 添加位置,和时间对应
  86. });
  87. let entity = _self.entitys.createEntity(); //创建一个实体
  88. //给实体赋值
  89. entity.name = "无人机";
  90. entity.availability = new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({ start : _self.startTime,stop : _self.stopTime})]); // 和时间轴关联
  91. entity.position = property;
  92. entity.orientation = new Cesium.VelocityOrientationProperty(property); //基于位置移动自动计算方向
  93. entity.model = _self.entitys.getModel({url:'../src/Cesium/Apps/SampleData/models/CesiumAir/Cesium_Air.gltf'}); // 模型数据,跨域,模型文件必须放本地
  94. entity.path = _self.entitys.getPath(); //路径
  95. _self.entityObj = _self.entitys.add(entity); //添加飞行
  96. _self.bindScan(); //绑定扫描物体
  97. }
  98. /**
  99. * 绑定扫描物
  100. */
  101. bindScan(){
  102. this.scanEntity = new entityFactory({type:"dynamicCylinder",data:{positions:this.entityObj.position.getValue(this.flyClock.currentTime),entity:this.entityObj,v:this.CoreV,cylinder:{legnth:5000,slices:10,bottomRadius:5000/2}}});
  103. this.scanEntityObj = this.entitys.add( this.scanEntity);
  104. }
  105. /**
  106. * flyInfo
  107. */
  108. flyInfo(){
  109. let _self = this;
  110. _self.handlerAction = new Handler(_self.CoreV);
  111. _self.handlerAction.Action(function(e){ //单击
  112. if(!e.position){
  113. return false;
  114. }
  115. _self.pickedFeature = _self.mouseManager.piObj(e.position);
  116. if (!Cesium.defined(_self.pickedFeature) && _self.pickedFeature == undefined){
  117. return false;
  118. };
  119. if(_self.pickedFeature.id == undefined){ //自己创建的
  120. return false;
  121. };
  122. let f_position = _self.mouseManager.piEllipsoid(_self.pickedFeature.id.position.getValue(_self.flyClock.currentTime));
  123. _self.pickedFeature.id.description = _self.infoTable( _self.pickedFeature.id.name,f_position) +
  124. '<h2> 扫描结果 </h2>' + _self.scanInfo(f_position) +
  125. '<h2> 侦察分析 </h2><div class="flytool"><button type="button" class="analysisGround" style="height:40px;margin:2px;">地面分析</button>' +
  126. '<button type="button" class="analysisRetrieve" style="height:40px;margin:2px;">地面检索</button>'+
  127. '<button type="button" class="analysisWord" style="height:40px;margin:2px;">分析报告</button></div>' +
  128. '<h2> 视频回放 </h2><div class="flyAMT"><video id="video_div" width="350" height="250" src="video/fly.mp4" controls autoplay></video></div>';
  129. setTimeout(function(){_self.Anction();},20);
  130. },_self.handlerAction.LEFT_CLICK)
  131. //时钟监听
  132. _self.flyClock.onTick.addEventListener(function(clock) {
  133. if(!clock.shouldAnimate)return;
  134. if(_self.pickedFeature == null){
  135. return false;
  136. }
  137. let position = _self.pickedFeature.id.position.getValue(clock.currentTime);
  138. let f_position = _self.mouseManager.piEllipsoid(position);
  139. _self.pickedFeature.id.description = _self.infoTable( _self.pickedFeature.id.name,f_position) +
  140. '<h2> 扫描结果 </h2>' + _self.scanInfo(f_position);
  141. });
  142. //分析工具 和 动画
  143. }
  144. /**
  145. * 坐标info
  146. */
  147. infoTable(f_name,cartesian){
  148. if(f_name == undefined && cartesian == undefined){
  149. return false;
  150. };
  151. let tr = "",table = `<h2> 位置点 </h2><table class="cesium-infoBox-defaultTable"><thead><tr><th>Name</th><th>Latitude</th><th>Longitude</th><th>Elevation</th></tr></thead><tbody>`;
  152. let f_point = [ parseInt(cartesian.longitude / Math.PI * 180), parseInt(cartesian.latitude / Math.PI * 180)];
  153. tr = `<tr><td>${f_name}</td><td>${f_point[0]}°</td><td>${f_point[1]}°</td><td> ${parseInt(cartesian.height)}</td></tr>`;
  154. return table + tr + `</tbody></table>`;
  155. }
  156. /**
  157. * 扫描info
  158. */
  159. scanInfo(position){
  160. if(!position){
  161. return false;
  162. }
  163. let tr = "",table = `<table class="cesium-infoBox-defaultTable"><thead><tr><th>类别</th><th>经度</th><th>纬度</th><th>总数</th></tr></thead><tbody>`;
  164. let f_point = [ parseInt(position.longitude / Math.PI * 180), parseInt(position.latitude / Math.PI * 180)];
  165. tr += `<tr><td>`+ '建筑物' +`</td><td>${f_point[0]}°</td><td>${f_point[1]}°</td><td>${parseInt(Math.floor(Math.random()*100))}</td></tr>`;
  166. tr += `<tr><td>`+ '车辆' +`</td><td>${f_point[0]}°</td><td>${f_point[1]}°</td><td>${parseInt(Math.floor(Math.random()*100))}</td></tr>`;
  167. return table + tr + `</tbody></table>`;
  168. }
  169. /**
  170. * 分析工具
  171. */
  172. Anction(){
  173. let iframe = document.getElementsByClassName('cesium-infoBox-iframe')[0];
  174. this.analysisGround(iframe.contentWindow.document);
  175. this.analysisRetrieve(iframe.contentWindow.document);
  176. this.analysisWord(iframe.contentWindow.document);
  177. }
  178. /**
  179. * 添加模型
  180. */
  181. addModel(){
  182. this.entitys.add(this.ModelManager.createCar(Cesium.Cartesian3.fromDegrees(this.mFlyPath[1].longitude , this.mFlyPath[1].dimension , 0)));
  183. }
  184. /**
  185. * 播放动画
  186. */
  187. playAMT(){
  188. let video_div = document.getElementById('video_div');
  189. }
  190. /**
  191. * 机身分析报告
  192. */
  193. analysisWord(doc){
  194. doc.getElementsByClassName("analysisWord")[0].onclick = function(){
  195. Components.TAG.analysisBox.open();
  196. }
  197. }
  198. /**
  199. * 地面检索
  200. */
  201. analysisRetrieve(doc){
  202. doc.getElementsByClassName("analysisRetrieve")[0].onclick = function(){
  203. Components.TAG.searchGround.create();
  204. }
  205. }
  206. /**
  207. * 地面分析
  208. */
  209. analysisGround(doc){
  210. doc.getElementsByClassName("analysisGround")[0].onclick = function(){
  211. Components.TAG.analysisBox.open();
  212. }
  213. }
  214. /**
  215. * 向后飞行
  216. */
  217. flyBack(){
  218. this.flySpeed = -10;
  219. this.flyClock.multiplier = this.flySpeed;
  220. }
  221. /**
  222. * 向前飞行
  223. */
  224. flyForward(){
  225. this.flySpeed = 10;
  226. this.flyClock.multiplier = this.flySpeed;
  227. }
  228. /**
  229. * 开始飞行
  230. */
  231. startFly(){
  232. this.flyClock.shouldAnimate = true;
  233. }
  234. /**
  235. * 暂停飞行
  236. */
  237. pauseFly(){
  238. this.flyClock.shouldAnimate = false;
  239. }
  240. /**
  241. * 清除飞行
  242. */
  243. removeFly(){
  244. this.CoreV.trackedEntity = null;
  245. let start = Cesium.JulianDate.fromDate(new Date());
  246. this.flyClock.startTime = start.clone();
  247. var stop = Cesium.JulianDate.addSeconds(start, 300000000, new Cesium.JulianDate());
  248. this.flyClock.stopTime = stop.clone();
  249. this.entitys.remove(this.entityObj);
  250. this.entitys.remove(this.polyLine);
  251. this.entitys.remove(this.scanEntityObj);
  252. this.pauseFly();
  253. }
  254. /**
  255. * 跟随视图
  256. */
  257. aircraftView(){
  258. this.ccc.aircraftView(this.entityObj);
  259. }
  260. /**
  261. * 顶部视图
  262. */
  263. topView(){
  264. this.ccc.sideView(this.entityObj);
  265. }
  266. /**
  267. * 侧边视图
  268. */
  269. sideView(){
  270. this.ccc.topView(this.entityObj);
  271. }
  272. /**
  273. * 保存自定义飞行
  274. */
  275. saveCustomFly(){
  276. let _self = this;
  277. if( _self.lnglatPositions.length > 0){
  278. _self.Tools.saveJsonText({
  279. jsonData : _self.mFlyPath,
  280. jsonName : 'flyJson.json'
  281. })
  282. }
  283. }
  284. /**
  285. * 开始自定义飞行
  286. */
  287. startCustomFly(){
  288. let _self = this;
  289. _self.removeFly();
  290. $.get('data/flyJson.json',{},function(json){
  291. if(json == null)return false;
  292. _self.mFlyPath = json;
  293. _self.initFly();
  294. });
  295. }
  296. /**
  297. * 自定义飞行
  298. */
  299. customFly(){
  300. let _self = this;
  301. _self.positions = [], _self.lnglatPositions = [];
  302. _self.handlerAction = new Handler(_self.CoreV);
  303. //单击
  304. _self.handlerAction.Action(function(e){
  305. if(!e.position){
  306. return false;
  307. }
  308. let cartesian = _self.mouseManager.piScreen(e.position); //拾取屏幕坐标
  309. if(_self.positions.length == 0)_self.positions.push(cartesian); //第一次创建保证有两个点
  310. _self.positions.push(cartesian);
  311. //飞行路径实体
  312. let lonlat = _self.mouseManager.screenToLonlat(e.position); //屏幕坐标转经纬度 高程
  313. _self.lnglatPositions.push({longitude:lonlat.lon, dimension:lonlat.lat, height: _self.flyHeight, time:_self.lnglatPositions.length * _self.flyInterval}); //时间间隔
  314. _self.handlerAction.COUNTER = _self.positions.length; //画线规则
  315. },_self.handlerAction.LEFT_CLICK);
  316. //移动
  317. _self.handlerAction.Actions(function(){},function(e){
  318. if(!e.endPosition){
  319. return false;
  320. }
  321. let cartesian = _self.mouseManager.piScreen(e.endPosition); //拾取屏幕坐标
  322. if (!Cesium.defined(_self.polyLine)) {
  323. _self.lineOption = new entityFactory({type:"createLine",data:_self.positions});
  324. _self.entitys.add(_self.lineOption);
  325. }else{
  326. _self.positions.pop();
  327. cartesian.y += (1 + Math.random());
  328. _self.positions.push(cartesian);
  329. }
  330. },_self.handlerAction.MOUSE_MOVE,_self.handlerAction.COUNTER);
  331. //双击
  332. _self.handlerAction.Action(function(e){
  333. _self.handlerAction.destroy();
  334. if(_self.positions.length == 0 ){
  335. return false;
  336. }
  337. _self.mFlyPath = _self.lnglatPositions;
  338. _self.saveCustomFly();
  339. },_self.handlerAction.LEFT_DOUBLE_CLICK);
  340. }
  341. /**
  342. * 键盘控制飞行
  343. */
  344. flyByKeyword(){
  345. console.log('暂不实现');
  346. }
  347. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/604768
推荐阅读
相关标签
  

闽ICP备14008679号