index.js 25 KB

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