diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/V2XWarnDataDrawer.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/V2XWarnDataDrawer.java index b6f0ed0894..b9e1b9b533 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/V2XWarnDataDrawer.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/V2XWarnDataDrawer.java @@ -16,6 +16,7 @@ import com.mogo.module.common.drawer.marker.SimpleWindow3DAdapter; import com.mogo.module.common.entity.MarkerLocation; import com.mogo.module.common.entity.MarkerShowEntity; import com.mogo.module.common.entity.V2XWarningEntity; +import com.mogo.module.common.utils.Trigonometric; import com.mogo.module.common.view.MarkerBaseFloor; import com.mogo.service.statusmanager.IMogoStatusChangedListener; import com.mogo.service.statusmanager.StatusDescriptor; @@ -122,15 +123,16 @@ public class V2XWarnDataDrawer extends BaseDrawer implements IMogoStatusChangedL } /* - * 2D资源绘制marker + * 2D资源绘制marker底部的红色圆圈 * */ private IMogoMarker drawMarkerWith2Resource(MarkerShowEntity markerShowEntity) { + MogoLatLng mogoLatLng = new MogoLatLng(markerShowEntity.getMarkerLocation().getLat(), markerShowEntity.getMarkerLocation().getLon()); + MogoLatLng newLocation = Trigonometric.getNewLocation(mogoLatLng, 80, 180); MogoMarkerOptions optionsRipple = new MogoMarkerOptions() - .latitude(markerShowEntity.getMarkerLocation().getLat()) - .longitude(markerShowEntity.getMarkerLocation().getLon()) + .latitude(newLocation.getLat()) + .longitude(newLocation.getLon()) .anchor(1.0f, 1.0f) .zIndex(MarkerDrawer.MARKER_Z_INDEX_HIGH); - optionsRipple .icon(ViewUtils.fromView(new EmptyMarkerView(mContext))); IMogoMarker marker = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager(mContext).addMarker(markerShowEntity.getMarkerType(), optionsRipple); diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/Trigonometric.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/Trigonometric.java new file mode 100644 index 0000000000..61f5a5183f --- /dev/null +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/Trigonometric.java @@ -0,0 +1,53 @@ +package com.mogo.module.common.utils; + +import com.mogo.map.MogoLatLng; + +/** + * @author liujing + * @description 描述 + * @since: 2021/4/13 + */ +public class Trigonometric { + 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 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-common/src/main/res/layout/module_common_warning_marker_bottom.xml b/modules/mogo-module-common/src/main/res/layout/module_common_warning_marker_bottom.xml index 1ec9b2b6ab..1bc7234fa3 100644 --- a/modules/mogo-module-common/src/main/res/layout/module_common_warning_marker_bottom.xml +++ b/modules/mogo-module-common/src/main/res/layout/module_common_warning_marker_bottom.xml @@ -1,12 +1,12 @@ + android:layout_height="match_parent" + android:orientation="vertical"> + android:src="@drawable/common_marker_bottom_floor" /> \ No newline at end of file diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/manager/impl/MoGoV2XCloundDataManager.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/manager/impl/MoGoV2XCloundDataManager.java index 6a7ff1d86d..985807685d 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/manager/impl/MoGoV2XCloundDataManager.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/manager/impl/MoGoV2XCloundDataManager.java @@ -12,6 +12,7 @@ import com.mogo.map.overlay.IMogoPolyline; import com.mogo.module.common.MogoApisHandler; import com.mogo.module.common.drawer.V2XWarnDataDrawer; import com.mogo.module.common.entity.V2XWarningEntity; +import com.mogo.module.common.utils.Trigonometric; import com.mogo.module.service.MarkerServiceHandler; import com.mogo.module.service.receiver.MogoReceiver; import com.mogo.module.v2x.MoGoV2XServicePaths; @@ -19,7 +20,6 @@ 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.manager.IMoGoV2XCloundDataManager; -import com.mogo.module.v2x.utils.LocationUtils; import com.mogo.utils.UiThreadHandler; import com.mogo.utils.WorkThreadHandler; @@ -39,7 +39,10 @@ public class MoGoV2XCloundDataManager implements IMoGoV2XCloundDataManager, IMog private boolean isSelfLineClear; private List fillPoints = new ArrayList();//停止线经纬度合集 private boolean isFirstLocation = false; - private MogoLatLng carLocation; + private MogoLatLng carLocation = new MogoLatLng( + MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLat(), + MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLon() + ); private static long showTime = 0; @@ -63,7 +66,7 @@ public class MoGoV2XCloundDataManager implements IMoGoV2XCloundDataManager, IMog isFirstLocation = false; if (cloundWarningInfo.getDirection() == 1) { //前方 - MogoLatLng newLocation = LocationUtils.getNewLocation((MogoLatLng) fillPoints.get(0), 80, cloundWarningInfo.getAngle()); + MogoLatLng newLocation = Trigonometric.getNewLocation((MogoLatLng) fillPoints.get(0), 80, cloundWarningInfo.getAngle()); //停止线前方画线 WorkThreadHandler.getInstance().postDelayed(() -> { //二轮车和行人的渲染和移动 @@ -126,7 +129,7 @@ public class MoGoV2XCloundDataManager implements IMoGoV2XCloundDataManager, IMog Log.d(V2XConst.LOG_NAME_WARN, " drawStopLine endLatlng lon =" + endLatlng.lon + "--lat =" + endLatlng.lat + "--startLatlng lon = " + startLatlng.lon + "-lat = " + startLatlng.lat); float distance = CoordinateUtils.calculateLineDistance(startLatlng.lon, startLatlng.lat, endLatlng.lon, endLatlng.lat); - MogoLatLng addMiddleLoc = LocationUtils.getNewLocation(startLatlng, distance / 2, mCloundWarningInfo.getAngle()); + MogoLatLng addMiddleLoc = Trigonometric.getNewLocation(startLatlng, distance / 2, mCloundWarningInfo.getAngle()); if (polyLine != null) { Log.d(V2XConst.LOG_NAME_WARN, "drawStopLine polyLine != null"); polyLine.setPoints(Arrays.asList(startLatlng, addMiddleLoc, endLatlng)); @@ -158,7 +161,7 @@ public class MoGoV2XCloundDataManager implements IMoGoV2XCloundDataManager, IMog MogoLatLng startLatlng = new MogoLatLng(info.getLat(), info.getLon()); MogoLatLng endLatlng = new MogoLatLng(info.getCollisionLat(), info.getCollisionLon()); float distance = CoordinateUtils.calculateLineDistance(startLatlng.lon, startLatlng.lat, endLatlng.lon, endLatlng.lat); - MogoLatLng addMiddleLoc = LocationUtils.getNewLocation(startLatlng, distance / 2, mCloundWarningInfo.getAngle()); + MogoLatLng addMiddleLoc = Trigonometric.getNewLocation(startLatlng, distance / 2, mCloundWarningInfo.getAngle()); if (polyLine != null) { Log.d(V2XConst.LOG_NAME_WARN, "polyLine != null"); polyLine.setPoints(Arrays.asList(startLatlng, addMiddleLoc, endLatlng)); @@ -225,7 +228,7 @@ public class MoGoV2XCloundDataManager implements IMoGoV2XCloundDataManager, IMog endLatlng = new MogoLatLng(mCloundWarningInfo.getDirection() == 1 ? carLocation.lat : mCloundWarningInfo.getCollisionLat(), mCloundWarningInfo.getDirection() == 1 ? carLocation.lon : mCloundWarningInfo.getCollisionLon()); float distance = CoordinateUtils.calculateLineDistance(startLatlng.lon, startLatlng.lat, endLatlng.lon, endLatlng.lat); - addMiddleLoc = LocationUtils.getNewLocation(startLatlng, distance / 2, mCloundWarningInfo.getAngle()); + addMiddleLoc = Trigonometric.getNewLocation(startLatlng, distance / 2, mCloundWarningInfo.getAngle()); Log.d(V2XConst.LOG_NAME_WARN, "drawSlefCarLine lon = " + carLocation.lon + "---lat = " + carLocation.lat); isFirstLocation = true; } @@ -265,11 +268,11 @@ public class MoGoV2XCloundDataManager implements IMoGoV2XCloundDataManager, IMog 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); + double angle = Trigonometric.getAngle(x.lon, x.lat, y.lon, y.lat); //根据距离和角度获取下个点的经纬度 fillPoints.add(x); for (int i = 1; i < 3; i++) { - MogoLatLng newLocation = LocationUtils.getNewLocation(x, average * i, angle); + MogoLatLng newLocation = Trigonometric.getNewLocation(x, average * i, angle); fillPoints.add(newLocation); } fillPoints.add(y); @@ -280,7 +283,7 @@ public class MoGoV2XCloundDataManager implements IMoGoV2XCloundDataManager, IMog } private MogoLatLng getMogoLat(MogoLatLng latlng) { - MogoLatLng newLocation = LocationUtils.getNewLocation(latlng, mCloundWarningInfo.getStopLineDistance(), mCloundWarningInfo.getDirection()); + MogoLatLng newLocation = Trigonometric.getNewLocation(latlng, mCloundWarningInfo.getStopLineDistance(), mCloundWarningInfo.getDirection()); return newLocation; } 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 75bb3d4554..9f3f54f6ce 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 @@ -16,6 +16,7 @@ import com.mogo.module.common.drawer.marker.SimpleWindow3DAdapter; import com.mogo.module.common.entity.MarkerLocation; import com.mogo.module.common.entity.MarkerShowEntity; import com.mogo.module.common.entity.V2XWarningEntity; +import com.mogo.module.common.utils.Trigonometric; import com.mogo.module.v2x.R; import com.mogo.module.v2x.V2XConst; import com.mogo.module.v2x.V2XServiceManager; @@ -99,7 +100,7 @@ public class V2XWarningMarker implements IV2XMarker { carlo = new MogoLatLng(lat, lon); } //自车行驶方向的前方*米的经纬度,该经纬度在停止线上 - MogoLatLng drawStopLineLon = LocationUtils.getNewLocation(carlo, mMarkerEntity.getStopLineDistance(), mMarkerEntity.getAngle()); + MogoLatLng drawStopLineLon = Trigonometric.getNewLocation(carlo, mMarkerEntity.getStopLineDistance(), mMarkerEntity.getAngle()); Log.d(TAG, "2D资源绘" + drawStopLineLon); MogoMarkerOptions optionsRipple = new MogoMarkerOptions() .latitude(drawStopLineLon.getLat()) 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 6f6dbc047a..088586d229 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 @@ -27,12 +27,6 @@ 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) { MogoRegeocodeQuery mogoRegeocodeQuery = new MogoRegeocodeQuery(); @@ -93,42 +87,6 @@ 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); - } - - /** * 获取传入的经纬度在车辆的什么位置 *