邓国辉 7 жил өмнө
parent
commit
71d8997be5
7 өөрчлөгдсөн 121 нэмэгдсэн , 166 устгасан
  1. 2 2
      Utils.ts
  2. 2 2
      __tests__/utils-test.ts
  3. 5 5
      __tests__/vars.ts
  4. 55 78
      index.ts
  5. 2 2
      lib/Utils.js
  6. 8 8
      lib/index.d.ts
  7. 47 69
      lib/index.js

+ 2 - 2
Utils.ts

@@ -85,6 +85,6 @@ export function isNumber(arg: any): boolean {
 
 export function hasPoint(obj: any): boolean {
     return (isObject(obj)
-        && isSafeString(obj.lat)
-        && isSafeString(obj.lng));
+        && isNumber(obj.lat)
+        && isNumber(obj.lng));
 }

+ 2 - 2
__tests__/utils-test.ts

@@ -66,8 +66,8 @@ for(let i=0; i<input.length; i++) {
 }
 
 let tests7: [any, boolean][] = [
-    [{'lat': '111.11', 'lng': '222.22'}, true],
-    [{'lat': 111.11, 'lng': 222.22}, false],
+    [{'lat': '111.11', 'lng': '222.22'}, false],
+    [{'lat': 111.11, 'lng': 222.22}, true],
     [{'lat': 111.11, 'lng': '222.22'}, false],
     [{'lat': 111.11}, false],
     [{}, false]

+ 5 - 5
__tests__/vars.ts

@@ -16,7 +16,7 @@ export const circleServer: AirspaceInfo.AirspaceInfoCircleServer = {
     unit: 1
 }
 
-export const circleLocal = <AirspaceInfo.AirspaceInfoCircleLocal>{"addr": "loc name", "airspaceId": "123", "airspaceType": 1, "height": "1000", "heightStandard": "米/真高", "lat": "123°24′00″", "lng": "40°18′00″", "name": "test", "note": "notes note", "radius": 123}
+export const circleLocal = <AirspaceInfo.AirspaceInfoCircleLocal>{"addr": "loc name", "airspaceId": "123", "airspaceType": 1, "height": "1000", "heightStandard": "米/真高", "lat": 123.4, "lng": 40.3, "name": "test", "note": "notes note", "radius": 123}
 
 export const polygonServer: AirspaceInfo.AirspaceInfoPolygonServer = {
     airspace_name: 'test',
@@ -32,7 +32,7 @@ export const polygonServer: AirspaceInfo.AirspaceInfoPolygonServer = {
     unit: 1
 }
 
-export const polygonLocal: AirspaceInfo.AirspaceInfoPolygonLocal = {"airspaceId": "123", "airspaceType": 3, "height": "123", "heightStandard": "米/真高", "name": "test", "note": "notes", "polygonPoints": [{"addr": "test", "lat": "123°24′00″", "lng": "40°18′00″"}]}
+export const polygonLocal: AirspaceInfo.AirspaceInfoPolygonLocal = {"airspaceId": "123", "airspaceType": 3, "height": "123", "heightStandard": "米/真高", "name": "test", "note": "notes", "polygonPoints": [{"addr": "test", "lat": 123.4, "lng": 40.3}]}
 
 export const lineServer1: AirspaceInfo.AirspaceInfoLineServer = {
     airspace_name: "test",
@@ -86,7 +86,7 @@ export const lineServer1: AirspaceInfo.AirspaceInfoLineServer = {
     airline_width: 12
 }
 
-export const lineLocal1: AirspaceInfo.AirspaceInfoLineLocal = {"airlineWidth": 12, "airspaceId": "123", "airspaceType": 2, "arrive": {"addr": "end loc", "lat": "123°24′00″", "lng": "40°18′00″"}, "dep": {"addr": "start loc", "height": "111", "heightStandard": "米(含以下)/标高", "lat": "123°24′00″", "lng": "40°18′00″"}, "name": "test", "note": "notes note", "passPoints": [{"addr": "test point", "height": "1000", "heightStandard": "米/标高", "lat": "123°24′00″", "lng": "40°18′00″", "pointType": 3}, {"airRouteId": 123, "airlineCode": "B334", "airlines": [{"lat": 123.4, "lng": 40.3, "point_code": "UAV22", "point_id": 123, "point_name": "test point"}], "height": "1111", "heightStandard": "米/真高", "pointType": 2}, {"height": "12222", "heightStandard": "米(含以下)/真高", "lat": "123°24′00″", "lng": "40°18′00″", "pointCode": "123", "pointId": 123, "pointName": "test point", "pointType": 1}]}
+export const lineLocal1: AirspaceInfo.AirspaceInfoLineLocal = {"airlineWidth": 12, "airspaceId": "123", "airspaceType": 2, "arrive": {"addr": "end loc", "lat": 123.4, "lng": 40.3}, "dep": {"addr": "start loc", "height": "111", "heightStandard": "米(含以下)/标高", "lat": 123.4, "lng": 40.3}, "name": "test", "note": "notes note", "passPoints": [{"addr": "test point", "height": "1000", "heightStandard": "米/标高", "lat": 123.4, "lng": 40.3, "pointType": 3}, {"airRouteId": 123, "airlineCode": "B334", "airlines": [{"lat": 123.4, "lng": 40.3, "point_code": "UAV22", "point_id": 123, "point_name": "test point"}], "height": "1111", "heightStandard": "米/真高", "pointType": 2}, {"height": "12222", "heightStandard": "米(含以下)/真高", "lat": 123.4, "lng": 40.3, "pointCode": "123", "pointId": 123, "pointName": "test point", "pointType": 1}]}
 
 export const lineServer2: AirspaceInfo.AirspaceInfoLineServer = {
     airspace_name: "test",
@@ -139,7 +139,7 @@ export const lineServer2: AirspaceInfo.AirspaceInfoLineServer = {
     }]
 }
 
-export const lineLocal2: AirspaceInfo.AirspaceInfoLineLocal = {"airspaceId": "123", "airspaceType": 2, "arrive": {"addr": "end loc", "lat": "123°24′00″", "lng": "40°18′00″"}, "dep": {"addr": "start loc", "height": "111", "heightStandard": "米(含以下)/标高", "lat": "123°24′00″", "lng": "40°18′00″"}, "name": "test", "note": "notes note", "passPoints": [{"addr": "test point", "height": "1000", "heightStandard": "米/标高", "lat": "123°24′00″", "lng": "40°18′00″", "pointType": 3}, {"airRouteId": 123, "airlineCode": "B334", "airlines": [{"lat": 123.4, "lng": 40.3, "point_code": "UAV22", "point_id": 123, "point_name": "test point"}], "height": "1111", "heightStandard": "米/真高", "pointType": 2}, {"height": "12222", "heightStandard": "米(含以下)/真高", "lat": "123°24′00″", "lng": "40°18′00″", "pointCode": "123", "pointId": 123, "pointName": "test point", "pointType": 1}]}
+export const lineLocal2: AirspaceInfo.AirspaceInfoLineLocal = {"airspaceId": "123", "airspaceType": 2, "arrive": {"addr": "end loc", "lat": 123.4, "lng": 40.3}, "dep": {"addr": "start loc", "height": "111", "heightStandard": "米(含以下)/标高", "lat": 123.4, "lng": 40.3}, "name": "test", "note": "notes note", "passPoints": [{"addr": "test point", "height": "1000", "heightStandard": "米/标高", "lat": 123.4, "lng": 40.3, "pointType": 3}, {"airRouteId": 123, "airlineCode": "B334", "airlines": [{"lat": 123.4, "lng": 40.3, "point_code": "UAV22", "point_id": 123, "point_name": "test point"}], "height": "1111", "heightStandard": "米/真高", "pointType": 2}, {"height": "12222", "heightStandard": "米(含以下)/真高", "lat": 123.4, "lng": 40.3, "pointCode": "123", "pointId": 123, "pointName": "test point", "pointType": 1}]}
 
 export const lineServer3: AirspaceInfo.AirspaceInfoLineServer = {
     airspace_name: "test",
@@ -163,4 +163,4 @@ export const lineServer3: AirspaceInfo.AirspaceInfoLineServer = {
     passing_points: []
 }
 
-export const lineLocal3: AirspaceInfo.AirspaceInfoLineLocal = {"airspaceId": "123", "airspaceType": 2, "arrive": {"addr": "end loc", "lat": "123°24′00″", "lng": "40°18′00″"}, "dep": {"addr": "start loc", "height": "111", "heightStandard": "米(含以下)/标高", "lat": "123°24′00″", "lng": "40°18′00″"}, "name": "test", "note": "notes note", "passPoints": []}
+export const lineLocal3: AirspaceInfo.AirspaceInfoLineLocal = {"airspaceId": "123", "airspaceType": 2, "arrive": {"addr": "end loc", "lat": 123.4, "lng": 40.3}, "dep": {"addr": "start loc", "height": "111", "heightStandard": "米(含以下)/标高", "lat": 123.4, "lng": 40.3}, "name": "test", "note": "notes note", "passPoints": []}

+ 55 - 78
index.ts

@@ -124,12 +124,12 @@ export interface AirspaceInfoPolygonServer {
 }
 
 // Local
-export interface CoordinateShortString {
-    lat: string;
-    lng: string;
+export interface CoordinateShort {
+    lat: number;
+    lng: number;
 }
 
-export interface LatLngAddrLocal extends CoordinateShortString {
+export interface LatLngAddrLocal extends CoordinateShort {
     addr: string;
 }
 
@@ -139,7 +139,7 @@ export interface LatLngPointLocal extends LatLngAddrLocal{
 }
 
 // Passpoint
-export interface PassingPointNavLocal extends CoordinateShortString {
+export interface PassingPointNavLocal extends CoordinateShort {
     pointType: 1;
     height: string;
     heightStandard: string;
@@ -159,7 +159,7 @@ export interface PassingPointAirlineLocal {
     airlines: Array<AirRoutePoint>;
 }
 
-export interface PassingPointNormalLocal extends CoordinateShortString {
+export interface PassingPointNormalLocal extends CoordinateShort {
     pointType: 3;
     height: string;
     heightStandard: string;
@@ -175,8 +175,8 @@ export interface AirspaceInfoCircleLocal {
     note: string;
 
     addr: string;
-    lat: string;
-    lng: string;
+    lat: number;
+    lng: number;
     radius: number;
     height: string;
     heightStandard: string;
@@ -269,8 +269,8 @@ export function convertAirspaceInfoServerToLocal(airspaceInfo
             name: ai.airspace_name,
             note: ai.note,
             addr: ai.center_loc,
-            lat: latLngDecimalToDegrees(ai.center_point_of_flying.lat),
-            lng: latLngDecimalToDegrees(ai.center_point_of_flying.lng),
+            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)
@@ -281,16 +281,16 @@ export function convertAirspaceInfoServerToLocal(airspaceInfo
         const ai: AirspaceInfoLineServer = <AirspaceInfoLineServer> airspaceInfo
         let dep = {
             addr: ai.start_loc,
-            lat: latLngDecimalToDegrees(ai.start_point.lat),
-            lng: latLngDecimalToDegrees(ai.start_point.lng),
+            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: latLngDecimalToDegrees(ai.end_point.lat),
-            lng: latLngDecimalToDegrees(ai.end_point.lng)
+            lat: ai.end_point.lat,
+            lng: ai.end_point.lng
         }
 
         let passPoints: (PassingPointNavLocal | PassingPointAirlineLocal | PassingPointNormalLocal)[] = []
@@ -300,8 +300,8 @@ export function convertAirspaceInfoServerToLocal(airspaceInfo
 
                 if (obj.point_type == Global.pointTypes.point) {
                     const pp = <PassingPointNormalServer>obj;
-                    const lat = latLngDecimalToDegrees(pp.lat)
-                    const lng = latLngDecimalToDegrees(pp.lng)
+                    const lat = pp.lat
+                    const lng = pp.lng
 
                     point = <PassingPointNormalLocal>{
                         pointType: pp.point_type,
@@ -310,8 +310,8 @@ export function convertAirspaceInfoServerToLocal(airspaceInfo
                     }
                 } else if (obj.point_type == Global.pointTypes.nav) {
                     const pp = <PassingPointNavServer>obj;
-                    const lat = latLngDecimalToDegrees(pp.lat)
-                    const lng = latLngDecimalToDegrees(pp.lng)
+                    const lat = pp.lat
+                    const lng = pp.lng
 
                     point = <PassingPointNavLocal>{
                         pointType: pp.point_type,
@@ -366,7 +366,7 @@ export function convertAirspaceInfoServerToLocal(airspaceInfo
                     defaultPointName = String.fromCharCode(defaultPointName.charCodeAt(0) + 1)
                 }
 
-                polygonPoints.push({addr, lat: latLngDecimalToDegrees(obj.lat), lng: latLngDecimalToDegrees(obj.lng)})
+                polygonPoints.push({addr, lat: obj.lat, lng: obj.lng})
             }
 
             return <AirspaceInfoPolygonLocal>{
@@ -396,8 +396,8 @@ export function convertAirspaceInfoLocalToServer(airspace
             note: isSafeString(ai.note) ? ai.note : null,
             radius_of_flying: parseInt(ai.radius + ''),
             center_point_of_flying: {
-                lng: latLngDegreesToDecimal(ai.lng),
-                lat: latLngDegreesToDecimal(ai.lat)
+                lng: ai.lng,
+                lat: ai.lat
             },
             center_loc: ai.addr,
             altitude: parseInt(ai.height),
@@ -413,15 +413,15 @@ export function convertAirspaceInfoLocalToServer(airspace
             note: ai.note,
             start_loc: ai.dep.addr,
             start_point: {
-                lng: latLngDegreesToDecimal(ai.dep.lng),
-                lat: latLngDegreesToDecimal(ai.dep.lat),
+                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: latLngDegreesToDecimal(ai.arrive.lng),
-                lat: latLngDegreesToDecimal(ai.arrive.lat)
+                lng: ai.arrive.lng,
+                lat: ai.arrive.lat
             }
         }
         if(ai.airlineWidth) {
@@ -438,8 +438,8 @@ export function convertAirspaceInfoLocalToServer(airspace
                     retObj = <PassingPointNormalServer>{
                         point_type: Global.pointTypes.point,
                         point_name: pp.addr,
-                        lat: latLngDegreesToDecimal(pp.lat),
-                        lng: latLngDegreesToDecimal(pp.lng)
+                        lat: pp.lat,
+                        lng: pp.lng
                     };
                 } else if (obj.pointType == Global.pointTypes.nav) {
                     const pp = <PassingPointNavLocal>obj;
@@ -448,8 +448,8 @@ export function convertAirspaceInfoLocalToServer(airspace
                         point_name: pp.pointName,
                         point_id: pp.pointId,
                         point_code: pp.pointCode,
-                        lat: latLngDegreesToDecimal(pp.lat),
-                        lng: latLngDegreesToDecimal(pp.lng)
+                        lat: pp.lat,
+                        lng: pp.lng
                     };
                 } else {
                     const pp = <PassingPointAirlineLocal>obj;
@@ -477,11 +477,6 @@ export function convertAirspaceInfoLocalToServer(airspace
     } else {
         const ai = <AirspaceInfoPolygonLocal> airspace;
 
-        let points = [];
-        for (let obj of ai.polygonPoints) {
-            points.push({ addr: obj.addr, lat: latLngDegreesToDecimal(obj.lat), lng: latLngDegreesToDecimal(obj.lng) })
-        }
-
         const polygon = <AirspaceInfoPolygonServer>{
             airspace_name: ai.name,
             airspace_id: ai.airspaceId,
@@ -489,7 +484,7 @@ export function convertAirspaceInfoLocalToServer(airspace
             note: ai.note,
             altitude: parseInt(ai.height),
             unit: Global.heightStandards.get(ai.heightStandard),
-            points
+            points: ai.polygonPoints
         };
         return polygon;
     }
@@ -560,8 +555,8 @@ function getCirclesAndMarkers(airspaceInfos: AirspaceInfo[], setStyle: (styleNam
                 coordinate.longitude = ai.center_point_of_flying.lng;
             } else {
                 let ai = <AirspaceInfoCircleLocal>tmpCircle;
-                coordinate.latitude = latLngDegreesToDecimal(ai.lat);
-                coordinate.longitude = latLngDegreesToDecimal(ai.lng);
+                coordinate.latitude = ai.lat;
+                coordinate.longitude = ai.lng;
             }
 
             let radius = (tmpCircle as any)[radiusFix];
@@ -570,8 +565,7 @@ function getCirclesAndMarkers(airspaceInfos: AirspaceInfo[], setStyle: (styleNam
                 let circle = <Circle>{lineWidth, strokeColor, fillColor, radius, coordinate}
                 circles.push(circle);
             } else {
-                // 这里的经纬度必定是数值, 所以最后一个参数是 2
-                markers.push(addOvalPointConfig(coordinate.latitude, coordinate.longitude, imageName, 2));
+                markers.push(addOvalPointConfig(coordinate.latitude, coordinate.longitude, imageName));
             }
         }
     }
@@ -588,26 +582,19 @@ function getCircleAndMarkerSelector(airspaceInfos: () => AirspaceInfo[], setStyl
     );
 }
 
-function getLatLng(latlng: number | string, dataType: number): number {
-    if(dataType == 1) { // 驼峰模式,新建计划的时候的格式
-        return latLngDegreesToDecimal(<string>latlng)
-    } else {
-        return <number>latlng
-    }
-}
 
-function drawLineConfig(lat: number | string, lng: number | string, dataType: number) {
+function drawLineConfig(lat: number, lng: number) {
     return {
-        latitude: getLatLng(lat, dataType),
-        longitude: getLatLng(lng, dataType)
+        latitude: lat,
+        longitude: lng
     };
 }
 
-function addOvalPointConfig(lat: number | string, lng: number | string, imageName: string, dataType: number) {
+function addOvalPointConfig(lat: number, lng: number, imageName: string) {
     return {
         coordinate: {
-            latitude: getLatLng(lat, dataType),
-            longitude: getLatLng(lng, dataType)
+            latitude: lat,
+            longitude: lng
         },
         imageName: imageName
     };
@@ -705,11 +692,10 @@ function getLinesRouter(lineProps: AirspaceInfoLine, lineAndMarkerStyle: ShapeSt
         strokeColor = lineAndMarkerStyle.strokeColor
     }
 
-    let startPoint, passPoints, endPoint, pointTypeFix, dataType, airlineWidth
+    let startPoint, passPoints, endPoint, pointTypeFix, airlineWidth
 
     if ((lineProps as any).start_point) {
         let ll = <AirspaceInfoLineServer>lineProps;
-        dataType = 2 // 下划线模式
 
         startPoint = ll['start_point']
         passPoints = ll['passing_points']
@@ -718,7 +704,6 @@ function getLinesRouter(lineProps: AirspaceInfoLine, lineAndMarkerStyle: ShapeSt
         airlineWidth = parseInt(ll['airline_width'] + '', 10)
     } else {
         let ll = <AirspaceInfoLineLocal>lineProps;
-        dataType = 1 // 驼峰模式
 
         startPoint = ll['dep']
         passPoints = ll['passPoints']
@@ -728,8 +713,8 @@ function getLinesRouter(lineProps: AirspaceInfoLine, lineAndMarkerStyle: ShapeSt
     }
 
     if (startPoint) {
-        coordinates.push(drawLineConfig(startPoint.lat, startPoint.lng, dataType));
-        markers.push(addOvalPointConfig(startPoint.lat, startPoint.lng, imageName, dataType));
+        coordinates.push(drawLineConfig(startPoint.lat, startPoint.lng));
+        markers.push(addOvalPointConfig(startPoint.lat, startPoint.lng, imageName));
     }
 
     if (Array.isArray(passPoints)) {
@@ -743,8 +728,8 @@ function getLinesRouter(lineProps: AirspaceInfoLine, lineAndMarkerStyle: ShapeSt
             if ( pointType == Global.pointTypes.point
                 || pointType == Global.pointTypes.nav) {
                 let pp = <PassingPointNav | PassingPointNormal>obj
-                coordinates.push(drawLineConfig(pp.lat, pp.lng, dataType));
-                markers.push(addOvalPointConfig(pp.lat, pp.lng, imageName, dataType));
+                coordinates.push(drawLineConfig(pp.lat, pp.lng));
+                markers.push(addOvalPointConfig(pp.lat, pp.lng, imageName));
             } else {
                 // 遇到一个航线,不需要和前前面的点连起来
                 let pp = <PassingPointAirline>obj
@@ -763,8 +748,8 @@ function getLinesRouter(lineProps: AirspaceInfoLine, lineAndMarkerStyle: ShapeSt
     }
 
     if (endPoint) {
-        coordinates.push(drawLineConfig(endPoint.lat, endPoint.lng, dataType));
-        markers.push(addOvalPointConfig(endPoint.lat, endPoint.lng, imageName, dataType));
+        coordinates.push(drawLineConfig(endPoint.lat, endPoint.lng));
+        markers.push(addOvalPointConfig(endPoint.lat, endPoint.lng, imageName));
     }
 
     if (coordinates.length > 1) {
@@ -784,12 +769,6 @@ function getFixedLatLng(point: {lat?: string | number, lng?: string | number, la
     let lat = pp.latitude ? pp.latitude : pp.lat
     let lng = pp.longitude ? pp.longitude : pp.lng
 
-    // 复制计划的数据,有的点是度数模式如 38°35′17″
-    if(isSafeString(lat)) {
-        lat = latLngDegreesToDecimal(<string>lat);
-        lng = latLngDegreesToDecimal(<string>lng);
-    }
-
     return [lat, lng]
 }
 
@@ -887,13 +866,11 @@ function getPolygon(polygonProps: AirspaceInfoPolygon, polygonAndMarkerStyle: Sh
         fillColor = polygonAndMarkerStyle.fillColor
     }
 
-    let pointsFix, dataType;
+    let pointsFix;
     if ((polygonProps as any).points) {
         pointsFix = 'points';
-        dataType = 2
     } else {
         pointsFix = 'polygonPoints';
-        dataType = 1 // 驼峰模式
     }
 
     if (Array.isArray((polygonProps as any)[pointsFix])) {
@@ -901,8 +878,8 @@ function getPolygon(polygonProps: AirspaceInfoPolygon, polygonAndMarkerStyle: Sh
             if (!obj) {
                 continue
             }
-            coordinates.push(drawLineConfig(obj.lat, obj.lng, dataType));
-            markers.push(addOvalPointConfig(obj.lat, obj.lng, imageName, dataType));
+            coordinates.push(drawLineConfig(obj.lat, obj.lng));
+            markers.push(addOvalPointConfig(obj.lat, obj.lng, imageName));
         }
     }
 
@@ -1163,7 +1140,7 @@ export function circleContent(airspaceInfo: AirspaceInfoCircle, type=3) {
         let content = []
         let loc = `以${airspaceInfo.addr}`
         if(type == 1 || type == 3)
-            loc += `(E${airspaceInfo.lng}, N${airspaceInfo.lat})`;
+            loc += `(E${latLngDecimalToDegrees(airspaceInfo.lng)}, N${latLngDecimalToDegrees(airspaceInfo.lat)})`;
         content.push(`${loc}为中心`)
         content.push(`半径${airspaceInfo.radius}米`);
         content.push(getHeight(airspaceInfo.height, airspaceInfo.heightStandard, type))
@@ -1247,7 +1224,7 @@ export function lineContent(airspaceInfo: AirspaceInfoLine, type=3): string {
         let content = [];
         content.push(`${airspaceInfo.dep.addr}`)
         if(type == 1 || type == 3)
-            content.push(`(E${airspaceInfo.dep.lng}, N${airspaceInfo.dep.lat})`)
+            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)) {
@@ -1258,12 +1235,12 @@ export function lineContent(airspaceInfo: AirspaceInfoLine, type=3): string {
                     let pp = <PassingPointNormalLocal>obj;
                     content.push(` - ${pp.addr}`)
                     if(type == 1 || type == 3)
-                        content.push(`(E${pp.lng}, N${pp.lat})`);
+                        content.push(`(E${latLngDecimalToDegrees(pp.lng)}, N${latLngDecimalToDegrees(pp.lat)})`);
                 } else if (obj.pointType == Global.pointTypes.nav) {
                     let pp = <PassingPointNavLocal>obj;
                     content.push(` - ${pp.pointCode}`)
                     if(type == 1 || type == 3)
-                        content.push(`(E${pp.lng}, N${pp.lat})`);
+                        content.push(`(E${latLngDecimalToDegrees(pp.lng)}, N${latLngDecimalToDegrees(pp.lat)})`);
                 } else {
                     let pp = <PassingPointAirlineLocal>obj;
                     content.push(` - ${pp.airlineCode}`);
@@ -1276,7 +1253,7 @@ export function lineContent(airspaceInfo: AirspaceInfoLine, type=3): string {
         }
         content.push(` - ${airspaceInfo.arrive.addr}`)
         if(type == 1 || type == 3)
-            content.push(`(E${airspaceInfo.arrive.lng}, N${airspaceInfo.arrive.lat})`);
+            content.push(`(E${latLngDecimalToDegrees(airspaceInfo.arrive.lng)}, N${latLngDecimalToDegrees(airspaceInfo.arrive.lat)})`);
         if(airspaceInfo.airlineWidth) {
             content.push(`,宽度:${airspaceInfo.airlineWidth}米`)
         }
@@ -1316,7 +1293,7 @@ export function polygonContent(airspaceInfo: AirspaceInfoPolygon, type=3): strin
             let obj = airspaceInfo.polygonPoints[i];
             let c = `${obj.addr ? obj.addr : ''}`
             if(type == 1 || type == 3)
-                c += `(E${obj.lng}, N${obj.lat})`
+                c += `(E${latLngDecimalToDegrees(obj.lng)}, N${latLngDecimalToDegrees(obj.lat)})`
             content.push(c)
         }
         let cc = content.join('、') + `${length}点连线范围内`

+ 2 - 2
lib/Utils.js

@@ -80,6 +80,6 @@ export function isNumber(arg) {
 }
 export function hasPoint(obj) {
     return (isObject(obj)
-        && isSafeString(obj.lat)
-        && isSafeString(obj.lng));
+        && isNumber(obj.lat)
+        && isNumber(obj.lng));
 }

+ 8 - 8
lib/index.d.ts

@@ -80,18 +80,18 @@ export interface AirspaceInfoPolygonServer {
     altitude: number;
     unit: number;
 }
-export interface CoordinateShortString {
-    lat: string;
-    lng: string;
+export interface CoordinateShort {
+    lat: number;
+    lng: number;
 }
-export interface LatLngAddrLocal extends CoordinateShortString {
+export interface LatLngAddrLocal extends CoordinateShort {
     addr: string;
 }
 export interface LatLngPointLocal extends LatLngAddrLocal {
     height: string;
     heightStandard: string;
 }
-export interface PassingPointNavLocal extends CoordinateShortString {
+export interface PassingPointNavLocal extends CoordinateShort {
     pointType: 1;
     height: string;
     heightStandard: string;
@@ -107,7 +107,7 @@ export interface PassingPointAirlineLocal {
     airlineCode: string;
     airlines: Array<AirRoutePoint>;
 }
-export interface PassingPointNormalLocal extends CoordinateShortString {
+export interface PassingPointNormalLocal extends CoordinateShort {
     pointType: 3;
     height: string;
     heightStandard: string;
@@ -119,8 +119,8 @@ export interface AirspaceInfoCircleLocal {
     name: string;
     note: string;
     addr: string;
-    lat: string;
-    lng: string;
+    lat: number;
+    lng: number;
     radius: number;
     height: string;
     heightStandard: string;

+ 47 - 69
lib/index.js

@@ -12,8 +12,8 @@ export function convertAirspaceInfoServerToLocal(airspaceInfo) {
             name: ai.airspace_name,
             note: ai.note,
             addr: ai.center_loc,
-            lat: latLngDecimalToDegrees(ai.center_point_of_flying.lat),
-            lng: latLngDecimalToDegrees(ai.center_point_of_flying.lng),
+            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)
@@ -23,15 +23,15 @@ export function convertAirspaceInfoServerToLocal(airspaceInfo) {
         const ai = airspaceInfo;
         let dep = {
             addr: ai.start_loc,
-            lat: latLngDecimalToDegrees(ai.start_point.lat),
-            lng: latLngDecimalToDegrees(ai.start_point.lng),
+            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: latLngDecimalToDegrees(ai.end_point.lat),
-            lng: latLngDecimalToDegrees(ai.end_point.lng)
+            lat: ai.end_point.lat,
+            lng: ai.end_point.lng
         };
         let passPoints = [];
         if (Array.isArray(ai.passing_points)) {
@@ -39,8 +39,8 @@ export function convertAirspaceInfoServerToLocal(airspaceInfo) {
                 let point;
                 if (obj.point_type == Global.pointTypes.point) {
                     const pp = obj;
-                    const lat = latLngDecimalToDegrees(pp.lat);
-                    const lng = latLngDecimalToDegrees(pp.lng);
+                    const lat = pp.lat;
+                    const lng = pp.lng;
                     point = {
                         pointType: pp.point_type,
                         addr: pp.point_name,
@@ -49,8 +49,8 @@ export function convertAirspaceInfoServerToLocal(airspaceInfo) {
                 }
                 else if (obj.point_type == Global.pointTypes.nav) {
                     const pp = obj;
-                    const lat = latLngDecimalToDegrees(pp.lat);
-                    const lng = latLngDecimalToDegrees(pp.lng);
+                    const lat = pp.lat;
+                    const lng = pp.lng;
                     point = {
                         pointType: pp.point_type,
                         pointId: pp.point_id,
@@ -100,7 +100,7 @@ export function convertAirspaceInfoServerToLocal(airspaceInfo) {
                     addr = defaultPointName;
                     defaultPointName = String.fromCharCode(defaultPointName.charCodeAt(0) + 1);
                 }
-                polygonPoints.push({ addr, lat: latLngDecimalToDegrees(obj.lat), lng: latLngDecimalToDegrees(obj.lng) });
+                polygonPoints.push({ addr, lat: obj.lat, lng: obj.lng });
             }
             return {
                 airspaceType,
@@ -125,8 +125,8 @@ export function convertAirspaceInfoLocalToServer(airspace) {
             note: isSafeString(ai.note) ? ai.note : null,
             radius_of_flying: parseInt(ai.radius + ''),
             center_point_of_flying: {
-                lng: latLngDegreesToDecimal(ai.lng),
-                lat: latLngDegreesToDecimal(ai.lat)
+                lng: ai.lng,
+                lat: ai.lat
             },
             center_loc: ai.addr,
             altitude: parseInt(ai.height),
@@ -143,15 +143,15 @@ export function convertAirspaceInfoLocalToServer(airspace) {
             note: ai.note,
             start_loc: ai.dep.addr,
             start_point: {
-                lng: latLngDegreesToDecimal(ai.dep.lng),
-                lat: latLngDegreesToDecimal(ai.dep.lat),
+                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: latLngDegreesToDecimal(ai.arrive.lng),
-                lat: latLngDegreesToDecimal(ai.arrive.lat)
+                lng: ai.arrive.lng,
+                lat: ai.arrive.lat
             }
         };
         if (ai.airlineWidth) {
@@ -166,8 +166,8 @@ export function convertAirspaceInfoLocalToServer(airspace) {
                     retObj = {
                         point_type: Global.pointTypes.point,
                         point_name: pp.addr,
-                        lat: latLngDegreesToDecimal(pp.lat),
-                        lng: latLngDegreesToDecimal(pp.lng)
+                        lat: pp.lat,
+                        lng: pp.lng
                     };
                 }
                 else if (obj.pointType == Global.pointTypes.nav) {
@@ -177,8 +177,8 @@ export function convertAirspaceInfoLocalToServer(airspace) {
                         point_name: pp.pointName,
                         point_id: pp.pointId,
                         point_code: pp.pointCode,
-                        lat: latLngDegreesToDecimal(pp.lat),
-                        lng: latLngDegreesToDecimal(pp.lng)
+                        lat: pp.lat,
+                        lng: pp.lng
                     };
                 }
                 else {
@@ -206,10 +206,6 @@ export function convertAirspaceInfoLocalToServer(airspace) {
     }
     else {
         const ai = airspace;
-        let points = [];
-        for (let obj of ai.polygonPoints) {
-            points.push({ addr: obj.addr, lat: latLngDegreesToDecimal(obj.lat), lng: latLngDegreesToDecimal(obj.lng) });
-        }
         const polygon = {
             airspace_name: ai.name,
             airspace_id: ai.airspaceId,
@@ -217,7 +213,7 @@ export function convertAirspaceInfoLocalToServer(airspace) {
             note: ai.note,
             altitude: parseInt(ai.height),
             unit: Global.heightStandards.get(ai.heightStandard),
-            points
+            points: ai.polygonPoints
         };
         return polygon;
     }
@@ -283,8 +279,8 @@ function getCirclesAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
             }
             else {
                 let ai = tmpCircle;
-                coordinate.latitude = latLngDegreesToDecimal(ai.lat);
-                coordinate.longitude = latLngDegreesToDecimal(ai.lng);
+                coordinate.latitude = ai.lat;
+                coordinate.longitude = ai.lng;
             }
             let radius = tmpCircle[radiusFix];
             if (radius) {
@@ -292,8 +288,7 @@ function getCirclesAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
                 circles.push(circle);
             }
             else {
-                // 这里的经纬度必定是数值, 所以最后一个参数是 2
-                markers.push(addOvalPointConfig(coordinate.latitude, coordinate.longitude, imageName, 2));
+                markers.push(addOvalPointConfig(coordinate.latitude, coordinate.longitude, imageName));
             }
         }
     }
@@ -302,25 +297,17 @@ function getCirclesAndMarkers(airspaceInfos, setStyle, currentAirspaceIndex) {
 function getCircleAndMarkerSelector(airspaceInfos, setStyle, currentAirspaceIndex) {
     return createSelector(airspaceInfos, () => setStyle, currentAirspaceIndex, getCirclesAndMarkers);
 }
-function getLatLng(latlng, dataType) {
-    if (dataType == 1) { // 驼峰模式,新建计划的时候的格式
-        return latLngDegreesToDecimal(latlng);
-    }
-    else {
-        return latlng;
-    }
-}
-function drawLineConfig(lat, lng, dataType) {
+function drawLineConfig(lat, lng) {
     return {
-        latitude: getLatLng(lat, dataType),
-        longitude: getLatLng(lng, dataType)
+        latitude: lat,
+        longitude: lng
     };
 }
-function addOvalPointConfig(lat, lng, imageName, dataType) {
+function addOvalPointConfig(lat, lng, imageName) {
     return {
         coordinate: {
-            latitude: getLatLng(lat, dataType),
-            longitude: getLatLng(lng, dataType)
+            latitude: lat,
+            longitude: lng
         },
         imageName: imageName
     };
@@ -401,10 +388,9 @@ function getLinesRouter(lineProps, lineAndMarkerStyle) {
         lineWidth = lineAndMarkerStyle.lineWidth;
         strokeColor = lineAndMarkerStyle.strokeColor;
     }
-    let startPoint, passPoints, endPoint, pointTypeFix, dataType, airlineWidth;
+    let startPoint, passPoints, endPoint, pointTypeFix, airlineWidth;
     if (lineProps.start_point) {
         let ll = lineProps;
-        dataType = 2; // 下划线模式
         startPoint = ll['start_point'];
         passPoints = ll['passing_points'];
         endPoint = ll['end_point'];
@@ -413,7 +399,6 @@ function getLinesRouter(lineProps, lineAndMarkerStyle) {
     }
     else {
         let ll = lineProps;
-        dataType = 1; // 驼峰模式
         startPoint = ll['dep'];
         passPoints = ll['passPoints'];
         endPoint = ll['arrive'];
@@ -421,8 +406,8 @@ function getLinesRouter(lineProps, lineAndMarkerStyle) {
         airlineWidth = parseInt(ll['airlineWidth'] + '', 10);
     }
     if (startPoint) {
-        coordinates.push(drawLineConfig(startPoint.lat, startPoint.lng, dataType));
-        markers.push(addOvalPointConfig(startPoint.lat, startPoint.lng, imageName, dataType));
+        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++) {
@@ -434,8 +419,8 @@ function getLinesRouter(lineProps, lineAndMarkerStyle) {
             if (pointType == Global.pointTypes.point
                 || pointType == Global.pointTypes.nav) {
                 let pp = obj;
-                coordinates.push(drawLineConfig(pp.lat, pp.lng, dataType));
-                markers.push(addOvalPointConfig(pp.lat, pp.lng, imageName, dataType));
+                coordinates.push(drawLineConfig(pp.lat, pp.lng));
+                markers.push(addOvalPointConfig(pp.lat, pp.lng, imageName));
             }
             else {
                 // 遇到一个航线,不需要和前前面的点连起来
@@ -451,8 +436,8 @@ function getLinesRouter(lineProps, lineAndMarkerStyle) {
         }
     }
     if (endPoint) {
-        coordinates.push(drawLineConfig(endPoint.lat, endPoint.lng, dataType));
-        markers.push(addOvalPointConfig(endPoint.lat, endPoint.lng, imageName, dataType));
+        coordinates.push(drawLineConfig(endPoint.lat, endPoint.lng));
+        markers.push(addOvalPointConfig(endPoint.lat, endPoint.lng, imageName));
     }
     if (coordinates.length > 1) {
         lines.push({ lineWidth, strokeColor, coordinates });
@@ -470,11 +455,6 @@ function getFixedLatLng(point) {
     let pp = point;
     let lat = pp.latitude ? pp.latitude : pp.lat;
     let lng = pp.longitude ? pp.longitude : pp.lng;
-    // 复制计划的数据,有的点是度数模式如 38°35′17″
-    if (isSafeString(lat)) {
-        lat = latLngDegreesToDecimal(lat);
-        lng = latLngDegreesToDecimal(lng);
-    }
     return [lat, lng];
 }
 function processAirlineWidth(lines, airlineWidth) {
@@ -551,22 +531,20 @@ function getPolygon(polygonProps, polygonAndMarkerStyle) {
         strokeColor = polygonAndMarkerStyle.strokeColor;
         fillColor = polygonAndMarkerStyle.fillColor;
     }
-    let pointsFix, dataType;
+    let pointsFix;
     if (polygonProps.points) {
         pointsFix = 'points';
-        dataType = 2;
     }
     else {
         pointsFix = 'polygonPoints';
-        dataType = 1; // 驼峰模式
     }
     if (Array.isArray(polygonProps[pointsFix])) {
         for (let obj of polygonProps[pointsFix]) {
             if (!obj) {
                 continue;
             }
-            coordinates.push(drawLineConfig(obj.lat, obj.lng, dataType));
-            markers.push(addOvalPointConfig(obj.lat, obj.lng, imageName, dataType));
+            coordinates.push(drawLineConfig(obj.lat, obj.lng));
+            markers.push(addOvalPointConfig(obj.lat, obj.lng, imageName));
         }
     }
     let polygon = { lineWidth, strokeColor, fillColor, coordinates };
@@ -760,7 +738,7 @@ export function circleContent(airspaceInfo, type = 3) {
         let content = [];
         let loc = `以${airspaceInfo.addr}`;
         if (type == 1 || type == 3)
-            loc += `(E${airspaceInfo.lng}, N${airspaceInfo.lat})`;
+            loc += `(E${latLngDecimalToDegrees(airspaceInfo.lng)}, N${latLngDecimalToDegrees(airspaceInfo.lat)})`;
         content.push(`${loc}为中心`);
         content.push(`半径${airspaceInfo.radius}米`);
         content.push(getHeight(airspaceInfo.height, airspaceInfo.heightStandard, type));
@@ -833,7 +811,7 @@ export function lineContent(airspaceInfo, type = 3) {
         let content = [];
         content.push(`${airspaceInfo.dep.addr}`);
         if (type == 1 || type == 3)
-            content.push(`(E${airspaceInfo.dep.lng}, N${airspaceInfo.dep.lat})`);
+            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;
@@ -843,13 +821,13 @@ export function lineContent(airspaceInfo, type = 3) {
                     let pp = obj;
                     content.push(` - ${pp.addr}`);
                     if (type == 1 || type == 3)
-                        content.push(`(E${pp.lng}, N${pp.lat})`);
+                        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${pp.lng}, N${pp.lat})`);
+                        content.push(`(E${latLngDecimalToDegrees(pp.lng)}, N${latLngDecimalToDegrees(pp.lat)})`);
                 }
                 else {
                     let pp = obj;
@@ -862,7 +840,7 @@ export function lineContent(airspaceInfo, type = 3) {
         }
         content.push(` - ${airspaceInfo.arrive.addr}`);
         if (type == 1 || type == 3)
-            content.push(`(E${airspaceInfo.arrive.lng}, N${airspaceInfo.arrive.lat})`);
+            content.push(`(E${latLngDecimalToDegrees(airspaceInfo.arrive.lng)}, N${latLngDecimalToDegrees(airspaceInfo.arrive.lat)})`);
         if (airspaceInfo.airlineWidth) {
             content.push(`,宽度:${airspaceInfo.airlineWidth}米`);
         }
@@ -898,7 +876,7 @@ export function polygonContent(airspaceInfo, type = 3) {
             let obj = airspaceInfo.polygonPoints[i];
             let c = `${obj.addr ? obj.addr : ''}`;
             if (type == 1 || type == 3)
-                c += `(E${obj.lng}, N${obj.lat})`;
+                c += `(E${latLngDecimalToDegrees(obj.lng)}, N${latLngDecimalToDegrees(obj.lat)})`;
             content.push(c);
         }
         let cc = content.join('、') + `${length}点连线范围内`;