f62_satellite_gjfx.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. <!-- 2017-12-4 14:24:12 | 修改 木遥(微信: 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,jedate,web-icons,bootstrap,bootstrap-table,layer,toastr,nprogress,haoutil,turf,mars3d,mars3d-space"
  26. ></script>
  27. <link href="css/style.css" rel="stylesheet" />
  28. </head>
  29. <body class="dark">
  30. <!--加载前进行操作提示,优化用户体验-->
  31. <div id="mask" class="signmask" onclick="removeMask()"></div>
  32. <div id="mars3dContainer" class="mars3d-container"></div>
  33. <!-- 面板 -->
  34. <div class="infoview">
  35. <table class="mars-table">
  36. <tr>
  37. <td class="nametd">过境区域:</td>
  38. <td>
  39. <input type="button" class="btn btn-primary" value="框选" id="drawRectangle" />
  40. <input type="button" class="btn btn-primary" value="圆形" id="drawCircle" />
  41. <input type="button" class="btn btn-primary" value="多边形" id="drawPolygon" />
  42. <input type="button" class="btn btn-primary" value="清除" id="drawClear" />
  43. </td>
  44. </tr>
  45. <tr>
  46. <td class="nametd">开始时间:</td>
  47. <td>
  48. <input type="text" class="form-control" id="txtStartTime" placeholder="YYYY-MM-DD" />
  49. </td>
  50. </tr>
  51. <tr>
  52. <td class="nametd">结束时间:</td>
  53. <td>
  54. <input type="text" class="form-control" id="txtEndTime" placeholder="YYYY-MM-DD" />
  55. </td>
  56. </tr>
  57. <tr>
  58. <td class="nametd"></td>
  59. <td>
  60. <input type="button" class="btn btn-primary" value="开始分析" onclick="startFX()" />
  61. <input type="button" class="btn btn-primary" value="清除" onclick="clearResult();" />
  62. </td>
  63. </tr>
  64. </table>
  65. <table id="table"></table>
  66. </div>
  67. <script src="./js/common.js"></script>
  68. <script type="text/javascript">
  69. "use script"; //开发环境建议开启严格模式
  70. var map;
  71. var graphicLayer;
  72. var tleArr;
  73. var drawGraphic;
  74. var $table;
  75. function initMap(options) {
  76. //合并属性参数,可覆盖config.json中的对应配置
  77. var mapOptions = mars3d.Util.merge(options, {
  78. scene: {
  79. center: { lat: 21.105826, lng: 108.202174, alt: 4426845, heading: 356, pitch: -77 },
  80. cameraController: {
  81. constrainedAxis: false, //解除在南北极区域鼠标操作限制
  82. },
  83. },
  84. });
  85. //创建三维地球场景
  86. map = new mars3d.Map("mars3dContainer", mapOptions);
  87. //创建矢量数据图层
  88. graphicLayer = new mars3d.layer.GraphicLayer();
  89. map.addLayer(graphicLayer);
  90. //加载示例数据
  91. // eslint-disable-next-line prettier/prettier
  92. // var hostiryData = {"startDate":"2021-05-31 19:56:18","endDate":"2021-05-31 20:56:18","geojson":{"type":"Feature","properties":{"id":"M-676224DB-E1C7-492B-BD4F-11245263E921","type":"rectangle","style":{"color":"#ffff00","opacity":0.2,"outline":true,"outlineColor":"#ffffff","materialType":"Color","clampToGround":false,"height":-1253.05}},"geometry":{"type":"Polygon","coordinates":[[[76.021252,46.81116,-1253.1],[152.705424,1.598719,-7200.1]]]}}}
  93. // $('#txtStartTime').val(hostiryData.startDate) //开始时间
  94. // $('#txtEndTime').val(hostiryData.endDate) //结束时间
  95. // drawGraphic = map.graphicLayer.loadGeoJSON(hostiryData.geojson)[0]
  96. initUI();
  97. queryTleChinaApiData()
  98. .then(function (data) {
  99. tleArr = data.data;
  100. console.log("卫星数量:" + tleArr.length);
  101. })
  102. .catch(function () {
  103. haoutil.msg("获取空间目标轨道数据异常!");
  104. });
  105. }
  106. // 访问后端接口,取数据
  107. function queryTleChinaApiData() {
  108. return new Promise(function (resolve, reject) {
  109. $.ajax({
  110. url: "//data.mars3d.cn/file/apidemo/tle-china.json",
  111. type: "get",
  112. dataType: "json",
  113. success: function (result) {
  114. resolve(result);
  115. },
  116. error: function (data) {
  117. reject(data);
  118. },
  119. });
  120. });
  121. }
  122. function initUI() {
  123. // eslint-disable-next-line no-undef
  124. jeDate("#txtStartTime", {
  125. theme: {
  126. bgcolor: "#135b91",
  127. pnColor: "#00CCFF",
  128. },
  129. format: "YYYY-MM-DD hh:mm:ss",
  130. zIndex: 20210825,
  131. });
  132. // eslint-disable-next-line no-undef
  133. jeDate("#txtEndTime", {
  134. theme: {
  135. bgcolor: "#135b91",
  136. pnColor: "#00CCFF",
  137. },
  138. format: "YYYY-MM-DD hh:mm:ss",
  139. zIndex: 20210825,
  140. });
  141. var now = Cesium.JulianDate.toDate(map.clock.currentTime);
  142. $("#txtStartTime").val(now.format("yyyy-MM-dd HH:mm:ss"));
  143. now.setMinutes(now.getMinutes() + 60);
  144. $("#txtEndTime").val(now.format("yyyy-MM-dd HH:mm:ss"));
  145. //框选查询 矩形
  146. $("#drawRectangle").click(function () {
  147. map.graphicLayer.clear();
  148. map.graphicLayer.startDraw({
  149. type: "rectangle",
  150. style: {
  151. color: "#ffff00",
  152. opacity: 0.2,
  153. outline: true,
  154. outlineColor: "#ffffff",
  155. },
  156. success: function (graphic) {
  157. drawGraphic = graphic;
  158. },
  159. });
  160. });
  161. //框选查询 多边
  162. $("#drawPolygon").click(function () {
  163. map.graphicLayer.clear();
  164. map.graphicLayer.startDraw({
  165. type: "polygon",
  166. style: {
  167. color: "#ffff00",
  168. opacity: 0.2,
  169. outline: true,
  170. outlineColor: "#ffffff",
  171. },
  172. success: function (graphic) {
  173. drawGraphic = graphic;
  174. },
  175. });
  176. });
  177. //框选查询 圆
  178. $("#drawCircle").click(function () {
  179. map.graphicLayer.clear();
  180. map.graphicLayer.startDraw({
  181. type: "circle",
  182. style: {
  183. color: "#ffff00",
  184. opacity: 0.2,
  185. outline: true,
  186. outlineColor: "#ffffff",
  187. },
  188. success: function (graphic) {
  189. drawGraphic = graphic;
  190. },
  191. });
  192. });
  193. $("#drawClear").click(function () {
  194. map.graphicLayer.clear();
  195. drawGraphic = null;
  196. });
  197. $table = $("#table");
  198. $table.bootstrapTable({
  199. height: 300,
  200. singleSelect: true, //单选
  201. pagination: false,
  202. iconsPrefix: "fa",
  203. columns: [
  204. {
  205. field: "name",
  206. title: "卫星名称",
  207. sortable: true,
  208. editable: false,
  209. align: "left",
  210. },
  211. {
  212. field: "inTime",
  213. title: "进入时间",
  214. sortable: true,
  215. editable: false,
  216. align: "left",
  217. },
  218. {
  219. field: "outTime",
  220. title: "飞出时间",
  221. sortable: true,
  222. editable: false,
  223. align: "left",
  224. },
  225. {
  226. field: "often",
  227. title: "飞行时长",
  228. sortable: true,
  229. editable: false,
  230. align: "left",
  231. },
  232. {
  233. field: "distance",
  234. title: "飞行距离",
  235. sortable: true,
  236. editable: false,
  237. align: "left",
  238. },
  239. ],
  240. onClickRow: function (item, $element, field) {
  241. var graphic = item._graphic;
  242. if (graphic == null) {
  243. // eslint-disable-next-line no-undef
  244. toastr.warning(item.name + " 无经纬度坐标信息!");
  245. return;
  246. }
  247. graphic.flyTo();
  248. },
  249. });
  250. }
  251. //清除效果
  252. function clearResult() {
  253. $table.bootstrapTable("load", []);
  254. graphicLayer.clear();
  255. }
  256. //================卫星过境===================================
  257. //颜色
  258. var pointClr = Cesium.Color.fromCssColorString("#ff0000").withAlpha(0.7);
  259. function startFX() {
  260. clearResult();
  261. if (!drawGraphic) {
  262. haoutil.msg("请先在图上绘制区域");
  263. return;
  264. }
  265. var startDate = new Date($("#txtStartTime").val()); //开始时间
  266. var endDate = new Date($("#txtEndTime").val()); //结束时间
  267. var startTimes = startDate.getTime();
  268. var endTimes = endDate.getTime();
  269. //记录参数值
  270. console.log(
  271. JSON.stringify({
  272. startDate: startDate.format("yyyy-MM-dd HH:mm:ss"),
  273. endDate: endDate.format("yyyy-MM-dd HH:mm:ss"),
  274. geojson: drawGraphic.toGeoJSON(),
  275. })
  276. );
  277. //范围相关信息
  278. var options = {
  279. startTimes: startTimes,
  280. endTimes: endTimes,
  281. graphic: drawGraphic,
  282. };
  283. //分析卫星位置
  284. var newSatelliteArr = []; //存储飞过指定范围的卫星的数据
  285. for (var ind = 0; ind < tleArr.length; ind++) {
  286. var item = tleArr[ind];
  287. var arr = fxOneSatellite(item, options);
  288. if (arr.length == 0) {
  289. continue;
  290. }
  291. item.inAreaPath = arr;
  292. newSatelliteArr.push(item);
  293. }
  294. showResult(newSatelliteArr);
  295. }
  296. function fxOneSatellite(item, options) {
  297. var inAreaPath = [];
  298. var lastObj = null;
  299. var graphic = options.graphic;
  300. var startTimes = options.startTimes;
  301. var endTimes = options.endTimes;
  302. var step = 10 * 1000; //插值数
  303. var nowTime = startTimes;
  304. var position;
  305. while (nowTime <= endTimes) {
  306. //根据时间计算卫星的位置
  307. let position = mars3d.Tle.getEcfPosition(item.tle1, item.tle2, nowTime);
  308. if (!position) {
  309. break;
  310. }
  311. //显示点[参考比较结果是否正确]
  312. var timeStr = new Date(nowTime).format("yyyy-MM-dd HH:mm:ss");
  313. var primitive = new mars3d.graphic.PointPrimitive({
  314. position: position,
  315. style: {
  316. color: pointClr,
  317. pixelSize: 3,
  318. },
  319. attr: item,
  320. tooltip: `编号:${item.norad} <br />卫星:${item.name} <br />时间:${timeStr}`,
  321. });
  322. graphicLayer.addGraphic(primitive);
  323. //判断是卫星否在缓冲区内
  324. var isInPoly = graphic.isInPoly(position);
  325. // console.log(`${item.name},时间:${timeStr},结果:${isInPoly}`);
  326. if (lastObj && !lastObj.isInPoly && isInPoly) {
  327. //表示进入范围
  328. inAreaPath.push({
  329. lastPosition: lastObj.position,
  330. lastTime: lastObj.time,
  331. time: nowTime,
  332. position: position,
  333. inOrOut: "in",
  334. });
  335. }
  336. if (lastObj && lastObj.isInPoly && !isInPoly) {
  337. //表示出范围
  338. inAreaPath.push({
  339. position: position,
  340. lastPosition: lastObj.position,
  341. lastTime: lastObj.time,
  342. time: nowTime,
  343. inOrOut: "out",
  344. });
  345. break;
  346. }
  347. lastObj = {
  348. position: position,
  349. isInPoly: isInPoly,
  350. time: nowTime,
  351. };
  352. nowTime += step;
  353. }
  354. if (lastObj && lastObj.isInPoly) {
  355. //表示出范围
  356. inAreaPath.push({
  357. position: position,
  358. lastPosition: lastObj.position,
  359. lastTime: lastObj.time,
  360. time: nowTime,
  361. inOrOut: "out",
  362. });
  363. }
  364. return inAreaPath;
  365. }
  366. //=====================结果展示==================================
  367. function showResult(newSatelliteArr) {
  368. //显示卫星条带
  369. var tableList = [];
  370. for (var ind = 0; ind < newSatelliteArr.length; ind++) {
  371. var item = newSatelliteArr[ind];
  372. var inAreaPath = item.inAreaPath;
  373. if (inAreaPath.length < 2) {
  374. continue;
  375. }
  376. var index = 0;
  377. if (inAreaPath[0].inOrOut == "out") {
  378. //保证从进入 开始计算
  379. index = 1;
  380. }
  381. for (var i = index; i < inAreaPath.length; i = i + 2) {
  382. var positions = [];
  383. var inTime;
  384. var outTime;
  385. if (inAreaPath[i].inOrOut == "in" && inAreaPath[i + 1].inOrOut == "out") {
  386. var inAttr = inAreaPath[i];
  387. var outAttr = inAreaPath[i + 1];
  388. if (inAttr?.lastPosition) {
  389. inTime = new Date(inAttr.lastTime).format("yyyy-M-d HH:mm:ss");
  390. positions.push(inAttr.lastPosition);
  391. }
  392. if (outAttr?.position) {
  393. positions.push(outAttr.position);
  394. outTime = new Date(outAttr.time).format("yyyy-M-d HH:mm:ss");
  395. }
  396. if (positions.length > 1) {
  397. var data = {
  398. positions: positions,
  399. name: item.name,
  400. inTime: inTime,
  401. outTime: outTime,
  402. often: haoutil.str.formatTime((outAttr.time - inAttr.lastTime) / 1000),
  403. distance: haoutil.str.formatLength(Cesium.Cartesian3.distance(positions[1], positions[0])),
  404. };
  405. tableList.push(data);
  406. showCorridor(data);
  407. }
  408. }
  409. }
  410. }
  411. $table.bootstrapTable("load", tableList);
  412. haoutil.msg("分析完成,共" + tableList.length + "条过境记录");
  413. }
  414. var corridor = [];
  415. function showCorridor(data) {
  416. var primitive = new mars3d.graphic.CorridorPrimitive({
  417. positions: data.positions,
  418. style: {
  419. width: 6000,
  420. cornerType: Cesium.CornerType.MITERED, //指定转角处样式
  421. color: "#00ff00",
  422. },
  423. });
  424. graphicLayer.addGraphic(primitive);
  425. var inthtml =
  426. '<table style="width:280px;">' +
  427. '<tr><th scope="col" colspan="4" style="text-align:center;font-size:15px;">信息</th></tr>' +
  428. "<tr><td >卫星名称:</td><td >" +
  429. data.name +
  430. " </td></tr>" +
  431. "<tr><td >进入时间:</td><td >" +
  432. data.inTime +
  433. " </td></tr>" +
  434. "<tr><td >飞出时间:</td><td >" +
  435. data.outTime +
  436. " </td></tr>" +
  437. "<tr><td >过境时长:</td><td >" +
  438. data.often +
  439. " </td></tr>" +
  440. "<tr><td >过境距离:</td><td >" +
  441. data.distance +
  442. " </td></tr>" +
  443. "</table>";
  444. primitive.bindPopup(inthtml);
  445. data._graphic = primitive;
  446. }
  447. </script>
  448. </body>
  449. </html>