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