f65_roamLine_plane_ray.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. <!-- 2017-12-7 14:56:03 | 修改 木遥(微信: http://marsgis.cn/weixin.html ) -->
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
  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. <script
  22. type="text/javascript"
  23. src="../lib/include-lib.js"
  24. libpath="../lib/"
  25. include="jquery,font-awesome,bootstrap,bootstrap-checkbox,bootstrap-slider,layer,haoutil,turf,mars3d"
  26. ></script>
  27. <link href="css/style.css" rel="stylesheet" />
  28. <style>
  29. .mp_table {
  30. width: 100%;
  31. border: #cde1de 1px solid;
  32. font-size: 12px;
  33. border-collapse: collapse;
  34. border-spacing: 0;
  35. }
  36. .mp_table tr td {
  37. padding: 5px 5px;
  38. text-align: left;
  39. border: #cde1de 1px solid;
  40. }
  41. .mp_table tr td:first-child {
  42. border-left: none;
  43. }
  44. .nametd {
  45. width: 40%;
  46. }
  47. .mp_input {
  48. height: 28px;
  49. line-height: 22px;
  50. padding: 3px 5px;
  51. box-sizing: border-box;
  52. font-size: 12px;
  53. border: 1px solid #e6e6e6;
  54. background-color: #fff;
  55. border-radius: 3px;
  56. display: block;
  57. width: 100%;
  58. outline: 0;
  59. box-sizing: border-box;
  60. }
  61. .mp_input:hover {
  62. border-color: #c9c9c9 !important;
  63. }
  64. .mp_input:focus {
  65. border-color: #3374e0 !important;
  66. }
  67. /*select*/
  68. .mp_select {
  69. height: 28px;
  70. line-height: 22px;
  71. padding: 0 5px;
  72. box-sizing: border-box;
  73. font-size: 12px;
  74. border: 1px solid #e6e6e6;
  75. background-color: #fff;
  76. border-radius: 3px;
  77. outline: 0;
  78. box-sizing: border-box;
  79. position: relative;
  80. }
  81. .mp_select:after {
  82. content: "";
  83. width: 0;
  84. height: 0;
  85. overflow: hidden;
  86. cursor: pointer;
  87. transition: all 0.2s;
  88. position: absolute;
  89. border-width: 6px;
  90. display: inline-block;
  91. top: 10px;
  92. right: 5px;
  93. border-style: solid dashed dashed;
  94. border-color: #c2c2c2 transparent transparent;
  95. }
  96. .mp_selected:after {
  97. top: 4px;
  98. border-style: dashed dashed solid;
  99. border-color: transparent transparent #c2c2c2;
  100. }
  101. .mp_select .mp_select_text {
  102. padding: 0 20px 0 0;
  103. height: 28px;
  104. line-height: 26px;
  105. overflow: hidden;
  106. }
  107. .mp_select_ul {
  108. background: #fff;
  109. border: #d6d6d6 1px solid;
  110. border-radius: 3px;
  111. padding: 5px 0;
  112. box-shadow: 1px 2px 1px rgba(0, 0, 0, 0.15);
  113. position: absolute;
  114. left: 0;
  115. z-index: 1000;
  116. color: #333;
  117. text-align: center;
  118. width: 100%;
  119. display: none;
  120. }
  121. .mp_select_ul li {
  122. margin: 0 5px;
  123. border-radius: 3px;
  124. text-align: left;
  125. height: 28px;
  126. line-height: 28px;
  127. text-indent: 5px;
  128. overflow: hidden;
  129. text-overflow: ellipsis;
  130. white-space: nowrap;
  131. }
  132. .mp_select_ul li:hover {
  133. background: #ecf1f8;
  134. }
  135. .mp_select_ul .selecton,
  136. .mp_select_ul .selecton:hover {
  137. background: #3374e0 !important;
  138. color: #fff !important;
  139. }
  140. /*dark*/
  141. .dark .mp_select {
  142. background-color: rgba(63, 72, 84, 0.6);
  143. }
  144. .dark .mp_select_ul {
  145. color: #ffffff;
  146. background-color: rgba(63, 72, 84, 0.8);
  147. }
  148. .dark .mp_select_ul li:hover {
  149. background-color: rgba(63, 72, 84, 1);
  150. }
  151. .dark .mp_select_ul .selecton,
  152. .mp_select_ul .selecton:hover {
  153. background: rgba(63, 72, 84, 1) !important;
  154. color: #fff !important;
  155. }
  156. .mp_head2 {
  157. width: 100%;
  158. height: 45px;
  159. line-height: 45px;
  160. text-align: center;
  161. }
  162. .dark .progress {
  163. margin: 0;
  164. background-color: #0b2931;
  165. }
  166. </style>
  167. </head>
  168. <body class="dark">
  169. <!--加载前进行操作提示,优化用户体验-->
  170. <div id="mask" class="signmask" onclick="removeMask()"></div>
  171. <div id="mars3dContainer" class="mars3d-container"></div>
  172. <!-- 控制 面板 -->
  173. <div class="infoview">
  174. <table class="mp_table">
  175. <tr>
  176. <td class="nametd">模型角度</td>
  177. <td>
  178. <div class="radio radio-info radio-inline">
  179. <input type="radio" id="jiaodu_1" value="1" name="jiaodu" />
  180. <label for="jiaodu_1">自动</label>
  181. </div>
  182. <div class="radio radio-info radio-inline">
  183. <input type="radio" id="jiaodu_2" value="2" name="jiaodu" checked />
  184. <label for="jiaodu_2">手动</label>
  185. </div>
  186. </td>
  187. </tr>
  188. <tr class="jiaodu_2_angele">
  189. <td class="nametd">heading值</td>
  190. <td>
  191. 根据路线自动计算
  192. <!-- <input id="model_heading" type="range" min="0" max="360" step="0.01" value="10" title="方向"> -->
  193. </td>
  194. </tr>
  195. <tr class="jiaodu_2_angele">
  196. <td class="nametd">pitch值(前后)</td>
  197. <td>
  198. <input id="model_pitch" title="倾角pitch" />
  199. </td>
  200. </tr>
  201. <tr class="jiaodu_2_angele">
  202. <td class="nametd">roll值(左右)</td>
  203. <td>
  204. <input id="model_roll" title="滚动角roll" />
  205. </td>
  206. </tr>
  207. </table>
  208. <input type="button" class="btn btn-primary" id="btnClear" value="清除地面投影" />
  209. </div>
  210. <!-- 信息 面板 -->
  211. <div class="infoview rightbottom" style="min-width: 200px">
  212. <table class="mp_table">
  213. <tr>
  214. <td class="nametd">总长度</td>
  215. <td id="td_alllength"></td>
  216. </tr>
  217. <tr>
  218. <td class="nametd">已漫游长度</td>
  219. <td id="td_length"></td>
  220. </tr>
  221. <tr>
  222. <td class="nametd">总时长</td>
  223. <td id="td_alltimes"></td>
  224. </tr>
  225. <tr>
  226. <td class="nametd">已漫游时间</td>
  227. <td id="td_times"></td>
  228. </tr>
  229. <tr>
  230. <td class="nametd">经度</td>
  231. <td id="td_jd"></td>
  232. </tr>
  233. <tr>
  234. <td class="nametd">经度</td>
  235. <td id="td_wd"></td>
  236. </tr>
  237. <tr>
  238. <td class="nametd">漫游高程</td>
  239. <td id="td_gd"></td>
  240. </tr>
  241. <tr>
  242. <td class="nametd">地面高程</td>
  243. <td id="td_dmhb"></td>
  244. </tr>
  245. <tr id="tr_ldgd">
  246. <td class="nametd">离地距离</td>
  247. <td id="td_ldgd"></td>
  248. </tr>
  249. <tr>
  250. <td colspan="2" style="width: 100%; text-align: center">
  251. <div class="progress">
  252. <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div>
  253. </div>
  254. </td>
  255. </tr>
  256. </table>
  257. </div>
  258. <div id="tipView" class="info-tips">(1) 不支持对地形的求交,目前仅对椭球体做投射。 <br /></div>
  259. <script src="./js/common.js"></script>
  260. <script type="text/javascript">
  261. "use script"; //开发环境建议开启严格模式
  262. var map;
  263. var roamLine;
  264. function initMap(options) {
  265. //合并属性参数,可覆盖config.json中的对应配置
  266. var mapOptions = mars3d.Util.merge(options, {
  267. scene: {
  268. center: { lat: 31.344715, lng: 115.783073, alt: 10056, heading: 158, pitch: -55 },
  269. globe: {
  270. // depthTestAgainstTerrain: true,
  271. },
  272. },
  273. });
  274. //创建三维地球场景
  275. map = new mars3d.Map("mars3dContainer", mapOptions);
  276. map.hasTerrain = false;
  277. //创建矢量数据图层
  278. var graphicLayer = new mars3d.layer.GraphicLayer();
  279. map.addLayer(graphicLayer);
  280. //该数据可以从 基础项目 飞行漫游功能界面操作后保存JSON
  281. var flydata = {
  282. speed: 200,
  283. positions: [
  284. [115.833866, 31.311451, 4000],
  285. [115.785116, 31.293944, 4000],
  286. [115.748115, 31.266263, 4000],
  287. [115.711031, 31.216472, 4000],
  288. ],
  289. model: {
  290. url: "//data.mars3d.cn/gltf/mars/zhanji.glb",
  291. scale: 0.01,
  292. minimumPixelSize: 100,
  293. show: true,
  294. },
  295. path: {
  296. color: "#ffff00",
  297. width: 3,
  298. show: true,
  299. },
  300. shadow: {
  301. type: "wall",
  302. show: true,
  303. },
  304. camera: {
  305. type: "zy",
  306. followedX: 50,
  307. followedZ: 10,
  308. },
  309. showGroundHeight: true,
  310. };
  311. roamLine = new mars3d.graphic.RoamLine(flydata);
  312. graphicLayer.addGraphic(roamLine);
  313. //启动漫游
  314. roamLine.start();
  315. testShading();
  316. initUI();
  317. if (map.viewer.timeline) {
  318. map.viewer.timeline.zoomTo(roamLine.startTime, roamLine.stopTime);
  319. }
  320. //显示基本信息,名称、总长、总时间
  321. $("#td_alltimes").html(haoutil.str.formatTime(roamLine.alltimes));
  322. $("#td_alllength").html(haoutil.str.formatLength(roamLine.alllen));
  323. roamLine.on(mars3d.EventType.change, (event) => {
  324. //面板显示相关信息
  325. showRealTimeInfo(event);
  326. });
  327. }
  328. function initUI() {
  329. //模型方向
  330. // $(".jiaodu_2_angele").hide();
  331. $('input:radio[name="jiaodu"]').change(function () {
  332. var isAuto = $(this).val() === "1";
  333. if (isAuto) {
  334. $(".jiaodu_2_angele").hide();
  335. } else {
  336. $(".jiaodu_2_angele").show();
  337. }
  338. updateModel(isAuto);
  339. });
  340. //滑动条
  341. $("#model_pitch")
  342. .slider({ min: -90, max: 90, step: 0.01, value: 0 })
  343. .on("change", (e) => {
  344. updateModel();
  345. });
  346. $("#model_roll")
  347. .slider({ min: -90, max: 90, step: 0.01, value: 10 })
  348. .on("change", (e) => {
  349. updateModel();
  350. });
  351. updateModel(false);
  352. }
  353. function updateModel(isAuto) {
  354. var pitch = Number($("#model_pitch").val());
  355. var roll = Number($("#model_roll").val());
  356. roamLine.updateAngle(isAuto, {
  357. pitch: pitch,
  358. roll: roll,
  359. });
  360. }
  361. //显示实时坐标和时间
  362. function showRealTimeInfo(params) {
  363. if (params == null) {
  364. return;
  365. }
  366. var val = Math.ceil((params.time * 100) / roamLine.alltimes);
  367. if (val < 1) {
  368. val = 1;
  369. }
  370. if (val > 100) {
  371. val = 100;
  372. }
  373. $(".progress-bar")
  374. .css("width", val + "%")
  375. .attr("aria-valuenow", val)
  376. .html(val + "%");
  377. $("#td_jd").html(params.lng);
  378. $("#td_wd").html(params.lat);
  379. $("#td_gd").html(haoutil.str.formatLength(params.alt));
  380. $("#td_times").html(haoutil.str.formatTime(params.time));
  381. $("#td_length").html(haoutil.str.formatLength(params.len));
  382. if (params.hbgd) {
  383. $("#td_dmhb").html(haoutil.str.formatLength(params.hbgd));
  384. } else {
  385. $("#td_dmhb").html("未知");
  386. }
  387. if (params.ldgd) {
  388. $("#td_ldgd").html(haoutil.str.formatLength(params.ldgd));
  389. } else {
  390. $("#td_ldgd").html("未知");
  391. }
  392. }
  393. var groundLayer; //地面投影图层
  394. function testShading() {
  395. //卫星朝向的中线地面点
  396. let line1 = new mars3d.graphic.PolylineEntity({
  397. positions: new Cesium.CallbackProperty(function (time) {
  398. var pt1 = roamLine.position,
  399. pt2 = centerPosion;
  400. if (!pt1 || !pt2) {
  401. return [];
  402. }
  403. return [pt1, pt2];
  404. }, false),
  405. style: {
  406. width: 2,
  407. color: "#ff0000",
  408. arcType: Cesium.ArcType.NONE,
  409. },
  410. });
  411. map.graphicLayer.addGraphic(line1);
  412. //卫星边线2点
  413. let graphicTriangle = new mars3d.graphic.PolylineEntity({
  414. positions: new Cesium.CallbackProperty(function (time) {
  415. var positions = getFourShadingPosition({
  416. angle: 2.4,
  417. angle2: 1.4,
  418. });
  419. return positions;
  420. }, false),
  421. style: {
  422. width: 2,
  423. color: "#0000ff",
  424. clampToGround: true,
  425. },
  426. });
  427. map.graphicLayer.addGraphic(graphicTriangle);
  428. //创建矢量数据图层
  429. groundLayer = new mars3d.layer.GraphicLayer();
  430. map.addLayer(groundLayer);
  431. setInterval(function () {
  432. if (!map.clock.shouldAnimate || !thisPositions) {
  433. return;
  434. }
  435. addPolygon();
  436. }, 1500);
  437. $("#btnClear").click(function () {
  438. groundLayer.clear();
  439. });
  440. }
  441. //获取地面的四棱台投影面
  442. var thisPositions;
  443. var centerPosion;
  444. function getFourShadingPosition(opts) {
  445. //位置
  446. var pt1 = roamLine.position;
  447. if (!pt1) {
  448. return;
  449. }
  450. var ellipsoid = map.scene.globe.ellipsoid;
  451. //张角
  452. var angle1 = Cesium.Math.toRadians(opts.angle) / 2;
  453. var heading = Cesium.Math.toRadians(Cesium.defaultValue(opts.heading, roamLine.heading));
  454. var pitch = Cesium.Math.toRadians(Cesium.defaultValue(opts.pitch, roamLine.pitch));
  455. var roll = Cesium.Math.toRadians(Cesium.defaultValue(opts.heading, roamLine.roll));
  456. //张角
  457. var angle2 = Cesium.Math.toRadians(opts.angle2) / 2;
  458. var ptLeft1 = mars3d.PointUtil.getRayEarthPosition(pt1, new Cesium.HeadingPitchRoll(heading, pitch + angle2, roll + angle1), true, ellipsoid);
  459. if (!ptLeft1) {
  460. return;
  461. }
  462. var ptRight1 = mars3d.PointUtil.getRayEarthPosition(pt1, new Cesium.HeadingPitchRoll(heading, pitch + angle2, roll - angle1), true, ellipsoid);
  463. if (!ptRight1) {
  464. return;
  465. }
  466. var ptRight2 = mars3d.PointUtil.getRayEarthPosition(pt1, new Cesium.HeadingPitchRoll(heading, pitch - angle2, roll - angle1), true, ellipsoid);
  467. if (!ptRight2) {
  468. return;
  469. }
  470. var ptLeft2 = mars3d.PointUtil.getRayEarthPosition(pt1, new Cesium.HeadingPitchRoll(heading, pitch - angle2, roll + angle1), true, ellipsoid);
  471. if (!ptLeft2) {
  472. return;
  473. }
  474. var ptLeft = Cesium.Cartesian3.midpoint(ptLeft1, ptLeft2, new Cesium.Cartesian3());
  475. var ptRight = Cesium.Cartesian3.midpoint(ptRight1, ptRight2, new Cesium.Cartesian3());
  476. thisPositions = [ptLeft, ptRight];
  477. centerPosion = Cesium.Cartesian3.midpoint(ptLeft, ptRight, new Cesium.Cartesian3());
  478. return [ptLeft1, ptRight1, ptRight2, ptLeft2, ptLeft1];
  479. }
  480. var lastPositions;
  481. function addPolygon() {
  482. if (lastPositions == null) {
  483. lastPositions = thisPositions;
  484. return;
  485. }
  486. var positions = [lastPositions[0], lastPositions[1], thisPositions[1], thisPositions[0]];
  487. lastPositions = thisPositions;
  488. var primitive = new mars3d.graphic.PolygonPrimitive({
  489. positions: positions,
  490. style: {
  491. color: "#ff0000",
  492. opacity: 0.3,
  493. },
  494. });
  495. groundLayer.addGraphic(primitive);
  496. if (groundLayer.length > 2000) {
  497. groundLayer.clear();
  498. }
  499. }
  500. </script>
  501. </body>
  502. </html>