| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- import { createSelector } from 'reselect';
- import Global from './Common';
- import {
- latLngDegreesToDecimal,
- isObject,
- isUndefined,
- isString,
- isSafeString,
- hasLine,
- hasPoint
- } from './Utils'
- let LatLon = require('geodesy').LatLonSpherical;
- function getCircleRegions(circle) {
- let latlon = new LatLon(circle.coordinate.latitude, circle.coordinate.longitude)
- 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 getCircles(airspaceInfos, setStyle, currentAirspaceIndex) {
- let circles = [];
- if (!Array.isArray(airspaceInfos)) {
- return { circles };
- }
- //通过该方法获取样式
- let circleStyle = setStyle('circle');
- for (let i = 0; i < airspaceInfos.length; i++) {
- let tmpCircle = airspaceInfos[i]
- if (tmpCircle.airspaceType == Global.airspaceType.circle && currentAirspaceIndex != i) {
- let coordinate = {};
- coordinate.latitude = latLngDegreesToDecimal(tmpCircle.lat);
- coordinate.longitude = latLngDegreesToDecimal(tmpCircle.lng);
- let radius = tmpCircle.radius;
- let circle = {
- lineWidth: circleStyle.lineWidth ? circleStyle.lineWidth : Global.amapLineWidth,
- strokeColor: circleStyle.strokeColor ? circleStyle.strokeColor : Global.amapStrokeColor,
- fillColor: circleStyle.fillColor ? circleStyle.fillColor : Global.amapFillColor,
- radius,
- coordinate
- }
- circles.push(circle);
- }
- }
- return circles;
- }
- function getCircleSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
- return createSelector(
- airspaceInfos,
- () => setStyle,
- currentAirspaceIndex,
- getCircles
- );
- }
- function drawLineConfig(lat, lng) {
- let coordinate = {};
- coordinate.latitude = latLngDegreesToDecimal(lat);
- coordinate.longitude = latLngDegreesToDecimal(lng);
- return coordinate;
- }
- function addOvalPointConfig(lat, lng, imageName) {
- let coordinate = {};
- coordinate.latitude = latLngDegreesToDecimal(lat);
- coordinate.longitude = latLngDegreesToDecimal(lng);
- let annotationConfig = {};
- annotationConfig.coordinate = coordinate;
- annotationConfig.imageName = imageName;
- return annotationConfig
- }
- function getAirwayLine(airway, pointBefore, pointAfter, lineAndMarkerStyle) {
- let found = 0
- let points = []
- for (let point of airway.points) {
- if (pointBefore.point_id == point.point_id || pointAfter.point_id == point.point_id) {
- found++
- points.push(Object.assign({}, point))
- continue
- }
- if (found == 1) {
- points.push(Object.assign({}, point))
- }
- }
- if (!(points.length > 0 && found == 2)) {
- // 如果两个点不全在航线上面,那么画全部航线
- points = airway.points
- }
- let line = {
- lineWidth: lineAndMarkerStyle.lineWidth ? lineAndMarkerStyle.lineWidth : Global.amapLineWidth,
- strokeColor: lineAndMarkerStyle.strokeColor ? lineAndMarkerStyle.strokeColor : Global.amapStrokeColor,
- coordinates: points
- }
- return { line };
- }
- function getLinesRouter(lineProps, lineAndMarkerStyle) {
- let coordinates = new Array();
- let markers = new Array();
- let lines = []
- if (hasLine(lineProps.dep)) {
- coordinates.push(drawLineConfig(lineProps.dep.lat, lineProps.dep.lng));
- markers.push(addOvalPointConfig(lineProps.dep.lat, lineProps.dep.lng, lineAndMarkerStyle.imageName ? lineAndMarkerStyle.imageName : 'BA_oval'));
- }
- if (Array.isArray(lineProps.passPoints)) {
- for (let i = 0; i < lineProps.passPoints.length; i++) {
- let obj = lineProps.passPoints[i]
- if (isObject(obj)) {
- continue;
- }
- if (obj.pointType == Global.pointTypes.point
- || obj.pointType == Global.pointTypes.nav) {
- coordinates.push(drawLineConfig(obj.lat, obj.lng));
- markers.push(addOvalPointConfig(obj.lat, obj.lng, lineAndMarkerStyle.imageName ? lineAndMarkerStyle.imageName : 'BA_oval'));
- } else {
- // 遇到一个航线,不需要和前前面的点连起来
- if (coordinates.length > 1) {
- lines.push({
- lineWidth: lineAndMarkerStyle.lineWidth ? lineAndMarkerStyle.lineWidth : Global.amapLineWidth,
- strokeColor: lineAndMarkerStyle.strokeColor ? lineAndMarkerStyle.strokeColor : Global.amapStrokeColor,
- coordinates: coordinates
- })
- }
- coordinates = []
- const pointBefore = i == 0 ? lineProps.dep : lineProps.passPoints[i - 1]
- const pointAfter = i == lineProps.passPoints.length - 1 ? lineProps.arrive : lineProps.passPoints[i + 1]
- lines.push(getAirwayLine(obj, pointBefore, pointAfter, lineAndMarkerStyle))
- }
- }
- }
- if (hasLine(lineProps.arrive)) {
- coordinates.push(drawLineConfig(lineProps.arrive.lat, lineProps.arrive.lng));
- markers.push(addOvalPointConfig(lineProps.arrive.lat, lineProps.arrive.lng, lineAndMarkerStyle.imageName ? lineAndMarkerStyle.imageName : 'BA_oval'));
- }
- if (coordinates.length > 1) {
- lines.push({
- lineWidth: lineAndMarkerStyle.lineWidth ? lineAndMarkerStyle.lineWidth : Global.amapLineWidth,
- strokeColor: lineAndMarkerStyle.strokeColor ? lineAndMarkerStyle.strokeColor : Global.amapStrokeColor,
- coordinates: coordinates
- });
- }
- return { lines, markers };
- }
- function getLinesAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
- let retLines = [];
- let retMarkers = [];
- if (!Array.isArray(airspaceInfos)) {
- return { lines: retLines, markers: retMarkers };
- }
- let lineStyle = setStyle('line');
- for (let i = 0; i < airspaceInfos.length; i++) {
- let tmpLine = airspaceInfos[i]
- if (tmpLine.airspaceType == Global.airspaceType.line && currentAirspaceIndex != i) {
- let { lines, markers } = getLinesRouter(tmpLine, lineStyle);
- retMarkers.push(...markers);
- retLines.push(...lines);
- }
- }
- return { lines: retLines, markers: retMarkers };
- }
- function getLineAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
- return createSelector(
- airspaceInfos,
- () => setStyle,
- currentAirspaceIndex,
- getLinesAndMarkers
- );
- }
- function getPolygon(polygonProps, polygonAndMarkerStyle) {
- let coordinates = new Array();
- let markers = new Array();
- if (Array.isArray(polygonProps.polygonPoints)) {
- for (let obj of polygonProps.polygonPoints) {
- if (!hasPoint(obj)) {
- continue;
- }
- coordinates.push(drawLineConfig(obj.lat, obj.lng));
- markers.push(addOvalPointConfig(obj.lat, obj.lng, polygonAndMarkerStyle.imageName ? polygonAndMarkerStyle.imageName : 'BA_oval'));
- }
- }
- if (coordinates.length > 0) {
- let polygon = {
- lineWidth: polygonAndMarkerStyle.lineWidth ? polygonAndMarkerStyle.lineWidth : Global.amapLineWidth,
- strokeColor: polygonAndMarkerStyle.strokeColor ? polygonAndMarkerStyle.strokeColor : Global.amapStrokeColor,
- fillColor: polygonAndMarkerStyle.fillColor ? polygonAndMarkerStyle.fillColor : Global.amapFillColor,
- coordinates: 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]
- if (polygon.airspaceType == 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(polygonAndMarkers, lineAndMarkers) {
- let markers = [];
- if (polygonAndMarkers) {
- markers = [...polygonAndMarkers.markers]
- }
- if (lineAndMarkers) {
- markers = [...markers, ...lineAndMarkers.markers]
- }
- return markers
- }
- function getMarkerSelector(polygonAndMarkers, lineAndMarkers) {
- return createSelector(
- 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 = getPolygonsAndMarkers.polygons;
- for (let i = 0; i < polygons.length; i++) {
- regionPoints.push(polygons.coordinates);
- }
- return regionPoints;
- }
- function getRegionPointsSelector(circles, lineAndMarkers, polygonAndMarkers) {
- return createSelector(
- circles,
- lineAndMarkers,
- polygonAndMarkers,
- getRegionPoints
- );
- }
- //获取selector
- export function getShapesSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
- currentAirspaceIndex = currentAirspaceIndex ? currentAirspaceIndex : () => -1;
- let circles = getCircleSelector(airspaceInfos, setStyle, currentAirspaceIndex);
- let lineAndMarkers = getLineAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex);
- let polygonAndMarkers = getPolygonAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex);
- let markers = getMarkerSelector(polygonAndMarkers, lineAndMarkers);
- let regionPoints = getRegionPointsSelector(circles, lineAndMarkers, polygonAndMarkers);
- return {
- markers,
- circles,
- lineAndMarkers,
- polygonAndMarkers,
- regionPoints
- }
- }
- //获取数组
- export function getShapes(airspaceInfos, setStyle, currentAirspaceIndex) {
- currentAirspaceIndex = currentAirspaceIndex ? currentAirspaceIndex : () => -1;
- let circles = getCircles(airspaceInfos, setStyle, currentAirspaceIndex);
- let lineAndMarkers = getLinesAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex);
- let polygonAndMarkers = getPolygonsAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex);
- let markers = getMarkers(polygonAndMarkers, lineAndMarkers);
- let regionPoints = getRegionPoints(circles, lineAndMarkers, polygonAndMarkers);
- return {
- markers,
- circles,
- lineAndMarkers,
- polygonAndMarkers,
- regionPoints
- }
- }
|