index.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. import { createSelector } from 'reselect';
  2. import Global from './Common';
  3. import {
  4. latLngDegreesToDecimal,
  5. latLngDecimalToDegrees,
  6. isObject,
  7. isSafeString
  8. } from './Utils'
  9. let LatLon = require('geodesy').LatLonSpherical;
  10. function getCircleRegions(circle) {
  11. let latlon = new LatLon(circle.coordinate.latitude, circle.coordinate.longitude)
  12. let d1 = latlon.destinationPoint(circle.radius, 0)
  13. let d2 = latlon.destinationPoint(circle.radius, 90)
  14. let d3 = latlon.destinationPoint(circle.radius, 180)
  15. let d4 = latlon.destinationPoint(circle.radius, 270)
  16. return [{ lat: d1.lat, lng: d1.lon }, { lat: d2.lat, lng: d2.lon }, { lat: d3.lat, lng: d3.lon }, { lat: d4.lat, lng: d4.lon }]
  17. }
  18. function getDefaultStyle() {
  19. let imageName = 'BA_oval'
  20. let lineWidth = Global.amapLineWidth
  21. let strokeColor = Global.amapStrokeColor
  22. let fillColor = Global.amapFillColor
  23. return {imageName, lineWidth, strokeColor, fillColor}
  24. }
  25. function getCircles(airspaceInfos, setStyle, currentAirspaceIndex) {
  26. let circles = [];
  27. if (!Array.isArray(airspaceInfos)) {
  28. return circles;
  29. }
  30. let {lineWidth, strokeColor, fillColor} = getDefaultStyle()
  31. //通过该方法获取样式
  32. let circleStyle = setStyle('circle');
  33. if(circleStyle) {
  34. lineWidth = circleStyle.lineWidth
  35. strokeColor = circleStyle.strokeColor
  36. fillColor = circleStyle.fillColor
  37. }
  38. for (let i = 0; i < airspaceInfos.length; i++) {
  39. let tmpCircle = airspaceInfos[i]
  40. let airspaceTypeFix, radiusFix
  41. if (tmpCircle.airspaceType) {
  42. airspaceTypeFix = 'airspaceType';
  43. radiusFix = 'radius'
  44. } else {
  45. airspaceTypeFix = 'airspace_type';
  46. radiusFix = 'radius_of_flying'
  47. }
  48. if (tmpCircle[airspaceTypeFix] == Global.airspaceType.circle && currentAirspaceIndex != i) {
  49. let coordinate = {};
  50. if (tmpCircle.center_point_of_flying) {
  51. coordinate.latitude = tmpCircle.center_point_of_flying.lat;
  52. coordinate.longitude = tmpCircle.center_point_of_flying.lng;
  53. } else {
  54. coordinate.latitude = latLngDegreesToDecimal(tmpCircle.lat);
  55. coordinate.longitude = latLngDegreesToDecimal(tmpCircle.lng);
  56. }
  57. let radius = tmpCircle[radiusFix];
  58. let circle = {lineWidth, strokeColor, fillColor, radius, coordinate}
  59. circles.push(circle);
  60. }
  61. }
  62. return circles;
  63. }
  64. function getCircleSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
  65. return createSelector(
  66. airspaceInfos,
  67. () => setStyle,
  68. currentAirspaceIndex,
  69. getCircles
  70. );
  71. }
  72. function getLatLng(latlng, dataType) {
  73. if(dataType == 1) { // 驼峰模式,新建计划的时候的格式
  74. return latLngDegreesToDecimal(latlng)
  75. } else {
  76. return latlng
  77. }
  78. }
  79. function drawLineConfig(lat, lng, dataType) {
  80. return {
  81. latitude: getLatLng(lat, dataType),
  82. longitude: getLatLng(lng, dataType)
  83. };
  84. }
  85. function addOvalPointConfig(lat, lng, imageName, dataType) {
  86. return {
  87. coordinate: {
  88. latitude: getLatLng(lat, dataType),
  89. longitude: getLatLng(lng, dataType)
  90. },
  91. imageName: imageName
  92. };
  93. }
  94. function pointCompare(point1, point2) {
  95. const pointId1 = point1.point_id || point1.pointId;
  96. const pointId2 = point2.point_id || point2.pointId;
  97. if(pointId1 == pointId2) {
  98. return true;
  99. }
  100. let [point1Lat, point1lng] = getFixedLatLng(point1)
  101. let [point2lat, point2lng] = getFixedLatLng(point2)
  102. if(myRound(point1Lat) == myRound(point2lat)
  103. && myRound(point1lng) == myRound(point2lng)) {
  104. return true
  105. } else {
  106. return false
  107. }
  108. }
  109. function getCrossPoint(points1, points2) {
  110. for(let point1 of points1) {
  111. for(let point2 of points2) {
  112. if (pointCompare(point1, point2))
  113. return point1
  114. }
  115. }
  116. }
  117. function getAirwayPoints(airway, pointBefore, pointAfter) {
  118. let found = 0
  119. let points = []
  120. let pointTypeFix, pointsFix
  121. if ('points' in airway) {
  122. pointTypeFix = 'point_type';
  123. pointsFix = 'points'
  124. } else {
  125. pointTypeFix = 'pointType'
  126. pointsFix = 'airlines'
  127. }
  128. // 如果前后是其他航线,那么找到交叉点作为前后的点
  129. if ( pointBefore[pointTypeFix] == Global.pointTypes.line ) {
  130. pointBefore = getCrossPoint(airway[pointsFix], pointBefore[pointsFix])
  131. }
  132. if(pointAfter[pointTypeFix] == Global.pointTypes.line) {
  133. pointAfter = getCrossPoint(airway[pointsFix], pointAfter[pointsFix])
  134. }
  135. for (let point of airway[pointsFix]) {
  136. if (pointCompare(pointBefore, point) || pointCompare(pointAfter, point)) {
  137. found++
  138. points.push(Object.assign({}, point))
  139. continue
  140. }
  141. if (found == 1) {
  142. points.push(Object.assign({}, point))
  143. }
  144. }
  145. if (!(points.length > 0 && found == 2)) {
  146. // 如果两个点不全在航线上面,那么画全部航线
  147. points = airway[pointsFix]
  148. }
  149. return points;
  150. }
  151. function getLinesRouter(lineProps, lineAndMarkerStyle) {
  152. let coordinates = new Array();
  153. let markers = new Array();
  154. let lines = []
  155. let {imageName, lineWidth, strokeColor} = getDefaultStyle()
  156. if (lineAndMarkerStyle) {
  157. imageName = lineAndMarkerStyle.imageName
  158. lineWidth = lineAndMarkerStyle.lineWidth
  159. strokeColor = lineAndMarkerStyle.strokeColor
  160. }
  161. let startPoint, passPoints, endPoint, pointTypeFix, dataType, airlineWidth
  162. if (lineProps.start_point) {
  163. dataType = 2 // 下划线模式
  164. startPoint = lineProps['start_point']
  165. passPoints = lineProps['passing_points']
  166. endPoint = lineProps['end_point']
  167. pointTypeFix = 'point_type';
  168. airlineWidth = parseInt(lineProps['airline_width'], 10)
  169. } else {
  170. dataType = 1 // 驼峰模式
  171. startPoint = lineProps['dep']
  172. passPoints = lineProps['passPoints']
  173. endPoint = lineProps['arrive']
  174. pointTypeFix = 'pointType'
  175. airlineWidth = parseInt(lineProps['airlineWidth'], 10)
  176. }
  177. if (startPoint) {
  178. coordinates.push(drawLineConfig(startPoint.lat, startPoint.lng, dataType));
  179. markers.push(addOvalPointConfig(startPoint.lat, startPoint.lng, imageName, dataType));
  180. }
  181. if (Array.isArray(passPoints)) {
  182. for (let i = 0; i < passPoints.length; i++) {
  183. let obj = passPoints[i]
  184. if (!isObject(obj)) { // 所有的 points/airway 都必须是 obj
  185. continue;
  186. }
  187. let pointType = obj[pointTypeFix]
  188. if ( pointType == Global.pointTypes.point
  189. || pointType == Global.pointTypes.nav) {
  190. coordinates.push(drawLineConfig(obj.lat, obj.lng, dataType));
  191. markers.push(addOvalPointConfig(obj.lat, obj.lng, imageName, dataType));
  192. } else {
  193. // 遇到一个航线,不需要和前前面的点连起来
  194. if (coordinates.length > 1) {
  195. lines.push({lineWidth, strokeColor, coordinates})
  196. }
  197. coordinates = []
  198. const pointBefore = i == 0 ? startPoint : passPoints[i - 1]
  199. const pointAfter = i == passPoints.length - 1 ? endPoint : passPoints[i + 1]
  200. lines.push({lineWidth, strokeColor, coordinates: getAirwayPoints(obj, pointBefore, pointAfter)})
  201. }
  202. }
  203. }
  204. if (endPoint) {
  205. coordinates.push(drawLineConfig(endPoint.lat, endPoint.lng, dataType));
  206. markers.push(addOvalPointConfig(endPoint.lat, endPoint.lng, imageName, dataType));
  207. }
  208. if (coordinates.length > 1) {
  209. lines.push({lineWidth, strokeColor, coordinates});
  210. }
  211. if(airlineWidth > 0) {
  212. // 有宽度的空域,需要线周围多画宽度的多边形
  213. let polygons = processAirlineWidth(lines, airlineWidth)
  214. return { lines, markers, polygons };
  215. } else {
  216. return { lines, markers, polygons: [] };
  217. }
  218. }
  219. function getFixedLatLng(point) {
  220. let lat = point.latitude ? point.latitude : point.lat
  221. let lng = point.longitude ? point.longitude : point.lng
  222. // 复制计划的数据,有的点是度数模式如 38°35′17″
  223. if(isSafeString(lat)) {
  224. lat = latLngDegreesToDecimal(lat);
  225. lng = latLngDegreesToDecimal(lng);
  226. }
  227. return [lat, lng]
  228. }
  229. function processAirlineWidth(lines, airlineWidth) {
  230. let polygons = []
  231. let {strokeColor, fillColor} = getDefaultStyle()
  232. for(let line of lines) {
  233. let points = line.coordinates
  234. for(let i=0; i<points.length-1; i++) {
  235. let [lat1, lng1] = getFixedLatLng(points[i])
  236. let [lat2, lng2] = getFixedLatLng(points[i+1])
  237. let point1 = new LatLon(lat1, lng1)
  238. let point2 = new LatLon(lat2, lng2)
  239. let coordinates = getCirclePoints(point1, point2, airlineWidth)
  240. polygons.push({lineWidth: 1, strokeColor, fillColor, coordinates})
  241. }
  242. }
  243. return polygons
  244. }
  245. function getCirclePoints(point1, point2, width) {
  246. let percision = 10 // 半圆处理为多边形的时候,半圆上取几个点
  247. let step = 180/percision
  248. let bearing = (360 + point1.bearingTo(point2) - 90) % 360 // 取正值
  249. let points = []
  250. for(let diff = 0; diff <= 180; diff += step) {
  251. let point = point2.destinationPoint(width, bearing + diff)
  252. points.push({lat: point.lat, lng: point.lon})
  253. }
  254. for(let diff = 180; diff <= 360; diff += step) {
  255. let point = point1.destinationPoint(width, bearing + diff)
  256. points.push({lat: point.lat, lng: point.lon})
  257. }
  258. return points
  259. }
  260. function myRound(num, digits) {
  261. if(digits == null)
  262. digits = 6 // 比较的精度,经纬度会被经过度分秒方式到浮点方式的转化
  263. return Math.round(num * Math.pow(10, digits)) / Math.pow(10, digits)
  264. }
  265. function getLinesPolygonsAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
  266. let retLines = [];
  267. let retMarkers = [];
  268. let retPolygons = [];
  269. if (!Array.isArray(airspaceInfos)) {
  270. return { lines: retLines, markers: retMarkers, polygons: retPolygons };
  271. }
  272. let lineStyle = setStyle('line');
  273. for (let i = 0; i < airspaceInfos.length; i++) {
  274. let tmpLine = airspaceInfos[i]
  275. let airspaceTypeFix;
  276. if (tmpLine.airspaceType)
  277. airspaceTypeFix = 'airspaceType';
  278. else
  279. airspaceTypeFix = 'airspace_type';
  280. if (tmpLine[airspaceTypeFix] == Global.airspaceType.line && currentAirspaceIndex != i) {
  281. let { lines, markers, polygons } = getLinesRouter(tmpLine, lineStyle);
  282. retMarkers.push(...markers);
  283. retLines.push(...lines);
  284. retPolygons.push(...polygons)
  285. }
  286. }
  287. return { lines: retLines, markers: retMarkers, polygons: retPolygons };
  288. }
  289. function getLinePolygonsAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
  290. return createSelector(
  291. airspaceInfos,
  292. () => setStyle,
  293. currentAirspaceIndex,
  294. getLinesPolygonsAndMarkers
  295. );
  296. }
  297. function getPolygon(polygonProps, polygonAndMarkerStyle) {
  298. let coordinates = new Array();
  299. let markers = new Array();
  300. let {imageName, lineWidth, strokeColor, fillColor} = getDefaultStyle()
  301. if (polygonAndMarkerStyle) {
  302. imageName = polygonAndMarkerStyle.imageName
  303. lineWidth = polygonAndMarkerStyle.lineWidth
  304. strokeColor = polygonAndMarkerStyle.strokeColor
  305. fillColor = polygonAndMarkerStyle.fillColor
  306. }
  307. let pointsFix, dataType;
  308. if (polygonProps.points) {
  309. pointsFix = 'points';
  310. dataType = 2
  311. } else {
  312. pointsFix = 'polygonPoints';
  313. dataType = 1 // 驼峰模式
  314. }
  315. if (Array.isArray(polygonProps[pointsFix])) {
  316. for (let obj of polygonProps[pointsFix]) {
  317. coordinates.push(drawLineConfig(obj.lat, obj.lng, dataType));
  318. markers.push(addOvalPointConfig(obj.lat, obj.lng, imageName, dataType));
  319. }
  320. }
  321. let polygon = {lineWidth, strokeColor, fillColor, coordinates};
  322. return { markers, polygon };
  323. }
  324. function getPolygonsAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
  325. let markers = [];
  326. let polygons = [];
  327. if (!Array.isArray(airspaceInfos)) {
  328. return { markers, polygons };
  329. }
  330. let polygonAndMarkerStyle = setStyle('polygon');
  331. for (let i = 0; i < airspaceInfos.length; i++) {
  332. let polygon = airspaceInfos[i]
  333. let airspaceTypeFix;
  334. if (polygon.airspaceType)
  335. airspaceTypeFix = 'airspaceType';
  336. else
  337. airspaceTypeFix = 'airspace_type';
  338. if (polygon[airspaceTypeFix] == Global.airspaceType.polygon && currentAirspaceIndex != i) {
  339. let retObj = getPolygon(polygon, polygonAndMarkerStyle);
  340. markers.push(...retObj.markers);
  341. polygons.push(retObj.polygon);
  342. }
  343. }
  344. return { markers, polygons };
  345. }
  346. function getPolygonAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
  347. return createSelector(
  348. airspaceInfos,
  349. () => setStyle,
  350. currentAirspaceIndex,
  351. getPolygonsAndMarkers
  352. );
  353. }
  354. function getMarkers(polygonAndMarkers, lineAndMarkers) {
  355. let markers = [];
  356. if (polygonAndMarkers) {
  357. markers = [...polygonAndMarkers.markers]
  358. }
  359. if (lineAndMarkers) {
  360. markers = [...markers, ...lineAndMarkers.markers]
  361. }
  362. return markers
  363. }
  364. function getMarkerSelector(polygonAndMarkers, lineAndMarkers) {
  365. return createSelector(
  366. polygonAndMarkers,
  367. lineAndMarkers,
  368. getMarkers
  369. )
  370. }
  371. function getRegionPoints(circles, lineAndMarkers, polygonAndMarkers) {
  372. let regionPoints = new Array();
  373. for (let i = 0; i < circles.length; i++) {
  374. regionPoints.push(...getCircleRegions(circles[i]));
  375. }
  376. let lines = lineAndMarkers.lines;
  377. for (let i = 0; i < lines.length; i++) {
  378. regionPoints.push(...lines[i].coordinates);
  379. }
  380. let polygons = polygonAndMarkers.polygons;
  381. for (let i = 0; i < polygons.length; i++) {
  382. regionPoints.push(...polygons[i].coordinates);
  383. }
  384. return regionPoints;
  385. }
  386. function getRegionPointsSelector(circles, lineAndMarkers, polygonAndMarkers) {
  387. return createSelector(
  388. circles,
  389. lineAndMarkers,
  390. polygonAndMarkers,
  391. getRegionPoints
  392. );
  393. }
  394. function getLines(lineAndMarker) {
  395. return lineAndMarker.lines;
  396. }
  397. function getLineSelector(lineAndMarker) {
  398. return createSelector(
  399. lineAndMarker,
  400. getLines
  401. );
  402. }
  403. function getPolygons(polygonAndMarkers, linePolygonsAndMarkers) {
  404. return [...polygonAndMarkers.polygons, ...linePolygonsAndMarkers.polygons];
  405. }
  406. function getPolygonSelector(polygonAndMarkers, linePolygonsAndMarkers) {
  407. return createSelector(
  408. polygonAndMarkers,
  409. linePolygonsAndMarkers,
  410. getPolygons
  411. );
  412. }
  413. let setStyle = (style) => {
  414. if (!style)
  415. return () => { return null }
  416. else
  417. return (shapeName) => style[shapeName]
  418. }
  419. //获取selector
  420. export function getShapesSelector(airspaceInfos, style, currentAirspaceIndex) {
  421. currentAirspaceIndex = currentAirspaceIndex ? currentAirspaceIndex : () => -1;
  422. let circles = getCircleSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
  423. let linePolygonsAndMarkers = getLinePolygonsAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
  424. let lines = getLineSelector(linePolygonsAndMarkers);
  425. let polygonAndMarkers = getPolygonAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
  426. let polygons = getPolygonSelector(polygonAndMarkers, linePolygonsAndMarkers);
  427. let markers = getMarkerSelector(polygonAndMarkers, linePolygonsAndMarkers);
  428. let regionPoints = getRegionPointsSelector(circles, linePolygonsAndMarkers, polygonAndMarkers);
  429. return {
  430. markers,
  431. circles,
  432. lines,
  433. polygons,
  434. regionPoints
  435. }
  436. }
  437. //获取数组
  438. export function getShapes(airspaceInfos, style, currentAirspaceIndex) {
  439. let {markers, polygons, circles, lines, regionPoints} =
  440. getShapesSelector((airspaceInfos)=>airspaceInfos, style, (currentAirspaceIndex)=>currentAirspaceIndex)
  441. return {
  442. markers: markers(airspaceInfos),
  443. circles: circles(airspaceInfos),
  444. lines: lines(airspaceInfos),
  445. polygons: polygons(airspaceInfos),
  446. regionPoints: regionPoints(airspaceInfos)
  447. }
  448. }
  449. // 总共 5 种格式, http://git.corp.brilliantaero.com/BA/Coco/issues/99#note_6358
  450. // 1. 全输出格式
  451. // 2. 简化格式
  452. // 3. 传真格式
  453. // 4. 用户端用的简化格式
  454. // 5. 极简格式
  455. function getHeight(num, unit, type) {
  456. let shortNum
  457. if(num >= 100) {
  458. shortNum = parseInt(num/100).toString()
  459. if(shortNum.length <2) {
  460. shortNum = '0' + shortNum
  461. }
  462. }
  463. let heightStandard = Global.heightStandardsById.get(unit)
  464. if(!heightStandard) {
  465. heightStandard = unit
  466. }
  467. // 这里统一使用数字判断
  468. let standardUnit = Global.heightStandards.get(heightStandard)
  469. let heightDesc
  470. switch(standardUnit) {
  471. case 1:
  472. heightDesc = ['H*真', '真高*米']
  473. break;
  474. case 2:
  475. heightDesc = ['H*标(含以下)', '标高*米(含以下)']
  476. break;
  477. case 3:
  478. heightDesc = ['H*真(含以下)', '标高*米(含以下)']
  479. break;
  480. default:
  481. heightDesc = ['H*标', '标高*米']
  482. }
  483. if(shortNum && (type == 1 || type == 2)) {
  484. // H02真,H02真(含以下)
  485. return heightDesc[0].replace('*', shortNum)
  486. } else {
  487. // 真高200米,真高200米(含以下)
  488. return heightDesc[1].replace('*', num)
  489. }
  490. }
  491. function getAirspaceName(airspaceInfo) {
  492. if(airspaceInfo.airspace_name) {
  493. return airspaceInfo.airspace_name
  494. } else {
  495. return airspaceInfo.name
  496. }
  497. }
  498. export function circleContent(airspaceInfo, type=3) {
  499. if(type == 5)
  500. return getAirspaceName(airspaceInfo)
  501. if('airspace_name' in airspaceInfo) {
  502. const lat = latLngDecimalToDegrees(airspaceInfo.center_point_of_flying.lat);
  503. const lng = latLngDecimalToDegrees(airspaceInfo.center_point_of_flying.lng);
  504. let content = [];
  505. let loc = `以${airspaceInfo.center_loc}`
  506. if(type == 1 || type == 3)
  507. loc += `(E${lng}, N${lat})`;
  508. content.push(`${loc}为中心`)
  509. content.push(`半径${airspaceInfo.radius_of_flying}米`);
  510. content.push(getHeight(airspaceInfo.altitude, airspaceInfo.unit, type))
  511. if (airspaceInfo.note)
  512. content.push(`备注:${airspaceInfo.note}`)
  513. let result = content = content.join(',');
  514. return result;
  515. } else {
  516. let content = []
  517. let loc = `以${airspaceInfo.addr}`
  518. if(type == 1 || type == 3)
  519. loc += `(E${airspaceInfo.lng}, N${airspaceInfo.lat})`;
  520. content.push(`${loc}为中心`)
  521. content.push(`半径${airspaceInfo.radius}米`);
  522. content.push(getHeight(airspaceInfo.height, airspaceInfo.heightStandard, type))
  523. if (airspaceInfo.note)
  524. content.push(`备注:${airspaceInfo.note}`)
  525. content = content.join(',');
  526. return content;
  527. }
  528. }
  529. function flyingCenter(item = {}){
  530. if(item == {}){
  531. return ;
  532. } else {
  533. return (
  534. "(E" + latLngDecimalToDegrees(item.lng) +
  535. ', ' +
  536. "N" + latLngDecimalToDegrees(item.lat) + ")"
  537. );
  538. }
  539. }
  540. export function lineContent(airspaceInfo, type=3) {
  541. if(type == 5)
  542. return getAirspaceName(airspaceInfo)
  543. if('airspace_name' in airspaceInfo) {
  544. let content = [];
  545. content.push(`${airspaceInfo.start_loc}`)
  546. if(type == 1 || type == 3)
  547. content.push(`${flyingCenter(airspaceInfo.start_point)}`)
  548. content.push(` - `)
  549. content.push(getHeight(airspaceInfo.start_point.altitude, airspaceInfo.start_point.unit, type))
  550. const passing_points = airspaceInfo.passing_points;
  551. if(Array.isArray(passing_points)) {
  552. for(let i = 0; i < passing_points.length; i++) {
  553. const obj = passing_points[i];
  554. const lat = latLngDecimalToDegrees(obj.lat)
  555. const lng = latLngDecimalToDegrees(obj.lng)
  556. if (obj.point_type == Global.pointTypes.point) {
  557. content.push(` - ${obj.point_name}`)
  558. if(type == 1 || type == 3)
  559. content.push(`(E${lng}, N${lat})`)
  560. } else if (obj.point_type == Global.pointTypes.nav) {
  561. content.push(` - ${obj.point_code}`)
  562. if(type == 1 || type == 3)
  563. content.push(`(E${lng}, N${lat})`)
  564. } else {
  565. content.push(` - ${obj.air_route_code}`)
  566. }
  567. if(obj.altitude) {
  568. content.push(` - ${getHeight(obj.altitude, obj.unit, type)}`)
  569. }
  570. }
  571. }
  572. content.push(` - ${airspaceInfo.end_loc}`)
  573. if(type == 1 || type == 3)
  574. content.push(`${flyingCenter(airspaceInfo.end_point)}`)
  575. if(isSafeString(airspaceInfo.airline_width)) {
  576. content.push(`,宽度:${airspaceInfo.airline_width}米`)
  577. }
  578. if(isSafeString(airspaceInfo.note)) {
  579. content.push(`,备注: ${airspaceInfo.note}`)
  580. }
  581. let result = content.join("")
  582. return result;
  583. } else {
  584. let content = [];
  585. content.push(`${airspaceInfo.dep.addr}`)
  586. if(type == 1 || type == 3)
  587. content.push(`(E${airspaceInfo.dep.lng}, N${airspaceInfo.dep.lat})`)
  588. content.push(` - ${getHeight(airspaceInfo.dep.height, airspaceInfo.dep.heightStandard, type)}`);
  589. if (Array.isArray(airspaceInfo.passPoints)) {
  590. let length = airspaceInfo.passPoints.length;
  591. for (let i = 0; i < length; i++) {
  592. let obj = airspaceInfo.passPoints[i];
  593. if (obj.pointType == Global.pointTypes.point) {
  594. content.push(` - ${obj.addr}`)
  595. if(type == 1 || type == 3)
  596. content.push(`(E${obj.lng}, N${obj.lat})`);
  597. } else if (obj.pointType == Global.pointTypes.nav) {
  598. content.push(` - ${obj.pointCode}`)
  599. if(type == 1 || type == 3)
  600. content.push(`(E${obj.lng}, N${obj.lat})`);
  601. } else {
  602. content.push(` - ${obj.airlineCode}`);
  603. }
  604. if(obj.height) {
  605. content.push(` - ${getHeight(obj.height, obj.heightStandard, type)}`)
  606. }
  607. }
  608. }
  609. content.push(` - ${airspaceInfo.arrive.addr}`)
  610. if(type == 1 || type == 3)
  611. content.push(`(E${airspaceInfo.arrive.lng}, N${airspaceInfo.arrive.lat})`);
  612. if(airspaceInfo.airlineWidth) {
  613. content.push(`,宽度:${airspaceInfo.airlineWidth}米`)
  614. }
  615. if (airspaceInfo.note)
  616. content.push(`,备注:${airspaceInfo.note}`)
  617. content = content.join('');
  618. return content;
  619. }
  620. }
  621. export function polygonContent(airspaceInfo, type=3) {
  622. if(type == 5)
  623. return getAirspaceName(airspaceInfo)
  624. if('airspace_name' in airspaceInfo) {
  625. let res = []
  626. let points = airspaceInfo.points
  627. for (let i = 0; i < points.length; i++) {
  628. let c = `${points[i].addr ? points[i].addr : ''}`
  629. if(type == 1 || type == 3)
  630. c += `(E${latLngDecimalToDegrees(points[i].lng)}, N${latLngDecimalToDegrees(points[i].lat)})`;
  631. res.push(c)
  632. }
  633. let content = [res.join('、')]
  634. content.push(`${airspaceInfo.points.length}点连线范围内`)
  635. content.push(`,${getHeight(airspaceInfo.altitude, airspaceInfo.unit, type)}`)
  636. if(isSafeString(airspaceInfo.note)) {
  637. content.push(`,备注:${airspaceInfo.note}`)
  638. }
  639. return content.join('');
  640. } else {
  641. let content = [];
  642. let length = airspaceInfo.polygonPoints.length;
  643. for (let i = 0; i < length; i++) {
  644. let obj = airspaceInfo.polygonPoints[i];
  645. let c = `${obj.addr ? obj.addr : ''}`
  646. c += `(E${obj.lng}, N${obj.lat})`
  647. content.push(c)
  648. }
  649. content = content.join('、') + `${length}点连线范围内`
  650. content += `,${getHeight(airspaceInfo.height, airspaceInfo.heightStandard, type)}`
  651. if (airspaceInfo.note)
  652. content = `${content},备注:${airspaceInfo.note}`
  653. return content;
  654. }
  655. }
  656. export {latLngDegreesToDecimal, latLngDecimalToDegrees}