|
|
@@ -15,6 +15,7 @@ import com.izouma.walkchina.dto.webservice.DirectionResponse;
|
|
|
import com.izouma.walkchina.dto.webservice.RouteStep;
|
|
|
import com.izouma.walkchina.exception.ServiceException;
|
|
|
import com.izouma.walkchina.repo.*;
|
|
|
+import com.izouma.walkchina.utils.LocationUtils;
|
|
|
import com.izouma.walkchina.utils.SecurityUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -64,6 +65,9 @@ public class MapService {
|
|
|
}
|
|
|
|
|
|
public Collection<UserMarker> usersInRegion(Long userId, MapRegion mapRegion) {
|
|
|
+ UserInfo userInfo = userInfoRepository.findById(userId).orElseThrow(new ServiceException("用户不存在"));
|
|
|
+ double dLat = mapRegion.getVirtualLocation().getLatitude() - userInfo.getLatitude();
|
|
|
+ double dLng = mapRegion.getVirtualLocation().getLongitude() - userInfo.getLongitude();
|
|
|
List<UserMarker> list = userInfoRepository.findInRegion(userId, mapRegion.getSouthwest().getLatitude(), mapRegion.getSouthwest().getLongitude(),
|
|
|
mapRegion.getNortheast().getLongitude(), mapRegion.getNortheast().getLongitude());
|
|
|
for (UserMarker userMarker : list) {
|
|
|
@@ -94,7 +98,7 @@ public class MapService {
|
|
|
City destination = Optional.ofNullable(userJourney.getDestination()).orElseThrow(new ServiceException("无记录"));
|
|
|
UserInfo userInfo = userInfoRepository.findById(userId).orElseThrow(new ServiceException("用户不存在"));
|
|
|
UserMap userMap = UserMap.builder()
|
|
|
- .polyline(minifyPolyline(userJourney.getPolyline()))
|
|
|
+ // .polyline(minifyPolyline(userJourney.getPolyline()))
|
|
|
// .polyline(userJourney.getPolyline())
|
|
|
.origin(origin)
|
|
|
.destination(destination)
|
|
|
@@ -105,6 +109,7 @@ public class MapService {
|
|
|
progressPolyline.addAll(stages.get(i).getPolyline());
|
|
|
}
|
|
|
JourneyStage latestStage = stages.get(stages.size() - 1);
|
|
|
+ userMap.setPolyline(minifyPolyline(latestStage.getPolyline()));
|
|
|
userMap.setDestination(latestStage.getDestination());
|
|
|
userMap.setNearOrigin(latestStage.getOrigin());
|
|
|
userMap.setProgress(latestStage.getProgress());
|
|
|
@@ -138,12 +143,18 @@ public class MapService {
|
|
|
// break;
|
|
|
// }
|
|
|
// }
|
|
|
- List<Double> extra = new ArrayList<>();
|
|
|
for (int i = 0; i <= endPoint(steps, latestStage.getDistance() * latestStage.getProgress()); i++) {
|
|
|
progressPolyline.add(latestStage.getPolyline().get(i));
|
|
|
}
|
|
|
|
|
|
- userMap.setProgressPolyline(minifyPolyline(progressPolyline));
|
|
|
+ List<Double> subPolyline = new ArrayList<>();
|
|
|
+ for (int i = 0; i < stages.size() - 1; i++) {
|
|
|
+ subPolyline.addAll(extractPolyline(stages.get(i).getPolyline()));
|
|
|
+ }
|
|
|
+ subPolyline.addAll(subPolyline(steps, latestStage.getDistance() * latestStage.getProgress(), latestStage.getPolyline()));
|
|
|
+ userMap.setProgressPolyline(compressPolyline(subPolyline));
|
|
|
+
|
|
|
+ // userMap.setProgressPolyline(minifyPolyline(progressPolyline));
|
|
|
// userMap.setProgressPolyline(progressPolyline);
|
|
|
return userMap;
|
|
|
}
|
|
|
@@ -170,6 +181,82 @@ public class MapService {
|
|
|
return steps.get(steps.size() - 1).getPolylineIdx().get(1);
|
|
|
}
|
|
|
|
|
|
+ List<Double> subPolyline(List<RouteStep> steps, double distance, List<Double> polyline) {
|
|
|
+ double d = 0;
|
|
|
+ double sd = 0;
|
|
|
+ int i = 0;
|
|
|
+ for (; i < steps.size(); i++) {
|
|
|
+ if (d + steps.get(i).getDistance() >= distance) {
|
|
|
+ sd = d + steps.get(i).getDistance() - distance;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ d += steps.get(i).getDistance();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Double> extracted = extractPolyline(polyline);
|
|
|
+ List<Double> subPolyline = new ArrayList<>();
|
|
|
+ for (int j = 0; j < steps.get(i).getPolylineIdx().get(0); j++) {
|
|
|
+ subPolyline.add(extracted.get(j));
|
|
|
+ }
|
|
|
+
|
|
|
+ int start = steps.get(i).getPolylineIdx().get(0);
|
|
|
+ int end = steps.get(i).getPolylineIdx().get(1);
|
|
|
+ double d1 = 0;
|
|
|
+ for (int j = start; j < end - 2; j += 2) {
|
|
|
+ double lat1 = extracted.get(j);
|
|
|
+ double lng1 = extracted.get(j + 1);
|
|
|
+ subPolyline.add(lat1);
|
|
|
+ subPolyline.add(lng1);
|
|
|
+ double lat2 = extracted.get(j + 2);
|
|
|
+ double lng2 = extracted.get(j + 3);
|
|
|
+ double dd = LocationUtils.getDistance(lat1, lng1, lat2, lng2);
|
|
|
+ if (d1 + dd >= sd) {
|
|
|
+ double p = (d1 + dd) / (d - steps.get(i).getDistance());
|
|
|
+ double lat3 = (lat2 - lat1) * p + lat1;
|
|
|
+ double lng3 = (lng2 - lng1) * p + lng1;
|
|
|
+ subPolyline.add(lat3);
|
|
|
+ subPolyline.add(lng3);
|
|
|
+ return subPolyline;
|
|
|
+ }
|
|
|
+ d1 += dd;
|
|
|
+ }
|
|
|
+ return subPolyline;
|
|
|
+ }
|
|
|
+
|
|
|
+ Location endPoint(List<RouteStep> steps, double distance, List<Double> polyline) {
|
|
|
+ double d = 0;
|
|
|
+ double sd = 0;
|
|
|
+ int i = 0;
|
|
|
+ for (; i < steps.size(); i++) {
|
|
|
+ if (d + steps.get(i).getDistance() >= distance) {
|
|
|
+ sd = d + steps.get(i).getDistance() - distance;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ d += steps.get(i).getDistance();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Double> extracted = extractPolyline(polyline);
|
|
|
+
|
|
|
+ int start = steps.get(i).getPolylineIdx().get(0);
|
|
|
+ int end = steps.get(i).getPolylineIdx().get(1);
|
|
|
+ double d1 = 0;
|
|
|
+ for (int j = start; j < end - 2; j += 2) {
|
|
|
+ double lat1 = extracted.get(j);
|
|
|
+ double lng1 = extracted.get(j + 1);
|
|
|
+ double lat2 = extracted.get(j + 2);
|
|
|
+ double lng2 = extracted.get(j + 3);
|
|
|
+ double dd = LocationUtils.getDistance(lat1, lng1, lat2, lng2);
|
|
|
+ if (d1 + dd >= sd) {
|
|
|
+ double p = (d1 + dd) / (d - steps.get(i).getDistance());
|
|
|
+ double lat3 = (lat2 - lat1) * p + lat1;
|
|
|
+ double lng3 = (lng2 - lng1) * p + lng1;
|
|
|
+ return new Location(lat3, lng3);
|
|
|
+ }
|
|
|
+ d1 += dd;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
List<Double> extractPolyline(List<Double> polyline) {
|
|
|
List<Double> list = new ArrayList<>(polyline);
|
|
|
for (int i = 2; i < list.size(); i++) {
|
|
|
@@ -191,7 +278,7 @@ public class MapService {
|
|
|
List<Double> extracted = extractPolyline(polyline);
|
|
|
list.add(polyline.get(0));
|
|
|
list.add(polyline.get(1));
|
|
|
- for (int i = 2; i < polyline.size(); i += 20) {
|
|
|
+ for (int i = 2; i < polyline.size(); i += 10) {
|
|
|
double d0 = Math.abs(polyline.get(i));
|
|
|
double d1 = Math.abs(polyline.get(i + 1));
|
|
|
if (d0 == 0 && d1 == 0) {
|