index.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  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 ? endPoint : passPoints[passPoints.length - 1]) : 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. if (!obj) {
  318. continue
  319. }
  320. coordinates.push(drawLineConfig(obj.lat, obj.lng, dataType));
  321. markers.push(addOvalPointConfig(obj.lat, obj.lng, imageName, dataType));
  322. }
  323. }
  324. let polygon = {lineWidth, strokeColor, fillColor, coordinates};
  325. return { markers, polygon };
  326. }
  327. function getPolygonsAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
  328. let markers = [];
  329. let polygons = [];
  330. if (!Array.isArray(airspaceInfos)) {
  331. return { markers, polygons };
  332. }
  333. let polygonAndMarkerStyle = setStyle('polygon');
  334. for (let i = 0; i < airspaceInfos.length; i++) {
  335. let polygon = airspaceInfos[i]
  336. let airspaceTypeFix;
  337. if (polygon.airspaceType)
  338. airspaceTypeFix = 'airspaceType';
  339. else
  340. airspaceTypeFix = 'airspace_type';
  341. if (polygon[airspaceTypeFix] == Global.airspaceType.polygon && currentAirspaceIndex != i) {
  342. let retObj = getPolygon(polygon, polygonAndMarkerStyle);
  343. markers.push(...retObj.markers);
  344. polygons.push(retObj.polygon);
  345. }
  346. }
  347. return { markers, polygons };
  348. }
  349. function getPolygonAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
  350. return createSelector(
  351. airspaceInfos,
  352. () => setStyle,
  353. currentAirspaceIndex,
  354. getPolygonsAndMarkers
  355. );
  356. }
  357. function getMarkers(polygonAndMarkers, lineAndMarkers) {
  358. let markers = [];
  359. if (polygonAndMarkers) {
  360. markers = [...polygonAndMarkers.markers]
  361. }
  362. if (lineAndMarkers) {
  363. markers = [...markers, ...lineAndMarkers.markers]
  364. }
  365. return markers
  366. }
  367. function getMarkerSelector(polygonAndMarkers, lineAndMarkers) {
  368. return createSelector(
  369. polygonAndMarkers,
  370. lineAndMarkers,
  371. getMarkers
  372. )
  373. }
  374. function getRegionPoints(circles, lineAndMarkers, polygonAndMarkers) {
  375. let regionPoints = new Array();
  376. for (let i = 0; i < circles.length; i++) {
  377. regionPoints.push(...getCircleRegions(circles[i]));
  378. }
  379. let lines = lineAndMarkers.lines;
  380. for (let i = 0; i < lines.length; i++) {
  381. regionPoints.push(...lines[i].coordinates);
  382. }
  383. let polygons = polygonAndMarkers.polygons;
  384. for (let i = 0; i < polygons.length; i++) {
  385. regionPoints.push(...polygons[i].coordinates);
  386. }
  387. return regionPoints;
  388. }
  389. function getRegionPointsSelector(circles, lineAndMarkers, polygonAndMarkers) {
  390. return createSelector(
  391. circles,
  392. lineAndMarkers,
  393. polygonAndMarkers,
  394. getRegionPoints
  395. );
  396. }
  397. function getLines(lineAndMarker) {
  398. return lineAndMarker.lines;
  399. }
  400. function getLineSelector(lineAndMarker) {
  401. return createSelector(
  402. lineAndMarker,
  403. getLines
  404. );
  405. }
  406. function getPolygons(polygonAndMarkers, linePolygonsAndMarkers) {
  407. return [...polygonAndMarkers.polygons, ...linePolygonsAndMarkers.polygons];
  408. }
  409. function getPolygonSelector(polygonAndMarkers, linePolygonsAndMarkers) {
  410. return createSelector(
  411. polygonAndMarkers,
  412. linePolygonsAndMarkers,
  413. getPolygons
  414. );
  415. }
  416. let setStyle = (style) => {
  417. if (!style)
  418. return () => { return null }
  419. else
  420. return (shapeName) => style[shapeName]
  421. }
  422. //获取selector
  423. export function getShapesSelector(airspaceInfos, style, currentAirspaceIndex) {
  424. currentAirspaceIndex = currentAirspaceIndex ? currentAirspaceIndex : () => -1;
  425. let circles = getCircleSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
  426. let linePolygonsAndMarkers = getLinePolygonsAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
  427. let lines = getLineSelector(linePolygonsAndMarkers);
  428. let polygonAndMarkers = getPolygonAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
  429. let polygons = getPolygonSelector(polygonAndMarkers, linePolygonsAndMarkers);
  430. let markers = getMarkerSelector(polygonAndMarkers, linePolygonsAndMarkers);
  431. let regionPoints = getRegionPointsSelector(circles, linePolygonsAndMarkers, polygonAndMarkers);
  432. return {
  433. markers,
  434. circles,
  435. lines,
  436. polygons,
  437. regionPoints
  438. }
  439. }
  440. //获取数组
  441. export function getShapes(airspaceInfos, style, currentAirspaceIndex) {
  442. let {markers, polygons, circles, lines, regionPoints} =
  443. getShapesSelector((airspaceInfos)=>airspaceInfos, style, (currentAirspaceIndex)=>currentAirspaceIndex)
  444. return {
  445. markers: markers(airspaceInfos),
  446. circles: circles(airspaceInfos),
  447. lines: lines(airspaceInfos),
  448. polygons: polygons(airspaceInfos),
  449. regionPoints: regionPoints(airspaceInfos)
  450. }
  451. }
  452. // 总共 5 种格式, http://git.corp.brilliantaero.com/BA/Coco/issues/99#note_6358
  453. // 1. 全输出格式
  454. // 2. 简化格式
  455. // 3. 传真格式
  456. // 4. 用户端用的简化格式
  457. // 5. 极简格式
  458. function getHeight(num, unit, type) {
  459. let shortNum
  460. if(num >= 100) {
  461. shortNum = parseInt(num/100).toString()
  462. if(shortNum.length <2) {
  463. shortNum = '0' + shortNum
  464. }
  465. }
  466. let heightStandard = Global.heightStandardsById.get(unit)
  467. if(!heightStandard) {
  468. heightStandard = unit
  469. }
  470. // 这里统一使用数字判断
  471. let standardUnit = Global.heightStandards.get(heightStandard)
  472. let heightDesc
  473. switch(standardUnit) {
  474. case 1:
  475. heightDesc = ['H*真', '真高*米']
  476. break;
  477. case 2:
  478. heightDesc = ['H*标(含以下)', '标高*米(含以下)']
  479. break;
  480. case 3:
  481. heightDesc = ['H*真(含以下)', '真高*米(含以下)']
  482. break;
  483. default:
  484. heightDesc = ['H*标', '标高*米']
  485. }
  486. if(shortNum && (type == 1 || type == 2)) {
  487. // H02真,H02真(含以下)
  488. return heightDesc[0].replace('*', shortNum)
  489. } else {
  490. // 真高200米,真高200米(含以下)
  491. return heightDesc[1].replace('*', num)
  492. }
  493. }
  494. function getAirspaceName(airspaceInfo) {
  495. if(airspaceInfo.airspace_name) {
  496. return airspaceInfo.airspace_name
  497. } else {
  498. return airspaceInfo.name
  499. }
  500. }
  501. export function circleContent(airspaceInfo, type=3) {
  502. if(type == 5)
  503. return getAirspaceName(airspaceInfo)
  504. if('airspace_name' in airspaceInfo) {
  505. const lat = latLngDecimalToDegrees(airspaceInfo.center_point_of_flying.lat);
  506. const lng = latLngDecimalToDegrees(airspaceInfo.center_point_of_flying.lng);
  507. let content = [];
  508. let loc = `以${airspaceInfo.center_loc}`
  509. if(type == 1 || type == 3)
  510. loc += `(E${lng}, N${lat})`;
  511. content.push(`${loc}为中心`)
  512. content.push(`半径${airspaceInfo.radius_of_flying}米`);
  513. content.push(getHeight(airspaceInfo.altitude, airspaceInfo.unit, type))
  514. if (airspaceInfo.note)
  515. content.push(`备注:${airspaceInfo.note}`)
  516. let result = content = content.join(',');
  517. return result;
  518. } else {
  519. let content = []
  520. let loc = `以${airspaceInfo.addr}`
  521. if(type == 1 || type == 3)
  522. loc += `(E${airspaceInfo.lng}, N${airspaceInfo.lat})`;
  523. content.push(`${loc}为中心`)
  524. content.push(`半径${airspaceInfo.radius}米`);
  525. content.push(getHeight(airspaceInfo.height, airspaceInfo.heightStandard, type))
  526. if (airspaceInfo.note)
  527. content.push(`备注:${airspaceInfo.note}`)
  528. content = content.join(',');
  529. return content;
  530. }
  531. }
  532. function flyingCenter(item = {}){
  533. if(item == {}){
  534. return ;
  535. } else {
  536. return (
  537. "(E" + latLngDecimalToDegrees(item.lng) +
  538. ', ' +
  539. "N" + latLngDecimalToDegrees(item.lat) + ")"
  540. );
  541. }
  542. }
  543. export function lineContent(airspaceInfo, type=3) {
  544. if(type == 5)
  545. return getAirspaceName(airspaceInfo)
  546. if('airspace_name' in airspaceInfo) {
  547. let content = [];
  548. content.push(`${airspaceInfo.start_loc}`)
  549. if(type == 1 || type == 3)
  550. content.push(`${flyingCenter(airspaceInfo.start_point)}`)
  551. content.push(` - `)
  552. content.push(getHeight(airspaceInfo.start_point.altitude, airspaceInfo.start_point.unit, type))
  553. const passing_points = airspaceInfo.passing_points;
  554. if(Array.isArray(passing_points)) {
  555. for(let i = 0; i < passing_points.length; i++) {
  556. const obj = passing_points[i];
  557. const lat = latLngDecimalToDegrees(obj.lat)
  558. const lng = latLngDecimalToDegrees(obj.lng)
  559. if (obj.point_type == Global.pointTypes.point) {
  560. content.push(` - ${obj.point_name}`)
  561. if(type == 1 || type == 3)
  562. content.push(`(E${lng}, N${lat})`)
  563. } else if (obj.point_type == Global.pointTypes.nav) {
  564. content.push(` - ${obj.point_code}`)
  565. if(type == 1 || type == 3)
  566. content.push(`(E${lng}, N${lat})`)
  567. } else {
  568. content.push(` - ${obj.air_route_code}`)
  569. }
  570. if(obj.altitude) {
  571. content.push(` - ${getHeight(obj.altitude, obj.unit, type)}`)
  572. }
  573. }
  574. }
  575. content.push(` - ${airspaceInfo.end_loc}`)
  576. if(type == 1 || type == 3)
  577. content.push(`${flyingCenter(airspaceInfo.end_point)}`)
  578. if(isSafeString(airspaceInfo.airline_width)) {
  579. content.push(`,宽度:${airspaceInfo.airline_width}米`)
  580. }
  581. if(isSafeString(airspaceInfo.note)) {
  582. content.push(`,备注: ${airspaceInfo.note}`)
  583. }
  584. let result = content.join("")
  585. return result;
  586. } else {
  587. let content = [];
  588. content.push(`${airspaceInfo.dep.addr}`)
  589. if(type == 1 || type == 3)
  590. content.push(`(E${airspaceInfo.dep.lng}, N${airspaceInfo.dep.lat})`)
  591. content.push(` - ${getHeight(airspaceInfo.dep.height, airspaceInfo.dep.heightStandard, type)}`);
  592. if (Array.isArray(airspaceInfo.passPoints)) {
  593. let length = airspaceInfo.passPoints.length;
  594. for (let i = 0; i < length; i++) {
  595. let obj = airspaceInfo.passPoints[i];
  596. if (obj.pointType == Global.pointTypes.point) {
  597. content.push(` - ${obj.addr}`)
  598. if(type == 1 || type == 3)
  599. content.push(`(E${obj.lng}, N${obj.lat})`);
  600. } else if (obj.pointType == Global.pointTypes.nav) {
  601. content.push(` - ${obj.pointCode}`)
  602. if(type == 1 || type == 3)
  603. content.push(`(E${obj.lng}, N${obj.lat})`);
  604. } else {
  605. content.push(` - ${obj.airlineCode}`);
  606. }
  607. if(obj.height) {
  608. content.push(` - ${getHeight(obj.height, obj.heightStandard, type)}`)
  609. }
  610. }
  611. }
  612. content.push(` - ${airspaceInfo.arrive.addr}`)
  613. if(type == 1 || type == 3)
  614. content.push(`(E${airspaceInfo.arrive.lng}, N${airspaceInfo.arrive.lat})`);
  615. if(airspaceInfo.airlineWidth) {
  616. content.push(`,宽度:${airspaceInfo.airlineWidth}米`)
  617. }
  618. if (airspaceInfo.note)
  619. content.push(`,备注:${airspaceInfo.note}`)
  620. content = content.join('');
  621. return content;
  622. }
  623. }
  624. export function polygonContent(airspaceInfo, type=3) {
  625. if(type == 5)
  626. return getAirspaceName(airspaceInfo)
  627. if('airspace_name' in airspaceInfo) {
  628. let res = []
  629. let points = airspaceInfo.points
  630. for (let i = 0; i < points.length; i++) {
  631. let c = `${points[i].addr ? points[i].addr : ''}`
  632. if(type == 1 || type == 3)
  633. c += `(E${latLngDecimalToDegrees(points[i].lng)}, N${latLngDecimalToDegrees(points[i].lat)})`;
  634. res.push(c)
  635. }
  636. let content = [res.join('、')]
  637. content.push(`${airspaceInfo.points.length}点连线范围内`)
  638. content.push(`,${getHeight(airspaceInfo.altitude, airspaceInfo.unit, type)}`)
  639. if(isSafeString(airspaceInfo.note)) {
  640. content.push(`,备注:${airspaceInfo.note}`)
  641. }
  642. return content.join('');
  643. } else {
  644. let content = [];
  645. let length = airspaceInfo.polygonPoints.length;
  646. for (let i = 0; i < length; i++) {
  647. let obj = airspaceInfo.polygonPoints[i];
  648. let c = `${obj.addr ? obj.addr : ''}`
  649. if(type == 1 || type == 3)
  650. c += `(E${obj.lng}, N${obj.lat})`
  651. content.push(c)
  652. }
  653. content = content.join('、') + `${length}点连线范围内`
  654. content += `,${getHeight(airspaceInfo.height, airspaceInfo.heightStandard, type)}`
  655. if (airspaceInfo.note)
  656. content = `${content},备注:${airspaceInfo.note}`
  657. return content;
  658. }
  659. }
  660. export {latLngDegreesToDecimal, latLngDecimalToDegrees}