index.js 25 KB

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