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 leftWidth = airlineWidth
  268. let rightWidth = airlineWidth
  269. if(halfAngle != 90) { //直线上面是 90 度,不需要计算斜边
  270. let angleToDecimal = halfAngle*Math.PI/180
  271. leftWidth = Math.abs(airlineWidth/Math.sin(angleToDecimal))
  272. rightWidth = Math.abs(airlineWidth/Math.sin(angleToDecimal))
  273. }
  274. let leftPoint = point.destinationPoint(leftWidth, leftBearing)
  275. let rightPoint = point.destinationPoint(rightWidth, rightBearing)
  276. return [leftPoint, rightPoint]
  277. }
  278. function myRound(num, digits) {
  279. if(digits == null)
  280. digits = 6 // 比较的精度,经纬度会被经过度分秒方式到浮点方式的转化
  281. return Math.round(num * Math.pow(10, digits)) / Math.pow(10, digits)
  282. }
  283. function isLineConnect(line1, line2) {
  284. // 判断 line1 的终点和 line2 的起点是否相同
  285. let line1LastPoint = line1.coordinates[line1.coordinates.length -1]
  286. let line2FirstPoint = line2.coordinates[0]
  287. let [line1lat, line1lng] = getFixedLatLng(line1LastPoint)
  288. let [line2lat, line2lng] = getFixedLatLng(line2FirstPoint)
  289. if(myRound(line1lat) == myRound(line2lat)
  290. && myRound(line1lng) == myRound(line2lng)) {
  291. return true
  292. } else {
  293. return false
  294. }
  295. }
  296. function getLinesPolygonsAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
  297. let retLines = [];
  298. let retMarkers = [];
  299. let retPolygons = [];
  300. if (!Array.isArray(airspaceInfos)) {
  301. return { lines: retLines, markers: retMarkers, polygons: retPolygons };
  302. }
  303. let lineStyle = setStyle('line');
  304. for (let i = 0; i < airspaceInfos.length; i++) {
  305. let tmpLine = airspaceInfos[i]
  306. let airspaceTypeFix;
  307. if (tmpLine.airspaceType)
  308. airspaceTypeFix = 'airspaceType';
  309. else
  310. airspaceTypeFix = 'airspace_type';
  311. if (tmpLine[airspaceTypeFix] == Global.airspaceType.line && currentAirspaceIndex != i) {
  312. let { lines, markers, polygons } = getLinesRouter(tmpLine, lineStyle);
  313. retMarkers.push(...markers);
  314. retLines.push(...lines);
  315. retPolygons.push(...polygons)
  316. }
  317. }
  318. return { lines: retLines, markers: retMarkers, polygons: retPolygons };
  319. }
  320. function getLinePolygonsAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
  321. return createSelector(
  322. airspaceInfos,
  323. () => setStyle,
  324. currentAirspaceIndex,
  325. getLinesPolygonsAndMarkers
  326. );
  327. }
  328. function getPolygon(polygonProps, polygonAndMarkerStyle) {
  329. let coordinates = new Array();
  330. let markers = new Array();
  331. let {imageName, lineWidth, strokeColor, fillColor} = getDefaultStyle()
  332. if (polygonAndMarkerStyle) {
  333. imageName = polygonAndMarkerStyle.imageName
  334. lineWidth = polygonAndMarkerStyle.lineWidth
  335. strokeColor = polygonAndMarkerStyle.strokeColor
  336. fillColor = polygonAndMarkerStyle.fillColor
  337. }
  338. let pointsFix, dataType;
  339. if (polygonProps.points) {
  340. pointsFix = 'points';
  341. dataType = 2
  342. } else {
  343. pointsFix = 'polygonPoints';
  344. dataType = 1 // 驼峰模式
  345. }
  346. if (Array.isArray(polygonProps[pointsFix])) {
  347. for (let obj of polygonProps[pointsFix]) {
  348. coordinates.push(drawLineConfig(obj.lat, obj.lng, dataType));
  349. markers.push(addOvalPointConfig(obj.lat, obj.lng, imageName, dataType));
  350. }
  351. }
  352. let polygon = {lineWidth, strokeColor, fillColor, coordinates};
  353. return { markers, polygon };
  354. }
  355. function getPolygonsAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
  356. let markers = [];
  357. let polygons = [];
  358. if (!Array.isArray(airspaceInfos)) {
  359. return { markers, polygons };
  360. }
  361. let polygonAndMarkerStyle = setStyle('polygon');
  362. for (let i = 0; i < airspaceInfos.length; i++) {
  363. let polygon = airspaceInfos[i]
  364. let airspaceTypeFix;
  365. if (polygon.airspaceType)
  366. airspaceTypeFix = 'airspaceType';
  367. else
  368. airspaceTypeFix = 'airspace_type';
  369. if (polygon[airspaceTypeFix] == Global.airspaceType.polygon && currentAirspaceIndex != i) {
  370. let retObj = getPolygon(polygon, polygonAndMarkerStyle);
  371. markers.push(...retObj.markers);
  372. polygons.push(retObj.polygon);
  373. }
  374. }
  375. return { markers, polygons };
  376. }
  377. function getPolygonAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
  378. return createSelector(
  379. airspaceInfos,
  380. () => setStyle,
  381. currentAirspaceIndex,
  382. getPolygonsAndMarkers
  383. );
  384. }
  385. function getMarkers(polygonAndMarkers, lineAndMarkers) {
  386. let markers = [];
  387. if (polygonAndMarkers) {
  388. markers = [...polygonAndMarkers.markers]
  389. }
  390. if (lineAndMarkers) {
  391. markers = [...markers, ...lineAndMarkers.markers]
  392. }
  393. return markers
  394. }
  395. function getMarkerSelector(polygonAndMarkers, lineAndMarkers) {
  396. return createSelector(
  397. polygonAndMarkers,
  398. lineAndMarkers,
  399. getMarkers
  400. )
  401. }
  402. function getRegionPoints(circles, lineAndMarkers, polygonAndMarkers) {
  403. let regionPoints = new Array();
  404. for (let i = 0; i < circles.length; i++) {
  405. regionPoints.push(...getCircleRegions(circles[i]));
  406. }
  407. let lines = lineAndMarkers.lines;
  408. for (let i = 0; i < lines.length; i++) {
  409. regionPoints.push(...lines[i].coordinates);
  410. }
  411. let polygons = polygonAndMarkers.polygons;
  412. for (let i = 0; i < polygons.length; i++) {
  413. regionPoints.push(...polygons[i].coordinates);
  414. }
  415. return regionPoints;
  416. }
  417. function getRegionPointsSelector(circles, lineAndMarkers, polygonAndMarkers) {
  418. return createSelector(
  419. circles,
  420. lineAndMarkers,
  421. polygonAndMarkers,
  422. getRegionPoints
  423. );
  424. }
  425. function getLines(lineAndMarker) {
  426. return lineAndMarker.lines;
  427. }
  428. function getLineSelector(lineAndMarker) {
  429. return createSelector(
  430. lineAndMarker,
  431. getLines
  432. );
  433. }
  434. function getPolygons(polygonAndMarkers, linePolygonsAndMarkers) {
  435. return [...polygonAndMarkers.polygons, ...linePolygonsAndMarkers.polygons];
  436. }
  437. function getPolygonSelector(polygonAndMarkers, linePolygonsAndMarkers) {
  438. return createSelector(
  439. polygonAndMarkers,
  440. linePolygonsAndMarkers,
  441. getPolygons
  442. );
  443. }
  444. let setStyle = (style) => {
  445. if (!style)
  446. return (shapeName) => { return null }
  447. else
  448. return (shapeName) => style[shapeName]
  449. }
  450. //获取selector
  451. export function getShapesSelector(airspaceInfos, style, currentAirspaceIndex) {
  452. currentAirspaceIndex = currentAirspaceIndex ? currentAirspaceIndex : () => -1;
  453. let circles = getCircleSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
  454. let linePolygonsAndMarkers = getLinePolygonsAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
  455. let lines = getLineSelector(linePolygonsAndMarkers);
  456. let polygonAndMarkers = getPolygonAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
  457. let polygons = getPolygonSelector(polygonAndMarkers, linePolygonsAndMarkers);
  458. let markers = getMarkerSelector(polygonAndMarkers, linePolygonsAndMarkers);
  459. let regionPoints = getRegionPointsSelector(circles, linePolygonsAndMarkers, polygonAndMarkers);
  460. return {
  461. markers,
  462. circles,
  463. lines,
  464. polygons,
  465. regionPoints
  466. }
  467. }
  468. //获取数组
  469. export function getShapes(airspaceInfos, style, currentAirspaceIndex) {
  470. let {markers, polygons, circles, lines, regionPoints} =
  471. getShapesSelector((airspaceInfos)=>airspaceInfos, style, (currentAirspaceIndex)=>currentAirspaceIndex)
  472. return {
  473. markers: markers(airspaceInfos),
  474. circles: circles(airspaceInfos),
  475. lines: lines(airspaceInfos),
  476. polygons: polygons(airspaceInfos),
  477. regionPoints: regionPoints(airspaceInfos)
  478. }
  479. }
  480. // 总共 5 种格式, http://git.corp.brilliantaero.com/BA/Coco/issues/99#note_6358
  481. // 1. 全输出格式
  482. // 2. 简化格式
  483. // 3. 传真格式
  484. // 4. 用户端用的简化格式
  485. // 5. 极简格式
  486. function getHeight(num, unit, type) {
  487. let shortNum
  488. if(num >= 100) {
  489. shortNum = parseInt(num/100).toString()
  490. if(shortNum.length <2) {
  491. shortNum = '0' + shortNum
  492. }
  493. }
  494. let heightStandard = Global.heightStandardsById.get(unit)
  495. if(!heightStandard) {
  496. heightStandard = unit
  497. }
  498. // 这里统一使用数字判断
  499. let standardUnit = Global.heightStandards.get(heightStandard)
  500. let heightDesc
  501. switch(standardUnit) {
  502. case 1:
  503. heightDesc = ['H*真', '真高*米']
  504. break;
  505. case 2:
  506. heightDesc = ['H*标(含以下)', '标高*米(含以下)']
  507. break;
  508. case 3:
  509. heightDesc = ['H*真(含以下)', '标高*米(含以下)']
  510. break;
  511. default:
  512. heightDesc = ['H*标', '标高*米']
  513. }
  514. if(shortNum && (type == 1 || type == 2)) {
  515. // H02真,H02真(含以下)
  516. return heightDesc[0].replace('*', shortNum)
  517. } else {
  518. // 真高200米,真高200米(含以下)
  519. return heightDesc[1].replace('*', num)
  520. }
  521. }
  522. function getAirspaceName(airspaceInfo) {
  523. if(airspaceInfo.airspace_name) {
  524. return airspaceInfo.airspace_name
  525. } else {
  526. return airspaceInfo.name
  527. }
  528. }
  529. export function circleContent(airspaceInfo, type=3) {
  530. if(type == 5)
  531. return getAirspaceName(airspaceInfo)
  532. if('airspace_name' in airspaceInfo) {
  533. const lat = latLngDecimalToDegrees(airspaceInfo.center_point_of_flying.lat);
  534. const lng = latLngDecimalToDegrees(airspaceInfo.center_point_of_flying.lng);
  535. let content = [];
  536. let loc = `以${airspaceInfo.center_loc}`
  537. if(type == 1 || type == 3)
  538. loc += `(E${lng}, N${lat})`;
  539. content.push(`${loc}为中心`)
  540. content.push(`半径${airspaceInfo.radius_of_flying}米`);
  541. content.push(getHeight(airspaceInfo.altitude, airspaceInfo.unit, type))
  542. if (airspaceInfo.note)
  543. content.push(`备注:${airspaceInfo.note}`)
  544. let result = content = content.join(',');
  545. return result;
  546. } else {
  547. let content = []
  548. let loc = `以${airspaceInfo.addr}`
  549. if(type == 1 || type == 3)
  550. loc += `(E${airspaceInfo.lng}, N${airspaceInfo.lat})`;
  551. content.push(`${loc}为中心`)
  552. content.push(`半径${airspaceInfo.radius}米`);
  553. content.push(getHeight(airspaceInfo.height, airspaceInfo.heightStandard, type))
  554. if (airspaceInfo.note)
  555. content.push(`备注:${airspaceInfo.note}`)
  556. content = content.join(',');
  557. return content;
  558. }
  559. }
  560. function flyingCenter(item = {}){
  561. if(item == {}){
  562. return ;
  563. } else {
  564. return (
  565. "(E" + latLngDecimalToDegrees(item.lng) +
  566. ', ' +
  567. "N" + latLngDecimalToDegrees(item.lat) + ")"
  568. );
  569. }
  570. }
  571. export function lineContent(airspaceInfo, type=3) {
  572. if(type == 5)
  573. return getAirspaceName(airspaceInfo)
  574. if('airspace_name' in airspaceInfo) {
  575. let content = [];
  576. content.push(`${airspaceInfo.start_loc}`)
  577. if(type == 1 || type == 3)
  578. content.push(`${flyingCenter(airspaceInfo.start_point)}`)
  579. content.push(` - `)
  580. content.push(getHeight(airspaceInfo.start_point.altitude, airspaceInfo.start_point.unit, type))
  581. const passing_points = airspaceInfo.passing_points;
  582. if(Array.isArray(passing_points)) {
  583. for(let i = 0; i < passing_points.length; i++) {
  584. const obj = passing_points[i];
  585. const lat = latLngDecimalToDegrees(obj.lat)
  586. const lng = latLngDecimalToDegrees(obj.lng)
  587. if (obj.point_type == Global.pointTypes.point) {
  588. content.push(` - ${obj.point_name}`)
  589. if(type == 1 || type == 3)
  590. content.push(`(E${lng}, N${lat})`)
  591. } else if (obj.point_type == Global.pointTypes.nav) {
  592. content.push(` - ${obj.point_code}`)
  593. if(type == 1 || type == 3)
  594. content.push(`(E${lng}, N${lat})`)
  595. } else {
  596. content.push(` - ${obj.air_route_code}`)
  597. }
  598. if(obj.altitude) {
  599. content.push(` - ${getHeight(obj.altitude, obj.unit, type)}`)
  600. }
  601. }
  602. }
  603. content.push(` - ${airspaceInfo.end_loc}`)
  604. if(type == 1 || type == 3)
  605. content.push(`${flyingCenter(airspaceInfo.end_point)}`)
  606. if(isSafeString(airspaceInfo.airline_width)) {
  607. content.push(`,宽度:${airspaceInfo.airline_width}米`)
  608. }
  609. if(isSafeString(airspaceInfo.note)) {
  610. content.push(`,备注: ${airspaceInfo.note}`)
  611. }
  612. let result = content.join("")
  613. return result;
  614. } else {
  615. let content = [];
  616. content.push(`${airspaceInfo.dep.addr}`)
  617. if(type == 1 || type == 3)
  618. content.push(`(E${airspaceInfo.dep.lng}, N${airspaceInfo.dep.lat})`)
  619. content.push(` - ${getHeight(airspaceInfo.dep.height, airspaceInfo.dep.heightStandard, type)}`);
  620. if (Array.isArray(airspaceInfo.passPoints)) {
  621. let length = airspaceInfo.passPoints.length;
  622. for (let i = 0; i < length; i++) {
  623. let obj = airspaceInfo.passPoints[i];
  624. if (obj.pointType == Global.pointTypes.point) {
  625. content.push(` - ${obj.addr}`)
  626. if(type == 1 || type == 3)
  627. content.push(`(E${obj.lng}, N${obj.lat})`);
  628. } else if (obj.pointType == Global.pointTypes.nav) {
  629. content.push(` - ${obj.pointCode}`)
  630. if(type == 1 || type == 3)
  631. content.push(`(E${obj.lng}, N${obj.lat})`);
  632. } else {
  633. content.push(` - ${obj.airlineCode}`);
  634. }
  635. if(obj.height) {
  636. content.push(` - ${getHeight(obj.height, obj.heightStandard, type)}`)
  637. }
  638. }
  639. }
  640. content.push(` - ${airspaceInfo.arrive.addr}`)
  641. if(type == 1 || type == 3)
  642. content.push(`(E${airspaceInfo.arrive.lng}, N${airspaceInfo.arrive.lat})`);
  643. if(airspaceInfo.airlineWidth) {
  644. content.push(`,宽度:${airspaceInfo.airlineWidth}米`)
  645. }
  646. if (airspaceInfo.note)
  647. content.push(`,备注:${airspaceInfo.note}`)
  648. content = content.join('');
  649. return content;
  650. }
  651. }
  652. export function polygonContent(airspaceInfo, type=3) {
  653. if(type == 5)
  654. return getAirspaceName(airspaceInfo)
  655. if('airspace_name' in airspaceInfo) {
  656. let res = []
  657. let points = airspaceInfo.points
  658. for (let i = 0; i < points.length; i++) {
  659. let c = `${points[i].addr ? points[i].addr : ''}`
  660. if(type == 1 || type == 3)
  661. c += `(E${latLngDecimalToDegrees(points[i].lng)}, N${latLngDecimalToDegrees(points[i].lat)})`;
  662. res.push(c)
  663. }
  664. let content = [res.join('、')]
  665. content.push(`${airspaceInfo.points.length}点连线范围内`)
  666. content.push(`,${getHeight(airspaceInfo.altitude, airspaceInfo.unit, type)}`)
  667. if(isSafeString(airspaceInfo.note)) {
  668. content.push(`,备注:${airspaceInfo.note}`)
  669. }
  670. return content.join('');
  671. } else {
  672. let content = [];
  673. let length = airspaceInfo.polygonPoints.length;
  674. for (let i = 0; i < length; i++) {
  675. let obj = airspaceInfo.polygonPoints[i];
  676. let c = `${obj.addr ? obj.addr : ''}`
  677. c += `(E${obj.lng}, N${obj.lat})`
  678. content.push(c)
  679. }
  680. content = content.join('、') + `${length}点连线范围内`
  681. content += `,${getHeight(airspaceInfo.height, airspaceInfo.heightStandard, type)}`
  682. if (airspaceInfo.note)
  683. content = `${content},备注:${airspaceInfo.note}`
  684. return content;
  685. }
  686. }
  687. export {latLngDegreesToDecimal, latLngDecimalToDegrees}