index.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const reselect_1 = require("reselect");
  4. const Common_1 = require("./Common");
  5. const Utils_1 = require("./Utils");
  6. exports.latLngDegreesToDecimal = Utils_1.latLngDegreesToDecimal;
  7. exports.latLngDecimalToDegrees = Utils_1.latLngDecimalToDegrees;
  8. let LatLon = require('geodesy').LatLonSpherical;
  9. function getCircleRegions(circle) {
  10. let latlon = new LatLon(circle.coordinate.latitude, circle.coordinate.longitude);
  11. let d1 = latlon.destinationPoint(circle.radius, 0);
  12. let d2 = latlon.destinationPoint(circle.radius, 90);
  13. let d3 = latlon.destinationPoint(circle.radius, 180);
  14. let d4 = latlon.destinationPoint(circle.radius, 270);
  15. 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 }];
  16. }
  17. function getDefaultStyle() {
  18. let imageName = 'BA_oval';
  19. let lineWidth = Common_1.default.amapLineWidth;
  20. let strokeColor = Common_1.default.amapStrokeColor;
  21. let fillColor = Common_1.default.amapFillColor;
  22. return { imageName, lineWidth, strokeColor, fillColor };
  23. }
  24. function getCirclesAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
  25. let circles = [];
  26. let markers = [];
  27. if (!Array.isArray(airspaceInfos)) {
  28. return { circles, markers };
  29. }
  30. let { imageName, 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. imageName = circleStyle.imageName;
  38. }
  39. for (let i = 0; i < airspaceInfos.length; i++) {
  40. let tmpCircle = airspaceInfos[i];
  41. let airspaceTypeFix, radiusFix, dataType;
  42. if (tmpCircle.airspaceType) {
  43. airspaceTypeFix = 'airspaceType';
  44. radiusFix = 'radius';
  45. dataType = 1;
  46. }
  47. else {
  48. airspaceTypeFix = 'airspace_type';
  49. radiusFix = 'radius_of_flying';
  50. dataType = 2;
  51. }
  52. if (tmpCircle[airspaceTypeFix] == Common_1.default.airspaceType.circle && currentAirspaceIndex != i) {
  53. let coordinate = {};
  54. if (tmpCircle.center_point_of_flying) {
  55. coordinate.latitude = tmpCircle.center_point_of_flying.lat;
  56. coordinate.longitude = tmpCircle.center_point_of_flying.lng;
  57. }
  58. else {
  59. coordinate.latitude = Utils_1.latLngDegreesToDecimal(tmpCircle.lat);
  60. coordinate.longitude = Utils_1.latLngDegreesToDecimal(tmpCircle.lng);
  61. }
  62. let radius = tmpCircle[radiusFix];
  63. if (radius) {
  64. let circle = { lineWidth, strokeColor, fillColor, radius, coordinate };
  65. circles.push(circle);
  66. }
  67. else {
  68. markers.push(addOvalPointConfig(coordinate.latitude, coordinate.longitude, imageName, dataType));
  69. }
  70. }
  71. }
  72. return { circles, markers };
  73. }
  74. function getCircleAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
  75. return reselect_1.createSelector(airspaceInfos, () => setStyle, currentAirspaceIndex, getCirclesAndMarkers);
  76. }
  77. function getLatLng(latlng, dataType) {
  78. if (dataType == 1) { // 驼峰模式,新建计划的时候的格式
  79. return Utils_1.latLngDegreesToDecimal(latlng);
  80. }
  81. else {
  82. return latlng;
  83. }
  84. }
  85. function drawLineConfig(lat, lng, dataType) {
  86. return {
  87. latitude: getLatLng(lat, dataType),
  88. longitude: getLatLng(lng, dataType)
  89. };
  90. }
  91. function addOvalPointConfig(lat, lng, imageName, dataType) {
  92. return {
  93. coordinate: {
  94. latitude: getLatLng(lat, dataType),
  95. longitude: getLatLng(lng, dataType)
  96. },
  97. imageName: imageName
  98. };
  99. }
  100. function pointCompare(point1, point2) {
  101. const pointId1 = point1.point_id || point1.pointId;
  102. const pointId2 = point2.point_id || point2.pointId;
  103. if (pointId1 == pointId2) {
  104. return true;
  105. }
  106. let [point1Lat, point1lng] = getFixedLatLng(point1);
  107. let [point2lat, point2lng] = getFixedLatLng(point2);
  108. if (myRound(point1Lat) == myRound(point2lat)
  109. && myRound(point1lng) == myRound(point2lng)) {
  110. return true;
  111. }
  112. else {
  113. return false;
  114. }
  115. }
  116. function getCrossPoint(points1, points2) {
  117. for (let point1 of points1) {
  118. for (let point2 of points2) {
  119. if (pointCompare(point1, point2))
  120. return point1;
  121. }
  122. }
  123. }
  124. function getAirwayPoints(airway, pointBefore, pointAfter) {
  125. let found = 0;
  126. let points = [];
  127. let pointTypeFix, pointsFix;
  128. if ('points' in airway) {
  129. pointTypeFix = 'point_type';
  130. pointsFix = 'points';
  131. }
  132. else {
  133. pointTypeFix = 'pointType';
  134. pointsFix = 'airlines';
  135. }
  136. // 如果前后是其他航线,那么找到交叉点作为前后的点
  137. if (pointBefore[pointTypeFix] == Common_1.default.pointTypes.line) {
  138. pointBefore = getCrossPoint(airway[pointsFix], pointBefore[pointsFix]);
  139. }
  140. if (pointAfter[pointTypeFix] == Common_1.default.pointTypes.line) {
  141. pointAfter = getCrossPoint(airway[pointsFix], pointAfter[pointsFix]);
  142. }
  143. for (let point of airway[pointsFix]) {
  144. if (pointCompare(pointBefore, point) || pointCompare(pointAfter, point)) {
  145. found++;
  146. points.push(Object.assign({}, point));
  147. continue;
  148. }
  149. if (found == 1) {
  150. points.push(Object.assign({}, point));
  151. }
  152. }
  153. if (!(points.length > 0 && found == 2)) {
  154. // 如果两个点不全在航线上面,那么画全部航线
  155. points = airway[pointsFix];
  156. }
  157. return points;
  158. }
  159. function getLinesRouter(lineProps, lineAndMarkerStyle) {
  160. let coordinates = new Array();
  161. let markers = new Array();
  162. let lines = [];
  163. let { imageName, lineWidth, strokeColor } = getDefaultStyle();
  164. if (lineAndMarkerStyle) {
  165. imageName = lineAndMarkerStyle.imageName;
  166. lineWidth = lineAndMarkerStyle.lineWidth;
  167. strokeColor = lineAndMarkerStyle.strokeColor;
  168. }
  169. let startPoint, passPoints, endPoint, pointTypeFix, dataType, airlineWidth;
  170. if (lineProps.start_point) {
  171. dataType = 2; // 下划线模式
  172. startPoint = lineProps['start_point'];
  173. passPoints = lineProps['passing_points'];
  174. endPoint = lineProps['end_point'];
  175. pointTypeFix = 'point_type';
  176. airlineWidth = parseInt(lineProps['airline_width'], 10);
  177. }
  178. else {
  179. dataType = 1; // 驼峰模式
  180. startPoint = lineProps['dep'];
  181. passPoints = lineProps['passPoints'];
  182. endPoint = lineProps['arrive'];
  183. pointTypeFix = 'pointType';
  184. airlineWidth = parseInt(lineProps['airlineWidth'], 10);
  185. }
  186. if (startPoint) {
  187. coordinates.push(drawLineConfig(startPoint.lat, startPoint.lng, dataType));
  188. markers.push(addOvalPointConfig(startPoint.lat, startPoint.lng, imageName, dataType));
  189. }
  190. if (Array.isArray(passPoints)) {
  191. for (let i = 0; i < passPoints.length; i++) {
  192. let obj = passPoints[i];
  193. if (!Utils_1.isObject(obj)) { // 所有的 points/airway 都必须是 obj
  194. continue;
  195. }
  196. let pointType = obj[pointTypeFix];
  197. if (pointType == Common_1.default.pointTypes.point
  198. || pointType == Common_1.default.pointTypes.nav) {
  199. coordinates.push(drawLineConfig(obj.lat, obj.lng, dataType));
  200. markers.push(addOvalPointConfig(obj.lat, obj.lng, imageName, dataType));
  201. }
  202. else {
  203. // 遇到一个航线,不需要和前前面的点连起来
  204. if (coordinates.length > 1) {
  205. lines.push({ lineWidth, strokeColor, coordinates });
  206. }
  207. coordinates = [];
  208. const pointBefore = i == 0 ? startPoint : passPoints[i - 1];
  209. const pointAfter = i == passPoints.length - 1 ? (endPoint ? endPoint : passPoints[passPoints.length - 1]) : passPoints[i + 1];
  210. lines.push({ lineWidth, strokeColor, coordinates: getAirwayPoints(obj, pointBefore, pointAfter) });
  211. }
  212. }
  213. }
  214. if (endPoint) {
  215. coordinates.push(drawLineConfig(endPoint.lat, endPoint.lng, dataType));
  216. markers.push(addOvalPointConfig(endPoint.lat, endPoint.lng, imageName, dataType));
  217. }
  218. if (coordinates.length > 1) {
  219. lines.push({ lineWidth, strokeColor, coordinates });
  220. }
  221. if (airlineWidth > 0) {
  222. // 有宽度的空域,需要线周围多画宽度的多边形
  223. let polygons = processAirlineWidth(lines, airlineWidth);
  224. return { lines, markers, polygons };
  225. }
  226. else {
  227. return { lines, markers, polygons: [] };
  228. }
  229. }
  230. function getFixedLatLng(point) {
  231. let lat = point.latitude ? point.latitude : point.lat;
  232. let lng = point.longitude ? point.longitude : point.lng;
  233. // 复制计划的数据,有的点是度数模式如 38°35′17″
  234. if (Utils_1.isSafeString(lat)) {
  235. lat = Utils_1.latLngDegreesToDecimal(lat);
  236. lng = Utils_1.latLngDegreesToDecimal(lng);
  237. }
  238. return [lat, lng];
  239. }
  240. function processAirlineWidth(lines, airlineWidth) {
  241. let polygons = [];
  242. let { strokeColor, fillColor } = getDefaultStyle();
  243. for (let line of lines) {
  244. let points = line.coordinates;
  245. for (let i = 0; i < points.length - 1; i++) {
  246. let [lat1, lng1] = getFixedLatLng(points[i]);
  247. let [lat2, lng2] = getFixedLatLng(points[i + 1]);
  248. let point1 = new LatLon(lat1, lng1);
  249. let point2 = new LatLon(lat2, lng2);
  250. let coordinates = getCirclePoints(point1, point2, airlineWidth);
  251. polygons.push({ lineWidth: 1, strokeColor, fillColor, coordinates });
  252. }
  253. }
  254. return polygons;
  255. }
  256. function getCirclePoints(point1, point2, width) {
  257. let percision = 10; // 半圆处理为多边形的时候,半圆上取几个点
  258. let step = 180 / percision;
  259. let bearing = (360 + point1.bearingTo(point2) - 90) % 360; // 取正值
  260. let points = [];
  261. for (let diff = 0; diff <= 180; diff += step) {
  262. let point = point2.destinationPoint(width, bearing + diff);
  263. points.push({ lat: point.lat, lng: point.lon });
  264. }
  265. for (let diff = 180; diff <= 360; diff += step) {
  266. let point = point1.destinationPoint(width, bearing + diff);
  267. points.push({ lat: point.lat, lng: point.lon });
  268. }
  269. return points;
  270. }
  271. function myRound(num, digits) {
  272. if (digits == null)
  273. digits = 6; // 比较的精度,经纬度会被经过度分秒方式到浮点方式的转化
  274. return Math.round(num * Math.pow(10, digits)) / Math.pow(10, digits);
  275. }
  276. function getLinesPolygonsAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
  277. let retLines = [];
  278. let retMarkers = [];
  279. let retPolygons = [];
  280. if (!Array.isArray(airspaceInfos)) {
  281. return { lines: retLines, markers: retMarkers, polygons: retPolygons };
  282. }
  283. let lineStyle = setStyle('line');
  284. for (let i = 0; i < airspaceInfos.length; i++) {
  285. let tmpLine = airspaceInfos[i];
  286. let airspaceTypeFix;
  287. if (tmpLine.airspaceType)
  288. airspaceTypeFix = 'airspaceType';
  289. else
  290. airspaceTypeFix = 'airspace_type';
  291. if (tmpLine[airspaceTypeFix] == Common_1.default.airspaceType.line && currentAirspaceIndex != i) {
  292. let { lines, markers, polygons } = getLinesRouter(tmpLine, lineStyle);
  293. retMarkers.push(...markers);
  294. retLines.push(...lines);
  295. retPolygons.push(...polygons);
  296. }
  297. }
  298. return { lines: retLines, markers: retMarkers, polygons: retPolygons };
  299. }
  300. function getLinePolygonsAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
  301. return reselect_1.createSelector(airspaceInfos, () => setStyle, currentAirspaceIndex, getLinesPolygonsAndMarkers);
  302. }
  303. function getPolygon(polygonProps, polygonAndMarkerStyle) {
  304. let coordinates = new Array();
  305. let markers = new Array();
  306. let { imageName, lineWidth, strokeColor, fillColor } = getDefaultStyle();
  307. if (polygonAndMarkerStyle) {
  308. imageName = polygonAndMarkerStyle.imageName;
  309. lineWidth = polygonAndMarkerStyle.lineWidth;
  310. strokeColor = polygonAndMarkerStyle.strokeColor;
  311. fillColor = polygonAndMarkerStyle.fillColor;
  312. }
  313. let pointsFix, dataType;
  314. if (polygonProps.points) {
  315. pointsFix = 'points';
  316. dataType = 2;
  317. }
  318. else {
  319. pointsFix = 'polygonPoints';
  320. dataType = 1; // 驼峰模式
  321. }
  322. if (Array.isArray(polygonProps[pointsFix])) {
  323. for (let obj of polygonProps[pointsFix]) {
  324. if (!obj) {
  325. continue;
  326. }
  327. coordinates.push(drawLineConfig(obj.lat, obj.lng, dataType));
  328. markers.push(addOvalPointConfig(obj.lat, obj.lng, imageName, dataType));
  329. }
  330. }
  331. let polygon = { lineWidth, strokeColor, fillColor, coordinates };
  332. return { markers, polygon };
  333. }
  334. function getPolygonsAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
  335. let markers = [];
  336. let polygons = [];
  337. if (!Array.isArray(airspaceInfos)) {
  338. return { markers, polygons };
  339. }
  340. let polygonAndMarkerStyle = setStyle('polygon');
  341. for (let i = 0; i < airspaceInfos.length; i++) {
  342. let polygon = airspaceInfos[i];
  343. let airspaceTypeFix;
  344. if (polygon.airspaceType)
  345. airspaceTypeFix = 'airspaceType';
  346. else
  347. airspaceTypeFix = 'airspace_type';
  348. if (polygon[airspaceTypeFix] == Common_1.default.airspaceType.polygon && currentAirspaceIndex != i) {
  349. let retObj = getPolygon(polygon, polygonAndMarkerStyle);
  350. markers.push(...retObj.markers);
  351. polygons.push(retObj.polygon);
  352. }
  353. }
  354. return { markers, polygons };
  355. }
  356. function getPolygonAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
  357. return reselect_1.createSelector(airspaceInfos, () => setStyle, currentAirspaceIndex, getPolygonsAndMarkers);
  358. }
  359. function getMarkers(circlesAndMarkers, polygonAndMarkers, lineAndMarkers) {
  360. let markers = [];
  361. if (circlesAndMarkers) {
  362. markers = [...circlesAndMarkers.markers];
  363. }
  364. if (polygonAndMarkers) {
  365. markers = [...markers, ...polygonAndMarkers.markers];
  366. }
  367. if (lineAndMarkers) {
  368. markers = [...markers, ...lineAndMarkers.markers];
  369. }
  370. return markers;
  371. }
  372. function getMarkerSelector(circlesAndMarkers, polygonAndMarkers, lineAndMarkers) {
  373. return reselect_1.createSelector(circlesAndMarkers, polygonAndMarkers, lineAndMarkers, getMarkers);
  374. }
  375. function getRegionPoints(circles, lineAndMarkers, polygonAndMarkers) {
  376. let regionPoints = new Array();
  377. for (let i = 0; i < circles.length; i++) {
  378. regionPoints.push(...getCircleRegions(circles[i]));
  379. }
  380. let lines = lineAndMarkers.lines;
  381. for (let i = 0; i < lines.length; i++) {
  382. regionPoints.push(...lines[i].coordinates);
  383. }
  384. let polygons = polygonAndMarkers.polygons;
  385. for (let i = 0; i < polygons.length; i++) {
  386. regionPoints.push(...polygons[i].coordinates);
  387. }
  388. return regionPoints;
  389. }
  390. function getRegionPointsSelector(circles, lineAndMarkers, polygonAndMarkers) {
  391. return reselect_1.createSelector(circles, lineAndMarkers, polygonAndMarkers, getRegionPoints);
  392. }
  393. function getCircles(circleAndMarker) {
  394. return circleAndMarker.circles;
  395. }
  396. function getCircleSelector(circleAndMarker) {
  397. return reselect_1.createSelector(circleAndMarker, getCircles);
  398. }
  399. function getLines(lineAndMarker) {
  400. return lineAndMarker.lines;
  401. }
  402. function getLineSelector(lineAndMarker) {
  403. return reselect_1.createSelector(lineAndMarker, getLines);
  404. }
  405. function getPolygons(polygonAndMarkers, linePolygonsAndMarkers) {
  406. return [...polygonAndMarkers.polygons, ...linePolygonsAndMarkers.polygons];
  407. }
  408. function getPolygonSelector(polygonAndMarkers, linePolygonsAndMarkers) {
  409. return reselect_1.createSelector(polygonAndMarkers, linePolygonsAndMarkers, getPolygons);
  410. }
  411. let setStyle = (style) => {
  412. if (!style)
  413. return () => { return null; };
  414. else
  415. return (shapeName) => style[shapeName];
  416. };
  417. //获取selector
  418. function getShapesSelector(airspaceInfos, style, currentAirspaceIndex) {
  419. currentAirspaceIndex = currentAirspaceIndex ? currentAirspaceIndex : () => -1;
  420. let circlesAndMarkers = getCircleAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
  421. let circles = getCircleSelector(circlesAndMarkers);
  422. let linePolygonsAndMarkers = getLinePolygonsAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
  423. let lines = getLineSelector(linePolygonsAndMarkers);
  424. let polygonAndMarkers = getPolygonAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
  425. let polygons = getPolygonSelector(polygonAndMarkers, linePolygonsAndMarkers);
  426. let markers = getMarkerSelector(circlesAndMarkers, polygonAndMarkers, linePolygonsAndMarkers);
  427. let regionPoints = getRegionPointsSelector(circles, linePolygonsAndMarkers, polygonAndMarkers);
  428. return {
  429. markers,
  430. circles,
  431. lines,
  432. polygons,
  433. regionPoints
  434. };
  435. }
  436. exports.getShapesSelector = getShapesSelector;
  437. //获取数组
  438. function getShapes(airspaceInfos, style, currentAirspaceIndex) {
  439. let { markers, polygons, circles, lines, regionPoints } = getShapesSelector((airspaceInfos) => airspaceInfos, style, (currentAirspaceIndex) => currentAirspaceIndex);
  440. return {
  441. markers: markers(airspaceInfos),
  442. circles: circles(airspaceInfos),
  443. lines: lines(airspaceInfos),
  444. polygons: polygons(airspaceInfos),
  445. regionPoints: regionPoints(airspaceInfos)
  446. };
  447. }
  448. exports.getShapes = getShapes;
  449. // 总共 5 种格式, http://git.corp.brilliantaero.com/BA/Coco/issues/99#note_6358
  450. // 1. 全输出格式
  451. // 2. 简化格式
  452. // 3. 传真格式
  453. // 4. 用户端用的简化格式
  454. // 5. 极简格式
  455. function getHeight(num, unit, type) {
  456. let shortNum;
  457. if (num >= 100) {
  458. shortNum = parseInt(num / 100).toString();
  459. if (shortNum.length < 2) {
  460. shortNum = '0' + shortNum;
  461. }
  462. }
  463. let heightStandard = Common_1.default.heightStandardsById.get(unit);
  464. if (!heightStandard) {
  465. heightStandard = unit;
  466. }
  467. // 这里统一使用数字判断
  468. let standardUnit = Common_1.default.heightStandards.get(heightStandard);
  469. let heightDesc;
  470. switch (standardUnit) {
  471. case 1:
  472. heightDesc = ['H*真', '真高*米'];
  473. break;
  474. case 2:
  475. heightDesc = ['H*标(含以下)', '标高*米(含以下)'];
  476. break;
  477. case 3:
  478. heightDesc = ['H*真(含以下)', '真高*米(含以下)'];
  479. break;
  480. default:
  481. heightDesc = ['H*标', '标高*米'];
  482. }
  483. if (shortNum && (type == 1 || type == 2)) {
  484. // H02真,H02真(含以下)
  485. return heightDesc[0].replace('*', shortNum);
  486. }
  487. else {
  488. // 真高200米,真高200米(含以下)
  489. return heightDesc[1].replace('*', num);
  490. }
  491. }
  492. function getAirspaceName(airspaceInfo) {
  493. if (airspaceInfo.airspace_name) {
  494. return airspaceInfo.airspace_name;
  495. }
  496. else {
  497. return airspaceInfo.name;
  498. }
  499. }
  500. function circleContent(airspaceInfo, type = 3) {
  501. if (type == 5)
  502. return getAirspaceName(airspaceInfo);
  503. if ('airspace_name' in airspaceInfo) {
  504. const lat = Utils_1.latLngDecimalToDegrees(airspaceInfo.center_point_of_flying.lat);
  505. const lng = Utils_1.latLngDecimalToDegrees(airspaceInfo.center_point_of_flying.lng);
  506. let content = [];
  507. let loc = `以${airspaceInfo.center_loc}`;
  508. if (type == 1 || type == 3)
  509. loc += `(E${lng}, N${lat})`;
  510. content.push(`${loc}为中心`);
  511. content.push(`半径${airspaceInfo.radius_of_flying}米`);
  512. content.push(getHeight(airspaceInfo.altitude, airspaceInfo.unit, type));
  513. if (airspaceInfo.note)
  514. content.push(`备注:${airspaceInfo.note}`);
  515. let result = content = content.join(',');
  516. return result;
  517. }
  518. else {
  519. let content = [];
  520. let loc = `以${airspaceInfo.addr}`;
  521. if (type == 1 || type == 3)
  522. loc += `(E${airspaceInfo.lng}, N${airspaceInfo.lat})`;
  523. content.push(`${loc}为中心`);
  524. content.push(`半径${airspaceInfo.radius}米`);
  525. content.push(getHeight(airspaceInfo.height, airspaceInfo.heightStandard, type));
  526. if (airspaceInfo.note)
  527. content.push(`备注:${airspaceInfo.note}`);
  528. content = content.join(',');
  529. return content;
  530. }
  531. }
  532. exports.circleContent = circleContent;
  533. function flyingCenter(item = {}) {
  534. if (item == {}) {
  535. return;
  536. }
  537. else {
  538. return ("(E" + Utils_1.latLngDecimalToDegrees(item.lng) +
  539. ', ' +
  540. "N" + Utils_1.latLngDecimalToDegrees(item.lat) + ")");
  541. }
  542. }
  543. function lineContent(airspaceInfo, type = 3) {
  544. if (type == 5)
  545. return getAirspaceName(airspaceInfo);
  546. if ('airspace_name' in airspaceInfo) {
  547. let content = [];
  548. content.push(`${airspaceInfo.start_loc}`);
  549. if (type == 1 || type == 3)
  550. content.push(`${flyingCenter(airspaceInfo.start_point)}`);
  551. content.push(` - `);
  552. content.push(getHeight(airspaceInfo.start_point.altitude, airspaceInfo.start_point.unit, type));
  553. const passing_points = airspaceInfo.passing_points;
  554. if (Array.isArray(passing_points)) {
  555. for (let i = 0; i < passing_points.length; i++) {
  556. const obj = passing_points[i];
  557. const lat = Utils_1.latLngDecimalToDegrees(obj.lat);
  558. const lng = Utils_1.latLngDecimalToDegrees(obj.lng);
  559. if (obj.point_type == Common_1.default.pointTypes.point) {
  560. content.push(` - ${obj.point_name}`);
  561. if (type == 1 || type == 3)
  562. content.push(`(E${lng}, N${lat})`);
  563. }
  564. else if (obj.point_type == Common_1.default.pointTypes.nav) {
  565. content.push(` - ${obj.point_code}`);
  566. if (type == 1 || type == 3)
  567. content.push(`(E${lng}, N${lat})`);
  568. }
  569. else {
  570. content.push(` - ${obj.air_route_code}`);
  571. }
  572. if (obj.altitude) {
  573. content.push(` - ${getHeight(obj.altitude, obj.unit, type)}`);
  574. }
  575. }
  576. }
  577. content.push(` - ${airspaceInfo.end_loc}`);
  578. if (type == 1 || type == 3)
  579. content.push(`${flyingCenter(airspaceInfo.end_point)}`);
  580. if (Utils_1.isSafeString(airspaceInfo.airline_width)) {
  581. content.push(`,宽度:${airspaceInfo.airline_width}米`);
  582. }
  583. if (Utils_1.isSafeString(airspaceInfo.note)) {
  584. content.push(`,备注: ${airspaceInfo.note}`);
  585. }
  586. let result = content.join("");
  587. return result;
  588. }
  589. else {
  590. let content = [];
  591. content.push(`${airspaceInfo.dep.addr}`);
  592. if (type == 1 || type == 3)
  593. content.push(`(E${airspaceInfo.dep.lng}, N${airspaceInfo.dep.lat})`);
  594. content.push(` - ${getHeight(airspaceInfo.dep.height, airspaceInfo.dep.heightStandard, type)}`);
  595. if (Array.isArray(airspaceInfo.passPoints)) {
  596. let length = airspaceInfo.passPoints.length;
  597. for (let i = 0; i < length; i++) {
  598. let obj = airspaceInfo.passPoints[i];
  599. if (obj.pointType == Common_1.default.pointTypes.point) {
  600. content.push(` - ${obj.addr}`);
  601. if (type == 1 || type == 3)
  602. content.push(`(E${obj.lng}, N${obj.lat})`);
  603. }
  604. else if (obj.pointType == Common_1.default.pointTypes.nav) {
  605. content.push(` - ${obj.pointCode}`);
  606. if (type == 1 || type == 3)
  607. content.push(`(E${obj.lng}, N${obj.lat})`);
  608. }
  609. else {
  610. content.push(` - ${obj.airlineCode}`);
  611. }
  612. if (obj.height) {
  613. content.push(` - ${getHeight(obj.height, obj.heightStandard, type)}`);
  614. }
  615. }
  616. }
  617. content.push(` - ${airspaceInfo.arrive.addr}`);
  618. if (type == 1 || type == 3)
  619. content.push(`(E${airspaceInfo.arrive.lng}, N${airspaceInfo.arrive.lat})`);
  620. if (airspaceInfo.airlineWidth) {
  621. content.push(`,宽度:${airspaceInfo.airlineWidth}米`);
  622. }
  623. if (airspaceInfo.note)
  624. content.push(`,备注:${airspaceInfo.note}`);
  625. content = content.join('');
  626. return content;
  627. }
  628. }
  629. exports.lineContent = lineContent;
  630. function polygonContent(airspaceInfo, type = 3) {
  631. if (type == 5)
  632. return getAirspaceName(airspaceInfo);
  633. if ('airspace_name' in airspaceInfo) {
  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${Utils_1.latLngDecimalToDegrees(points[i].lng)}, N${Utils_1.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 (Utils_1.isSafeString(airspaceInfo.note)) {
  646. content.push(`,备注:${airspaceInfo.note}`);
  647. }
  648. return content.join('');
  649. }
  650. else {
  651. let content = [];
  652. let length = airspaceInfo.polygonPoints.length;
  653. for (let i = 0; i < length; i++) {
  654. let obj = airspaceInfo.polygonPoints[i];
  655. let c = `${obj.addr ? obj.addr : ''}`;
  656. if (type == 1 || type == 3)
  657. c += `(E${obj.lng}, N${obj.lat})`;
  658. content.push(c);
  659. }
  660. content = content.join('、') + `${length}点连线范围内`;
  661. content += `,${getHeight(airspaceInfo.height, airspaceInfo.heightStandard, type)}`;
  662. if (airspaceInfo.note)
  663. content = `${content},备注:${airspaceInfo.note}`;
  664. return content;
  665. }
  666. }
  667. exports.polygonContent = polygonContent;