diff --git a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/marker/AMapMarkerWrapper.java b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/marker/AMapMarkerWrapper.java index 2f3ca549fd..09a6cd26c2 100644 --- a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/marker/AMapMarkerWrapper.java +++ b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/marker/AMapMarkerWrapper.java @@ -479,8 +479,8 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer { return; } -// mMarker.startSmooth( newPoints, ( int ) duration ); - mMarker.addDynamicAnchorPostion( newPoints.get( newPoints.size() - 1 ), ( int ) duration ); + mMarker.startSmooth( newPoints, ( int ) duration ); +// mMarker.addDynamicAnchorPostion( newPoints.get( newPoints.size() - 1 ), ( int ) duration ); } @Override diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/SnapshotSetDataDrawer.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/SnapshotSetDataDrawer.java index e227e3f7c2..af49364169 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/SnapshotSetDataDrawer.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/SnapshotSetDataDrawer.java @@ -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 { diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/PointInterpolatorUtil.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/PointInterpolatorUtil.java new file mode 100644 index 0000000000..ca1cee5461 --- /dev/null +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/PointInterpolatorUtil.java @@ -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 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 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 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); + } +}