airline.js 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776
  1. import * as mars3d from "@/static/lib/mars3d/mars3d.js"
  2. import * as Cesium from "@/static/lib/Cesium/Cesium.js"
  3. import * as turf from '@turf/turf'
  4. import getMapJson from "@/utils/mapjson";
  5. let refId
  6. let maps, smallMap
  7. let graphicLayer
  8. let uav //飞行器
  9. let position
  10. let lineToGroundLayer
  11. let lineGraphic //连接地面的线
  12. let wayPointList = [] // 航点数组
  13. let waylinePositions = [] //需要连线的坐标111
  14. let line //航线
  15. let groundLineList = []
  16. let polygon, graphic
  17. let isEdit = false
  18. let isIngraphic = false
  19. let targetPoint = null
  20. let targetHeight = null
  21. let isleft = false
  22. let boundgraphic = null
  23. let workLayer
  24. let clockTimer = null
  25. function getActionParam(type, params) {
  26. // console.log(type, params,4444)
  27. let actionType = {
  28. orientedShoot: {
  29. type: 'orientedShoot',
  30. name: '定向拍照',
  31. actionTriggerType: 'reachPoint',
  32. svg: 'takePhoto',
  33. actionUUID: params['wpml:actionUUID'],
  34. fileType: params['wpml:payloadLensIndex'] == 'visable,ir' ? 3 : params['wpml:payloadLensIndex'] == 'visable' ? 1 : 2
  35. },
  36. startRecord: {
  37. type: 'startRecord',
  38. name: '开始录像',
  39. actionTriggerType: 'reachPoint',
  40. svg: 'startRecord',
  41. actionUUID: params['wpml:actionUUID'],
  42. fileType: params['wpml:payloadLensIndex'] == 'visable,ir' ? 3 : params['wpml:payloadLensIndex'] == 'visable' ? 1 : 2
  43. },
  44. stopRecord: {
  45. type: 'stopRecord',
  46. name: '停止录像',
  47. actionTriggerType: 'reachPoint',
  48. svg: 'stopRecord',
  49. actionUUID: params['wpml:actionUUID']
  50. },
  51. hover: {
  52. type: 'hover',
  53. name: '悬停',
  54. actionTriggerType: 'reachPoint',
  55. svg: 'hover',
  56. time: type == 'hover' ? params['wpml:hoverTime'] : '',
  57. actionUUID: params['wpml:actionUUID']
  58. },
  59. rotateYaw: {
  60. type: 'rotateYaw',
  61. name: '飞行器偏航角',
  62. actionTriggerType: 'reachPoint',
  63. svg: 'rotateYaw',
  64. uavRotate: type == 'rotateYaw' ? params['wpml:aircraftHeading'] : '',
  65. actionUUID: params['wpml:actionUUID']
  66. },
  67. gimbalRotate: {
  68. type: 'gimbalRotate',
  69. name: '云台俯仰角',
  70. actionTriggerType: 'reachPoint',
  71. svg: 'gimbalRotate',
  72. gimbalRotate: type == 'gimbalRotate' ? params['wpml:gimbalPitchRotateAngle'] : '',
  73. actionUUID: params['wpml:actionUUID']
  74. },
  75. zoom: {
  76. type: 'gimbalRotate',
  77. name: '变焦',
  78. actionTriggerType: 'zoom',
  79. svg: 'gimbalRotate',
  80. actionUUID: params['wpml:actionUUID']
  81. },
  82. takePhoto: {
  83. type: 'gimbalRotate',
  84. name: '变焦',
  85. actionTriggerType: 'zoom',
  86. svg: 'gimbalRotate',
  87. actionUUID: params['wpml:actionUUID']
  88. },
  89. panoShot: {
  90. type: 'panoShot',
  91. name: '全景拍照',
  92. actionTriggerType: 'panoShot',
  93. svg: 'panoShot',
  94. actionUUID: params['wpml:actionUUID']
  95. },
  96. ai: {
  97. type: 'ai',
  98. name: 'ai',
  99. actionTriggerType: 'ai',
  100. svg: 'ai',
  101. actionUUID: params['wpml:actionUUID']
  102. },
  103. }
  104. return actionType[type]
  105. }
  106. export function initLineMap() {
  107. maps = new mars3d.Map("wayline-main-map", getMapJson());
  108. workLayer = new mars3d.layer.GraphicLayer()
  109. graphicLayer = new mars3d.layer.GraphicLayer()
  110. lineToGroundLayer = new mars3d.layer.GraphicLayer()
  111. maps.addLayer(graphicLayer)
  112. maps.addLayer(lineToGroundLayer)
  113. maps.addLayer(workLayer)
  114. // addWmts(token)
  115. return maps
  116. }
  117. export function clearAll() {
  118. maps ? maps.graphicLayer.clear() : ''
  119. graphicLayer = null
  120. }
  121. export function closeMap() {
  122. waylineStore.distance = null
  123. waylineStore.wayPointList = []
  124. waylineStore.wayPointNum = 0
  125. waylineStore.workTime = ''
  126. waylineStore.qinxie_result = null //重置倾斜摄影总数据
  127. maps ? maps.graphicLayer.clear() : ''
  128. if (waylineStore.currentEditWayline && waylineStore.currentEditWayline.wayLineId) {
  129. waylineStore.currentEditWayline.wayLineId = null;
  130. }
  131. waylineStore.polygonList = []
  132. graphicLayer = null
  133. waylinePositions = []
  134. groundLineList = []
  135. uav = null
  136. lineGraphic = null
  137. clearInterval(clockTimer)
  138. if (maps) {
  139. maps.destroy()
  140. maps = null
  141. lineToGroundLayer = null
  142. }
  143. if (smallMap) {
  144. smallMap.destroy()
  145. smallMap = null
  146. }
  147. }
  148. export function initSmallMap(data) {
  149. smallMap = new mars3d.Map("view-map", setSmallMapScene());
  150. if (data) {
  151. smallMap.setCameraView(data)
  152. }
  153. window.smallMap = smallMap
  154. // addWmts(token)
  155. }
  156. export function flyToPoint({ lng, lat, alt }) {
  157. smallMap.flyToPoint(new mars3d.LngLatPoint(lng, lat, alt), {
  158. radius: 2000,
  159. heading: 12,
  160. alt: 936,
  161. pitch: -32.8
  162. });
  163. }
  164. export function changeSmallView(data) {
  165. smallMap.setCameraView(data)
  166. }
  167. export function setSmallMapScene() {
  168. let json = {
  169. scene: {
  170. center: {
  171. lat: 27.62,
  172. lng: 111.59,
  173. alt: 1336414,
  174. heading: 0,
  175. pitch: -90
  176. },
  177. fxaa: true, // 不开启抗锯齿,可视域会闪烁
  178. globe: {
  179. depthTestAgainstTerrain: true // 不加无法投射到地形上
  180. },
  181. contextOptions: {
  182. webgl: {
  183. preserveDrawingBuffer: true // 截图是黑色时,需要将该项设置为true
  184. }
  185. },
  186. requestRenderMode: true,
  187. cameraController: {
  188. zoomFactor: 2, // 相机缩放速度的乘数
  189. }
  190. },
  191. control: {
  192. contextmenu: { hasDefault: false } // 右键菜单
  193. },
  194. terrain: {
  195. url: "//data.mars3d.cn/terrain",
  196. show: true,
  197. },
  198. basemaps: [{
  199. name: '天地图卫星',
  200. icon: 'img/basemaps/tdt_img.jpg',
  201. type: 'tdt',
  202. layer: 'img_d',
  203. key: ['938106e971ecf05ce7355a3af2a58099'],
  204. show: true
  205. },
  206. { type: "gaode", layer: "img_z", show: true, zIndex: 12 }
  207. ],
  208. }
  209. return json
  210. }
  211. // 设置起飞点
  212. export function addTakeoffPoint() {
  213. maps.setSceneOptions({
  214. center: {
  215. lat: waylineStore.center.lat,
  216. lng: waylineStore.center.lng,
  217. alt: 2000,
  218. heading: 12,
  219. pitch: -85
  220. }
  221. })
  222. const graphic = new mars3d.graphic.BillboardEntity({
  223. position: new mars3d.LngLatPoint(waylineStore.center.lng, waylineStore.center.lat, waylineStore.center.alt),
  224. style: {
  225. image: "/assets/wayline/airport.png",
  226. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  227. verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  228. width: 60,
  229. height: 60,
  230. clampToGround: true,
  231. visibleDepth: false,
  232. scaleByDistance: false,
  233. scale: 0.8,
  234. zIndex: 200,
  235. }
  236. })
  237. graphicLayer.addGraphic(graphic)
  238. waylinePositions.push(graphic)
  239. //记录起飞点
  240. waylineStore.takeoffPoint = graphic
  241. let takeoffPoint = mars3d.LngLatPoint.fromCartesian(
  242. waylineStore.takeoffPoint._position_draw
  243. ? waylineStore.takeoffPoint._position_draw
  244. : waylineStore.takeoffPoint._position
  245. );
  246. waylineStore.takeoffPointHeight = takeoffPoint._alt
  247. addUAV(graphic._position, ((uav) => {
  248. // // 罗盘旋转
  249. uav.on(mars3d.EventType.updateStyle, e => {
  250. waylineStore.heading = e.style.heading
  251. });
  252. }))
  253. }
  254. // 这里是添加面状航线
  255. export function addPolygonWayline() {
  256. maps.setSceneOptions({
  257. center: {
  258. lat: waylineStore.center.lat,
  259. lng: waylineStore.center.lng,
  260. alt: 2000,
  261. heading: 12,
  262. pitch: -85
  263. }
  264. })
  265. const graphic = new mars3d.graphic.BillboardEntity({
  266. position: new mars3d.LngLatPoint(waylineStore.center.lng, waylineStore.center.lat, waylineStore.center.alt),
  267. style: {
  268. image: "/assets/wayline/airport.png",
  269. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  270. verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  271. width: 60,
  272. height: 60,
  273. clampToGround: true,
  274. visibleDepth: false,
  275. scaleByDistance: false,
  276. scale: 0.8,
  277. zIndex: 200,
  278. }
  279. })
  280. graphicLayer.addGraphic(graphic)
  281. waylinePositions.push(graphic)
  282. //记录起飞点
  283. waylineStore.takeoffPoint = graphic
  284. let takeoffPoint = mars3d.LngLatPoint.fromCartesian(
  285. waylineStore.takeoffPoint._position_draw
  286. ? waylineStore.takeoffPoint._position_draw
  287. : waylineStore.takeoffPoint._position
  288. );
  289. waylineStore.takeoffPointHeight = takeoffPoint._alt
  290. // addStartHigeht(takeoffPoint)
  291. //编辑面状航线
  292. drawPolygon()
  293. }
  294. async function drawPolygon() {
  295. polygon = maps.graphicLayer.startDraw({
  296. type: "polygon",
  297. style: {
  298. color: "#4786ef",
  299. opacity: 0.5,
  300. outline: false,
  301. outlineWidth: 3,
  302. outlineColor: "#ffffff",
  303. clampToGround: true,
  304. visibleDepth: false,
  305. zIndex: 299,
  306. label: {
  307. background: true,
  308. verticalOrigin: Cesium.VerticalOrigin.TOP,
  309. backgroundColor: '#000000',
  310. backgroundOpacity: 0.7,
  311. backgroundPadding: 10,
  312. text: "",
  313. font_size: 14,
  314. color: "#ffffff",
  315. clampToGround: true,
  316. visibleDepth: false,
  317. }
  318. },
  319. })
  320. maps.graphicLayer.on(mars3d.EventType.drawCreated, function (event) {
  321. waylineStore.Obliquephoto.pointsArr = event.positions
  322. event.positions.forEach(i => {
  323. waylineStore.polygonList.push(mars3d.LngLatPoint.fromCartesian(i))
  324. })
  325. if (waylineStore.currentEditWayline.wayLineType == 2) {
  326. showPolygonWayline()
  327. } else {
  328. startEditObliquephotographyline()
  329. }
  330. })
  331. }
  332. function showPolygonWayline() {
  333. if (line) {
  334. line.remove()
  335. }
  336. let coordinates = []
  337. waylineStore.polygonList.forEach(i => {
  338. let a = `${i._lng},${i._lat},0`
  339. coordinates.push(a)
  340. })
  341. waylineStore.currentEditWayline.kmzJSON.Document.Folder.Placemark.Polygon.outerBoundaryIs.LinearRing.coordinates = coordinates.join(' ')
  342. let takeoffPoint = mars3d.LngLatPoint.fromCartesian(
  343. waylineStore.takeoffPoint._position_draw
  344. ? waylineStore.takeoffPoint._position_draw
  345. : waylineStore.takeoffPoint._position
  346. );
  347. waylineStore.currentEditWayline.kmzJSON.Document['wpml:missionConfig']['wpml:takeOffRefPoint'] =
  348. takeoffPoint._lat + "," + takeoffPoint._lng + "," + takeoffPoint._alt;
  349. waylineStore.currentEditWayline.kmzJSON.Document.Folder.Placemark['wpml:ellipsoidHeight'] = 80
  350. waylineStore.currentEditWayline.kmzJSON.Document.Folder.Placemark['wpml:height'] = 80
  351. let RESULT_MAP = generate2dwayline(waylineStore.currentEditWayline, "myMap")
  352. waylineStore.polygonResult = RESULT_MAP
  353. line = new mars3d.graphic.PolylinePrimitive({
  354. // asynchronous: false,
  355. positions: RESULT_MAP.PATH_ON_MAP,
  356. style: {
  357. width: 5,
  358. // color: "#0BD790",
  359. materialType: mars3d.MaterialType.LineFlow,
  360. materialOptions: {
  361. // color: "#0BD790",
  362. image: '/assets/wayline/line-interval2.png',
  363. repeat: new Cesium.Cartesian2(20, 1),
  364. speed: 1
  365. }
  366. }
  367. });
  368. if (!lineToGroundLayer) {
  369. lineToGroundLayer = new mars3d.layer.GraphicLayer();
  370. maps.addLayer(lineToGroundLayer);
  371. }
  372. lineToGroundLayer.addGraphic(line);
  373. }
  374. export function setPolygonWayline() {
  375. if (line) {
  376. line.remove()
  377. }
  378. let RESULT_MAP = generate2dwayline(waylineStore.currentEditWayline, "myMap")
  379. waylineStore.polygonResult = RESULT_MAP
  380. line = new mars3d.graphic.PolylinePrimitive({
  381. // asynchronous: false,
  382. positions: RESULT_MAP.PATH_ON_MAP,
  383. style: {
  384. width: 5,
  385. // color: "#0BD790",
  386. materialType: mars3d.MaterialType.LineFlow,
  387. materialOptions: {
  388. // color: "#0BD790",
  389. image: '/assets/wayline/line-interval2.png',
  390. repeat: new Cesium.Cartesian2(20, 1),
  391. speed: 1
  392. }
  393. }
  394. });
  395. if (!lineToGroundLayer) {
  396. lineToGroundLayer = new mars3d.layer.GraphicLayer();
  397. maps.addLayer(lineToGroundLayer);
  398. }
  399. lineToGroundLayer.addGraphic(line);
  400. }
  401. function addStartHigeht(takeoffPoint) {
  402. const graphic = new mars3d.graphic.LabelEntity({
  403. position: new mars3d.LngLatPoint(takeoffPoint._lng, takeoffPoint._lat, takeoffPoint.alt),
  404. style: {
  405. text: "高度" + takeoffPoint.alt,
  406. font_size: 46, // 字号放大一倍
  407. scale: 0.5, // scale传0.5
  408. font_family: "楷体",
  409. color: "#00ffff",
  410. outline: true,
  411. outlineColor: "#000000",
  412. outlineWidth: 2,
  413. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  414. verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  415. visibleDepth: false
  416. },
  417. })
  418. graphicLayer.addGraphic(graphic)
  419. }
  420. // 添加飞行器
  421. function addUAV(position, callback) {
  422. let copy = waylineStore.center
  423. let point = new mars3d.LngLatPoint(copy.lng, copy.lat, copy.alt);
  424. let point2 = new mars3d.LngLatPoint(copy.lng, copy.lat, 0);
  425. let height = 0
  426. mars3d.PointUtil.getSurfaceHeight(maps.scene, point).then(result => {
  427. height = result.height_original.toFixed(2) - result.height.toFixed(2);
  428. position = position
  429. let a = point2.toCartesian()
  430. //规定要初始默认 离地高度为120 则需要换算 120减去初始的离地高 这是差值 waylineStore.center.alt 是机巢初始的经纬度高 则初始经纬度高加上差值
  431. uav = new mars3d.graphic.ModelEntity({
  432. name: "警车",
  433. position: mars3d.PointUtil.addPositionsHeight(a, 120 - height + waylineStore.center.alt
  434. ),
  435. style: {
  436. url: "/assets/wayline/UAV.gltf",
  437. scale: 0.02,
  438. minimumPixelSize: 48,
  439. // minimumPixelSize: 1,
  440. heading: 0,
  441. pitch: 0,
  442. roll: 0,
  443. zIndex: 999,
  444. visibleDepth: false,
  445. },
  446. })
  447. graphicLayer.addGraphic(uav)
  448. waylineStore.UAVOptions = uav.options.position
  449. uav.flyTo({
  450. radius: 2000,
  451. heading: 12,
  452. alt: 936,
  453. pitch: -32.8
  454. });
  455. callback(uav)
  456. }
  457. );
  458. }
  459. export function updatePosition(keys) {
  460. if (refId) {
  461. window.cancelAnimationFrame(refId);
  462. }
  463. refId = window.requestAnimationFrame(() => {
  464. if (keys && keys.length > 0 && uav) {
  465. if (keys.indexOf('q') !== -1 || keys.indexOf('Q') !== -1) {
  466. let heading = uav.options.style.heading - 0.4;
  467. uav.setStyle({ heading: heading })
  468. }
  469. if (keys.indexOf('e') !== -1 || keys.indexOf('E') !== -1) {
  470. let heading = uav.options.style.heading + 0.4;
  471. uav.setStyle({ heading: heading })
  472. }
  473. if (keys.indexOf('w') !== -1 || keys.indexOf('W') !== -1) {
  474. let newPosition = mars3d.PointUtil.getPositionByDirectionAndLen(uav._position, uav.options.style.heading - 90, 1);
  475. uav.setOptions({ position: newPosition })
  476. position = newPosition;
  477. }
  478. if (keys.indexOf('s') !== -1 || keys.indexOf('S') !== -1) {
  479. let newPosition = mars3d.PointUtil.getPositionByDirectionAndLen(uav._position, uav.options.style.heading + 90, 1);
  480. uav.setOptions({ position: newPosition })
  481. position = newPosition;
  482. }
  483. if (keys.indexOf('a') !== -1 || keys.indexOf('A') !== -1) {
  484. let newPosition = mars3d.PointUtil.getPositionByDirectionAndLen(uav._position, uav.options.style.heading + 180, 1);
  485. uav.setOptions({ position: newPosition })
  486. position = newPosition;
  487. }
  488. if (keys.indexOf('d') !== -1 || keys.indexOf('D') !== -1) {
  489. let newPosition = mars3d.PointUtil.getPositionByDirectionAndLen(uav._position, uav.options.style.heading, 1);
  490. uav.setOptions({ position: newPosition })
  491. position = newPosition;
  492. }
  493. if (keys.indexOf('c') !== -1 || keys.indexOf('C') !== -1) {
  494. let newPosition = mars3d.PointUtil.addPositionsHeight(uav._position, 1);
  495. mars3d.PointUtil.getSurfaceHeight(maps.scene, mars3d.LngLatPoint.fromCartesian(newPosition)).then(result => {
  496. if (result.height_original.toFixed(2) - result.height.toFixed(2) > 150) {
  497. ElMessage({
  498. message: '已超出飞行高度',
  499. type: 'warning',
  500. plain: true,
  501. })
  502. return
  503. } else {
  504. uav.setOptions({ position: newPosition })
  505. position = newPosition;
  506. }
  507. })
  508. }
  509. if (keys.indexOf('z') !== -1 || keys.indexOf('Z') !== -1) {
  510. let newPosition = mars3d.PointUtil.addPositionsHeight(uav._position, -1);
  511. mars3d.PointUtil.getSurfaceHeight(maps.scene, mars3d.LngLatPoint.fromCartesian(newPosition)).then(result => {
  512. })
  513. uav.setOptions({ position: newPosition })
  514. position = newPosition;
  515. }
  516. updatePosition(keys);
  517. updateToGroundLine()
  518. waylineStore.UAVOptions = uav.options.position
  519. } else {
  520. window.cancelAnimationFrame(refId);
  521. }
  522. });
  523. }
  524. /**
  525. * @description 更新到地面的连接线
  526. *
  527. */
  528. function updateToGroundLine() {
  529. if (!lineGraphic) {
  530. lineToGroundLayer = new mars3d.layer.GraphicLayer();
  531. maps.addLayer(lineToGroundLayer);
  532. // let lonlatheight = GISUtils.cartesian3ToLonLatAlt(this.viewer, this.position);
  533. let p = mars3d.LngLatPoint.fromCartesian(uav != undefined ? uav._position : [])
  534. let a = [p._lng, p._lat, 0]
  535. lineGraphic = new mars3d.graphic.PolylinePrimitive({
  536. asynchronous: false,
  537. positions: [
  538. a,
  539. mars3d.PointUtil.addPositionsHeight(
  540. uav != undefined ? uav._position : [],
  541. )
  542. ],
  543. style: {
  544. width: 1,
  545. color: '#FFFF00',
  546. zIndex: 1,
  547. materialType: mars3d.MaterialType.PolylineDash, // 虚线
  548. materialOptions: {
  549. color: '#FFFF00',
  550. dashLength: 6
  551. }
  552. }
  553. });
  554. lineToGroundLayer.addGraphic(lineGraphic);
  555. } else {
  556. let newPosition = mars3d.LngLatPoint.fromCartesian(uav != undefined ? uav._position : []);
  557. let a = [newPosition._lng, newPosition._lat, 0]
  558. lineGraphic.setOptions({
  559. positions: [a, mars3d.PointUtil.addPositionsHeight(
  560. uav ? uav._position : [],
  561. )]
  562. })
  563. }
  564. }
  565. //鼠标双击添加航点
  566. export function dbClickAddWaypoint(data) {
  567. if (!lineToGroundLayer) {
  568. lineToGroundLayer = new mars3d.layer.GraphicLayer();
  569. maps.addLayer(lineToGroundLayer);
  570. }
  571. let point = mars3d.LngLatPoint.fromCartesian(data)
  572. let position = [point._lng, point._lat, uav._point._alt]
  573. const wayPoint = new mars3d.graphic.BillboardEntity({
  574. position: position,
  575. asynchronous: false,
  576. style: {
  577. image: '/assets/wayline/waypoint-active.png',
  578. // image: "img/wayline/dock.png",
  579. // image: dockImg,
  580. scale: 0.6,
  581. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  582. verticalOrigin: Cesium.VerticalOrigin.CENTER,
  583. pixelOffset: [0, -16],
  584. highlight: {
  585. image: '/assets/wayline/waypoint-active.png'
  586. },
  587. // 新建航点字体设置
  588. label: {
  589. text: waylineStore.wayPointList.length > 0 ? waylineStore.wayPointList.length + 1 : 1,
  590. font_family: '微软雅黑',
  591. font_size: 16,
  592. color: '#FFFFFF',
  593. visibleDepth: false,
  594. pixelOffset: [0, -22]
  595. },
  596. zIndex: 201
  597. },
  598. attr: []
  599. })
  600. // 这块是判断航点是否与当前航线重合
  601. let checkLine = []
  602. let heightArr = []
  603. let ischeck = false;
  604. let isHeightHave = false
  605. let isPointOnCurPoints = false
  606. let points = [wayPoint._point._lng, wayPoint._point._lat]
  607. waylineStore.wayPointList.forEach(i => {
  608. let point = [i._point._lng, i._point._lat]
  609. checkLine.push(point)
  610. heightArr.push(i._point._alt)
  611. if (Math.abs(point[0] - points[0]) < 0.00001) {
  612. ischeck = true
  613. }
  614. })
  615. if (ischeck) {
  616. ElMessage({
  617. message: '飞机处于航点上,无法新增航点',
  618. type: 'warning',
  619. plain: true,
  620. })
  621. return
  622. }
  623. heightArr.forEach(i => {
  624. if (i == wayPoint._point._alt) {
  625. isHeightHave = true
  626. }
  627. })
  628. if (waylineStore.wayPointList.length >= 2) {
  629. isPointOnCurPoints = turf.booleanPointOnLine(turf.point(points), turf.lineString(checkLine))
  630. } else if (waylineStore.wayPointList.length == 1) {
  631. let point1 = turf.point([waylineStore.wayPointList[0]._point._lng, waylineStore.wayPointList[0]._point._lat])
  632. let point2 = turf.point(points)
  633. isPointOnCurPoints = turf.booleanEqual(point1, point2)
  634. }
  635. if (isPointOnCurPoints && isHeightHave) {
  636. ElMessage({
  637. message: '飞机处于航点上,无法新增航点',
  638. type: 'warning',
  639. plain: true,
  640. })
  641. return
  642. }
  643. // wayPointList.push(wayPoint)
  644. waylineStore.wayPointList.push(wayPoint)
  645. waylineStore.wayPoint = wayPoint
  646. waylineStore.wayPointNum = waylineStore.wayPointList.length
  647. graphicLayer.addGraphic(wayPoint)
  648. // waylinePositions.push(uav._position)
  649. updataWayPointStyle()
  650. lineWaypoint()
  651. wayPoint.on(mars3d.EventType.mouseOver, function (e) {
  652. isIngraphic = true
  653. targetPoint = e.graphic
  654. targetHeight = e.graphic._point._alt
  655. })
  656. wayPoint.on(mars3d.EventType.mouseOut, function (e) {
  657. isIngraphic = false
  658. targetPoint = null
  659. waylineStore.wayPoint = e.graphic
  660. chooseWayPoint(e.id)
  661. })
  662. }
  663. //添加航点
  664. export function addWaypoint() {
  665. if (!lineToGroundLayer) {
  666. lineToGroundLayer = new mars3d.layer.GraphicLayer();
  667. maps.addLayer(lineToGroundLayer);
  668. }
  669. let point = mars3d.LngLatPoint.fromCartesian(uav._position)
  670. let position = [point._lng, point._lat, point._alt]
  671. const wayPoint = new mars3d.graphic.BillboardEntity({
  672. position: position,
  673. asynchronous: false,
  674. style: {
  675. image: '/assets/wayline/waypoint-active.png',
  676. // image: "img/wayline/dock.png",
  677. // image: dockImg,
  678. scale: 0.6,
  679. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  680. verticalOrigin: Cesium.VerticalOrigin.CENTER,
  681. visibleDepth: true,
  682. pixelOffset: [0, -16],
  683. highlight: {
  684. image: '/assets/wayline/waypoint-active.png'
  685. },
  686. // 新建航点字体设置
  687. label: {
  688. text: waylineStore.wayPointList.length > 0 ? waylineStore.wayPointList.length + 1 : 1,
  689. font_family: '微软雅黑',
  690. font_size: 20,
  691. color: '#FFFFFF',
  692. visibleDepth: false,
  693. pixelOffset: [0, -22]
  694. },
  695. zIndex: 201
  696. },
  697. attr: []
  698. })
  699. wayPoint.on(mars3d.EventType.click, (e) => {
  700. waylineStore.wayPoint = e.graphic
  701. chooseWayPoint(e.id)
  702. })
  703. // wayPointList.push(wayPoint)
  704. // 这块是判断航点是否与当前航线重合
  705. let checkLine = []
  706. let heightArr = []
  707. waylineStore.wayPointList.forEach(i => {
  708. let point = [i._point._lng, i._point._lat]
  709. checkLine.push(point)
  710. heightArr.push(i._point._alt)
  711. })
  712. let points = [wayPoint._point._lng, wayPoint._point._lat]
  713. let isPointOnCurPoints = false;
  714. let isHeightHave = false
  715. heightArr.forEach(i => {
  716. if (i == wayPoint._point._alt) {
  717. isHeightHave = true
  718. }
  719. })
  720. if (waylineStore.wayPointList.length >= 2) {
  721. isPointOnCurPoints = turf.booleanPointOnLine(turf.point(points), turf.lineString(checkLine))
  722. } else if (waylineStore.wayPointList.length == 1) {
  723. let point1 = turf.point([waylineStore.wayPointList[0]._point._lng, waylineStore.wayPointList[0]._point._lat])
  724. let point2 = turf.point(points)
  725. isPointOnCurPoints = turf.booleanEqual(point1, point2)
  726. }
  727. if (isPointOnCurPoints && isHeightHave) {
  728. ElMessage({
  729. message: '飞机处于航点上,无法新增航点',
  730. type: 'warning',
  731. plain: true,
  732. })
  733. return
  734. }
  735. waylineStore.wayPointList.push(wayPoint)
  736. waylineStore.wayPoint = wayPoint
  737. waylineStore.wayPointNum = waylineStore.wayPointList.length
  738. graphicLayer.addGraphic(wayPoint)
  739. updataWayPointStyle()
  740. lineWaypoint()
  741. wayPoint.on(mars3d.EventType.mouseOver, function (e) {
  742. isIngraphic = true
  743. targetPoint = e.graphic
  744. targetHeight = e.graphic._point._alt
  745. })
  746. wayPoint.on(mars3d.EventType.mouseOut, function (e) {
  747. isIngraphic = false
  748. targetPoint = null
  749. waylineStore.wayPoint = e.graphic
  750. chooseWayPoint(e.id)
  751. })
  752. }
  753. export function deleteWayPoint(id) {
  754. waylineStore.wayPointNum--
  755. waylineStore.wayPointList.forEach((i, index) => {
  756. if (i.id == id) {
  757. graphicLayer.getGraphicById(id).remove()
  758. waylineStore.wayPointList.splice(index, 1);
  759. lineWaypoint()
  760. updataWayPointStyle()
  761. }
  762. })
  763. // waylineStore.wayPointNum = waylineStore.wayPointList.length 11
  764. }
  765. export function chooseWayPoint(id) {
  766. waylineStore.wayPointList.forEach((i, index) => {
  767. if (i.id == id) {
  768. i.setStyle({ image: '/assets/wayline/waypoint-active.png' })
  769. eventBus.emit('changeIndex', index)
  770. } else {
  771. i.setStyle({ image: '/assets/wayline/waypoint.png' })
  772. }
  773. })
  774. }
  775. // 更新航点的状态
  776. function updataWayPointStyle() {
  777. waylineStore.wayPointList.forEach((i, index) => {
  778. if (index < waylineStore.wayPointList.length - 1) {
  779. i.setStyle({ image: '/assets/wayline/waypoint.png', label: { text: index + 1 } })
  780. } else {
  781. i.setStyle({ image: '/assets/wayline/waypoint-active.png', label: { text: index + 1 } })
  782. }
  783. })
  784. }
  785. // 把航点给连接起来 1航线!!
  786. function lineWaypoint() {
  787. if (line) {
  788. line.remove()
  789. }
  790. if (!lineToGroundLayer) {
  791. lineToGroundLayer = new mars3d.layer.GraphicLayer();
  792. maps.addLayer(lineToGroundLayer);
  793. }
  794. let positions = []
  795. let waylineList = [...waylinePositions, ...waylineStore.wayPointList]
  796. waylineList.forEach(i => {
  797. let newPosition = mars3d.LngLatPoint.fromCartesian(i.position);
  798. let a = [newPosition._lng, newPosition._lat, newPosition._alt]
  799. positions.push(a)
  800. })
  801. line = new mars3d.graphic.PolylinePrimitive({
  802. asynchronous: false,
  803. positions: positions,
  804. style: {
  805. width: 5,
  806. // color: "#0BD790",
  807. materialType: mars3d.MaterialType.LineFlow,
  808. visibleDepth: false,
  809. materialOptions: {
  810. // color: "#0BD790",
  811. image: '/assets/wayline/line-interval2.png',
  812. repeat: new Cesium.Cartesian2(20, 1),
  813. speed: 1
  814. }
  815. }
  816. });
  817. waylineStore.distance = mars3d.MeasureUtil.formatDistance(line.distance)
  818. // 计算首尾距离 添加总航程
  819. let start = positions[0]
  820. let end = positions[positions.length - 1]
  821. start[2] = 66
  822. end[2] = 66
  823. let backLinePosition = [start, end]
  824. let backLine
  825. backLine = new mars3d.graphic.PolylinePrimitive({
  826. asynchronous: false,
  827. positions: backLinePosition,
  828. style: {
  829. width: 5,
  830. // color: "#0BD790",
  831. materialType: mars3d.MaterialType.LineFlow,
  832. materialOptions: {
  833. // color: "#0BD790",
  834. image: '/assets/wayline/line-interval2.png',
  835. repeat: new Cesium.Cartesian2(20, 1),
  836. speed: 1
  837. }
  838. }
  839. });
  840. // 因为是直线返回 不计算高度问题 直接把首尾高度设为一致 随意值 只要一致就行
  841. waylineStore.backDistance = mars3d.MeasureUtil.formatDistance(backLine.distance)
  842. let time;
  843. let distance;
  844. let backDistance;
  845. if (waylineStore.currentEditWayline.wayLineType == 1) {
  846. distance = waylineStore.distance;
  847. backDistance = waylineStore.backDistance;
  848. if (distance.includes("米")) {
  849. distance = Number(waylineStore.distance.split("米")[0]);
  850. } else if (distance.includes("公里")) {
  851. distance = Number(waylineStore.distance.split("公里")[0]) * 1000;
  852. }
  853. if (backDistance.includes("米")) {
  854. backDistance = Number(waylineStore.backDistance.split("米")[0]);
  855. } else if (backDistance.includes("公里")) {
  856. backDistance = Number(waylineStore.backDistance.split("公里")[0]) * 1000;
  857. }
  858. time = Math.ceil((distance + backDistance) / waylineStore.speed);
  859. waylineStore.workTime = time;
  860. } else if (waylineStore.currentEditWayline.wayLineType == 2) {
  861. distance = Number(waylineStore.polygonResult.COMMON_INFO.waylineLength);
  862. waylineStore.speed =
  863. waylineStore.polygonResult.KMZ_INFO.wayline.Document.Folder[
  864. "wpml:autoFlightSpeed"
  865. ];
  866. time = Math.ceil(distance / waylineStore.speed);
  867. }
  868. lineToGroundLayer.addGraphic(line);
  869. ToGroundLine()
  870. }
  871. // 画线
  872. export function drawLine(positions) {
  873. // if (line) {
  874. // line.remove()
  875. // }
  876. console.log('lineToGroundLayer', lineToGroundLayer)
  877. if (!lineToGroundLayer) {
  878. lineToGroundLayer = new mars3d.layer.GraphicLayer();
  879. smallMap.addLayer(lineToGroundLayer);
  880. }
  881. line = new mars3d.graphic.PolylinePrimitive({
  882. // asynchronous: false,
  883. positions: positions,
  884. style: {
  885. width: 5,
  886. // color: "#0BD790",
  887. materialType: mars3d.MaterialType.LineFlow,
  888. materialOptions: {
  889. // color: "#0BD790",
  890. image: '/assets/wayline/line-interval2.png',
  891. repeat: new Cesium.Cartesian2(20, 1),
  892. speed: 1
  893. }
  894. }
  895. });
  896. lineToGroundLayer.addGraphic(line);
  897. return line
  898. }
  899. // 为每个航点添加连接地面的线
  900. function ToGroundLine() {
  901. if (groundLineList.length) {
  902. groundLineList.forEach(i => {
  903. i.remove()
  904. })
  905. }
  906. waylineStore.wayPointList.forEach((i, index) => {
  907. let middel = JSON.parse(JSON.stringify(i._point))
  908. let p = new mars3d.LngLatPoint(middel._lng, middel._lat, middel._alt)
  909. let height = 0
  910. mars3d.PointUtil.getSurfaceHeight(maps.scene, p).then(result => {
  911. height = (result.height_original.toFixed(2) - result.height.toFixed(2)).toFixed(2)
  912. let a = [p._lng, p._lat, 0]
  913. let constpoSition
  914. if (i.position.z) {
  915. constpoSition = i.position
  916. } else {
  917. constpoSition = i._position_draw
  918. }
  919. let groundLine = new mars3d.graphic.PolylinePrimitive({
  920. asynchronous: false,
  921. positions: [
  922. a,
  923. mars3d.PointUtil.addPositionsHeight(
  924. constpoSition,
  925. )
  926. ],
  927. style: {
  928. width: 1,
  929. color: '#FFFFFF',
  930. zIndex: 1,
  931. materialType: mars3d.MaterialType.PolylineDash, // 虚线111
  932. materialOptions: {
  933. color: '#FFFFFF',
  934. dashLength: 6
  935. },
  936. label: {
  937. text: `高度:${height}`,
  938. font_size: 18,
  939. color: "#ffffff",
  940. distanceDisplayCondition: true,
  941. distanceDisplayCondition_far: 500000,
  942. distanceDisplayCondition_near: 0,
  943. clampToGround: true,
  944. visibleDepth: false,
  945. }
  946. },
  947. });
  948. lineToGroundLayer.addGraphic(groundLine);
  949. groundLineList.push(groundLine)
  950. })
  951. })
  952. }
  953. export function showTheWayline() {
  954. let wayline = waylineStore.currentEditWayline.kmzJSON.Document
  955. // 先获取 起飞点的信息
  956. let takeoff = wayline['wpml:missionConfig']['wpml:takeOffRefPoint'].split(',')
  957. setTakeOffPoint(takeoff, wayline.Folder.Placemark)
  958. // 2. 获取航点的信息
  959. setWaylinePoint(wayline.Folder.Placemark, takeoff)
  960. }
  961. function setTakeOffPoint(takeoff, mark) {
  962. const graphic = new mars3d.graphic.BillboardEntity({
  963. position: new mars3d.LngLatPoint(takeoff[1], takeoff[0], takeoff[2]),
  964. style: {
  965. image: "/assets/wayline/airport.png",
  966. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  967. verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  968. clampToGround: true,
  969. visibleDepth: true,
  970. scaleByDistance: false,
  971. zIndex: 200,
  972. highlight: {
  973. image: "/assets/wayline/airport.png",
  974. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  975. verticalOrigin: Cesium.VerticalOrigin.CENTER
  976. },
  977. }
  978. })
  979. graphicLayer.addGraphic(graphic)
  980. // waylinePositions.push(graphic)
  981. waylinePositions.push(graphic)
  982. // 需要的话再说1 反显的时候让飞行器和最后一个航点处于同一个位置
  983. // let lnglat= mark[mark.length-1].Point.coordinates.split(',')
  984. // let navPositin = [Number(lnglat[0]), Number(lnglat[1]), mark[mark.length-1]['wpml:executeHeight']]
  985. //记录起飞点
  986. waylineStore.takeoffPoint = graphic
  987. waylineStore.takeoffPointHeight = waylineStore.takeoffPoint._point._alt
  988. addUAV(graphic._position, ((uav) => {
  989. // // 罗盘旋转
  990. uav.on(mars3d.EventType.updateStyle, e => {
  991. waylineStore.heading = e.style.heading
  992. });
  993. }))
  994. graphic.flyTo({
  995. radius: 2000,
  996. heading: 12,
  997. alt: 936,
  998. pitch: -72.8
  999. });
  1000. }
  1001. // 设置 航点
  1002. function setWaylinePoint(arr, takeoff) {
  1003. if (!isArray(arr)) {
  1004. let ponitList = []
  1005. ponitList.push(arr)
  1006. arr = ponitList
  1007. }
  1008. lineToGroundLayer = new mars3d.layer.GraphicLayer();
  1009. maps.addLayer(lineToGroundLayer);
  1010. waylineStore.wayPointList = []
  1011. arr.forEach(i => {
  1012. let alt
  1013. let lnglat = i.Point.coordinates.split(',')
  1014. if (i['wpml:ellipsoidHeight']) {
  1015. alt = i['wpml:ellipsoidHeight'] + Number(takeoff[2])
  1016. } else {
  1017. alt = i['wpml:executeHeight'] + + Number(takeoff[2])
  1018. }
  1019. let position = [Number(lnglat[0]), Number(lnglat[1]), alt]
  1020. let index = i['wpml:index'] + 1
  1021. let wayPoint = new mars3d.graphic.BillboardEntity({
  1022. position: new mars3d.LngLatPoint(position[0], position[1], position[2]),
  1023. style: {
  1024. image: '/assets/wayline/waypoint.png',
  1025. // image: "img/wayline/dock.png",
  1026. // image: dockImg,
  1027. scale: 0.6,
  1028. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  1029. verticalOrigin: Cesium.VerticalOrigin.CENTER,
  1030. clampToGround: false,
  1031. visibleDepth: true,
  1032. scaleByDistance: false,
  1033. pixelOffset: [0, -16],
  1034. highlight: {
  1035. image: '/assets/wayline/waypoint-active.png'
  1036. },
  1037. // 新建航点字体设置
  1038. label: {
  1039. // text: '航点' + (this_.waylinePointLayer.length === 0 ? '1' : this_.waylinePointLayer.length + 1) + '高度:' + (Math.floor(position.altitude)),
  1040. // text: '航点' + (this_.waylinePointLayer.length === 0 ? '1' : this_.waylinePointLayer.length + 1),
  1041. text: index,
  1042. font_family: '微软雅黑',
  1043. font_size: 16,
  1044. color: '#FFFFFF',
  1045. visibleDepth: false,
  1046. pixelOffset: [0, -22]
  1047. },
  1048. zIndex: 201
  1049. },
  1050. })
  1051. wayPoint.on(mars3d.EventType.click, (e) => {
  1052. waylineStore.wayPoint = e.graphic
  1053. chooseWayPoint(e.id)
  1054. })
  1055. wayPoint.options.attr.actionList = []
  1056. if (i['wpml:actionGroup']) {
  1057. if (i['wpml:actionGroup']['wpml:action'] && !i['wpml:actionGroup']['wpml:action'].length) {
  1058. wayPoint.options.attr.actionList.push(getActionParam(i['wpml:actionGroup']['wpml:action']['wpml:actionActuatorFunc'], i['wpml:actionGroup']['wpml:action']['wpml:actionActuatorFuncParam']))
  1059. } else if (i['wpml:actionGroup']['wpml:action'].length) { //多个动作
  1060. i['wpml:actionGroup']['wpml:action'].forEach(j => {
  1061. wayPoint.options.attr.actionList.push(getActionParam(j['wpml:actionActuatorFunc'], j['wpml:actionActuatorFuncParam']))
  1062. })
  1063. }
  1064. }
  1065. waylineStore.wayPointList.push(wayPoint)
  1066. waylineStore.wayPoint = wayPoint
  1067. waylineStore.wayPointNum = waylineStore.wayPointList.length
  1068. graphicLayer.addGraphic(wayPoint)
  1069. updataWayPointStyle()
  1070. wayPoint.on(mars3d.EventType.mouseOver, function (e) {
  1071. isIngraphic = true
  1072. targetPoint = e.graphic
  1073. targetHeight = e.graphic._point._alt
  1074. })
  1075. wayPoint.on(mars3d.EventType.mouseOut, function (e) {
  1076. isIngraphic = false
  1077. targetPoint = null
  1078. waylineStore.wayPoint = e.graphic
  1079. chooseWayPoint(e.id)
  1080. })
  1081. })
  1082. lineWaypoint()
  1083. }
  1084. //反显面状航线
  1085. export function reverseShowPolygonWayline() {
  1086. let wayline = waylineStore.currentEditWayline.kmzJSON.Document
  1087. // 先获取 起飞点的信息
  1088. let takeoff = wayline['wpml:missionConfig']['wpml:takeOffRefPoint'].split(',')
  1089. setTakeOffPointPolygon(takeoff)
  1090. if (waylineStore.currentEditWayline.wayLineType == 2) {
  1091. showRectangle(wayline)
  1092. } else {
  1093. showObliquePolygon(wayline)
  1094. }
  1095. }
  1096. //反显倾斜摄影
  1097. function showObliquePolygon(wayline) {
  1098. let point = wayline.Folder.Placemark.Polygon.outerBoundaryIs.LinearRing.coordinates
  1099. let positions = []
  1100. let xyzArr = []
  1101. point.split(' ').forEach(i => {
  1102. let xyz = Cesium.Cartesian3.fromDegrees(i.split(',')[0], i.split(',')[1], i.split(',')[2])
  1103. positions.push([i.split(',')[0], i.split(',')[1], i.split(',')[2]])
  1104. xyzArr.push(xyz)
  1105. })
  1106. const graphic = new mars3d.graphic.PolygonEntity({
  1107. positions: positions,
  1108. style: {
  1109. color: "#3388ff",
  1110. opacity: 0.5,
  1111. outline: false,
  1112. clampToGround: true,
  1113. visibleDepth: true,
  1114. },
  1115. })
  1116. // let xyzString = wayline.Folder.Placemark['wpml:xyz']
  1117. // let xyzArr = []
  1118. // xyzString.split(' ').forEach(i => {
  1119. // let Cartesian = new Cesium.Cartesian3(Number(i.split(',')[0]) , Number(i.split(',')[1]), Number(i.split(',')[2]));
  1120. // xyzArr.push(Cartesian)
  1121. // })
  1122. waylineStore.Obliquephoto.pointsArr = xyzArr
  1123. waylineStore.Obliquephoto.height = wayline.Folder.Placemark['wpml:height']
  1124. waylineStore.Obliquephoto.lateralOverlapRate = wayline.Folder.Placemark['wpml:overlap']['wpml:orthoCameraOverlapW']
  1125. waylineStore.Obliquephoto.TiltLateralOverlapRate = wayline.Folder.Placemark['wpml:overlap']['wpml:inclinedCameraOverlapW']
  1126. waylineStore.Obliquephoto.mainCourseAngle = wayline.Folder.Placemark['wpml:direction']
  1127. maps.graphicLayer.addGraphic(graphic)
  1128. startEditObliquephotographyline()
  1129. }
  1130. function setTakeOffPointPolygon(takeoff) {
  1131. const graphic = new mars3d.graphic.BillboardEntity({
  1132. position: new mars3d.LngLatPoint(takeoff[1], takeoff[0], takeoff[2]),
  1133. style: {
  1134. image: "/assets/wayline/takeoff-active.png",
  1135. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  1136. verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  1137. clampToGround: true,
  1138. visibleDepth: true,
  1139. scaleByDistance: false,
  1140. zIndex: 200,
  1141. highlight: {
  1142. image: "/assets/wayline/takeoff-active.png",
  1143. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  1144. verticalOrigin: Cesium.VerticalOrigin.CENTER
  1145. },
  1146. }
  1147. })
  1148. graphicLayer.addGraphic(graphic)
  1149. // waylinePositions.push(graphic)
  1150. waylineStore.takeoffPoint = graphic
  1151. waylinePositions.push(graphic)
  1152. let takeoffPoint = mars3d.LngLatPoint.fromCartesian(
  1153. waylineStore.takeoffPoint._position_draw
  1154. ? waylineStore.takeoffPoint._position_draw
  1155. : waylineStore.takeoffPoint._position
  1156. );
  1157. waylineStore.Obliquephoto.startPoint = {
  1158. lng: takeoffPoint._lng,
  1159. lat: takeoffPoint._lat,
  1160. height: takeoffPoint._alt
  1161. }
  1162. graphic.flyTo({
  1163. radius: 2000,
  1164. heading: 12,
  1165. alt: 936,
  1166. pitch: -32.8
  1167. });
  1168. }
  1169. function showRectangle(wayline) {
  1170. let point = wayline.Folder.Placemark.Polygon.outerBoundaryIs.LinearRing.coordinates
  1171. let positions = []
  1172. point.split(' ').forEach(i => {
  1173. positions.push([i.split(',')[0], i.split(',')[1], i.split(',')[2]])
  1174. })
  1175. const graphic = new mars3d.graphic.PolygonEntity({
  1176. positions: positions,
  1177. style: {
  1178. color: "#3388ff",
  1179. opacity: 0.5,
  1180. outline: true,
  1181. clampToGround: true,
  1182. visibleDepth: true,
  1183. },
  1184. })
  1185. maps.graphicLayer.addGraphic(graphic)
  1186. bindLayerContextMenu()
  1187. let RESULT_MAP = generate2dwayline(waylineStore.currentEditWayline, "myMap")
  1188. waylineStore.distance = Number(RESULT_MAP.COMMON_INFO.waylineLength)
  1189. waylineStore.speed = RESULT_MAP.KMZ_INFO.wayline.Document.Folder["wpml:autoFlightSpeed"]
  1190. waylineStore.workTime = Math.ceil(waylineStore.distance / waylineStore.speed)
  1191. line = new mars3d.graphic.PolylinePrimitive({
  1192. // asynchronous: false,
  1193. positions: RESULT_MAP.PATH_ON_MAP,
  1194. style: {
  1195. width: 5,
  1196. // color: "#0BD790",
  1197. materialType: mars3d.MaterialType.LineFlow,
  1198. materialOptions: {
  1199. // color: "#0BD7901",
  1200. image: '/img/wayline/line-interval2.png',
  1201. repeat: new Cesium.Cartesian2(20, 1),
  1202. speed: 1
  1203. }
  1204. }
  1205. });
  1206. if (!lineToGroundLayer) {
  1207. lineToGroundLayer = new mars3d.layer.GraphicLayer();
  1208. maps.addLayer(lineToGroundLayer);
  1209. }
  1210. lineToGroundLayer.addGraphic(line);
  1211. }
  1212. export function clearWayline() {
  1213. waylineStore.wayPointList = []
  1214. waylineStore.wayPointNum = 0
  1215. graphicLayer ? graphicLayer.remove() : ''
  1216. lineToGroundLayer ? lineToGroundLayer.remove() : ''
  1217. graphicLayer = null
  1218. waylinePositions = []
  1219. groundLineList = []
  1220. uav = null
  1221. lineToGroundLayer = null
  1222. lineGraphic.remove()
  1223. }
  1224. // 绑定矢量对象编辑
  1225. export function bindLayerContextMenu() {
  1226. maps.graphicLayer.bindContextMenu([{
  1227. text: "开始编辑对象",
  1228. icon: "fa fa-edit",
  1229. show: function (e) {
  1230. const graphic = e.graphic
  1231. if (!graphic || !graphic.hasEdit) {
  1232. return false
  1233. }
  1234. return !graphic.isEditing
  1235. },
  1236. callback: (e) => {
  1237. const graphic = e.graphic
  1238. if (!graphic) {
  1239. return false
  1240. }
  1241. if (graphic) {
  1242. maps.graphicLayer.startEditing(graphic)
  1243. }
  1244. }
  1245. },
  1246. {
  1247. text: "停止编辑对象",
  1248. icon: "fa fa-edit",
  1249. show: function (e) {
  1250. const graphic = e.graphic
  1251. if (!graphic || !graphic.hasEdit) {
  1252. return false
  1253. }
  1254. return graphic.isEditing
  1255. },
  1256. callback: (e) => {
  1257. //编辑结束后重新保存一下
  1258. const graphic = e.graphic
  1259. if (!graphic) {
  1260. return false
  1261. }
  1262. if (graphic) {
  1263. graphic.stopEditing()
  1264. }
  1265. graphic._positions_show.forEach(i => {
  1266. waylineStore.polygonList.push(mars3d.LngLatPoint.fromCartesian(i))
  1267. })
  1268. waylineStore.Obliquephoto.pointsArr = graphic._positions_show
  1269. if (waylineStore.currentEditWayline.wayLineType == 2) {
  1270. showPolygonWayline()
  1271. } else if (waylineStore.currentEditWayline.wayLineType == 3) {
  1272. startEditObliquephotographyline()
  1273. }
  1274. }
  1275. },
  1276. {
  1277. text: "删除对象",
  1278. icon: "fa fa-trash-o",
  1279. show: (event) => {
  1280. graphic = event.graphic
  1281. },
  1282. callback: (e) => {
  1283. graphic = e.graphic
  1284. if (!graphic) {
  1285. return
  1286. }
  1287. const parent = graphic.parent // 右击是编辑点时1
  1288. graphicLayer.removeGraphic(graphic)
  1289. }
  1290. },
  1291. ])
  1292. }
  1293. export function bindwayPointMenu() {
  1294. graphicLayer.bindContextMenu([{
  1295. text: "开始编辑对象",
  1296. icon: "fa fa-edit",
  1297. show: function (e) {
  1298. const graphic = e.graphic
  1299. if (!graphic || !graphic.hasEdit) {
  1300. return false
  1301. }
  1302. return !graphic.isEditing
  1303. },
  1304. callback: (e) => {
  1305. const graphic = e.graphic
  1306. if (!graphic) {
  1307. return false
  1308. }
  1309. if (graphic) {
  1310. graphicLayer.startEditing(graphic)
  1311. }
  1312. }
  1313. },
  1314. ])
  1315. }
  1316. export function goWhere(data) {
  1317. maps.flyToPoint(new mars3d.LngLatPoint(data.lng, data.lat, data.alt), {
  1318. radius: 2000,
  1319. heading: 12,
  1320. alt: 936,
  1321. pitch: -32.8
  1322. });
  1323. }
  1324. export function changePointHeight(height) {
  1325. waylineStore.wayPointList.forEach(i => {
  1326. let point = i._point
  1327. let newPosition = [point._lng, point._lat, point._alt + height]
  1328. i.setOptions({
  1329. position: newPosition
  1330. })
  1331. lineWaypoint()
  1332. })
  1333. }
  1334. export function goLocalPosition(data, type) {
  1335. let radius
  1336. // type == 1 ? 80000 : type == 2 ? 40000 : type == 3 ? 20000 : 8000, // 距离目标点的距离
  1337. switch (type) {
  1338. case 1:
  1339. radius = 80000;
  1340. break;
  1341. case 2:
  1342. radius = 40000;
  1343. break;
  1344. case 3:
  1345. radius = 20000;
  1346. break;
  1347. case 5:
  1348. radius = 1036414;
  1349. break;
  1350. case 6:
  1351. radius = 2000;
  1352. break;
  1353. default:
  1354. radius = 8000;
  1355. }
  1356. const position = new mars3d.LngLatPoint(data.lng, data.lat, 10)
  1357. maps.flyToPoint(position, {
  1358. radius: radius,
  1359. duration: 4,
  1360. complete: function (e) {
  1361. // 飞行完成回调方法
  1362. // graphic.openPopup()
  1363. }
  1364. })
  1365. }
  1366. export function getWaylineParams(kml) {
  1367. console.log(kml, 8828)
  1368. }
  1369. //倾斜摄影
  1370. export function Obliquephotography() {
  1371. maps.setSceneOptions({
  1372. center: {
  1373. lat: waylineStore.center.lat,
  1374. lng: waylineStore.center.lng,
  1375. alt: 2000,
  1376. heading: 12,
  1377. pitch: -85
  1378. }
  1379. })
  1380. const graphic = new mars3d.graphic.BillboardEntity({
  1381. position: new mars3d.LngLatPoint(waylineStore.center.lng, waylineStore.center.lat, waylineStore.center.alt),
  1382. style: {
  1383. image: "/assets/wayline/airport.png",
  1384. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  1385. verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  1386. width: 60,
  1387. height: 60,
  1388. clampToGround: true,
  1389. visibleDepth: false,
  1390. scaleByDistance: false,
  1391. scale: 0.8,
  1392. zIndex: 200,
  1393. }
  1394. })
  1395. graphicLayer.addGraphic(graphic)
  1396. waylinePositions.push(graphic)
  1397. //记录起飞点
  1398. waylineStore.takeoffPoint = graphic
  1399. let takeoffPoint = mars3d.LngLatPoint.fromCartesian(
  1400. waylineStore.takeoffPoint._position_draw
  1401. ? waylineStore.takeoffPoint._position_draw
  1402. : waylineStore.takeoffPoint._position
  1403. );
  1404. waylineStore.takeoffPointHeight = takeoffPoint._alt
  1405. waylineStore.Obliquephoto.startPoint = {
  1406. lng: takeoffPoint._lng,
  1407. lat: takeoffPoint._lat,
  1408. height: takeoffPoint._alt
  1409. }
  1410. drawPolygon()
  1411. }
  1412. //开始编辑倾斜摄影
  1413. export function startEditObliquephotographyline() {
  1414. eventBus.emit('getObliquephotography', waylineStore.Obliquephoto)
  1415. }
  1416. //显示倾斜摄影的航线
  1417. export function showObliquephotographyline(data) {
  1418. console.log(data, 5555555)
  1419. data.target.pointArr.forEach(i => {
  1420. let a = new Cesium.Cartesian3(i.x, i.y, i.z);
  1421. i = mars3d.LngLatPoint.fromCartesian(a)
  1422. })
  1423. if (line) {
  1424. line.remove()
  1425. }
  1426. line = new mars3d.graphic.PolylinePrimitive({
  1427. // asynchronous: false,
  1428. positions: data.target.pointArr,
  1429. style: {
  1430. width: 5,
  1431. // color: "#0BD790",
  1432. materialType: mars3d.MaterialType.LineFlow,
  1433. materialOptions: {
  1434. // color: "#0BD790",
  1435. image: '/assets/wayline/line-interval2.png',
  1436. repeat: new Cesium.Cartesian2(20, 1),
  1437. speed: 1
  1438. }
  1439. }
  1440. });
  1441. lineToGroundLayer.addGraphic(line);
  1442. if (boundgraphic) {
  1443. boundgraphic.remove()
  1444. }
  1445. //倾斜摄影的范围
  1446. boundgraphic = new mars3d.graphic.PolygonEntity({
  1447. positions: data.target.boundArr,
  1448. style: {
  1449. color: "#4786ef",
  1450. opacity: 0.2,
  1451. outline: false,
  1452. clampToGround: true,
  1453. visibleDepth: true,
  1454. zIndex: 221
  1455. },
  1456. })
  1457. graphicLayer.addGraphic(boundgraphic)
  1458. countLineInfo()
  1459. }
  1460. function countLineInfo() {
  1461. let distance = 0
  1462. waylineStore.qinxie_result.ALL_pointArr.forEach(i => {
  1463. let line = new mars3d.graphic.PolylinePrimitive({
  1464. asynchronous: false,
  1465. positions: i.pointArr,
  1466. style: {
  1467. width: 5,
  1468. // color: "#0BD790",
  1469. materialType: mars3d.MaterialType.LineFlow,
  1470. visibleDepth: false,
  1471. materialOptions: {
  1472. // color: "#0BD790",
  1473. image: '/assets/wayline/line-interval2.png',
  1474. repeat: new Cesium.Cartesian2(20, 1),
  1475. speed: 1
  1476. }
  1477. }
  1478. });
  1479. distance += Number(mars3d.MeasureUtil.formatDistance(line.distance, { unit: 'km' }).split("公里")[0])
  1480. })
  1481. waylineStore.distance = distance.toFixed(2) + '公里'
  1482. waylineStore.workTime = distance * 1000 / waylineStore.speed
  1483. waylineStore.picNum = Math.floor(waylineStore.workTime / 2)
  1484. }
  1485. export function addWorkLayer(data) {
  1486. workLayer.clear()
  1487. const ENITTY_CLASS = {
  1488. point: "PointEntity",
  1489. polygon: "PolygonEntity",
  1490. polyline: "PolylineEntity",
  1491. circle: "CircleEntity",
  1492. };
  1493. let params = JSON.parse(data.layerData)
  1494. params.forEach(i => {
  1495. let layer = new mars3d.graphic[ENITTY_CLASS[i.json.type]](i.json);
  1496. workLayer.addGraphic(layer)
  1497. // maps.addLayer(layer)
  1498. })
  1499. }
  1500. export function clearWorkLayer() {
  1501. workLayer.clear()
  1502. }