| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- import { createSelector } from 'reselect';
- import Global from './Common';
- import { latLngDegreesToDecimal } from './Utils'
- export default class AmapShapesManager {
- _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 }
- }
- _getCircleSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
- return createSelector(
- airspaceInfos,
- () => setStyle,
- currentAirspaceIndex,
- _getCircles
- );
- }
- _isObject(arg) {
- return typeof arg === 'object' && arg !== null;
- }
- _hasLine(obj) {
- return (isObject(obj)
- && isSafeString(obj.addr)
- && isSafeString(obj.lat)
- && isSafeString(obj.lng));
- }
- _hasPoint(obj) {
- return (isObject(obj)
- && isSafeString(obj.lat)
- && isSafeString(obj.lng));
- }
- _drawLineConfig(lat, lng) {
- let coordinate = {};
- coordinate.latitude = latLngDegreesToDecimal(lat);
- coordinate.longitude = latLngDegreesToDecimal(lng);
- return coordinate;
- }
- _addOvalPointConfig(lat, lng, imageName) {
- let coordinate = {};
- coordinate.latitude = latLngDegreesToDecimal(lat);
- coordinate.longitude = latLngDegreesToDecimal(lng);
- let annotationConfig = {};
- annotationConfig.coordinate = coordinate;
- annotationConfig.imageName = imageName;
- return annotationConfig
- }
- _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 };
- }
- _getLinesRouter(lineProps, lineAndMarkerStyle) {
- let coordinates = new Array();
- let markers = new Array();
- let lines = []
- if (this._hasLine(lineProps.dep)) {
- coordinates.push(this._drawLineConfig(lineProps.dep.lat, lineProps.dep.lng));
- markers.push(this._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 (this._isObject(obj)) {
- continue;
- }
- if (obj.pointType == Global.pointTypes.point
- || obj.pointType == Global.pointTypes.nav) {
- coordinates.push(this._drawLineConfig(obj.lat, obj.lng));
- markers.push(this._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(this._getAirwayLine(obj, pointBefore, pointAfter, lineAndMarkerStyle))
- }
- }
- }
- if (this._hasLine(lineProps.arrive)) {
- coordinates.push(this._drawLineConfig(lineProps.arrive.lat, lineProps.arrive.lng));
- markers.push(this._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 };
- }
- _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 } = this._getLinesRouter(tmpLine, lineStyle);
- retMarkers.push(...markers);
- retLines.push(...lines);
- }
- }
- return { lines: retLines, markers: retMarkers };
- }
- _getLineAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
- return createSelector(
- airspaceInfos,
- () => setStyle,
- currentAirspaceIndex,
- _getLinesAndMarkers
- );
- }
- _getPolygon = (polygonProps, polygonAndMarkerStyle) => {
- let coordinates = new Array();
- let markers = new Array();
- if (Array.isArray(polygonProps.polygonPoints)) {
- for (let obj of polygonProps.polygonPoints) {
- if (!this._hasPoint(obj)) {
- continue;
- }
- coordinates.push(this._drawLineConfig(obj.lat, obj.lng));
- markers.push(this._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 };
- }
- }
- _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.flyingTypes.polygon && currentAirspaceIndex != i) {
- let retObj = this._getPolygon(polygon)
- markers.push(...retObj.markers);
- polygons.push(retObj.polygon);
- }
- }
- return { markers, polygons };
- }
- _getPolygonAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
- return createSelector(
- airspaceInfos,
- () => setStyle,
- currentAirspaceIndex,
- _getPolygonsAndMarkers
- );
- }
- _getMarkers(polygonAndMarkers,lineAndMarkers){
- let markers = [];
- if (polygonAndMarkers) {
- markers = [...polygonAndMarkers.markers]
- }
- if (lineAndMarkers) {
- markers = [...markers, ...lineAndMarkers.markers]
- }
- return markers
- }
- _getMarkerSelector(polygonAndMarkers,lineAndMarkers) {
- return createSelector(
- polygonAndMarkers,
- lineAndMarkers,
- _getMarkers
- )
- }
- static getShapesSelect(airspaceInfos, setStyle, currentAirspaceIndex) {
- currentAirspaceIndex = currentAirspaceIndex ? currentAirspaceIndex : () => -1;
- let circles = this._getCircleSelector(airspaceInfos, setStyle, currentAirspaceIndex);
- let lineAndMarkers = this._getLineAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex);
- let polygonAndMarkers = this._getPolygonAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex);
- let markers = this._getMarkerSelector(polygonAndMarkers,lineAndMarkers);
- return {
- markers,
- circles,
- lineAndMarkers,
- polygonAndMarkers
- }
- }
- static getShapes(airspaceInfos, setStyle, currentAirspaceIndex) {
- currentAirspaceIndex = currentAirspaceIndex ? currentAirspaceIndex : () => -1;
- let circles = this._getCircles(airspaceInfos, setStyle, currentAirspaceIndex);
- let lineAndMarkers = this._getLinesAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex);
- let polygonAndMarkers = this._getPolygonsAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex);
- let markers = this._getMarkers(polygonAndMarkers,lineAndMarkers);
- return {
- markers,
- circles,
- lineAndMarkers,
- polygonAndMarkers
- }
- }
- }
|