| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889 |
- import { createSelector } from 'reselect';
- import Global from './Common';
- import { latLngDegreesToDecimal, latLngDecimalToDegrees, isObject, isSafeString, hasPoint, isNumber } from './Utils';
- let LatLon = require('geodesy').LatLonSpherical;
- export function convertAirspaceInfoServerToLocal(airspaceInfo) {
- const airspaceType = airspaceInfo.airspace_type;
- if (airspaceType == Global.airspaceType.circle) {
- const ai = airspaceInfo;
- return {
- airspaceType,
- airspaceId: ai.airspace_id,
- name: ai.airspace_name,
- note: ai.note,
- addr: ai.center_loc,
- lat: ai.center_point_of_flying.lat,
- lng: ai.center_point_of_flying.lng,
- radius: ai.radius_of_flying,
- height: ai.altitude + "",
- heightStandard: Global.heightStandardsById.get(ai.unit)
- };
- }
- if (airspaceType == Global.airspaceType.line) {
- const ai = airspaceInfo;
- let dep = {
- addr: ai.start_loc,
- lat: ai.start_point.lat,
- lng: ai.start_point.lng,
- height: ai.start_point.altitude + "",
- heightStandard: Global.heightStandardsById.get(ai.start_point.unit)
- };
- let arrive = {
- addr: ai.end_loc,
- lat: ai.end_point.lat,
- lng: ai.end_point.lng
- };
- let passPoints = [];
- if (Array.isArray(ai.passing_points)) {
- for (let obj of ai.passing_points) {
- let point;
- if (obj.point_type == Global.pointTypes.point) {
- const pp = obj;
- const lat = pp.lat;
- const lng = pp.lng;
- point = {
- pointType: pp.point_type,
- addr: pp.point_name,
- lat, lng
- };
- }
- else if (obj.point_type == Global.pointTypes.nav) {
- const pp = obj;
- const lat = pp.lat;
- const lng = pp.lng;
- point = {
- pointType: pp.point_type,
- pointId: pp.point_id,
- pointCode: pp.point_code,
- pointName: pp.point_name,
- lat, lng
- };
- }
- else {
- const pp = obj;
- point = {
- pointType: pp.point_type,
- airRouteId: pp.airway,
- airlineCode: pp.air_route_code,
- airlines: pp.points
- };
- }
- if (isNumber(obj.altitude) && isNumber(obj.unit)) {
- point.height = obj.altitude + "";
- point.heightStandard = Global.heightStandardsById.get(obj.unit);
- }
- else {
- point.height = "";
- point.heightStandard = [...Global.heightStandards.keys()][0];
- }
- passPoints.push(point);
- }
- }
- return Object.assign({
- airspaceType,
- airspaceId: ai.airspace_id,
- name: ai.airspace_name,
- note: ai.note,
- dep,
- arrive,
- passPoints
- }, (ai.airline_width ? { airlineWidth: ai.airline_width } : {}));
- }
- if (airspaceType == Global.airspaceType.polygon) {
- const ai = airspaceInfo;
- if (Array.isArray(ai.points)) {
- let polygonPoints = new Array();
- let defaultPointName = 'A';
- for (let obj of ai.points) {
- let addr = obj.addr;
- if (!addr) {
- addr = defaultPointName;
- defaultPointName = String.fromCharCode(defaultPointName.charCodeAt(0) + 1);
- }
- polygonPoints.push({ addr, lat: obj.lat, lng: obj.lng });
- }
- return {
- airspaceType,
- airspaceId: ai.airspace_id,
- name: ai.airspace_name,
- note: ai.note,
- height: ai.altitude + '',
- heightStandard: Global.heightStandardsById.get(ai.unit),
- polygonPoints
- };
- }
- }
- return null;
- }
- export function convertAirspaceInfoLocalToServer(airspace) {
- if (airspace.airspaceType == Global.airspaceType.circle) {
- const ai = airspace;
- const circle = {
- airspace_name: ai.name,
- airspace_id: ai.airspaceId,
- airspace_type: Global.airspaceType.circle,
- note: isSafeString(ai.note) ? ai.note : null,
- radius_of_flying: parseInt(ai.radius + ''),
- center_point_of_flying: {
- lng: ai.lng,
- lat: ai.lat
- },
- center_loc: ai.addr,
- altitude: parseInt(ai.height),
- unit: Global.heightStandards.get(ai.heightStandard)
- };
- return circle;
- }
- else if (airspace.airspaceType == Global.airspaceType.line) {
- const ai = airspace;
- let line = {
- airspace_name: ai.name,
- airspace_id: ai.airspaceId,
- airspace_type: Global.airspaceType.line,
- note: ai.note,
- start_loc: ai.dep.addr,
- start_point: {
- lng: ai.dep.lng,
- lat: ai.dep.lat,
- altitude: parseInt(ai.dep.height),
- unit: Global.heightStandards.get(ai.dep.heightStandard)
- },
- end_loc: ai.arrive.addr,
- end_point: {
- lng: ai.arrive.lng,
- lat: ai.arrive.lat
- }
- };
- if (ai.airlineWidth) {
- line['airline_width'] = ai.airlineWidth;
- }
- if (Array.isArray(ai.passPoints) && ai.passPoints.length > 0) {
- let passing_points = [];
- for (let obj of ai.passPoints) {
- let retObj;
- if (obj.pointType == Global.pointTypes.point && hasPoint(obj)) {
- const pp = obj;
- retObj = {
- point_type: Global.pointTypes.point,
- point_name: pp.addr,
- lat: pp.lat,
- lng: pp.lng
- };
- }
- else if (obj.pointType == Global.pointTypes.nav) {
- const pp = obj;
- retObj = {
- point_type: Global.pointTypes.nav,
- point_name: pp.pointName,
- point_id: pp.pointId,
- point_code: pp.pointCode,
- lat: pp.lat,
- lng: pp.lng
- };
- }
- else {
- const pp = obj;
- retObj = {
- point_type: Global.pointTypes.line,
- airway: pp.airRouteId,
- air_route_code: pp.airlineCode,
- points: pp.airlines
- };
- }
- if (isSafeString(obj.height) && isSafeString(obj.heightStandard)) {
- retObj.altitude = parseInt(obj.height);
- // @ts-ignore
- retObj.unit = Global.heightStandards.get(obj.heightStandard);
- }
- passing_points.push(retObj);
- }
- line.passing_points = passing_points;
- }
- else {
- line.passing_points = [];
- }
- return line;
- }
- else {
- const ai = airspace;
- const polygon = {
- airspace_name: ai.name,
- airspace_id: ai.airspaceId,
- airspace_type: Global.airspaceType.polygon,
- note: ai.note,
- altitude: parseInt(ai.height),
- unit: Global.heightStandards.get(ai.heightStandard),
- points: ai.polygonPoints
- };
- return polygon;
- }
- }
- function getCircleRegions(circle) {
- let lat, lng;
- if (circle.coordinate.latitude) {
- let coord = circle.coordinate;
- lat = coord.latitude;
- lng = coord.longitude;
- }
- else {
- let coord = circle.coordinate;
- lat = coord.lat;
- lng = coord.lng;
- }
- let latlon = new LatLon(lat, lng);
- let d1 = latlon.destinationPoint(circle.radius, 0);
- let d2 = latlon.destinationPoint(circle.radius, 90);
- let d3 = latlon.destinationPoint(circle.radius, 180);
- let d4 = latlon.destinationPoint(circle.radius, 270);
- 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 }];
- }
- function getDefaultStyle() {
- let imageName = 'BA_oval';
- let lineWidth = Global.amapLineWidth;
- let strokeColor = Global.amapStrokeColor;
- let fillColor = Global.amapFillColor;
- return { imageName, lineWidth, strokeColor, fillColor };
- }
- function getCirclesAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
- let circles = [];
- let markers = [];
- if (!Array.isArray(airspaceInfos)) {
- return { circles, markers };
- }
- let { imageName, lineWidth, strokeColor, fillColor } = getDefaultStyle();
- //通过该方法获取样式
- let circleStyle = setStyle('circle');
- if (circleStyle) {
- lineWidth = circleStyle.lineWidth;
- strokeColor = circleStyle.strokeColor;
- fillColor = circleStyle.fillColor;
- imageName = circleStyle.imageName;
- }
- for (let i = 0; i < airspaceInfos.length; i++) {
- let tmpCircle = airspaceInfos[i];
- let airspaceTypeFix, radiusFix;
- if (tmpCircle.airspaceType) {
- airspaceTypeFix = 'airspaceType';
- radiusFix = 'radius';
- }
- else {
- airspaceTypeFix = 'airspace_type';
- radiusFix = 'radius_of_flying';
- }
- if (tmpCircle[airspaceTypeFix] == Global.airspaceType.circle && currentAirspaceIndex != i) {
- let coordinate = { latitude: 0, longitude: 0 };
- if (tmpCircle.center_point_of_flying) {
- let ai = tmpCircle;
- coordinate.latitude = ai.center_point_of_flying.lat;
- coordinate.longitude = ai.center_point_of_flying.lng;
- }
- else {
- let ai = tmpCircle;
- coordinate.latitude = ai.lat;
- coordinate.longitude = ai.lng;
- }
- let radius = tmpCircle[radiusFix];
- if (radius) {
- let circle = { lineWidth, strokeColor, fillColor, radius, coordinate };
- circles.push(circle);
- }
- else {
- markers.push(addOvalPointConfig(coordinate.latitude, coordinate.longitude, imageName));
- }
- }
- }
- return { circles, markers };
- }
- function getCircleAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
- return createSelector(airspaceInfos, () => setStyle, currentAirspaceIndex, getCirclesAndMarkers);
- }
- function drawLineConfig(lat, lng) {
- return {
- latitude: lat,
- longitude: lng
- };
- }
- function addOvalPointConfig(lat, lng, imageName) {
- return {
- coordinate: {
- latitude: lat,
- longitude: lng
- },
- imageName: imageName
- };
- }
- function pointCompare(point1, point2) {
- if (!point1 || !point2) {
- return false;
- }
- const pointId1 = point1.point_id;
- const pointId2 = point2.point_id;
- if (pointId1 == pointId2) {
- return true;
- }
- let [point1Lat, point1lng] = getFixedLatLng(point1);
- let [point2lat, point2lng] = getFixedLatLng(point2);
- if (myRound(point1Lat) == myRound(point2lat)
- && myRound(point1lng) == myRound(point2lng)) {
- return true;
- }
- else {
- return false;
- }
- }
- function getCrossPoint(points1, points2) {
- for (let point1 of points1) {
- for (let point2 of points2) {
- if (pointCompare(point1, point2))
- return point1;
- }
- }
- return undefined;
- }
- function getAirwayPoints(airway, pointBefore, pointAfter) {
- let found = 0;
- let points = [];
- let pointTypeFix, pointsFix, airRoutePoint;
- if ('points' in airway) {
- pointTypeFix = 'point_type';
- pointsFix = 'points';
- airRoutePoint = airway['points'];
- }
- else {
- pointTypeFix = 'pointType';
- pointsFix = 'airlines';
- airRoutePoint = airway['airlines'];
- }
- let crossPointBefore, crossPointAfter;
- // 如果前后是其他航线,那么找到交叉点作为前后的点
- if (pointBefore[pointTypeFix] == Global.pointTypes.line) {
- crossPointBefore = getCrossPoint(airRoutePoint, pointBefore[pointsFix]);
- }
- if (pointAfter[pointTypeFix] == Global.pointTypes.line) {
- crossPointAfter = getCrossPoint(airRoutePoint, pointAfter[pointsFix]);
- }
- for (let point of airRoutePoint) {
- if (pointCompare(crossPointBefore, point) || pointCompare(crossPointAfter, point)) {
- found++;
- points.push(Object.assign({}, point));
- continue;
- }
- if (found == 1) {
- points.push(Object.assign({}, point));
- }
- }
- if (!(points.length > 0 && found == 2)) {
- // 如果两个点不全在航线上面,那么画全部航线
- points = airRoutePoint;
- }
- return points;
- }
- function getLinesRouter(lineProps, lineAndMarkerStyle) {
- let coordinates = new Array();
- let markers = new Array();
- let lines = [];
- let { imageName, lineWidth, strokeColor } = getDefaultStyle();
- if (lineAndMarkerStyle) {
- imageName = lineAndMarkerStyle.imageName;
- lineWidth = lineAndMarkerStyle.lineWidth;
- strokeColor = lineAndMarkerStyle.strokeColor;
- }
- let startPoint, passPoints, endPoint, pointTypeFix, airlineWidth;
- if (lineProps.start_point) {
- let ll = lineProps;
- startPoint = ll['start_point'];
- passPoints = ll['passing_points'];
- endPoint = ll['end_point'];
- pointTypeFix = 'point_type';
- airlineWidth = parseInt(ll['airline_width'] + '', 10);
- }
- else {
- let ll = lineProps;
- startPoint = ll['dep'];
- passPoints = ll['passPoints'];
- endPoint = ll['arrive'];
- pointTypeFix = 'pointType';
- airlineWidth = parseInt(ll['airlineWidth'] + '', 10);
- }
- if (startPoint) {
- coordinates.push(drawLineConfig(startPoint.lat, startPoint.lng));
- markers.push(addOvalPointConfig(startPoint.lat, startPoint.lng, imageName));
- }
- if (Array.isArray(passPoints)) {
- for (let i = 0; i < passPoints.length; i++) {
- let obj = passPoints[i];
- if (!isObject(obj)) { // 所有的 points/airway 都必须是 obj
- continue;
- }
- let pointType = obj[pointTypeFix];
- if (pointType == Global.pointTypes.point
- || pointType == Global.pointTypes.nav) {
- let pp = obj;
- coordinates.push(drawLineConfig(pp.lat, pp.lng));
- markers.push(addOvalPointConfig(pp.lat, pp.lng, imageName));
- }
- else {
- // 遇到一个航线,不需要和前前面的点连起来
- let pp = obj;
- if (coordinates.length > 1) {
- lines.push({ lineWidth, strokeColor, coordinates });
- }
- coordinates = [];
- const pointBefore = i == 0 ? startPoint : passPoints[i - 1];
- const pointAfter = i == passPoints.length - 1 ? (endPoint ? endPoint : passPoints[passPoints.length - 1]) : passPoints[i + 1];
- lines.push({ lineWidth, strokeColor, coordinates: getAirwayPoints(pp, pointBefore, pointAfter) });
- }
- }
- }
- if (endPoint) {
- coordinates.push(drawLineConfig(endPoint.lat, endPoint.lng));
- markers.push(addOvalPointConfig(endPoint.lat, endPoint.lng, imageName));
- }
- if (coordinates.length > 1) {
- lines.push({ lineWidth, strokeColor, coordinates });
- }
- if (airlineWidth > 0) {
- // 有宽度的空域,需要线周围多画宽度的多边形
- let polygons = processAirlineWidth(lines, airlineWidth);
- return { lines, markers, polygons };
- }
- else {
- return { lines, markers, polygons: [] };
- }
- }
- function getFixedLatLng(point) {
- let pp = point;
- let lat = pp.latitude ? pp.latitude : pp.lat;
- let lng = pp.longitude ? pp.longitude : pp.lng;
- return [lat, lng];
- }
- function processAirlineWidth(lines, airlineWidth) {
- let polygons = [];
- let { strokeColor, fillColor } = getDefaultStyle();
- for (let line of lines) {
- let points = line.coordinates;
- for (let i = 0; i < points.length - 1; i++) {
- let [lat1, lng1] = getFixedLatLng(points[i]);
- let [lat2, lng2] = getFixedLatLng(points[i + 1]);
- let point1 = new LatLon(lat1, lng1);
- let point2 = new LatLon(lat2, lng2);
- let coordinates = getCirclePoints(point1, point2, airlineWidth);
- polygons.push({ lineWidth: 1, strokeColor, fillColor, coordinates });
- }
- }
- return polygons;
- }
- function getCirclePoints(point1, point2, width) {
- let percision = 10; // 半圆处理为多边形的时候,半圆上取几个点
- let step = 180 / percision;
- let bearing = (360 + point1.bearingTo(point2) - 90) % 360; // 取正值
- let points = [];
- for (let diff = 0; diff <= 180; diff += step) {
- let point = point2.destinationPoint(width, bearing + diff);
- points.push({ lat: point.lat, lng: point.lon });
- }
- for (let diff = 180; diff <= 360; diff += step) {
- let point = point1.destinationPoint(width, bearing + diff);
- points.push({ lat: point.lat, lng: point.lon });
- }
- return points;
- }
- function myRound(num, digits) {
- if (digits == null)
- digits = 6; // 比较的精度,经纬度会被经过度分秒方式到浮点方式的转化
- return Math.round(num * Math.pow(10, digits)) / Math.pow(10, digits);
- }
- function getLinesPolygonsAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
- let retLines = [];
- let retMarkers = [];
- let retPolygons = [];
- if (!Array.isArray(airspaceInfos)) {
- return { lines: retLines, markers: retMarkers, polygons: retPolygons };
- }
- let lineStyle = setStyle('line');
- for (let i = 0; i < airspaceInfos.length; i++) {
- let tmpLine = airspaceInfos[i];
- let airspaceTypeFix;
- if (tmpLine.airspaceType)
- airspaceTypeFix = 'airspaceType';
- else
- airspaceTypeFix = 'airspace_type';
- if (tmpLine[airspaceTypeFix] == Global.airspaceType.line && currentAirspaceIndex != i) {
- let lineProps = tmpLine;
- let { lines, markers, polygons } = getLinesRouter(lineProps, lineStyle);
- retMarkers.push(...markers);
- retLines.push(...lines);
- retPolygons.push(...polygons);
- }
- }
- return { lines: retLines, markers: retMarkers, polygons: retPolygons };
- }
- function getLinePolygonsAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
- return createSelector(airspaceInfos, () => setStyle, currentAirspaceIndex, getLinesPolygonsAndMarkers);
- }
- function getPolygon(polygonProps, polygonAndMarkerStyle) {
- let coordinates = new Array();
- let markers = new Array();
- let { imageName, lineWidth, strokeColor, fillColor } = getDefaultStyle();
- if (polygonAndMarkerStyle) {
- imageName = polygonAndMarkerStyle.imageName;
- lineWidth = polygonAndMarkerStyle.lineWidth;
- strokeColor = polygonAndMarkerStyle.strokeColor;
- fillColor = polygonAndMarkerStyle.fillColor;
- }
- let pointsFix;
- if (polygonProps.points) {
- pointsFix = 'points';
- }
- else {
- pointsFix = 'polygonPoints';
- }
- if (Array.isArray(polygonProps[pointsFix])) {
- for (let obj of polygonProps[pointsFix]) {
- if (!obj) {
- continue;
- }
- coordinates.push(drawLineConfig(obj.lat, obj.lng));
- markers.push(addOvalPointConfig(obj.lat, obj.lng, imageName));
- }
- }
- let polygon = { lineWidth, strokeColor, fillColor, coordinates };
- return { markers, polygon };
- }
- function getPolygonsAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
- let markers = [];
- let polygons = [];
- if (!Array.isArray(airspaceInfos)) {
- return { markers, polygons };
- }
- let polygonAndMarkerStyle = setStyle('polygon');
- for (let i = 0; i < airspaceInfos.length; i++) {
- let polygon = airspaceInfos[i];
- let airspaceTypeFix;
- if (polygon.airspaceType)
- airspaceTypeFix = 'airspaceType';
- else
- airspaceTypeFix = 'airspace_type';
- if (polygon[airspaceTypeFix] == Global.airspaceType.polygon && currentAirspaceIndex != i) {
- let retObj = getPolygon(polygon, polygonAndMarkerStyle);
- markers.push(...retObj.markers);
- polygons.push(retObj.polygon);
- }
- }
- return { markers, polygons };
- }
- function getPolygonAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
- return createSelector(airspaceInfos, () => setStyle, currentAirspaceIndex, getPolygonsAndMarkers);
- }
- function getMarkers(circlesAndMarkers, polygonAndMarkers, lineAndMarkers) {
- let markers = [];
- if (circlesAndMarkers) {
- markers = [...circlesAndMarkers.markers];
- }
- if (polygonAndMarkers) {
- markers = [...markers, ...polygonAndMarkers.markers];
- }
- if (lineAndMarkers) {
- markers = [...markers, ...lineAndMarkers.markers];
- }
- return markers;
- }
- function getMarkerSelector(circlesAndMarkers, polygonAndMarkers, lineAndMarkers) {
- return createSelector(circlesAndMarkers, polygonAndMarkers, lineAndMarkers, getMarkers);
- }
- function getRegionPoints(circles, lineAndMarkers, polygonAndMarkers) {
- let regionPoints = new Array();
- for (let i = 0; i < circles.length; i++) {
- regionPoints.push(...getCircleRegions(circles[i]));
- }
- let lines = lineAndMarkers.lines;
- for (let i = 0; i < lines.length; i++) {
- regionPoints.push(...lines[i].coordinates);
- }
- let polygons = polygonAndMarkers.polygons;
- for (let i = 0; i < polygons.length; i++) {
- regionPoints.push(...polygons[i].coordinates);
- }
- return regionPoints;
- }
- function getRegionPointsSelector(circles, lineAndMarkers, polygonAndMarkers) {
- return createSelector(circles, lineAndMarkers, polygonAndMarkers, getRegionPoints);
- }
- function getCircles(circlesAndMarkers) {
- return circlesAndMarkers.circles;
- }
- function getCircleSelector(circlesAndMarkers) {
- return createSelector(circlesAndMarkers, getCircles);
- }
- function getLines(lineAndMarker) {
- return lineAndMarker.lines;
- }
- function getLineSelector(lineAndMarker) {
- return createSelector(lineAndMarker, getLines);
- }
- function getPolygons(polygonAndMarkers, linePolygonsAndMarkers) {
- return [...polygonAndMarkers.polygons, ...linePolygonsAndMarkers.polygons];
- }
- function getPolygonSelector(polygonAndMarkers, linePolygonsAndMarkers) {
- return createSelector(polygonAndMarkers, linePolygonsAndMarkers, getPolygons);
- }
- let setStyle = (styles) => {
- if (!styles)
- return () => null;
- else
- return (shapeName) => styles[shapeName];
- };
- //获取selector
- export function getShapesSelector(airspaceInfos, style, currentAirspaceIndex) {
- currentAirspaceIndex = currentAirspaceIndex ? currentAirspaceIndex : () => -1;
- let circlesAndMarkers = getCircleAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
- let circles = getCircleSelector(circlesAndMarkers);
- let linePolygonsAndMarkers = getLinePolygonsAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
- let lines = getLineSelector(linePolygonsAndMarkers);
- let polygonAndMarkers = getPolygonAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
- let polygons = getPolygonSelector(polygonAndMarkers, linePolygonsAndMarkers);
- let markers = getMarkerSelector(circlesAndMarkers, polygonAndMarkers, linePolygonsAndMarkers);
- let regionPoints = getRegionPointsSelector(circles, linePolygonsAndMarkers, polygonAndMarkers);
- return {
- markers,
- circles,
- lines,
- polygons,
- regionPoints
- };
- }
- //获取数组
- export function getShapes(airspaceInfos, style, currentAirspaceIndex) {
- let { markers, polygons, circles, lines, regionPoints } = getShapesSelector(() => airspaceInfos, style, () => currentAirspaceIndex);
- return {
- markers: markers(airspaceInfos),
- circles: circles(airspaceInfos),
- lines: lines(airspaceInfos),
- polygons: polygons(airspaceInfos),
- regionPoints: regionPoints(airspaceInfos)
- };
- }
- // 总共 5 种格式, http://git.corp.brilliantaero.com/BA/Coco/issues/99#note_6358
- // 1. 全输出格式
- // 2. 简化格式
- // 3. 传真格式
- // 4. 用户端用的简化格式
- // 5. 极简格式
- function getHeight(height, unit, type) {
- let shortNum;
- const num = +height; // to number
- if (num >= 100) {
- shortNum = parseInt(num / 100 + '').toString();
- if (shortNum.length < 2) {
- shortNum = '0' + shortNum;
- }
- }
- let heightStandard = Global.heightStandardsById.get(unit);
- if (!heightStandard) {
- heightStandard = unit;
- }
- // 这里统一使用数字判断
- let standardUnit = Global.heightStandards.get(heightStandard);
- let heightDesc;
- switch (standardUnit) {
- case 1:
- heightDesc = ['H*真', '真高*米'];
- break;
- case 2:
- heightDesc = ['H*标(含以下)', '标高*米(含以下)'];
- break;
- case 3:
- heightDesc = ['H*真(含以下)', '真高*米(含以下)'];
- break;
- default:
- heightDesc = ['H*标', '标高*米'];
- }
- if (shortNum && (type == 1 || type == 2)) {
- // H02真,H02真(含以下)
- return heightDesc[0].replace('*', shortNum);
- }
- else {
- // 真高200米,真高200米(含以下)
- return heightDesc[1].replace('*', height + '');
- }
- }
- function getAirspaceName(airspaceInfo) {
- if (airspaceInfo.airspace_name) {
- const ai = airspaceInfo;
- return ai.airspace_name;
- }
- else {
- const ai = airspaceInfo;
- return ai.name;
- }
- }
- export function circleContent(airspaceInfo, type = 3) {
- if (type == 5)
- return getAirspaceName(airspaceInfo);
- if ('airspace_name' in airspaceInfo) {
- const lat = latLngDecimalToDegrees(airspaceInfo.center_point_of_flying.lat);
- const lng = latLngDecimalToDegrees(airspaceInfo.center_point_of_flying.lng);
- let content = [];
- let loc = `以${airspaceInfo.center_loc}`;
- if (type == 1 || type == 3)
- loc += `(E${lng}, N${lat})`;
- content.push(`${loc}为中心`);
- content.push(`半径${airspaceInfo.radius_of_flying}米`);
- content.push(getHeight(airspaceInfo.altitude, airspaceInfo.unit, type));
- if (airspaceInfo.note)
- content.push(`备注:${airspaceInfo.note}`);
- return content.join(',');
- }
- else {
- let content = [];
- let loc = `以${airspaceInfo.addr}`;
- if (type == 1 || type == 3)
- loc += `(E${latLngDecimalToDegrees(airspaceInfo.lng)}, N${latLngDecimalToDegrees(airspaceInfo.lat)})`;
- content.push(`${loc}为中心`);
- content.push(`半径${airspaceInfo.radius}米`);
- content.push(getHeight(airspaceInfo.height, airspaceInfo.heightStandard, type));
- if (airspaceInfo.note)
- content.push(`备注:${airspaceInfo.note}`);
- return content.join(',');
- }
- }
- function flyingCenter(item = {}) {
- if (item == {}) {
- return "";
- }
- const pp = item;
- return ("(E" + latLngDecimalToDegrees(pp.lng) +
- ', ' +
- "N" + latLngDecimalToDegrees(pp.lat) + ")");
- }
- export function lineContent(airspaceInfo, type = 3) {
- if (type == 5)
- return getAirspaceName(airspaceInfo);
- if ('airspace_name' in airspaceInfo) {
- let content = [];
- content.push(`${airspaceInfo.start_loc}`);
- if (type == 1 || type == 3)
- content.push(`${flyingCenter(airspaceInfo.start_point)}`);
- content.push(` - `);
- content.push(getHeight(airspaceInfo.start_point.altitude, airspaceInfo.start_point.unit, type));
- const passing_points = airspaceInfo.passing_points;
- if (Array.isArray(passing_points)) {
- for (let i = 0; i < passing_points.length; i++) {
- const obj = passing_points[i];
- if (obj.point_type == Global.pointTypes.point) {
- let pp = obj;
- const lat = latLngDecimalToDegrees(pp.lat);
- const lng = latLngDecimalToDegrees(pp.lng);
- content.push(` - ${pp.point_name}`);
- if (type == 1 || type == 3)
- content.push(`(E${lng}, N${lat})`);
- }
- else if (obj.point_type == Global.pointTypes.nav) {
- let pp = obj;
- const lat = latLngDecimalToDegrees(pp.lat);
- const lng = latLngDecimalToDegrees(pp.lng);
- content.push(` - ${pp.point_code}`);
- if (type == 1 || type == 3)
- content.push(`(E${lng}, N${lat})`);
- }
- else {
- let pp = obj;
- content.push(` - ${pp.air_route_code}`);
- }
- if (obj.altitude) {
- content.push(` - ${getHeight(obj.altitude, obj.unit, type)}`);
- }
- }
- }
- content.push(` - ${airspaceInfo.end_loc}`);
- if (type == 1 || type == 3)
- content.push(`${flyingCenter(airspaceInfo.end_point)}`);
- if (isSafeString(airspaceInfo.airline_width)) {
- content.push(`,宽度:${airspaceInfo.airline_width}米`);
- }
- if (isSafeString(airspaceInfo.note)) {
- content.push(`,备注: ${airspaceInfo.note}`);
- }
- let result = content.join("");
- return result;
- }
- else {
- let content = [];
- content.push(`${airspaceInfo.dep.addr}`);
- if (type == 1 || type == 3)
- content.push(`(E${latLngDecimalToDegrees(airspaceInfo.dep.lng)}, N${latLngDecimalToDegrees(airspaceInfo.dep.lat)})`);
- content.push(` - ${getHeight(airspaceInfo.dep.height, airspaceInfo.dep.heightStandard, type)}`);
- if (Array.isArray(airspaceInfo.passPoints)) {
- let length = airspaceInfo.passPoints.length;
- for (let i = 0; i < length; i++) {
- let obj = airspaceInfo.passPoints[i];
- if (obj.pointType == Global.pointTypes.point) {
- let pp = obj;
- content.push(` - ${pp.addr}`);
- if (type == 1 || type == 3)
- content.push(`(E${latLngDecimalToDegrees(pp.lng)}, N${latLngDecimalToDegrees(pp.lat)})`);
- }
- else if (obj.pointType == Global.pointTypes.nav) {
- let pp = obj;
- content.push(` - ${pp.pointCode}`);
- if (type == 1 || type == 3)
- content.push(`(E${latLngDecimalToDegrees(pp.lng)}, N${latLngDecimalToDegrees(pp.lat)})`);
- }
- else {
- let pp = obj;
- content.push(` - ${pp.airlineCode}`);
- }
- if (obj.height) {
- content.push(` - ${getHeight(obj.height, obj.heightStandard, type)}`);
- }
- }
- }
- content.push(` - ${airspaceInfo.arrive.addr}`);
- if (type == 1 || type == 3)
- content.push(`(E${latLngDecimalToDegrees(airspaceInfo.arrive.lng)}, N${latLngDecimalToDegrees(airspaceInfo.arrive.lat)})`);
- if (airspaceInfo.airlineWidth) {
- content.push(`,宽度:${airspaceInfo.airlineWidth}米`);
- }
- if (airspaceInfo.note)
- content.push(`,备注:${airspaceInfo.note}`);
- return content.join('');
- }
- }
- export function polygonContent(airspaceInfo, type = 3) {
- if (type == 5)
- return getAirspaceName(airspaceInfo);
- if ('airspace_name' in airspaceInfo) {
- let res = [];
- let points = airspaceInfo.points;
- for (let i = 0; i < points.length; i++) {
- let c = `${points[i].addr ? points[i].addr : ''}`;
- if (type == 1 || type == 3)
- c += `(E${latLngDecimalToDegrees(points[i].lng)}, N${latLngDecimalToDegrees(points[i].lat)})`;
- res.push(c);
- }
- let content = [res.join('、')];
- content.push(`${airspaceInfo.points.length}点连线范围内`);
- content.push(`,${getHeight(airspaceInfo.altitude, airspaceInfo.unit, type)}`);
- if (isSafeString(airspaceInfo.note)) {
- content.push(`,备注:${airspaceInfo.note}`);
- }
- return content.join('');
- }
- else {
- let content = [];
- let length = airspaceInfo.polygonPoints.length;
- for (let i = 0; i < length; i++) {
- let obj = airspaceInfo.polygonPoints[i];
- let c = `${obj.addr ? obj.addr : ''}`;
- if (type == 1 || type == 3)
- c += `(E${latLngDecimalToDegrees(obj.lng)}, N${latLngDecimalToDegrees(obj.lat)})`;
- content.push(c);
- }
- let cc = content.join('、') + `${length}点连线范围内`;
- cc += `,${getHeight(airspaceInfo.height, airspaceInfo.heightStandard, type)}`;
- if (airspaceInfo.note)
- cc += `,备注:${airspaceInfo.note}`;
- return cc;
- }
- }
- export { latLngDegreesToDecimal, latLngDecimalToDegrees };
|