index.js 25 KB

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