增加吸附道路算法
This commit is contained in:
@@ -16,6 +16,7 @@ import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.R;
|
||||
import com.mogo.module.common.api.CallChatApi;
|
||||
import com.mogo.module.common.constants.DataTypes;
|
||||
import com.mogo.module.common.utils.PointInterpolatorUtil;
|
||||
import com.mogo.realtime.entity.CloudLocationInfo;
|
||||
import com.mogo.realtime.entity.CloudRoadData;
|
||||
import com.mogo.realtime.entity.MogoSnapshotSetData;
|
||||
@@ -31,14 +32,13 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public
|
||||
/*
|
||||
* @author congtaowang
|
||||
* @since 2020/10/28
|
||||
*
|
||||
* 云端数据绘制
|
||||
*/
|
||||
class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClickListener, IMogoStatusChangedListener {
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/10/28
|
||||
*
|
||||
* 云端数据绘制
|
||||
*/
|
||||
public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClickListener, IMogoStatusChangedListener {
|
||||
|
||||
private static final String TAG = "SnapshotSetDataDrawer";
|
||||
|
||||
@@ -210,6 +210,7 @@ class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClickListen
|
||||
interval2 = 45;
|
||||
}
|
||||
interval2 -= 25;
|
||||
PointInterpolatorUtil.interpolate(points);
|
||||
marker.startSmoothInMs( points, interval2 );
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.mogo.module.common.utils;
|
||||
|
||||
import com.mogo.cloud.commons.utils.CoordinateUtils;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 点之间插值工具类
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
public class PointInterpolatorUtil {
|
||||
private static final String TAG = "PointInterpolatorUtil";
|
||||
private static final int DISTANCE_THRESHOLD = 2;
|
||||
|
||||
public static void interpolate(List<MogoLatLng> points) {
|
||||
if (points.size() >= 2) {
|
||||
// 插值
|
||||
for (int i = 0; i < points.size() - 1; i++) {
|
||||
MogoLatLng current = points.get(i);
|
||||
MogoLatLng next = points.get(i + 1);
|
||||
float distance = CoordinateUtils.calculateLineDistance(current.lon, current.lat, next.lon, next.lat);
|
||||
Logger.d(TAG, i + ": " + distance);
|
||||
if (distance > DISTANCE_THRESHOLD) {
|
||||
int inter = (int) (distance / DISTANCE_THRESHOLD);
|
||||
for (int j = 0; j < inter; j++) {
|
||||
double newLat = current.lat + (next.lat - current.lat) * 2 * (j + 1) / distance;
|
||||
double newLon = current.lon + (next.lon - current.lon) * 2 * (j + 1) / distance;
|
||||
Logger.d(TAG, "distance: " + distance + ", j: " + j + ", nextLat: " + next.lat + ", nextLon: " + next.lon + ", newLat: " + newLat + ", newLon: " + newLon);
|
||||
points.add(i + 1, new MogoLatLng(newLat, newLon));
|
||||
current = points.get(++i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static MogoLatLng mergeToRoad(MogoLatLng current, List<MogoLatLng> road) {
|
||||
closeStart = 0;
|
||||
closeEnd = road.size() - 1;
|
||||
getCloseTwoPoint(current, road);
|
||||
MogoLatLng start = road.get(closeStart);
|
||||
MogoLatLng end = road.get(closeEnd);
|
||||
return getFoot(current, start, end);
|
||||
}
|
||||
|
||||
private static int closeStart = 0;
|
||||
private static int closeEnd = 0;
|
||||
|
||||
private static void getCloseTwoPoint(MogoLatLng current, List<MogoLatLng> road) {
|
||||
if (closeEnd - closeStart == 1) {
|
||||
return;
|
||||
}
|
||||
MogoLatLng start = road.get(closeStart);
|
||||
MogoLatLng end = road.get(closeEnd);
|
||||
float startDistance = CoordinateUtils.calculateLineDistance(start.lon, start.lat, current.lon, current.lat);
|
||||
float endDistance = CoordinateUtils.calculateLineDistance(end.lon, end.lat, current.lon, current.lat);
|
||||
if (startDistance > endDistance) {
|
||||
closeStart += (closeEnd - closeStart) / 2;
|
||||
} else {
|
||||
closeEnd -= (closeEnd - closeStart) / 2;
|
||||
}
|
||||
getCloseTwoPoint(current, road);
|
||||
}
|
||||
|
||||
private static MogoLatLng getFoot(MogoLatLng pt, MogoLatLng beginPt, MogoLatLng endPt) {
|
||||
double dx = beginPt.lat - endPt.lat;
|
||||
double dy = beginPt.lon - endPt.lon;
|
||||
|
||||
double u = (pt.lat - beginPt.lat) * (beginPt.lat - endPt.lat) +
|
||||
(pt.lon - beginPt.lon) * (beginPt.lon - endPt.lon);
|
||||
u = u / (dx * dx + dy * dy);
|
||||
return new MogoLatLng(beginPt.lat + u * dx, beginPt.lon + u * dy);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user