index.js 23 KB

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