camera.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  1. <template>
  2. <div class="sm-function-module-content" v-show="cameraShow">
  3. <Tabs value="">
  4. <TabPane :label="Resource.flyRoute" name="fxxl">
  5. <!-- <label class="label-container">{{ Resource.flyRoute }}</label>
  6. <input
  7. class="sm-input"
  8. type="file"
  9. accept=".fpf"
  10. id="flyFile"
  11. style="width: 100%"
  12. /> -->
  13. <div class="importFly">
  14. <span>{{ Resource.flyRoute }}</span>
  15. <input type="file" accept=".fpf" id="flyFile" style="width: 100%" />
  16. </div>
  17. <div class="flybox">
  18. <i
  19. class="el-icon-video-play flyBtn"
  20. @click="flyStart"
  21. :title="Resource.startFly"
  22. ></i>
  23. <i
  24. class="el-icon-video-pause flyBtn"
  25. @click="flyPause"
  26. :title="Resource.pauseFly"
  27. ></i>
  28. <i
  29. class="el-icon-document-delete flyBtn"
  30. @click="flyStop"
  31. :title="Resource.stopFly"
  32. ></i>
  33. </div>
  34. <div class="sm-function-module-sub-section">
  35. <label class="label-container">{{ Resource.stopChoose }}</label>
  36. <select
  37. class="sm-select"
  38. id="stopList"
  39. v-model="stopSelected"
  40. ></select>
  41. </div>
  42. <div class="sm-function-module-sub-section">
  43. <label class="label-container">{{ Resource.observe }}</label>
  44. <div class="flexbox">
  45. <el-button type="primary" size="mini" @click="onSpinClk">{{
  46. Resource.rotatePoint
  47. }}</el-button>
  48. <el-button type="primary" size="mini" @click="onCancelSpinClk">
  49. {{ Resource.cancelRotatePoint }}
  50. </el-button>
  51. <!-- <label>{{ Resource.pauseFly }}</label>
  52. <input type="checkbox" v-model="stopFlyCircle" />
  53. <label>{{ Resource.rotateCirculation }}</label>
  54. <input type="checkbox" v-model="circulation" /> -->
  55. <el-checkbox v-model="stopFlyCircle">{{
  56. Resource.pauseFly
  57. }}</el-checkbox>
  58. <el-checkbox v-model="circulation">{{
  59. Resource.rotateCirculation
  60. }}</el-checkbox>
  61. </div>
  62. <label class="label-container">{{ Resource.rotateSpeed }}</label>
  63. <div class="sm-solider-input-box">
  64. <input
  65. class="min-solider"
  66. min="0"
  67. max="50"
  68. step="0.1"
  69. style="width: 63%"
  70. type="range"
  71. v-model="speed"
  72. />
  73. <input
  74. class="min-solider"
  75. min="0"
  76. max="50"
  77. step="0.1"
  78. style="width: 34%"
  79. type="number"
  80. v-model="speed"
  81. />
  82. </div>
  83. </div>
  84. <div class="sm-function-module-sub-section">
  85. <label class="label-container">{{ Resource.underground }}</label>
  86. <br />
  87. <label class="sm-viewshed-label-right">{{
  88. Resource.openUnderground
  89. }}</label>
  90. <input type="checkbox" v-model="underground" />
  91. <div class="sm-function-module-sub-section">
  92. <label class="label-container">{{
  93. Resource.cameraMinimumZoomDistance
  94. }}</label>
  95. <input
  96. class="sm-input-long"
  97. min="0"
  98. type="number"
  99. v-model="cameraMinimumZoomDistance"
  100. />
  101. </div>
  102. <div class="sm-function-module-sub-section">
  103. <label class="label-container">{{
  104. Resource.SurfaceTransparency
  105. }}</label>
  106. <input
  107. class="sm-input-long"
  108. min="0"
  109. max="1.0"
  110. step="0.01"
  111. type="number"
  112. v-model="SurfaceTransparency"
  113. />
  114. </div>
  115. </div>
  116. </TabPane>
  117. <TabPane :label="Resource.createFlyRoute" name="cjfxxl">
  118. <div class="icon-list" style="width: 12.96rem">
  119. <span
  120. v-for="(item, index) in state.itemOptions"
  121. :key="index"
  122. class="icon-span"
  123. :title="item.lable"
  124. :class="item.isSelect ? 'selected-icon' : ''"
  125. @click="changleIconItem(item)"
  126. >
  127. <i
  128. class="iconfont iconSize"
  129. :class="item.iconName"
  130. style="margin-top: 0px"
  131. ></i>
  132. </span>
  133. </div>
  134. <div v-show="state.customRouteNames.length > 0">
  135. <div class="row-item">
  136. <span>已经添加站点</span>
  137. <div>
  138. <!-- <n-select
  139. v-model="state.selectedAddedStopIndex"
  140. :options="state.routeStops"
  141. label-field="stopName"
  142. value-field="index"
  143. /> -->
  144. <el-select v-model="state.selectedAddedStopIndex">
  145. <el-option
  146. v-for="item in state.routeStops"
  147. :key="item.value"
  148. :label="item.stopName"
  149. :value="item.index"
  150. >
  151. </el-option>
  152. </el-select>
  153. </div>
  154. </div>
  155. <div class="row-item" style="margin-bottom: 0px">
  156. <span></span>
  157. <div class="row-content" style="display: flex">
  158. <el-checkbox v-model="showRoute" /><span class="checkbox-lable"
  159. >显示路线</span
  160. >
  161. <el-checkbox v-model="showStop" /><span class="checkbox-lable"
  162. >显示站点</span
  163. >
  164. </div>
  165. </div>
  166. <div>
  167. <label class="label-container">飞行速度</label>
  168. <div class="sm-solider-input-box">
  169. <input
  170. class="min-solider"
  171. min="0"
  172. max="500"
  173. step="1"
  174. style="width: 63%"
  175. type="range"
  176. v-model="state.routeSpeed"
  177. />
  178. <span>{{ state.routeSpeed }}</span>
  179. </div>
  180. </div>
  181. <!-- <div class="block">
  182. <span class="demonstration">飞行速度</span>
  183. <el-slider v-model="state.routeSpeed" step="1" min="0" max="500" style="width: 63%"></el-slider>
  184. <span>{{ state.routeSpeed }}</span>
  185. </div> -->
  186. <div class="icon-list" style="width: 12.96rem">
  187. <span
  188. v-for="(item, index) in state.actionOptions"
  189. :key="index"
  190. class="icon-span"
  191. :title="item.lable"
  192. :class="item.isSelect ? 'selected-icon' : ''"
  193. @click="changleIconItemAction(item)"
  194. >
  195. <i
  196. class="iconfont iconSize"
  197. :class="item.iconName"
  198. style="margin-top: 0px"
  199. ></i>
  200. </span>
  201. </div>
  202. <div class="btn-row-item" style="margin-left: 0.94rem">
  203. <el-button
  204. type="info"
  205. color="#3499E5"
  206. text-color="#fff"
  207. @click="downLoad"
  208. style="margin-right: 0.1rem; margin-left: 0.03rem"
  209. >下载</el-button
  210. >
  211. <el-button
  212. class="btn-secondary"
  213. @click="clearRoute"
  214. color="rgba(255, 255, 255, 0.65)"
  215. ghost
  216. >清除</el-button
  217. >
  218. </div>
  219. </div>
  220. <!-- <rotate></rotate> -->
  221. <div class="row-item">
  222. <span>绕点旋转</span>
  223. <!-- <div style="width: 12.96rem">
  224. <n-switch v-model="state.rotateShow" size="small" />
  225. </div> -->
  226. <el-switch
  227. v-model="state.rotateShow"
  228. active-color="#13ce66"
  229. inactive-color="#ff4949"
  230. >
  231. </el-switch>
  232. </div>
  233. <div v-show="state.rotateShow">
  234. <div class="flexbox">
  235. <el-button type="primary" size="mini" @click="onSpinClk">{{
  236. Resource.rotatePoint
  237. }}</el-button>
  238. <el-button type="primary" size="mini" @click="onCancelSpinClk">
  239. {{ Resource.cancelRotatePoint }}
  240. </el-button>
  241. <el-checkbox v-model="stopFlyCircle">{{
  242. Resource.pauseFly
  243. }}</el-checkbox>
  244. <el-checkbox v-model="circulation">{{
  245. Resource.rotateCirculation
  246. }}</el-checkbox>
  247. </div>
  248. <label class="label-container">{{ Resource.rotateSpeed }}</label>
  249. <div class="sm-solider-input-box">
  250. <input
  251. class="min-solider"
  252. min="0"
  253. max="50"
  254. step="0.1"
  255. style="width: 63%"
  256. type="range"
  257. v-model="speed"
  258. />
  259. <input
  260. class="min-solider"
  261. min="0"
  262. max="50"
  263. step="0.1"
  264. style="width: 34%"
  265. type="number"
  266. v-model="speed"
  267. />
  268. </div>
  269. </div>
  270. </TabPane>
  271. </Tabs>
  272. </div>
  273. </template>
  274. <script>
  275. let flyManager,
  276. camera,
  277. flyCircleDrawHandler,
  278. createXml,
  279. currentStops,
  280. routeCollection;
  281. let flyLineXmls = [];
  282. import tool from "./tool";
  283. import createFlyLine_xml from "./fly-line-xml.js";
  284. import rotate from "./rotate.vue";
  285. // ,
  286. // let pointLightSourceDrawHandler,
  287. // spotOrDirectionalLightSourceDrawHandler,
  288. // spotOrDirectionalLightSourceCountHandler,
  289. // spotOrDirectionalLightSourceAdding = false,
  290. // spotOrDirectionalLightPositions = [],
  291. // entityPointLightPairs = new Map(), // Entity和点光源对象的键值对
  292. // entitySpotLightPairs = new Map(), // Entity和聚光灯对象的键值对
  293. // entityDirectionalLightPairs = new Map(); // Entity和平行光对象的键值对
  294. export default {
  295. name: "sceneCamera",
  296. components: {
  297. rotate,
  298. },
  299. data() {
  300. return {
  301. sharedState: store.state,
  302. stopSelected: [],
  303. stopFlyCircle: false,
  304. circulation: true,
  305. flyCirclePoint: null,
  306. speed: 1,
  307. underground: false,
  308. SurfaceTransparency: 1,
  309. cameraMinimumZoomDistance: -1000,
  310. isDestroyFlag: true,
  311. // 设置默认值数据
  312. state: {
  313. routeType: "customRoute", //自定义还得指定路线类型
  314. fileSrc: "", //文件地址,不能同时使用fpfUrl
  315. fpfUrl: null, //指定fpf路径
  316. selectedStopIndex: 0, //选中当前站点
  317. addCurrentStopIndex: 0, // 记录当前添加站点的索引并赋值给站点index,以便n-select
  318. showRoute: false, //显示路线
  319. showStop: false, //显示站点
  320. currentStopNames: [], //当前路线的站点名称集合
  321. currentStopNamesIndex: 0, // 记录当前路线的索引并赋值,以便n-select
  322. //自定义
  323. customRouteNames: [], //保存自定义路线名称
  324. addCurrentRouteIndex: 0, // 当前路线索引,以便n-select
  325. customRouteSelectedIndex: null, //自定义选中路线索引
  326. routeStops: [], //自定义当前路线的站点集合
  327. selectedAddedStopIndex: undefined, //自定义已加站点选中索引
  328. //站点
  329. setStopName: "Stop-1", //设置当前站点名称
  330. setStopSpeed: 0, // 设置当前站点速度
  331. stopPlayMode: "StopPause", //设置站点模式:默认停留
  332. waitTime: 0, //停留时间
  333. surroundDuration: 1, //环绕模式时间
  334. //飞行路线设置
  335. isAlongline: false, //获取或者设置该飞行路线是否是沿线飞行。
  336. routeSpeed: 200, //飞行路线速度
  337. isSaveAutoFlag: false,
  338. // allRoutes:[]
  339. itemOptions: [
  340. {
  341. index: 1,
  342. lable: "添加站点",
  343. iconName: "el-icon-circle-plus-outline",
  344. isSelect: false,
  345. },
  346. {
  347. index: 2,
  348. lable: "删除站点",
  349. iconName: "el-icon-delete",
  350. isSelect: false,
  351. },
  352. {
  353. index: 3,
  354. lable: "恢复",
  355. iconName: "el-icon-refresh-right",
  356. isSelect: false,
  357. },
  358. {
  359. index: 4,
  360. lable: "保存",
  361. iconName: "el-icon-document",
  362. isSelect: false,
  363. },
  364. ],
  365. actionOptions: [
  366. {
  367. index: 1,
  368. lable: "播放",
  369. iconName: "el-icon-video-play",
  370. isSelect: false,
  371. },
  372. {
  373. index: 2,
  374. lable: "暂停",
  375. iconName: "el-icon-video-pause",
  376. isSelect: false,
  377. },
  378. {
  379. index: 3,
  380. lable: "停止",
  381. iconName: "el-icon-help",
  382. isSelect: false,
  383. },
  384. ],
  385. },
  386. showRoute: false, //显示路线
  387. showStop: false, //显示站点
  388. };
  389. },
  390. computed: {
  391. cameraShow: function () {
  392. return this.sharedState.sceneAtttribute[1];
  393. },
  394. SceneAtttributeShow: function () {
  395. return this.sharedState.toolBar[3];
  396. },
  397. },
  398. beforeDestroy() {
  399. if (this.isDestroyFlag && camera) {
  400. camera = undefined;
  401. if (flyCircleDrawHandler) {
  402. // flyCircleDrawHandler.destroy();
  403. flyCircleDrawHandler = undefined;
  404. }
  405. if (flyManager) {
  406. flyManager.destroy();
  407. flyManager = this.undefined;
  408. }
  409. }
  410. },
  411. mounted() {
  412. if (this.SceneAtttributeShow && this.basicOptions) {
  413. this.init();
  414. }
  415. //初始化站点文件保存
  416. this.initFlyManager();
  417. },
  418. methods: {
  419. //子组件部分
  420. init() {
  421. if (camera) {
  422. return;
  423. }
  424. camera = scene.camera;
  425. camera.flyCircleLoop = true;
  426. },
  427. flyStart() {
  428. console.log(flyManager, "flyManager");
  429. // if (flyManager) {
  430. // flyManager.play();
  431. // } else {
  432. let routes = new Cesium.RouteCollection(viewer.entities);
  433. let fileInput = document.getElementById("flyFile");
  434. let file = fileInput.files[0];
  435. if (!file) {
  436. return; // 没有选择fpf文件无法开始执行
  437. }
  438. let reader = new FileReader();
  439. reader.onload = function (e) {
  440. // 读取操作完成时出发
  441. let XMLContent = e.target.result;
  442. routes.fromXML(XMLContent);
  443. };
  444. reader.readAsBinaryString(file);
  445. //创建飞行管理对象
  446. flyManager = new Cesium.FlyManager({
  447. scene: scene,
  448. routes: routes,
  449. });
  450. flyManager.stopArrived.addEventListener(function (routeStop) {
  451. routeStop.waitTime = 1;
  452. });
  453. if (flyManager.readyPromise) {
  454. Cesium.when(flyManager.readyPromise, function () {
  455. let currentRoute = flyManager.currentRoute;
  456. currentRoute.isLineVisible = true;
  457. currentRoute.isStopVisible = true;
  458. let allStops = flyManager.getAllRouteStops();
  459. let menu = document.getElementById("stopList");
  460. for (let i = 0, j = allStops.length; i < j; i++) {
  461. let option = document.createElement("option");
  462. option.textContent = Resource.stop + (i + 1);
  463. console.log(Resource, "asdas");
  464. option.value = allStops[i].index;
  465. menu.appendChild(option);
  466. }
  467. flyManager.play();
  468. });
  469. }
  470. // }
  471. },
  472. flyPause() {
  473. flyManager && flyManager.pause();
  474. },
  475. flyStop() {
  476. flyManager && flyManager.stop();
  477. },
  478. onSpinClk(evt) {
  479. this.isDestroyFlag = false;
  480. if (!flyCircleDrawHandler) {
  481. flyCircleDrawHandler = new Cesium.DrawHandler(
  482. viewer,
  483. Cesium.DrawMode.Point
  484. );
  485. flyCircleDrawHandler.activeEvt.addEventListener(function (isActive) {
  486. if (isActive == true) {
  487. viewer.enableCursorStyle = false;
  488. viewer._element.style.cursor = "";
  489. document.body.classList.add("drawCur");
  490. } else {
  491. viewer.enableCursorStyle = true;
  492. document.body.classList.remove("drawCur");
  493. }
  494. });
  495. flyCircleDrawHandler.drawEvt.addEventListener((result) => {
  496. this.flyCirclePoint = result.object.position;
  497. viewer.entities.removeById("fly-circle-point");
  498. viewer.entities.add({
  499. id: "fly-circle-point",
  500. position: this.flyCirclePoint,
  501. billboard: {
  502. image: "@/../static/images/flypng/flyCircle.png",
  503. scaleByDistance: new Cesium.NearFarScalar(10, 1.0, 1000, 0.1),
  504. disableDepthTestDistance: Number.POSITIVE_INFINITY, // 关闭深度检测,使billboard不至于被裁剪
  505. },
  506. });
  507. camera.stopFlyCircle(); // 先停止之前的旋转,再开始新的旋转
  508. camera.flyCircle(this.flyCirclePoint);
  509. flyCircleDrawHandler.clear();
  510. });
  511. }
  512. flyCircleDrawHandler.activate();
  513. },
  514. onCancelSpinClk() {
  515. this.isDestroyFlag = true;
  516. camera.stopFlyCircle();
  517. viewer.entities.removeById("fly-circle-point");
  518. this.flyCirclePoint = null;
  519. },
  520. // 功能切换
  521. changleIconItem(item) {
  522. this.state.itemOptions.map((itemObj) => {
  523. if (itemObj.index == item.index) {
  524. itemObj.isSelect = true;
  525. } else {
  526. itemObj.isSelect = false;
  527. }
  528. });
  529. switch (item.index) {
  530. case 1: {
  531. this.addStop();
  532. break;
  533. }
  534. case 2: {
  535. this.deleteStop();
  536. break;
  537. }
  538. case 3: {
  539. this.restStops();
  540. break;
  541. }
  542. case 4: {
  543. this.saveStop();
  544. break;
  545. }
  546. default:
  547. break;
  548. }
  549. },
  550. // 添加站点
  551. addStop() {
  552. if (flyManager) {
  553. flyManager.stop();
  554. }
  555. let point = viewer.camera.position;
  556. let position = tool.CartesiantoDegrees(point);
  557. let stop = {
  558. stopName: this.state.setStopName,
  559. index: this.state.addCurrentStopIndex,
  560. point: position,
  561. heading: viewer.camera.heading,
  562. tilt: viewer.camera.pitch,
  563. speed: this.state.setStopSpeed,
  564. stopPlayMode: this.state.stopPlayMode,
  565. surroundDuration: this.state.surroundDuration,
  566. waitTime: this.state.waitTime,
  567. };
  568. this.state.routeStops.push(stop);
  569. if (this.state.isSaveAutoFlag) {
  570. this.saveStop(); // 一旦添加站点,立即保存
  571. }
  572. let routeLen = this.state.routeStops.length;
  573. if (routeLen > 0)
  574. this.state.addCurrentStopIndex =
  575. this.state.routeStops[routeLen - 1].index + 1; // 保证新增的站点index始终比前一位大1
  576. this.$message.success(`${"站点添加成功"}: ${this.state.setStopName}`);
  577. if (this.state.routeStops.length > 0) {
  578. let len = this.state.routeStops.length;
  579. let lastStopName = this.state.routeStops[len - 1].stopName;
  580. let index = lastStopName.split("-")[1] || 1;
  581. let name = "Stop-" + (Number(index) + 1);
  582. this.state.setStopName = name;
  583. }
  584. this.state.selectedAddedStopIndex =
  585. this.state.routeStops[this.state.routeStops.length - 1].index;
  586. },
  587. // 清除选中站点
  588. deleteStop() {
  589. let delIndex = this.state.routeStops.findIndex(
  590. (e) => e.index == this.state.selectedAddedStopIndex
  591. );
  592. this.state.routeStops.splice(delIndex, 1);
  593. if (this.state.routeStops.length > 1 && this.state.isSaveAutoFlag) {
  594. this.saveStop(); // 一旦删除站点,实时保存
  595. }
  596. if (this.state.routeStops.length > 0) {
  597. this.state.selectedAddedStopIndex =
  598. this.state.routeStops[this.state.routeStops.length - 1].index;
  599. return;
  600. }
  601. this.state.selectedAddedStopIndex = undefined;
  602. this.state.setStopName = "Stop-1";
  603. },
  604. // 重置当前路线
  605. restStops() {
  606. let route = flyManager.currentRoute;
  607. if (route) {
  608. route.isLineVisible = false;
  609. route.isStopVisible = false;
  610. }
  611. this.state.setStopName = "Stop-1";
  612. this.state.routeStops = [];
  613. this.state.addCurrentStopIndex = 0;
  614. this.state.selectedAddedStopIndex = 0;
  615. // this.state.routeStops.length = 0;
  616. // this.state.setStopSpeed = 0;
  617. // this.state.stopPlayMode = "StopPause";
  618. // this.state.waitTime = 0;
  619. // this.state.surroundDuration = 1;
  620. },
  621. // 保存站点
  622. saveStop() {
  623. console.log(5, this.state.routeStops);
  624. if (this.state.routeStops.length < 2) {
  625. if (this.state.customRouteNames.length == 0) {
  626. this.$message.waring("至少两个节点才能保存");
  627. console.log(1111);
  628. }
  629. return;
  630. }
  631. // 飞行路线配置
  632. let route = {
  633. routeName: "飞行路线-1",
  634. index: this.state.addCurrentRouteIndex,
  635. speed: this.state.routeSpeed,
  636. isAlongLine: "False",
  637. routeStops: this.state.routeStops,
  638. };
  639. let xml = createXml.createXMLflyLine(route);
  640. flyLineXmls[0] = xml;
  641. this.state.isSaveAutoFlag = true; //一旦点击保存,开启实时自动保存
  642. // 保证只有一条飞行路线
  643. if (this.state.customRouteNames.length === 0) {
  644. this.state.customRouteNames.push({
  645. label: route.routeName,
  646. value: route.index,
  647. });
  648. }
  649. this.updateRouteCollection();
  650. this.state.addCurrentRouteIndex++;
  651. if (this.state.customRouteSelectedIndex === null)
  652. this.state.customRouteSelectedIndex = 0;
  653. },
  654. // 更新飞行路径
  655. updateRouteCollection() {
  656. flyManager && flyManager.stop();
  657. let route = flyManager.currentRoute;
  658. if (route) route.clear(); //清除之前的
  659. routeCollection = new Cesium.RouteCollection(viewer.entities); //飞行路线底层默认第一条路线,所以重新new
  660. routeCollection.fromXML(flyLineXmls[0]); // 默认飞行路径只有一条
  661. this.readyPromise();
  662. },
  663. // 异步飞行管理准备就绪函数
  664. readyPromise() {
  665. routeCollection.readyPromise.then(() => {
  666. flyManager.routes = routeCollection;
  667. let route = flyManager.currentRoute;
  668. route.isLineVisible = this.state.showRoute;
  669. route.isStopVisible = this.state.showStop;
  670. this.updateCurrentStops();
  671. });
  672. },
  673. // 更新当前路线站点
  674. updateCurrentStops() {
  675. this.state.currentStopNames.length = 0;
  676. currentStops = flyManager.getAllRouteStops();
  677. this.state.currentStopNamesIndex = 0;
  678. for (let i = 0, j = currentStops.length; i < j; i++) {
  679. let stopName = currentStops[i].stopName || "Stop" + (i + 1);
  680. this.state.currentStopNames.push({
  681. label: stopName,
  682. value: this.state.currentStopNamesIndex,
  683. });
  684. this.state.currentStopNamesIndex++;
  685. }
  686. },
  687. //初始化飞行管理
  688. initFlyManager() {
  689. routeCollection = new Cesium.RouteCollection(viewer.entities);
  690. flyManager = new Cesium.FlyManager({
  691. scene: viewer.scene,
  692. routes: routeCollection,
  693. });
  694. createXml = new createFlyLine_xml();
  695. },
  696. // 操作切换
  697. changleIconItemAction(item) {
  698. this.state.actionOptions.map((itemObj) => {
  699. if (itemObj.index == item.index) {
  700. itemObj.isSelect = true;
  701. } else {
  702. itemObj.isSelect = false;
  703. }
  704. });
  705. switch (item.index) {
  706. case 1: {
  707. this.flyStart(); //开始
  708. break;
  709. }
  710. case 2: {
  711. this.flyPause(); //暂停
  712. break;
  713. }
  714. case 3: {
  715. this.flyStop(); //停止
  716. break;
  717. }
  718. default:
  719. break;
  720. }
  721. },
  722. // 下载选择的飞行路线fpf文件
  723. downLoad() {
  724. let data = flyLineXmls[this.state.customRouteSelectedIndex];
  725. if (!data) return;
  726. let blob = new Blob([data]); //将返回的数据包装成blob(方法的具体使用参考mdn)
  727. let alink = document.createElement("a");
  728. alink.download = "fly-route.fpf"; //文件名,大部分浏览器兼容,IE10及以下不兼容
  729. alink.href = URL.createObjectURL(blob); //根据blob 创建 url
  730. alink.click(); //自动点击
  731. },
  732. // 清除选中飞行路线
  733. clearRoute() {
  734. flyManager.stop();
  735. if (flyLineXmls.length < 1) return;
  736. flyLineXmls.splice(this.state.customRouteSelectedIndex, 1);
  737. this.state.customRouteNames.splice(
  738. this.state.customRouteSelectedIndex,
  739. 1
  740. );
  741. if (flyLineXmls.length > 0) {
  742. this.state.customRouteSelectedIndex = 0;
  743. return;
  744. }
  745. this.state.customRouteSelectedIndex = null;
  746. this.state.currentStopNames.length = 0;
  747. let route = flyManager.currentRoute;
  748. if (route) route.clear(); //清除之前的
  749. this.state.routeStops = [];
  750. this.state.setStopName = "Stop-1";
  751. this.state.isSaveAutoFlag = false;
  752. this.state.selectedAddedStopIndex = undefined;
  753. this.state.addCurrentStopIndex = 0;
  754. },
  755. },
  756. watch: {
  757. cameraShow: function (val) {
  758. if (val) {
  759. this.init();
  760. }
  761. },
  762. stopSelected(val) {
  763. //各个站点事件
  764. flyManager && flyManager.pause();
  765. let index = Number(val);
  766. let route = flyManager.currentRoute;
  767. let stop = route.get(index);
  768. flyManager.currentStopIndex = index;
  769. flyManager.viewToStop(stop);
  770. },
  771. stopFlyCircle(val) {
  772. if (val) {
  773. camera.stopFlyCircle();
  774. } else {
  775. if (this.flyCirclePoint) {
  776. camera.flyCircle(this.flyCirclePoint);
  777. }
  778. }
  779. },
  780. circulation(val) {
  781. camera.flyCircleLoop = val;
  782. },
  783. speed(val) {
  784. camera.speedRatio = Number(val);
  785. },
  786. underground(val) {
  787. viewer.scene.undergroundMode = val;
  788. if (val) {
  789. viewer.scene.screenSpaceCameraController.minimumZoomDistance = Number(
  790. this.cameraMinimumZoomDistance
  791. );
  792. } else {
  793. viewer.scene.screenSpaceCameraController.minimumZoomDistance = 1;
  794. }
  795. },
  796. cameraMinimumZoomDistance(val) {
  797. viewer.scene.screenSpaceCameraController.minimumZoomDistance =
  798. Number(val);
  799. },
  800. SurfaceTransparency(val) {
  801. viewer.scene.globe.globeAlpha = parseFloat(val);
  802. },
  803. showRoute(val) {
  804. let route = flyManager.currentRoute;
  805. if (route) route.isLineVisible = val;
  806. },
  807. showStop(val) {
  808. let route = flyManager.currentRoute;
  809. if (route) route.isStopVisible = val;
  810. },
  811. },
  812. };
  813. </script>
  814. <style lang="scss" scoped>
  815. @import "camera";
  816. </style>