index.js 26 KB

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