m35_wrjhp.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
  6. <meta name="author" content="火星科技 http://mars3d.cn " />
  7. <meta name="apple-touch-fullscreen" content="yes" />
  8. <meta name="apple-mobile-web-app-capable" content="yes" />
  9. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  10. <meta name="format-detection" content="telephone=no" />
  11. <meta name="x5-fullscreen" content="true" />
  12. <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
  13. <!-- 标题及搜索关键字 -->
  14. <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
  15. <meta
  16. name="description"
  17. content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型 gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包 地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
  18. />
  19. <link rel="shortcut icon" type="image/x-icon" href="" />
  20. <title>无人机航拍过程 </title>
  21. <!--第三方lib-->
  22. <script
  23. type="text/javascript"
  24. src="../lib/include-lib.js"
  25. libpath="../lib/"
  26. include="jquery,font-awesome,bootstrap,layer,haoutil,turf,mars3d"
  27. ></script>
  28. <link href="css/style.css" rel="stylesheet" />
  29. </head>
  30. <body class="dark">
  31. <!--加载前进行操作提示,优化用户体验-->
  32. <div id="mask" class="signmask" onclick="removeMask()"></div>
  33. <div id="mars3dContainer" class="mars3d-container"></div>
  34. <script src="./js/common.js"></script>
  35. <script type="text/javascript">
  36. "use script"; //开发环境建议开启严格模式
  37. var map;
  38. let graphicLayer;
  39. function initMap(options) {
  40. //合并属性参数,可覆盖config.json中的对应配置
  41. var mapOptions = mars3d.Util.merge(options, {
  42. scene: {
  43. center: {
  44. lat: 31.30003,
  45. lng: 116.08603,
  46. alt: 11445.39,
  47. heading: 51.4,
  48. pitch: -86.6,
  49. roll: 2.3,
  50. },
  51. },
  52. });
  53. delete mapOptions.terrain;
  54. //创建三维地球场景
  55. map = new mars3d.Map("mars3dContainer", mapOptions);
  56. //创建矢量数据图层
  57. graphicLayer = new mars3d.layer.GraphicLayer();
  58. map.addLayer(graphicLayer);
  59. //飞行区域边界线
  60. let graphic = new mars3d.graphic.PolygonEntity({
  61. positions: [
  62. [116.069898, 31.303655],
  63. [116.098708, 31.322126],
  64. [116.108063, 31.311256],
  65. [116.079317, 31.292959],
  66. [116.069898, 31.303655],
  67. ],
  68. style: {
  69. color: "#ffff00",
  70. outline: true,
  71. outlineWidth: 3,
  72. outlineColor: "#00ff00",
  73. },
  74. });
  75. graphicLayer.addGraphic(graphic);
  76. graphic.startFlicker({
  77. time: 3, //闪烁时长(秒)
  78. onEnd: function () {
  79. //结束后自动移除
  80. graphic.style = { fill: false };
  81. work4HP.activate(); //闪烁结束后开始飞行
  82. },
  83. });
  84. }
  85. //功能4
  86. var work4HP = {
  87. flySpeed: 600, //飞行速度
  88. psNum: 400, //投射间隔路程
  89. frameNum: 0,
  90. arr4LinePrimitive: [],
  91. arrColor: [new Cesium.Color(1.0, 0.0, 0.0, 0.3), new Cesium.Color(0.0, 1.0, 0, 0.3), new Cesium.Color(0.0, 0.0, 1, 0.3)],
  92. //激活功能
  93. activate() {
  94. //飞行路线
  95. this.roamLine = new mars3d.graphic.RoamLine({
  96. name: "无人机航拍",
  97. speed: this.flySpeed,
  98. positions: [
  99. [116.077374, 31.294215, 1000],
  100. [116.107153, 31.312963, 1000],
  101. [116.103816, 31.316868, 1000],
  102. [116.074092, 31.297972, 1000],
  103. [116.07068, 31.301908, 1000],
  104. [116.100465, 31.320893, 1000],
  105. ],
  106. model: {
  107. url: "//data.mars3d.cn/gltf/mars/wrj.glb",
  108. scale: 0.02,
  109. minimumPixelSize: 50,
  110. show: true,
  111. },
  112. path: {
  113. color: "#ffff00",
  114. width: 3,
  115. isAll: false,
  116. show: true,
  117. },
  118. clockLoop: false, //是否循环播放
  119. });
  120. graphicLayer.addGraphic(this.roamLine);
  121. this.roamLine.start();
  122. this.roamLine.on(mars3d.EventType.end, this.disable, this);
  123. //视角切换(分步执行)
  124. map.setCameraViewList([
  125. {
  126. lat: 31.261244,
  127. lng: 116.087805,
  128. alt: 4571.19,
  129. heading: 2.3,
  130. pitch: -45.4,
  131. roll: 357.6,
  132. stop: 4,
  133. },
  134. {
  135. lat: 31.299649,
  136. lng: 116.129938,
  137. alt: 2725.83,
  138. heading: 290.2,
  139. pitch: -34,
  140. roll: 358.1,
  141. stop: 4,
  142. },
  143. {
  144. lat: 31.288891,
  145. lng: 116.106146,
  146. alt: 4268.26,
  147. heading: 325.4,
  148. pitch: -55.7,
  149. roll: 357.5,
  150. },
  151. ]);
  152. this.stepNum = Math.floor(this.psNum / (this.flySpeed / 100)); //时间 = 路程 / 速度
  153. map.on(mars3d.EventType.clockTick, this.clock_onTick, this); //时钟跳动 每秒钟执行一次函数 场景事件
  154. },
  155. clock_onTick(e) {
  156. if (!map.clock.shouldAnimate) {
  157. return;
  158. }
  159. this.frameNum++;
  160. //当前的路线中的点位
  161. var currIndex = this.roamLine.currIndex; //当前飞行的线路,共五条线,从零开始
  162. if (currIndex % 2 == 0) {
  163. if (this.frameNum % this.stepNum == 0) {
  164. //计算方向
  165. var p1, p2;
  166. if (currIndex == 0 || !currIndex) {
  167. p1 = this.roamLine.positions[0];
  168. p2 = this.roamLine.positions[1];
  169. } else {
  170. p1 = this.roamLine.positions[currIndex + 1];
  171. p2 = this.roamLine.positions[currIndex];
  172. }
  173. if (!p1 || !p2) {
  174. return;
  175. }
  176. // 获取起点坐标到终点坐标的 Heading Pitch Roll方向角度值
  177. var hpr = mars3d.PointUtil.getHeadingPitchRollForLine(p1, p2);
  178. // 将弧度转换为度
  179. var heading = Cesium.Math.toDegrees(hpr.heading);
  180. //添加四棱锥体线
  181. var graphicFrustum = new mars3d.graphic.FrustumPrimitive({
  182. position: this.roamLine.position,
  183. style: {
  184. angle: 15,
  185. angle2: 12,
  186. heading: heading,
  187. length: Cesium.Cartographic.fromCartesian(this.roamLine.position).height,
  188. fill: false,
  189. outline: true,
  190. outlineColor: "#ffffff",
  191. outlineOpacity: 1.0,
  192. },
  193. asynchronous: false,
  194. flat: true,
  195. });
  196. graphicLayer.addGraphic(graphicFrustum);
  197. console.log(graphicFrustum);
  198. this.arr4LinePrimitive.push(graphicFrustum);
  199. }
  200. if (this.frameNum % this.stepNum == 10) {
  201. //移除四棱锥体线 保持只有一个椎体线
  202. if (this.arr4LinePrimitive.length > 0) {
  203. graphicLayer.removeGraphic(this.arr4LinePrimitive.shift());
  204. }
  205. }
  206. }
  207. if (this.frameNum % this.stepNum == 0 && currIndex % 2 == 0) {
  208. if (this.arr4LinePrimitive.length > 0) {
  209. let graphicFrustum = this.arr4LinePrimitive[this.arr4LinePrimitive.length - 1];
  210. //地面的4个顶点坐标
  211. let positions = graphicFrustum.getRayEarthPositions();
  212. //添加地面矩形
  213. var primitive = new mars3d.graphic.PolygonPrimitive({
  214. positions: positions,
  215. style: {
  216. color: this.arrColor[graphicLayer.length % this.arrColor.length],
  217. zIndex: graphicLayer.length,
  218. },
  219. });
  220. graphicLayer.addGraphic(primitive);
  221. }
  222. }
  223. },
  224. //释放功能
  225. disable() {
  226. map.off(mars3d.EventType.clockTick, this.clock_onTick, this); //时钟跳动 每秒钟执行一次函数 场景事件
  227. this.roamLine.stop();
  228. this.arr4LinePrimitive = [];
  229. this.frameNum = 0;
  230. },
  231. };
  232. </script>
  233. </body>
  234. </html>