Jelajahi Sumber

Merge branch 'delete_react_in_dependencies' into 'master'

Delete react in dependencies

See merge request BA/amap-shapes-generator!3
wd 7 tahun lalu
induk
melakukan
da778e009b
4 mengubah file dengan 98 tambahan dan 52 penghapusan
  1. 2 13
      Common.js
  2. 0 1
      Utils.js
  3. 96 36
      index.js
  4. 0 2
      package.json

+ 2 - 13
Common.js

@@ -1,8 +1,3 @@
-import {
-    Platform,
-} from 'react-native';
-
-
 let Global = {
     airspaceType: {
         circle: 1,
@@ -19,14 +14,8 @@ let Global = {
 }
 
 Global.amapLineWidth = 3;
-Global.amapStrokeColor = Platform.select({
-    ios: () => 0x58A8F5,
-    android: () => "#58A8F5"
-})();
+Global.amapStrokeColor = "#58A8F5";
 
-Global.amapFillColor = Platform.select({
-    ios: () => 0xF4F9FC66,
-    android: () => "#1158A8F5" //ARGB in Android
-})();
+Global.amapFillColor = "#1158A8F5";
 
 module.exports = Global;

+ 0 - 1
Utils.js

@@ -55,7 +55,6 @@ function isString(arg) {
 
 function hasLine(obj) {
     return (isObject(obj)
-        && isSafeString(obj.addr)
         && isSafeString(obj.lat)
         && isSafeString(obj.lng));
 }

+ 96 - 36
index.js

@@ -23,17 +23,27 @@ function getCircleRegions(circle) {
 function getCircles(airspaceInfos, setStyle, currentAirspaceIndex) {
     let circles = [];
     if (!Array.isArray(airspaceInfos)) {
-        return { circles };
+        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 airspaceTypeFix;
+        if (tmpCircle.airspaceType)
+            airspaceTypeFix = 'airspaceType';
+        else
+            airspaceTypeFix = 'airspace_type';
+        if (tmpCircle[airspaceTypeFix] == Global.airspaceType.circle && currentAirspaceIndex != i) {
             let coordinate = {};
-            coordinate.latitude = latLngDegreesToDecimal(tmpCircle.lat);
-            coordinate.longitude = latLngDegreesToDecimal(tmpCircle.lng);
-            let radius = tmpCircle.radius;
+            if (tmpCircle.center_point_of_flying) {
+                coordinate.latitude = tmpCircle.center_point_of_flying.lat;
+                coordinate.longitude = tmpCircle.center_point_of_flying.lng;
+            } else {
+                coordinate.latitude = latLngDegreesToDecimal(tmpCircle.lat);
+                coordinate.longitude = latLngDegreesToDecimal(tmpCircle.lng);
+            }
+            let radius = tmpCircle.radius_of_flying;
             let circle = {
                 lineWidth: circleStyle.lineWidth ? circleStyle.lineWidth : Global.amapLineWidth,
                 strokeColor: circleStyle.strokeColor ? circleStyle.strokeColor : Global.amapStrokeColor,
@@ -114,22 +124,45 @@ function getLinesRouter(lineProps, lineAndMarkerStyle) {
     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'));
+    let startPointFix;
+    if (lineProps.start_point)
+        startPointFix = 'start_point';
+    else
+        startPointFix = 'dep';
+    if (hasLine(lineProps[startPointFix])) {
+        coordinates.push(startPointFix == 'dep' ? drawLineConfig(lineProps[startPointFix].lat, lineProps[startPointFix].lng) : { latitude: lineProps[startPointFix].lat, longitude: lineProps[startPointFix].lng });
+        markers.push(startPointFix == 'dep' ? addOvalPointConfig(lineProps[startPointFix].lat, lineProps[startPointFix].lng, lineAndMarkerStyle.imageName ? lineAndMarkerStyle.imageName : 'BA_oval') : { coordinate: { latitude: lineProps[startPointFix].lat, longitude: lineProps[startPointFix].lng }, imageName: 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]
+    let passingPointsFix;
+    if (lineProps.passing_points)
+        passingPointsFix = 'passing_points';
+    else
+        passingPointsFix = 'passPoints';
+
+    let endPointFix;
+    if (lineProps.end_point)
+        endPointFix = 'end_point';
+    else
+        endPointFix = 'arrive'
+
+    if (Array.isArray(lineProps[passingPointsFix])) {
+        for (let i = 0; i < lineProps[passingPointsFix].length; i++) {
+            let obj = lineProps[passingPointsFix][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'));
+            let pointTypeFix;
+            if (obj.point_type)
+                pointTypeFix = 'point_type';
+            else
+                pointTypeFix = 'pointType'
+
+            if (obj[pointTypeFix] == Global.pointTypes.point
+                || obj[pointTypeFix] == Global.pointTypes.nav) {
+                coordinates.push(pointTypeFix == 'pointType' ? drawLineConfig(obj.lat, obj.lng) : { latitude: obj.lat, longitude: obj.lng });
+                markers.push(pointTypeFix == 'pointType' ? addOvalPointConfig(obj.lat, obj.lng, lineAndMarkerStyle.imageName ? lineAndMarkerStyle.imageName : 'BA_oval') : { coordinate: { latitude: obj.lat, longitude: obj.lng }, imageName: lineAndMarkerStyle.imageName ? lineAndMarkerStyle.imageName : 'BA_oval' });
             } else {
                 // 遇到一个航线,不需要和前前面的点连起来
                 if (coordinates.length > 1) {
@@ -142,17 +175,17 @@ function getLinesRouter(lineProps, lineAndMarkerStyle) {
 
                 coordinates = []
 
-                const pointBefore = i == 0 ? lineProps.dep : lineProps.passPoints[i - 1]
-                const pointAfter = i == lineProps.passPoints.length - 1 ? lineProps.arrive : lineProps.passPoints[i + 1]
+                const pointBefore = i == 0 ? lineProps[startPointFix] : lineProps[passingPointsFix][i - 1]
+                const pointAfter = i == lineProps[passingPointsFix].length - 1 ? lineProps[endPointFix] : lineProps[passingPointsFix][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 (hasLine(lineProps[endPointFix])) {
+        coordinates.push(endPointFix == 'arrive' ? drawLineConfig(lineProps[endPointFix].lat, lineProps[endPointFix].lng) : { latitude: lineProps[endPointFix].lat, longitude: lineProps[endPointFix].lng });
+        markers.push(endPointFix == 'arrive' ? addOvalPointConfig(lineProps[endPointFix].lat, lineProps[endPointFix].lng, lineAndMarkerStyle.imageName ? lineAndMarkerStyle.imageName : 'BA_oval') : { coordinate: { latitude: lineProps[endPointFix].lat, longitude: lineProps[endPointFix].lng }, imageName: lineAndMarkerStyle.imageName ? lineAndMarkerStyle.imageName : 'BA_oval' });
     }
 
     if (coordinates.length > 1) {
@@ -176,7 +209,12 @@ function getLinesAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
     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 airspaceTypeFix;
+        if (tmpLine.airspaceType)
+            airspaceTypeFix = 'airspaceType';
+        else
+            airspaceTypeFix = 'airspace_type';
+        if (tmpLine[airspaceTypeFix] == Global.airspaceType.line && currentAirspaceIndex != i) {
             let { lines, markers } = getLinesRouter(tmpLine, lineStyle);
             retMarkers.push(...markers);
             retLines.push(...lines);
@@ -200,13 +238,19 @@ function getPolygon(polygonProps, polygonAndMarkerStyle) {
     let coordinates = new Array();
     let markers = new Array();
 
-    if (Array.isArray(polygonProps.polygonPoints)) {
-        for (let obj of polygonProps.polygonPoints) {
+    let pointsFix;
+    if (polygonProps.points)
+        pointsFix = 'points';
+    else
+        pointsFix = 'polygonPoints';
+
+    if (Array.isArray(polygonProps[pointsFix])) {
+        for (let obj of polygonProps[pointsFix]) {
             if (!hasPoint(obj)) {
                 continue;
             }
-            coordinates.push(drawLineConfig(obj.lat, obj.lng));
-            markers.push(addOvalPointConfig(obj.lat, obj.lng, polygonAndMarkerStyle.imageName ? polygonAndMarkerStyle.imageName : 'BA_oval'));
+            coordinates.push(pointsFix == 'polygonPoints' ? drawLineConfig(obj.lat, obj.lng) : { latitude: obj.lat, longitude: obj.lng });
+            markers.push(pointsFix == 'polygonPoints' ? addOvalPointConfig(obj.lat, obj.lng, polygonAndMarkerStyle.imageName ? polygonAndMarkerStyle.imageName : 'BA_oval') : { coordinate: { latitude: obj.lat, longitude: obj.lng }, imageName: polygonAndMarkerStyle.imageName ? polygonAndMarkerStyle.imageName : 'BA_oval' });
         }
     }
 
@@ -232,7 +276,12 @@ function getPolygonsAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
     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 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);
@@ -272,17 +321,21 @@ function getMarkerSelector(polygonAndMarkers, lineAndMarkers) {
 
 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;
+
+    let polygons = polygonAndMarkers.polygons;
     for (let i = 0; i < polygons.length; i++) {
         regionPoints.push(polygons.coordinates);
     }
+
     return regionPoints;
 }
 
@@ -317,13 +370,20 @@ function getPolygonSelector(polygonAndMarkers) {
     );
 }
 
+let setStyle = (style) => {
+    if (!style)
+        return (shapeName) => { return {key:0} }
+    else
+        return (shapeName) => style[shapeName]
+}
+
 //获取selector
-export function getShapesSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
+export function getShapesSelector(airspaceInfos, style, currentAirspaceIndex) {
     currentAirspaceIndex = currentAirspaceIndex ? currentAirspaceIndex : () => -1;
-    let circles = getCircleSelector(airspaceInfos, setStyle, currentAirspaceIndex);
-    let lineAndMarkers = getLineAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex);
+    let circles = getCircleSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
+    let lineAndMarkers = getLineAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
     let lines = getLineSelector(lineAndMarkers);
-    let polygonAndMarkers = getPolygonAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex);
+    let polygonAndMarkers = getPolygonAndMarkerSelector(airspaceInfos, setStyle(style), currentAirspaceIndex);
     let polygons = getPolygonSelector(polygonAndMarkers);
     let markers = getMarkerSelector(polygonAndMarkers, lineAndMarkers);
     let regionPoints = getRegionPointsSelector(circles, lineAndMarkers, polygonAndMarkers);
@@ -336,13 +396,13 @@ export function getShapesSelector(airspaceInfos, setStyle, currentAirspaceIndex)
     }
 }
 //获取数组
-export function getShapes(airspaceInfos, setStyle, currentAirspaceIndex) {
+export function getShapes(airspaceInfos, style, currentAirspaceIndex) {
     currentAirspaceIndex = currentAirspaceIndex ? currentAirspaceIndex : () => -1;
-    let circles = getCircles(airspaceInfos, setStyle, currentAirspaceIndex);
-    let lineAndMarkers = getLinesAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex);
+    let circles = getCircles(airspaceInfos, setStyle(style), currentAirspaceIndex);
+    let lineAndMarkers = getLinesAndMarkers(airspaceInfos, setStyle(style), currentAirspaceIndex);
     let lines = getLines(lineAndMarkers);
-    let polygonAndMarkers = getPolygonsAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex);
-    let polygons = getPolygons(getPolygonsAndMarkers);
+    let polygonAndMarkers = getPolygonsAndMarkers(airspaceInfos, setStyle(style), currentAirspaceIndex);
+    let polygons = getPolygons(polygonAndMarkers);
     let markers = getMarkers(polygonAndMarkers, lineAndMarkers);
     let regionPoints = getRegionPoints(circles, lineAndMarkers, polygonAndMarkers);
     return {

+ 0 - 2
package.json

@@ -7,8 +7,6 @@
     "test": "jest"
   },
   "dependencies": {
-    "react": "16.2.0",
-    "react-native": "0.52.0",
     "reselect": "^3.0.1",
     "geodesy": "^1.1.2"
   },