diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/V2XWarningEntity.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/V2XWarningEntity.java index 4510dd5821..df3e48319a 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/V2XWarningEntity.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/V2XWarningEntity.java @@ -163,6 +163,10 @@ public class V2XWarningEntity implements Serializable { this.warningContent = warningContent; } + public void setStopLines(List stopLines) { + this.stopLines = stopLines; + } + public int getType() { return type; } @@ -199,18 +203,6 @@ public class V2XWarningEntity implements Serializable { return speed; } - public String getTargetColor() { - return targetColor; - } - - public String getRoadId() { - return roadId; - } - - public String getLaneId() { - return laneId; - } - public String getUuid() { return uuid; } @@ -219,10 +211,6 @@ public class V2XWarningEntity implements Serializable { return color; } - public String getCarId() { - return carId; - } - public String getWarningContent() { if (this.warningContent == null) { setTipContent(type); @@ -254,6 +242,10 @@ public class V2XWarningEntity implements Serializable { return stopLineDistance; } + public List getStopLines() { + return stopLines; + } + @Override public String toString() { return "V2XWarningEntity{" + diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XWarningMarker.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XWarningMarker.java index f2492e97ba..cb6c5decb6 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XWarningMarker.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XWarningMarker.java @@ -2,6 +2,7 @@ package com.mogo.module.v2x.scenario.scene.warning; import android.content.Context; +import com.mogo.cloud.commons.utils.CoordinateUtils; import com.mogo.map.MogoLatLng; import com.mogo.map.marker.IMogoMarker; import com.mogo.map.marker.MogoMarkerOptions; @@ -15,11 +16,11 @@ import com.mogo.module.v2x.V2XConst; import com.mogo.module.v2x.V2XServiceManager; import com.mogo.module.v2x.entity.model.DrawLineInfo; import com.mogo.module.v2x.scenario.view.IV2XMarker; +import com.mogo.module.v2x.utils.LocationUtils; import com.mogo.utils.WorkThreadHandler; import java.util.ArrayList; import java.util.List; -import java.util.logging.Handler; /** * @author liujing @@ -45,7 +46,7 @@ public class V2XWarningMarker implements IV2XMarker { if (MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) { clearPOI(); WorkThreadHandler.getInstance().postDelayed(() -> { - IMogoMarker marker = drawMarker(markerShowEntity); + IMogoMarker marker = drawMarkerAndReturn(markerShowEntity); //如果有预警碰撞点,识别物与预警碰撞点之间连线,并执行平移动画 if (mMarkerEntity.getCollisionLat() > 0 && mMarkerEntity.getCollisionLon() != 0) { drawLine(); @@ -62,7 +63,32 @@ public class V2XWarningMarker implements IV2XMarker { } - public IMogoMarker drawMarker(MarkerShowEntity markerShowEntity) { + public void pointsBetween() { + try { + List stopLines = mMarkerEntity.getStopLines(); + if (stopLines.size() > 1) { + MogoLatLng x = mMarkerEntity.getStopLines().get(0); + MogoLatLng y = mMarkerEntity.getStopLines().get(1); + //两点间的距离 + float distance = CoordinateUtils.calculateLineDistance(x.lon, x.lat, y.lon, y.lat); + float average = distance / 3; + //两点间的角度 + double angle = LocationUtils.getAngle(x.lon, x.lat, y.lon, y.lat); + //根据距离和角度获取下个点的经纬度 + List replenish = new ArrayList(); + for (int i = 1; i < 3; i++) { + MogoLatLng newLocation = LocationUtils.getNewLocation(x, average * i, angle); + replenish.add(newLocation); + } + } + } catch (Exception e) { + + } + + } + + //绘制marker + public IMogoMarker drawMarkerAndReturn(MarkerShowEntity markerShowEntity) { MogoMarkerOptions options = new MogoMarkerOptions() .object(markerShowEntity) .latitude(markerShowEntity.getMarkerLocation().getLat()) @@ -76,6 +102,7 @@ public class V2XWarningMarker implements IV2XMarker { return marker; } + //绘制线 public void drawLine() { DrawLineInfo drawLineInfo = new DrawLineInfo(); MogoLatLng slatLng = new MogoLatLng(mMarkerEntity.getLat(), mMarkerEntity.getLon()); @@ -85,6 +112,7 @@ public class V2XWarningMarker implements IV2XMarker { V2XServiceManager.getMoGoWarnPolylineManager().drawWarnPolyline(mContext, drawLineInfo); } + //平移 public void smooth(IMogoMarker marker) { List latLngs = new ArrayList<>(); MogoLatLng sLocation = new MogoLatLng(mMarkerEntity.getLat(), mMarkerEntity.getLon()); diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/utils/LocationUtils.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/utils/LocationUtils.java index 5df1ff2fcb..fd2d26506d 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/utils/LocationUtils.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/utils/LocationUtils.java @@ -28,8 +28,14 @@ import com.mogo.utils.network.utils.GsonUtil; */ public class LocationUtils { private static final String TAG = "LocationUtils"; + private final static double radius_b = 6378137;//大半径 + private final static double radius_s = 6356725;//小半径 + private static double mRadLo; + private static double mRadLa; + private static double Ec; + private static double Ed; - public static void geoCodeSearch(MogoLocation location,IMogoGeoSearchListener listener) { + public static void geoCodeSearch(MogoLocation location, IMogoGeoSearchListener listener) { MogoRegeocodeQuery mogoRegeocodeQuery = new MogoRegeocodeQuery(); mogoRegeocodeQuery.setPoint(new MogoLatLng(location.getLatitude(), location.getLongitude())); @@ -83,6 +89,39 @@ public class LocationUtils { return latLon; } + /* + * 计算两点间的角度 + * */ + public static double getAngle(double lon1, double lat1, double lon2, + double lat2) { + double fLat = Math.PI * (lat1) / 180.0; + double fLng = Math.PI * (lon1) / 180.0; + double tLat = Math.PI * (lat2) / 180.0; + double tLng = Math.PI * (lon2) / 180.0; + double degree = (Math.atan2(Math.sin(tLng - fLng) * Math.cos(tLat), Math.cos(fLat) * Math.sin(tLat) - + Math.sin(fLat) * Math.cos(tLat) * Math.cos(tLng - fLng))) * 180.0 / Math.PI; + if (degree >= 0) { + return degree; + } else { + return 360 + degree; + } + } + + /* + * 根据角度获取指定距离点的经纬度 + * */ + public static MogoLatLng getNewLocation(MogoLatLng st, double distance, double angle) { + mRadLo = st.getLon() * Math.PI / 180.; + mRadLa = st.getLat() * Math.PI / 180.; + Ec = radius_s + (radius_b - radius_s) * (90. - st.lat) / 90; + Ed = Ec * Math.cos(mRadLa); + + double dx = distance * Math.sin(Math.toRadians(angle)); + double dy = distance * Math.cos(Math.toRadians(angle)); + double lon_new = (dx / Ed + mRadLo) * 180. / Math.PI; + double lat_new = (dy / Ec + mRadLa) * 180. / Math.PI; + return new MogoLatLng(lat_new, lon_new); + } } diff --git a/modules/mogo-module-v2x/src/main/res/raw/scenario_warning_event_data.json b/modules/mogo-module-v2x/src/main/res/raw/scenario_warning_event_data.json index 57fdbc8e8c..557ff1ab14 100644 --- a/modules/mogo-module-v2x/src/main/res/raw/scenario_warning_event_data.json +++ b/modules/mogo-module-v2x/src/main/res/raw/scenario_warning_event_data.json @@ -7,12 +7,12 @@ "collisionLon": 116.417634, "stopLines":[ { - "stopLineLat": 39.977082, - "stopLineLon": 116.417553 + "lat": 39.977082, + "lon": 116.417553 }, { - "stopLineLat": 39.977078, - "stopLineLon": 116.417666 + "lat": 39.977078, + "lon": 116.417666 } ], "from": 1,