Переглянути джерело

Merge branch 'fix_2airway_bug' into 'master'

fix #1

Closes #1

See merge request BA/amap-shapes-generator!7
haoxinlei 7 роки тому
батько
коміт
5b8938b2c5
1 змінених файлів з 29 додано та 7 видалено
  1. 29 7
      index.js

+ 29 - 7
index.js

@@ -88,17 +88,39 @@ function addOvalPointConfig(lat, lng, imageName, dataType) {
 }
 
 
+function getCrossPoint(points1, points2) {
+    for(let point1 of points1) {
+        for(let point2 of points2) {
+            if (point1.point_id == point2.point_id)
+                return point1
+        }
+    }
+}
+
 function getAirwayPoints(airway, pointBefore, pointAfter) {
     let found = 0
     let points = []
 
-    let airwayPoints
-    if (points in airway)
-        airwayPoints = airway.points
-    else
-        airwayPoints = airway.airlines
+    let pointTypeFix, pointsFix
+
+    if (points in airway) {
+        pointTypeFix = 'point_type';
+        pointsFix = 'points'
+    } else {
+        pointTypeFix = 'pointType'
+        pointsFix = 'airlines'
+    }
+
+    // 如果前后是其他航线,那么找到交叉点作为前后的点
+    if ( pointBefore[pointTypeFix] == Global.pointTypes.line ) {
+        pointBefore = getCrossPoint(airway[pointsFix], pointBefore[pointsFix])
+    }
+
+    if(pointAfter[pointTypeFix] == Global.pointTypes.line) {
+        pointAfter = getCrossPoint(airway[pointsFix], pointAfter[pointsFix])
+    }
 
-    for (let point of airwayPoints) {
+    for (let point of airway[pointsFix]) {
         if (pointBefore.point_id == point.point_id || pointAfter.point_id == point.point_id) {
             found++
             points.push(Object.assign({}, point))
@@ -112,7 +134,7 @@ function getAirwayPoints(airway, pointBefore, pointAfter) {
 
     if (!(points.length > 0 && found == 2)) {
         // 如果两个点不全在航线上面,那么画全部航线
-        points = airwayPoints
+        points = airway[pointsFix]
     }
 
     return points;