shuhao 4 månader sedan
förälder
incheckning
5180f4fa54
1 ändrade filer med 11 tillägg och 5 borttagningar
  1. 11 5
      src/views/authentic/authenticMap.js

+ 11 - 5
src/views/authentic/authenticMap.js

@@ -320,16 +320,22 @@ class AuthenticMap {
                     // const list = features.getGeometry().getCoordinates();
                     // const arr = list[0][0].find(subArray => subArray.includes(coordinates))
                   let arr = []
-                  let i = 0
+                  let i = 0;let curDistance = 0
                   for(let subArray of coordinates[0]){
                     let from = turf.point(subArray);
                     let to = turf.point(lonlat);
                     let options = { units: "miles" };
                     let distance = turf.distance(from, to, options);
-                    if(distance < 0.001){
-                      arr = subArray
-                      mapData.pointIndex = i
-                      break
+                    if(distance < 0.1){
+                      if(curDistance == 0){
+                        arr = subArray
+                        curDistance = distance
+                        mapData.pointIndex = i
+                      }else if(curDistance > distance){
+                        arr = subArray
+                        curDistance = distance
+                        mapData.pointIndex = i
+                      }
                     }
                     i++
                   }