cesiumViewer.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. <template>
  2. <div id="cesiumContainer">
  3. </div>
  4. </template>
  5. <script>
  6. import cesiumEntityUtils from "@/utils/cesiumEntityUtils";
  7. import GlobleCountryLine from "../../assets/MapData/GlobleCountryLine.json";
  8. let viewer;
  9. export default {
  10. name: "cesiumViewer",
  11. data() {
  12. return {
  13. globleLines: GlobleCountryLine,
  14. locationLonLat: [],
  15. rwxxztVis: null,
  16. projectEntitys: {},
  17. showAll: true
  18. };
  19. },
  20. computed: {
  21. mapPoint() {
  22. return this.$store.state.xqglMapPointVisible
  23. },
  24. mapRectangle() {
  25. return this.$store.state.xqglMapRectangleVisible
  26. },
  27. clickedTargetRow() {
  28. return this.$store.state.xqglClickedTargetRowForCesiumSetView
  29. },
  30. currentRouteName() {
  31. return this.$route.name;
  32. }
  33. },
  34. watch: {
  35. currentRouteName: {
  36. handler(newValue) {
  37. if (viewer) {
  38. this.displayTimeLine(newValue === 'rwjsPage' && this.rwxxztVis);
  39. return;
  40. }
  41. const t = setInterval(() => {
  42. if (viewer) {
  43. this.displayTimeLine(newValue === 'rwjsPage' && this.rwxxztVis);
  44. clearInterval(t);
  45. }
  46. }, 10);
  47. },
  48. immediate: true,
  49. },
  50. locationLonLat: {
  51. deep: true,
  52. handler(newval) {
  53. this.$store.dispatch("xqglMapPointLonLat", newval)
  54. }
  55. },
  56. mapPoint(newPoint) {
  57. // this.moveEntities(this.thisviewer);
  58. this.moveMapLeftEventMonitor(window.viewer);
  59. console.log("地图上得到点击,地图点选的信息:", newPoint);
  60. this.mapClickPointAdd(window.viewer)
  61. },
  62. mapRectangle(newRec) {
  63. // this.moveEntities(this.thisviewer);
  64. this.moveMapLeftEventMonitor(window.viewer)
  65. console.log("地图上得到点击,地图框选的信息:", newRec);
  66. this.mapDrawRectangle(window.viewer)
  67. },
  68. clickedTargetRow(newClickedRow) {
  69. //测试点位添加
  70. const viewer = window.viewer;
  71. cesiumEntityUtils.removeCustomLayer(viewer, "xqgl");
  72. cesiumEntityUtils.addCustomLayer(viewer, "xqgl")
  73. let datasource = cesiumEntityUtils.getCustomLayer(viewer, "xqgl");
  74. newClickedRow.forEach((item, index) => {
  75. let lon = null;
  76. let lat = null;
  77. if (item.pointDTOList.length === 1) {
  78. lon = item.pointDTOList[0].lng;
  79. lat = item.pointDTOList[0].lat;
  80. }
  81. // cesiumEntityUtils.controlLayer(viewer, "xqgl", false)
  82. if (datasource) {
  83. let position = Cesium.Cartesian3.fromDegrees(lon, lat);
  84. datasource.entities.add({
  85. id: 'target' + index,
  86. position: position,
  87. billboard: {
  88. image: './static/icon/target_red.svg',
  89. width: 16,
  90. height: 16
  91. }
  92. });
  93. }
  94. })
  95. return
  96. // ----------------------------------------------
  97. let lon = null;
  98. let lat = null;
  99. if (newClickedRow.pointDTOList.length === 1) {
  100. lon = newClickedRow.pointDTOList[0].lng;
  101. lat = newClickedRow.pointDTOList[0].lat;
  102. this.addClickTargetPoint(lon, lat, true);
  103. }
  104. if (newClickedRow.pointDTOList.length === 4) {
  105. // lon = (newClickedRow.pointDTOList[0].lng + newClickedRow.pointDTOList[3].lng) / 2;
  106. // lat = (newClickedRow.pointDTOList[0].lat + newClickedRow.pointDTOList[3].lat) / 2;
  107. let polygon = [];
  108. let pointsSort = newClickedRow.pointDTOList.sort((a, b) => a.sequence - b.sequence);
  109. pointsSort.forEach(item => {
  110. polygon.push(item.lng);
  111. polygon.push(item.lat);
  112. });
  113. let polygonObj = {
  114. id: newClickedRow.targetId,
  115. name: newClickedRow.targetName,
  116. material: Cesium.Color.fromCssColorString('rgba(255,0,0,0.5)'),
  117. polygon,
  118. };
  119. this.addClickTargetRectangle([polygonObj]);
  120. }
  121. // this.addClickTargetPoint(lon, lat, true)
  122. // console.log("地图上得到目标列表被单击的行数据:", newClickedRow);
  123. },
  124. },
  125. mounted() {
  126. this.initViewer();
  127. this.componentsEvents();
  128. },
  129. methods: {
  130. initViewer() {
  131. viewer = new Cesium.Viewer("cesiumContainer", {
  132. // 连接地图服务
  133. // imageryProvider: new Cesium.UrlTemplateImageryProvider({
  134. // // url: "http://192.168.1.188:9109/map/?z={z}&x={x}&y={y}",
  135. // url: window.mapUrl,
  136. // tilingScheme: new Cesium.WebMercatorTilingScheme(),
  137. // maximumLevel: 7,
  138. // show: false
  139. // }),
  140. imageryProvider: new Cesium.ArcGisMapServerImageryProvider({
  141. // url: window.mapUrl + ":9109/map/?z={z}&x={x}&y={y}",
  142. url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer",
  143. tilingScheme: new Cesium.WebMercatorTilingScheme(),
  144. maximumLevel: 7,
  145. show: false
  146. }),
  147. animation: true,//true
  148. baseLayerPicker: false,
  149. geocoder: false,
  150. homeButton: false,
  151. sceneModePicker: false,
  152. timeline: true,//true
  153. navigationHelpButton: false,
  154. fullscreenButton: false
  155. });
  156. // viewer.dataSources.add(
  157. // Cesium.GeoJsonDataSource.load("MapData/GlobleCountryLine.json")
  158. // )
  159. viewer.clock.shouldAnimate = true;
  160. viewer._cesiumWidget._creditContainer.style.display = "none";
  161. viewer.scene.globe.enableLighting = true;
  162. viewer.camera.setView({
  163. destination: Cesium.Cartesian3.fromDegrees(115.48, 32.67, 40000000.0),
  164. orientation: {
  165. pitch: Cesium.Math.toRadians(-88)
  166. }
  167. });
  168. cesiumEntityUtils.formatterDateToUTC8(viewer, true);
  169. cesiumEntityUtils.polylineMaterial();
  170. window.viewer = viewer
  171. // this.addGlobleLine()
  172. document.oncontextmenu = function () {
  173. return false
  174. }
  175. let handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
  176. let tempStore = this.$store
  177. handler.setInputAction(function (click) {
  178. tempStore.dispatch("xqglContentVisible", true)
  179. }, Cesium.ScreenSpaceEventType.RIGHT_CLICK)
  180. },
  181. componentsEvents() {
  182. let self = this;
  183. //需求解译窗口列表添加
  184. this.$events.on("xqjy-addwindow", function (datas) {
  185. self.addWindowsOrPointByXqjy(datas, "windows")
  186. })
  187. //需求解译窗口列表删除
  188. this.$events.on("xqjy-deletewindow", function (datas) {
  189. self.deleteWindowByXqjy(datas)
  190. })
  191. //需求解译目标任务点展示
  192. this.$events.on("xqjy-target", function (data) {
  193. cesiumEntityUtils.controlLayer(viewer, 'xqgl', false)
  194. self.addWindowsOrPointByXqjy(data, "target")
  195. });
  196. //需求管理目标点添加
  197. this.$events.on('xqgl-targetList', function (datas) {
  198. //移除临时绘制图形
  199. let datasource = cesiumEntityUtils.getCustomLayer(viewer, "xqgl");
  200. if (datasource) {
  201. datasource.entities.removeById("selectTarget");
  202. }
  203. self.addTargetList("xqgl", datas)
  204. })
  205. this.$events.on('xqgl-cancelselect', function () {
  206. //移除临时绘制图形
  207. let datasource = cesiumEntityUtils.getCustomLayer(viewer, "xqgl");
  208. if (datasource) {
  209. datasource.entities.removeById("selectTarget");
  210. }
  211. })
  212. //专题切换通知
  213. this.$events.on("topic-switch", function (data) {
  214. if (!self.showAll)
  215. return
  216. const viewer = window.viewer;
  217. cesiumEntityUtils.controlLayer(viewer, data.from, false)
  218. cesiumEntityUtils.controlLayer(viewer, data.to, true)
  219. })
  220. this.$events.on("rwjs-hideall", function () {
  221. const viewer = window.viewer;
  222. self.showAll = !self.showAll
  223. cesiumEntityUtils.controlLayer(viewer, ['rwjs', 'rwjs-satelliteTracks', 'rwjs-stations', 'xqgl', 'jcfw', 'xqjy', 'xqch'], self.showAll)
  224. })
  225. this.$events.on("rwjs-targetshow", function (data) {
  226. cesiumEntityUtils.controlLayer(viewer, 'rwjs', data)
  227. })
  228. //任务监视地面站添加
  229. this.$events.on("rwjs-addStation", data => {
  230. cesiumEntityUtils.addCustomLayer(viewer, "rwjs-stations");
  231. cesiumEntityUtils.addModels(viewer, "rwjs-stations", data);
  232. })
  233. //任务监视目标点添加
  234. this.$events.on('rwjs-targetList', function (datas) {
  235. // console.log("@datas", datas);
  236. //移除临时绘制图形
  237. // viewer.entities.remove(viewer.entities.getById('selectTarget'));
  238. self.addTargetList("rwjs", datas);
  239. })
  240. this.$events.on('rwjs-wxgcxxStripe', function (datas) {
  241. // debugger
  242. self.addTargetList("rwjs", datas, true);
  243. })
  244. this.$events.on("rwjs-wxyxzt", (datas) => {
  245. self.addTracks("rwjs-satelliteTracks", datas);
  246. })
  247. this.$events.on("sys-initView", (type) => {
  248. this.initView(viewer, type);
  249. })
  250. this.$events.on("sys-change2D3D", () => {
  251. self.changeViewerModel();
  252. })
  253. this.$events.on("sys-showTimeLine", (show) => {
  254. self.rwxxztVis = show;
  255. self.displayTimeLine(show);
  256. })
  257. this.$events.on("sys-showTrack", (type) => {
  258. this.initView(viewer, type);
  259. this.isTrackShow(undefined, type);
  260. })
  261. },
  262. changeViewerModel() {
  263. viewer.scene.mode == Cesium.SceneMode.SCENE3D ? (viewer.scene.mode = Cesium.SceneMode.SCENE2D) : (viewer.scene.mode = Cesium.SceneMode.SCENE3D);
  264. },
  265. displayTimeLine(show) {
  266. if (viewer) {
  267. if (show) {
  268. viewer.animation.container.style.display = "block"
  269. viewer.timeline.container.style.display = "block"
  270. viewer.animation.container.style.zIndex = 9
  271. viewer.timeline.container.style.zIndex = 9
  272. } else {
  273. viewer.animation.container.style.display = "none"
  274. viewer.timeline.container.style.display = "none"
  275. }
  276. }
  277. },
  278. initView(viewer, type = "all") {
  279. const heights = {
  280. "lowTrack": 20000000,
  281. "highTrack": 25000000,
  282. "all": 40000000,
  283. }
  284. viewer.camera.flyTo({
  285. destination: Cesium.Cartesian3.fromDegrees(115.48, 32.67, heights[type]),
  286. orientation: {
  287. pitch: Cesium.Math.toRadians(-88)
  288. }
  289. });
  290. },
  291. moveEntities(viewer) {
  292. viewer.entities.removeAll();
  293. },
  294. moveMapLeftEventMonitor(viewer) {
  295. viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
  296. },
  297. mapClickPointAdd(viewer) {
  298. let self = this;
  299. let handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
  300. handler.setInputAction(function (event) {
  301. cesiumEntityUtils.addCustomLayer(viewer, "xqgl")
  302. let datasource = cesiumEntityUtils.getCustomLayer(viewer, "xqgl");
  303. let clickPosition = viewer.scene.camera.pickEllipsoid(event.position);
  304. let radiansPos = Cesium.Cartographic.fromCartesian(clickPosition);
  305. cesiumEntityUtils.flyToTargetPoint(viewer, Cesium.Math.toDegrees(radiansPos.longitude), Cesium.Math.toDegrees(radiansPos.latitude), 20000000);
  306. if (datasource) {
  307. datasource.entities.removeById("selectTarget");
  308. datasource.entities.add({
  309. id: 'selectTarget',
  310. position: clickPosition,
  311. point: {
  312. color: Cesium.Color.YELLOW,
  313. pixelSize: 10
  314. }
  315. })
  316. }
  317. self.locationLonLat = [];
  318. self.locationLonLat.push(Cesium.Math.toDegrees(radiansPos.longitude));
  319. self.locationLonLat.push(Cesium.Math.toDegrees(radiansPos.latitude));
  320. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  321. },
  322. mapDrawRectangle(viewer) {
  323. if (viewer) {
  324. const self = this;
  325. let clickPoint = [];
  326. let sefstore = this.$store
  327. // 鼠标左键绘制
  328. let handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
  329. handler.setInputAction(function (movement) {
  330. const earthPosition = viewer.camera.pickEllipsoid(movement.position, viewer.scene.globe.ellipsoid); //当前世界坐标笛卡尔积
  331. if (Cesium.defined(earthPosition)) {
  332. // 判断现在是第几个点
  333. if (clickPoint.length === 0) { //还没有点,添加第一个点
  334. clickPoint.push(earthPosition)
  335. } else {
  336. //绘制矩形
  337. clickPoint.push(earthPosition)
  338. // 绘制矩形
  339. const rectangleHand = Cesium.Rectangle.fromCartesianArray(clickPoint)
  340. cesiumEntityUtils.addCustomLayer(viewer, "xqgl")
  341. let datasource = cesiumEntityUtils.getCustomLayer(viewer, "xqgl");
  342. if (datasource) {
  343. datasource.entities.removeById("selectTarget");
  344. datasource.entities.add({
  345. id: 'selectTarget',
  346. name: 'drawRectangle',
  347. rectangle: {
  348. coordinates: rectangleHand,
  349. height: 0,
  350. material: Cesium.Color.RED.withAlpha(0.4),
  351. outline: true,
  352. outlineColor: Cesium.Color.BLUE.withAlpha(0.5),
  353. },
  354. });
  355. }
  356. const northwest = Cesium.Rectangle.northwest(rectangleHand); //西北角弧度坐标(左上)
  357. const southwest = Cesium.Rectangle.southwest(rectangleHand); //西南角弧度坐标(左下)
  358. const northeast = Cesium.Rectangle.northeast(rectangleHand); //东北角弧度坐标(右上)
  359. const southeast = Cesium.Rectangle.southeast(rectangleHand); //东南角弧度坐标(右下)
  360. // 转换为经纬度
  361. const leftTop = [Cesium.Math.toDegrees(northwest.longitude), Cesium.Math.toDegrees(northwest.latitude)]; //左上角经度
  362. const leftBottom = [Cesium.Math.toDegrees(southwest.longitude), Cesium.Math.toDegrees(southwest.latitude)]; //左下角经度
  363. const rightTop = [Cesium.Math.toDegrees(northeast.longitude), Cesium.Math.toDegrees(northeast.latitude)]; //右上角经度
  364. const rightBottom = [Cesium.Math.toDegrees(southeast.longitude), Cesium.Math.toDegrees(southeast.latitude)]; //右下角经度
  365. cesiumEntityUtils.flyToTargetPoint(viewer, (leftTop[0] + rightBottom[0]) / 2, (leftTop[1] + rightBottom[1]) / 2, 20000000);
  366. const data = {
  367. leftTop: leftTop,
  368. leftBottom: leftBottom,
  369. rightTop: rightTop,
  370. rightBottom: rightBottom,
  371. }
  372. const dataarr = [leftTop, rightTop, rightBottom, leftBottom]
  373. sefstore.dispatch('xqglMapRectangleLonLats', dataarr)
  374. // console.log("矩形四角坐标:",data);
  375. console.log("矩形四角坐标arr:", sefstore.state.xqglMapRectangleLonLats);
  376. clickPoint = []; //清空
  377. }
  378. }
  379. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  380. }
  381. },
  382. addGlobleLine() {
  383. const features = this.globleLines.geometries;
  384. const instances = [];
  385. for (let i = 0; i < features.length; i++) {
  386. const polygonArr = features[i].coordinates;
  387. const polygon = new Cesium.PolylineGeometry({
  388. positions: Cesium.Cartesian3.fromDegreesArray(polygonArr.toString().split(',')),
  389. width: 3,
  390. vertexFormat: Cesium.PolylineColorAppearance.VERTEX_FORMAT
  391. })
  392. instances.push(new Cesium.GeometryInstance({
  393. geometry: polygon,
  394. attributes: {
  395. color: Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color.fromCssColorString("rgba(217,212,85,1)"))
  396. }
  397. }))
  398. }
  399. const primitive = new Cesium.Primitive({
  400. geometryInstances: instances,
  401. appearance: new Cesium.PolylineColorAppearance(),
  402. asynchronous: false
  403. })
  404. window.viewer.scene.primitives.add(primitive)
  405. },
  406. addClickTargetRectangle(polygons) {
  407. const viewer = window.viewer;
  408. cesiumEntityUtils.removeCustomLayer(viewer, "xqgl");
  409. cesiumEntityUtils.addCustomLayer(viewer, "xqgl");
  410. // cesiumEntityUtils.controlLayer(viewer, "xqgl", true)
  411. cesiumEntityUtils.addCustomPolygons(viewer, "xqgl", polygons);
  412. cesiumEntityUtils.flyToTargetPolygon(viewer, polygons[0].polygon, 8000000);
  413. },
  414. addClickTargetPoint(lon, lat, isLocation) {
  415. const viewer = window.viewer;
  416. cesiumEntityUtils.removeCustomLayer(viewer, "xqgl");
  417. cesiumEntityUtils.addCustomLayer(viewer, "xqgl")
  418. // cesiumEntityUtils.controlLayer(viewer, "xqgl", false)
  419. let datasource = cesiumEntityUtils.getCustomLayer(viewer, "xqgl");
  420. if (datasource) {
  421. datasource.entities.removeById("target");
  422. let position = Cesium.Cartesian3.fromDegrees(lon, lat);
  423. datasource.entities.add({
  424. id: 'target',
  425. position: position,
  426. billboard: {
  427. image: './static/icon/target_red.svg',
  428. width: 16,
  429. height: 16
  430. }
  431. });
  432. if (isLocation) {
  433. cesiumEntityUtils.flyToTargetPoint(viewer, lon, lat, 20000000);
  434. }
  435. }
  436. },
  437. addWindowsOrPointByXqjy(datas, type) {
  438. const viewer = window.viewer;
  439. // cesiumEntityUtils.controlAllLayer(viewer, false);
  440. // if (type === 'target') {
  441. // cesiumEntityUtils.removeCustomLayer(viewer, 'xqjy')
  442. // }
  443. cesiumEntityUtils.addCustomLayer(viewer, "xqjy")
  444. // cesiumEntityUtils.controlLayer
  445. if (type === 'target') {
  446. const targetType = datas.type;
  447. const target = datas.data;
  448. if (target === null)
  449. return;
  450. if (targetType === 'point') {
  451. cesiumEntityUtils.addCustomPoints(viewer, "xqjy", target);
  452. cesiumEntityUtils.flyToTargetPoint(viewer, target.lon, target.lat, 8000000)
  453. } else {
  454. cesiumEntityUtils.addCustomPolygons(viewer, "xqjy", target);
  455. cesiumEntityUtils.flyToTargetPolygon(viewer, target.polygon, 8000000)
  456. }
  457. } else {
  458. if (datas.length == 0) {
  459. return
  460. }
  461. cesiumEntityUtils.addCustomPolygons(viewer, "xqjy", datas);
  462. // let polygon = [];
  463. // datas.forEach(data => {
  464. // polygon = polygon.concat(data.polygon)
  465. // });
  466. // cesiumEntityUtils.flyToTargetPolygon(viewer, polygon, 20000000)
  467. }
  468. },
  469. deleteWindowByXqjy(datas) {
  470. const viewer = window.viewer;
  471. cesiumEntityUtils.removeCustomLayerEntitysById(viewer, "xqjy", datas)
  472. },
  473. addTargetList(dsId, datas, isStripe = false) {
  474. // debugger
  475. const viewer = window.viewer;
  476. if (datas.length == 0) {
  477. // cesiumEntityUtils.removeCustomLayer(viewer, "xqgl")
  478. cesiumEntityUtils.removeCustomLayer(viewer, dsId)
  479. return
  480. }
  481. // cesiumEntityUtils.addCustomLayer(viewer, "xqgl")
  482. cesiumEntityUtils.addCustomLayer(viewer, dsId)
  483. let targetPoints = [];
  484. let targetPoylgons = []
  485. datas.forEach(data => {
  486. const id = data.id;
  487. const name = data.targetName
  488. let points = data.pointDTOList;
  489. if (points.length == 1) {
  490. targetPoints.push({
  491. id: id,
  492. name: name,
  493. lon: points[0].lng,
  494. lat: points[0].lat,
  495. size: 10,
  496. style: {
  497. color: 'red',
  498. },
  499. color: Cesium.Color.fromCssColorString('#f10808')
  500. })
  501. cesiumEntityUtils.addCustomPoints(viewer, dsId, targetPoints)
  502. dsId === 'rwjs' && cesiumEntityUtils.flyToTargetPoint(viewer, points[0].lng, points[0].lat, 8000000)
  503. }
  504. if (points.length > 1) {
  505. let polygon = [];
  506. points.forEach(point => {
  507. polygon.push(point.lng || point.longitude)
  508. polygon.push(point.lat || point.latitude)
  509. })
  510. targetPoylgons.push({
  511. id: id,
  512. name: name,
  513. isRhumb: true,//矩形按照贴经纬线形状绘制
  514. polygon: polygon,
  515. height: 10,
  516. style: {
  517. color: 'red',
  518. size: 5
  519. },
  520. material: isStripe ? Cesium.Color.fromCssColorString('rgba(237,245,11,0.5)') : Cesium.Color.fromCssColorString('#f10808'),
  521. })
  522. cesiumEntityUtils.addCustomPolygons(viewer, dsId, targetPoylgons)
  523. dsId === 'rwjs' && cesiumEntityUtils.flyToTargetPolygon(viewer, polygon, 8000000)
  524. }
  525. })
  526. },
  527. addTracks(dsId, tracks) {
  528. const {trackData, startTime, endTime, satelliteList, tasks} = tracks
  529. const viewer = window.viewer;
  530. cesiumEntityUtils.createCZML(viewer, dsId, startTime, endTime, trackData);
  531. //绘制投影
  532. let self = this;
  533. let _viewer = viewer;
  534. let timer = setInterval(() => {
  535. if (window.trackShow) {
  536. self.addSatelliteProjection(satelliteList, tasks);
  537. // this.setCurrentTime(_viewer, "2022-04-09T15:06:10")
  538. clearInterval(timer);
  539. window.trackShow = false;
  540. }
  541. }, 500);
  542. },
  543. //添加卫星投影
  544. addSatelliteProjection(satelliteList, tasks) {
  545. const viewer = window.viewer;
  546. satelliteList.forEach(item => {
  547. const wxSource = viewer.dataSources.getByName(item.wxSourceId)[0];
  548. if (!wxSource) return;
  549. const itemEntity = cesiumEntityUtils.getEntityByIdDS(wxSource, item.name);
  550. if (itemEntity) {
  551. this.projectEntitys[item.name] = cesiumEntityUtils.drawProjection(viewer, 1, itemEntity, false, item);
  552. }
  553. });
  554. this.taskRun(tasks);
  555. },
  556. //任务执行监听
  557. taskRun(tasks) {
  558. const stationDsId = "rwjs-stations"
  559. const satelliteDsId = "rwjs-satelliteTracks"
  560. const lineId = "rwjs-taskSimulationLine"
  561. tasks.cdTasks.forEach((taskItem, index) => {
  562. let times = [];
  563. times.push({
  564. start: Cesium.JulianDate.fromDate(new Date(taskItem.startTime)),
  565. stop: Cesium.JulianDate.fromDate(new Date(taskItem.endTime))
  566. });
  567. const station = cesiumEntityUtils.getEntityByIdDS(viewer.dataSources.getByName(stationDsId)[0], taskItem.stationCode);
  568. const satellite = cesiumEntityUtils.getEntityByIdDS(viewer.dataSources.getByName(satelliteDsId)[0], taskItem.satelliteCode);
  569. if (times.length > 0) {
  570. const option = {
  571. viewer: viewer,
  572. dsId: satelliteDsId,
  573. lineId: lineId + index,
  574. satellite,
  575. station,
  576. times,
  577. direction: taskItem.type, //可选 'SC' 和 'CK', 不传,默认为 'SC'
  578. };
  579. cesiumEntityUtils.addLineBetweenTwoEntity(option);
  580. }
  581. });
  582. // 投影可见任务,相机开关机
  583. // console.log("this.projectEntitys:", this.projectEntitys);
  584. tasks.proTasks.forEach(proTask => {
  585. proTask.startTime = this.timeToUTM(proTask.startTime)
  586. proTask.endTime = this.timeToUTM(proTask.endTime)
  587. cesiumEntityUtils.projectionVisible(viewer, this.projectEntitys[proTask.satelliteCode], proTask)
  588. })
  589. },
  590. timeToUTM(strTime) {
  591. let d = this.$moment(strTime)
  592. return d.subtract(8, 'h').format("YYYY-MM-DD HH:mm:ss")
  593. },
  594. isTrackShow(dsId = "rwjs-satelliteTracks", type = "all", show = true) {
  595. // type 的可选项:lowTrack,highTrack,all
  596. const tracksLayer = viewer.dataSources.getByName(dsId)[0];
  597. if (!tracksLayer) {
  598. return
  599. }
  600. tracksLayer.entities.values.forEach(et => {
  601. if (et.description) {
  602. const tempType = et.description.getValue();
  603. if (type === 'all') {
  604. et.show = true;
  605. } else {
  606. et.show = tempType === type;
  607. }
  608. }
  609. });
  610. },
  611. },
  612. };
  613. </script>
  614. <style lang="scss" scoped>
  615. #cesiumContainer {
  616. width: 100%;
  617. height: 100%;
  618. }
  619. </style>