From 14d32eef0a20407dc7a68be092a635383665cf53 Mon Sep 17 00:00:00 2001 From: renwj Date: Fri, 15 Apr 2022 19:37:07 +0800 Subject: [PATCH] =?UTF-8?q?[RoutingOpt]=E4=BF=AE=E6=AD=A3=E8=BD=A6?= =?UTF-8?q?=E5=89=8D=E5=BC=95=E5=AF=BC=E7=BA=BF=E6=8B=96=E5=B0=BE=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [RouterOpt]优化代码逻辑 --- .../ui/BusPassengerMapDirectionView.java | 4 +- .../ui/TaxiPassengerMapDirectionView.java | 2 +- .../hmi/ui/setting/DebugSettingView.kt | 2 +- .../collect/MoGoMapDataCollectProvider.kt | 2 +- .../function/smp/SmallMapDirectionView.java | 2 +- .../function/v2x/events/V2XEventManager.kt | 2 +- .../manager/impl/MoGoV2XPolylineManager.java | 126 ++++---- .../warning/V2XFrontWarningScenario.java | 2 +- .../mogo/eagle/core/data/map/MogoLatLng.java | 6 +- .../map/listener/IMoGoMapLocationListener.kt | 2 +- .../map/CallerMapLocationListenerManager.kt | 8 +- .../java/com/mogo/map/AMapViewWrapper.java | 45 ++- .../mogo/map/location/ALocationClient.java | 2 +- .../common/utils/DrivingDirectionUtils.java | 36 +++ .../routeoverlay/MogoRouteOverlayManager.java | 203 ++++++------- .../routeoverlay/RouteOverlayDrawer.java | 268 ++++++++++++++---- 16 files changed, 472 insertions(+), 240 deletions(-) diff --git a/OCH/mogo-och-bus-passenger/src/main/java/com/mogo/och/bus/passenger/ui/BusPassengerMapDirectionView.java b/OCH/mogo-och-bus-passenger/src/main/java/com/mogo/och/bus/passenger/ui/BusPassengerMapDirectionView.java index f7055ae50b..117e3a3c85 100644 --- a/OCH/mogo-och-bus-passenger/src/main/java/com/mogo/och/bus/passenger/ui/BusPassengerMapDirectionView.java +++ b/OCH/mogo-och-bus-passenger/src/main/java/com/mogo/och/bus/passenger/ui/BusPassengerMapDirectionView.java @@ -174,11 +174,11 @@ public class BusPassengerMapDirectionView @Override - public void onLocationChanged(@Nullable MogoLocation location) { - CallerLogger.INSTANCE.d(M_BUS_P + TAG, "onCarLocationChanged2 :" + location.getLatitude() + ":" + location.getLongitude()); + public void onLocationChanged(@Nullable MogoLocation location, int from) { if (location == null) { return; } + CallerLogger.INSTANCE.d(M_BUS_P + TAG, "onCarLocationChanged2 :" + location.getLatitude() + ":" + location.getLongitude()); LatLng currentLatLng = new LatLng(location.getLatitude(), location.getLongitude()); //更新车辆位置 diff --git a/OCH/mogo-och-taxi-passenger/src/main/java/com/mogo/och/taxi/passenger/ui/TaxiPassengerMapDirectionView.java b/OCH/mogo-och-taxi-passenger/src/main/java/com/mogo/och/taxi/passenger/ui/TaxiPassengerMapDirectionView.java index 940bd0f086..4565a45ab7 100644 --- a/OCH/mogo-och-taxi-passenger/src/main/java/com/mogo/och/taxi/passenger/ui/TaxiPassengerMapDirectionView.java +++ b/OCH/mogo-och-taxi-passenger/src/main/java/com/mogo/och/taxi/passenger/ui/TaxiPassengerMapDirectionView.java @@ -172,7 +172,7 @@ public class TaxiPassengerMapDirectionView @Override - public void onLocationChanged(@Nullable MogoLocation location) { + public void onLocationChanged(@org.jetbrains.annotations.Nullable MogoLocation location, int from) { CallerLogger.INSTANCE.d(M_TAXI_P + TAG, "onCarLocationChanged2 :" + location.getLatitude()+":"+location.getLongitude()); if (location == null){ return; diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/DebugSettingView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/DebugSettingView.kt index c8760bf959..2525e72797 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/DebugSettingView.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/DebugSettingView.kt @@ -1655,7 +1655,7 @@ class DebugSettingView @JvmOverloads constructor( } } - override fun onLocationChanged(location: MogoLocation?) { + override fun onLocationChanged(location: MogoLocation?, from: Int) { } diff --git a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/impl/collect/MoGoMapDataCollectProvider.kt b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/impl/collect/MoGoMapDataCollectProvider.kt index 4bedb63ea8..106c932862 100644 --- a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/impl/collect/MoGoMapDataCollectProvider.kt +++ b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/impl/collect/MoGoMapDataCollectProvider.kt @@ -148,7 +148,7 @@ class MoGoMapDataCollectProvider : IMoGoMapDataCollectProvider, OnTaskListener, } } - override fun onLocationChanged(location: MogoLocation?) { + override fun onLocationChanged(location: MogoLocation?, from: Int) { location ?: return executor.get()?.updateLocation( location.longitude, diff --git a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/SmallMapDirectionView.java b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/SmallMapDirectionView.java index a86bf21e7a..5b671fdd3a 100644 --- a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/SmallMapDirectionView.java +++ b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/SmallMapDirectionView.java @@ -162,7 +162,7 @@ public class SmallMapDirectionView @Override - public void onLocationChanged(@Nullable MogoLocation location) { + public void onLocationChanged(@org.jetbrains.annotations.Nullable MogoLocation location, int from) { if (location == null) { return; } diff --git a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/V2XEventManager.kt b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/V2XEventManager.kt index 795d4e6a15..7564821f33 100644 --- a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/V2XEventManager.kt +++ b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/V2XEventManager.kt @@ -322,7 +322,7 @@ object V2XEventManager : IMoGoMapLocationListener, IMoGoTokenCallback, IV2XCallb }) } - override fun onLocationChanged(location: MogoLocation?) { + override fun onLocationChanged(location: MogoLocation?, from: Int) { location ?: return BridgeApi.location.set(location) if (V2XManager.hasInit()) { diff --git a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/manager/impl/MoGoV2XPolylineManager.java b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/manager/impl/MoGoV2XPolylineManager.java index 2a104b9933..451f7a4285 100644 --- a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/manager/impl/MoGoV2XPolylineManager.java +++ b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/manager/impl/MoGoV2XPolylineManager.java @@ -35,70 +35,70 @@ public class MoGoV2XPolylineManager implements IMoGoV2XPolylineManager { @Override public void drawablePolyline(Context context, V2XRoadEventEntity roadEventEntity) { - try { - if (mMogoPolyline != null) { - mMogoPolyline.remove(); - } - boolean isRoadEventPOIShow = false; - boolean isOtherSeekHelpPOIShow = false; - IMoGoV2XStatusManager v2xStatus = BridgeApi.INSTANCE.v2xStatus(); - if (v2xStatus != null) { - isRoadEventPOIShow = v2xStatus.isRoadEventPOIShow(); - isOtherSeekHelpPOIShow = v2xStatus.isOtherSeekHelpPOIShow(); - } - boolean isVrMode = false; - IMogoStatusManager statusManager = BridgeApi.INSTANCE.statusManager(); - if (statusManager != null) { - isVrMode = statusManager.isVrMode(); - } +// try { +// if (mMogoPolyline != null) { +// mMogoPolyline.remove(); +// } +// boolean isRoadEventPOIShow = false; +// boolean isOtherSeekHelpPOIShow = false; +// IMoGoV2XStatusManager v2xStatus = BridgeApi.INSTANCE.v2xStatus(); +// if (v2xStatus != null) { +// isRoadEventPOIShow = v2xStatus.isRoadEventPOIShow(); +// isOtherSeekHelpPOIShow = v2xStatus.isOtherSeekHelpPOIShow(); +// } +// boolean isVrMode = false; +// IMogoStatusManager statusManager = BridgeApi.INSTANCE.statusManager(); +// if (statusManager != null) { +// isVrMode = statusManager.isVrMode(); +// } - if ((isRoadEventPOIShow - || isOtherSeekHelpPOIShow) - && V2XStatusManager.getInstance().getTargetMoGoLatLng() != null - && !isVrMode - ) { - // 连接线参数 - MogoPolylineOptions options = new MogoPolylineOptions().setGps(true); - - // 渐变色 - List colors = new ArrayList<>(); - - if (EventTypeEnum.ALERT_TRAFFIC_LIGHT_SUGGEST.getPoiType().equals(roadEventEntity.getPoiType()) - || EventTypeEnum.ALERT_TRAFFIC_LIGHT_WARNING.getPoiType().equals(roadEventEntity.getPoiType()) - || EventTypeEnum.FOURS_BLOCK_UP.getPoiType().equals(roadEventEntity.getPoiType()) - || EventTypeEnum.ALERT_CAR_TROUBLE_WARNING.getPoiType().equals(roadEventEntity.getPoiType())) { - colors.add(0xFFFFA31A); - colors.add(0xFFFFA31A); - } else { - colors.add(0xFFE32F46); - colors.add(0xFFE32F46); - } - // 线条粗细,渐变,渐变色值 - options.width(10).useGradient(true).colorValues(colors); - - // 当前车辆位置 - MogoLatLng carLocation = new MogoLatLng( - CallerAutoPilotStatusListenerManager.INSTANCE.getCurWgs84Lat(), - CallerAutoPilotStatusListenerManager.INSTANCE.getCurWgs84Lon() - ); - - if (carLocation != null) { - options.add(carLocation); - } else { - options.add(V2XStatusManager.getInstance().getLocation()); - } - // 目标车辆、道路事件位置 - options.add(V2XStatusManager.getInstance().getTargetMoGoLatLng()); - - // 绘制线的对象 - IMogoOverlayManager overlay = MogoOverlayManager.getInstance(); - if (overlay != null) { - mMogoPolyline = overlay.addPolyline(options); - } - } - } catch (Exception e) { - e.printStackTrace(); - } +// if ((isRoadEventPOIShow +// || isOtherSeekHelpPOIShow) +// && V2XStatusManager.getInstance().getTargetMoGoLatLng() != null +// && !isVrMode +// ) { +// // 连接线参数 +// MogoPolylineOptions options = new MogoPolylineOptions().setGps(true); +// +// // 渐变色 +// List colors = new ArrayList<>(); +// +// if (EventTypeEnum.ALERT_TRAFFIC_LIGHT_SUGGEST.getPoiType().equals(roadEventEntity.getPoiType()) +// || EventTypeEnum.ALERT_TRAFFIC_LIGHT_WARNING.getPoiType().equals(roadEventEntity.getPoiType()) +// || EventTypeEnum.FOURS_BLOCK_UP.getPoiType().equals(roadEventEntity.getPoiType()) +// || EventTypeEnum.ALERT_CAR_TROUBLE_WARNING.getPoiType().equals(roadEventEntity.getPoiType())) { +// colors.add(0xFFFFA31A); +// colors.add(0xFFFFA31A); +// } else { +// colors.add(0xFFE32F46); +// colors.add(0xFFE32F46); +// } +// // 线条粗细,渐变,渐变色值 +// options.width(10).useGradient(true).colorValues(colors); +// +// // 当前车辆位置 +// MogoLatLng carLocation = new MogoLatLng( +// CallerAutoPilotStatusListenerManager.INSTANCE.getCurWgs84Lat(), +// CallerAutoPilotStatusListenerManager.INSTANCE.getCurWgs84Lon() +// ); +// +// if (carLocation != null) { +// options.add(carLocation); +// } else { +// options.add(V2XStatusManager.getInstance().getLocation()); +// } +// // 目标车辆、道路事件位置 +// options.add(V2XStatusManager.getInstance().getTargetMoGoLatLng()); +// +// // 绘制线的对象 +// IMogoOverlayManager overlay = MogoOverlayManager.getInstance(); +// if (overlay != null) { +// mMogoPolyline = overlay.addPolyline(options); +// } +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } } @Override diff --git a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/scenario/scene/warning/V2XFrontWarningScenario.java b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/scenario/scene/warning/V2XFrontWarningScenario.java index ffd35821fe..585e5ee0bc 100644 --- a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/scenario/scene/warning/V2XFrontWarningScenario.java +++ b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/scenario/scene/warning/V2XFrontWarningScenario.java @@ -106,7 +106,7 @@ public class V2XFrontWarningScenario extends AbsV2XScenario implements IMoGoMapL } @Override - public void onLocationChanged(@org.jetbrains.annotations.Nullable MogoLocation location) { + public void onLocationChanged(@org.jetbrains.annotations.Nullable MogoLocation location, int from) { sV2XWarningMarker.onCarLocationChanged2(location); } diff --git a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/map/MogoLatLng.java b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/map/MogoLatLng.java index ae61f4523a..d7e21d6e2d 100644 --- a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/map/MogoLatLng.java +++ b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/map/MogoLatLng.java @@ -13,8 +13,8 @@ import java.util.Objects; */ public class MogoLatLng implements Parcelable { - public final double lat; - public final double lon; + public double lat; + public double lon; public double angle; @@ -26,6 +26,8 @@ public class MogoLatLng implements Parcelable { public String provider; + public double distance; + public MogoLatLng( double lat, double lon ) { this.lat = lat; this.lon = lon; diff --git a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/map/listener/IMoGoMapLocationListener.kt b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/map/listener/IMoGoMapLocationListener.kt index 9bcba46cd3..e5ae4b3c34 100644 --- a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/map/listener/IMoGoMapLocationListener.kt +++ b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/map/listener/IMoGoMapLocationListener.kt @@ -13,5 +13,5 @@ interface IMoGoMapLocationListener { * * @param location 新定位点 */ - fun onLocationChanged(location: MogoLocation?) + fun onLocationChanged(location: MogoLocation?, from: Int) } \ No newline at end of file diff --git a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/map/CallerMapLocationListenerManager.kt b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/map/CallerMapLocationListenerManager.kt index d459ef05ee..46cbd2487d 100644 --- a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/map/CallerMapLocationListenerManager.kt +++ b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/map/CallerMapLocationListenerManager.kt @@ -40,7 +40,7 @@ object CallerMapLocationListenerManager : CallerBase() { return } mMapStyleChangeListeners[tag] = listener - listener.onLocationChanged(mLocation) + listener.onLocationChanged(mLocation, 0) } /** @@ -73,19 +73,19 @@ object CallerMapLocationListenerManager : CallerBase() { * 触发 地图样式改变 监听 */ fun invokeMapLocationChangeListener() { - invokeMapLocationChangeListener(mLocation) + invokeMapLocationChangeListener(mLocation, 0) } /** * 触发 地图样式改变 监听 * @param location 选中状态 */ - fun invokeMapLocationChangeListener(location: MogoLocation?) { + fun invokeMapLocationChangeListener(location: MogoLocation?, from: Int) { mLocation = location mMapStyleChangeListeners.forEach { val tag = it.key val listener = it.value - listener.onLocationChanged(location) + listener.onLocationChanged(location, from) } } diff --git a/libraries/mogo-map/src/main/java/com/mogo/map/AMapViewWrapper.java b/libraries/mogo-map/src/main/java/com/mogo/map/AMapViewWrapper.java index c2fc03b5f3..c31be32fd2 100644 --- a/libraries/mogo-map/src/main/java/com/mogo/map/AMapViewWrapper.java +++ b/libraries/mogo-map/src/main/java/com/mogo/map/AMapViewWrapper.java @@ -13,6 +13,9 @@ import android.graphics.Point; import android.graphics.Rect; import android.location.Location; import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.SystemClock; import android.os.Trace; import android.text.TextUtils; import android.util.Log; @@ -305,6 +308,10 @@ public class AMapViewWrapper implements IMogoMapView, mMapView.setOnCameraChangeListener(null); CallerLogger.INSTANCE.d(M_MAP+TAG, "map onDestroy"); } + + if (mLocationTask != null) { + mainHandler.removeCallbacks(mLocationTask); + } } @Override @@ -662,18 +669,47 @@ public class AMapViewWrapper implements IMogoMapView, return ObjectUtils.transformCenterLine(MapDataApi.INSTANCE.getCenterLineInfo(lon, lat, angle)); } + private static class LocationTask implements Runnable { + + private MogoLocation location; + + public void setMoGoLocation(MogoLocation location) { + this.location = location; + } + + @Override + public void run() { + if (location != null) { + CallerMapLocationListenerManager.INSTANCE.invokeMapLocationChangeListener(location, 1); + location = null; + } + } + } + + private volatile LocationTask mLocationTask; + + private final Handler mainHandler = new Handler(Looper.getMainLooper()); + @Override public void onLocationChanged(@NotNull com.zhidaoauto.map.sdk.open.location.MogoLocation location) { - MogoLocation mLastLocation = ObjectUtils.fromLocation(location); - UiThreadHandler.post(() -> CallerMapLocationListenerManager.INSTANCE.invokeMapLocationChangeListener(mLastLocation)); - + MogoLocation currentLocation = ObjectUtils.fromLocation(location); + if (Looper.myLooper() == Looper.getMainLooper()) { + CallerMapLocationListenerManager.INSTANCE.invokeMapLocationChangeListener(currentLocation, 1); + } else { + if (mLocationTask == null) { + mLocationTask = new LocationTask(); + } + mLocationTask.setMoGoLocation(currentLocation); + mainHandler.removeCallbacks(mLocationTask); + mainHandler.post(mLocationTask); + } Location sysLocation = new Location(location.getProvider()); sysLocation.setAltitude(location.getAltitude()); sysLocation.setLatitude(location.getLat()); sysLocation.setLongitude(location.getLon()); sysLocation.setProvider(location.getProvider()); sysLocation.setAccuracy(location.getAcceleration()); - sysLocation.setTime(location.getDuration()); + sysLocation.setTime(location.duration); sysLocation.setBearing((float) location.getHeading()); sysLocation.setSpeed(location.getSpeed()); @@ -687,7 +723,6 @@ public class AMapViewWrapper implements IMogoMapView, .putString(SharedPrefsConstants.LOCATION_LONGITUDE, String.valueOf(location.getLon())); } - if (MogoCarLocationChangedListenerRegister.getInstance().getListener() != null) { MogoCarLocationChangedListenerRegister.getInstance().getListener().onCarLocationChanged2(sysLocation); } diff --git a/libraries/mogo-map/src/main/java/com/mogo/map/location/ALocationClient.java b/libraries/mogo-map/src/main/java/com/mogo/map/location/ALocationClient.java index 29dc726857..c0110baeac 100644 --- a/libraries/mogo-map/src/main/java/com/mogo/map/location/ALocationClient.java +++ b/libraries/mogo-map/src/main/java/com/mogo/map/location/ALocationClient.java @@ -115,7 +115,7 @@ public class ALocationClient implements IMogoLocationClient { } Trace.beginSection( "timer.onLocationChanged" ); mLastLocation = ObjectUtils.fromLocation( location ); - UiThreadHandler.post(() -> CallerMapLocationListenerManager.INSTANCE.invokeMapLocationChangeListener(mLastLocation)); + UiThreadHandler.post(() -> CallerMapLocationListenerManager.INSTANCE.invokeMapLocationChangeListener(mLastLocation, 0)); Set< IMogoLocationListener > listeners = MogoLocationListenerRegister.getInstance().getListeners(); synchronized ( listeners ) { diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/DrivingDirectionUtils.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/DrivingDirectionUtils.java index a2514c954a..0adacdbbc7 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/DrivingDirectionUtils.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/DrivingDirectionUtils.java @@ -2,6 +2,8 @@ package com.mogo.module.common.utils; import static java.lang.Math.PI; +import android.util.Pair; + /** * author : donghongyu * e-mail : 1358506549@qq.com @@ -11,6 +13,40 @@ import static java.lang.Math.PI; */ public class DrivingDirectionUtils { + public static long getDegreeOfCar2Poi2(double x1, double y1, double x2, double y2, double x1_angle) { + Pair newPoint = calculateNewPoint(x1, y1, x1_angle, 10); + if (newPoint != null) { + double angle = getAngle(x1, y1, newPoint.first, newPoint.second, x2, y2); + return Math.round(angle + 0.5); + } + return 0; + } + + public static double distance(double x1, double y1, double x2, double y2) { + return Math.sqrt(Math.pow(x1 - x2, 2.0) + Math.pow(y1 - y2, 2.0)); + } + + private static double getAngle(double sx, double sy, double x1, double y1, double x2, double y2) { + x1 = x1 - sx; + y1 = y1 - sy; + x2 = x2 - sx; + y2 = y2 - sy; + double product = x1 * x2 + y1 * y2; + double radians = Math.acos(product / (Math.sqrt(Math.pow(x1, 2.0) + Math.pow(y1, 2.0)) * Math.sqrt(Math.pow(x2, 2.0) + Math.pow(y2, 2.0)))); + return Math.toDegrees(radians); + } + + public static Pair calculateNewPoint(double x, double y, double angle, double distance) { + if (distance == 0) { + return null; + } + double radian = Math.toRadians(angle); + double radianCandle = Math.toRadians(90.0 - angle); + double nX = x + distance * Math.sin(radian) / 100000.0; + double nY = y + distance * Math.sin(radianCandle) / 100000.0; + return Pair.create(nX, nY); + } + /** * 计算车辆行驶方向 与 poi点到车辆的连线 间的夹角 * diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/routeoverlay/MogoRouteOverlayManager.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/routeoverlay/MogoRouteOverlayManager.java index 7ad39389d2..10adc65e6a 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/routeoverlay/MogoRouteOverlayManager.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/routeoverlay/MogoRouteOverlayManager.java @@ -3,11 +3,14 @@ package com.mogo.module.service.routeoverlay; import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_OLD_ROUTE; import android.content.Context; +import android.os.SystemClock; +import android.util.Log; import androidx.annotation.NonNull; import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo; import com.mogo.eagle.core.data.config.FunctionBuildConfig; +import com.mogo.eagle.core.data.deva.scene.SceneModule; import com.mogo.eagle.core.data.map.MogoLatLng; import com.mogo.eagle.core.data.map.MogoLocation; import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotPlanningListener; @@ -15,15 +18,21 @@ import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener; import com.mogo.eagle.core.function.api.map.listener.IMoGoMapLocationListener; import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager; import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningListenerManager; +import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager; import com.mogo.eagle.core.function.call.map.CallerMapLocationListenerManager; import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger; +import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant; import com.mogo.module.common.utils.DrivingDirectionUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; import mogo.telematics.pad.MessagePad; import mogo_msg.MogoReportMsg; @@ -33,17 +42,19 @@ public class MogoRouteOverlayManager implements IMoGoMapLocationListener { private static volatile MogoRouteOverlayManager sInstance; private Context mContext; - private String TAG = "MogoRouteOverlayManager"; - private String TAG2 = "MogoRouteOverlayManager routes"; + private String TAG = "route"; private int STATUS_AUTOPILOT = 0;//0 非自动驾驶 ; 1 自动驾驶 - private MogoLatLng mEnding; + // private MogoLatLng mEnding; private MogoLocation mLocation; - private List mTrajectoryList = new ArrayList<>(); + private AtomicBoolean isArriveAtStation = new AtomicBoolean(false); + + private volatile List mTrajectoryList = null; private MogoRouteOverlayManager(Context context) { mContext = context; } + public void init() { CallerAutopilotPlanningListenerManager.INSTANCE.addListener(TAG, this); CallerAutoPilotStatusListenerManager.INSTANCE.addListener(TAG, this); @@ -62,50 +73,73 @@ public class MogoRouteOverlayManager implements return sInstance; } - private void intiDrawer() { - RouteOverlayDrawer.getInstance(mContext).initDraw(); - } + private StringBuilder trajectoryMsg = null; @Override - public void onAutopilotTrajectory(List trajectoryInfos) { - if (trajectoryInfos == null || trajectoryInfos.size() == 0) { - return; - } - StringBuilder builder = new StringBuilder(); - builder.append("{"); - builder.append(System.currentTimeMillis()).append(";"); - builder.append(mLocation.getLongitude()).append(";"); - builder.append(mLocation.getLatitude()).append(";"); - builder.append(mLocation.getAltitude()).append(";"); - builder.append(mLocation.getBearing()).append(";"); - builder.append(mLocation.getSpeed()).append(";"); - List mogoLatLngs = new ArrayList<>(); - for (int i = 0; i < trajectoryInfos.size(); i++) { - // 临时解决车尾拖线问题,丢弃距离车最近的几个经纬度,原因是惯性导航的中心靠近车尾,会导致经纬度靠近尾部,且两个数据不同频 - if (i > 5) { - - MessagePad.TrajectoryPoint a = trajectoryInfos.get(i); - builder.append(a.getLongitude()).append(","); - builder.append(a.getLatitude()).append(","); - mogoLatLngs.add(new MogoLatLng(a.getLatitude(), a.getLongitude())); + public void onAutopilotTrajectory(@NonNull List items) { + long start = SystemClock.elapsedRealtime(); + try { + if (isArriveAtStation.get()) { + return; } + if (items.size() == 0) { + return; + } + MogoLocation location = mLocation; + if (location == null) { + return; + } + mTrajectoryList = items; + Map tags = CallerDevaToolsManager.INSTANCE.getModuleTAG(); + boolean isPrintLog = false; + if (tags != null && tags.containsKey(SceneConstant.M_OLD_ROUTE)) { + SceneModule scene = tags.get(M_OLD_ROUTE); + isPrintLog = scene.getLog(); + } + if (isPrintLog) { + if (trajectoryMsg == null) { + trajectoryMsg = new StringBuilder(128); + } + if (trajectoryMsg.length() > 0) { + trajectoryMsg.setLength(0); + } + trajectoryMsg.append("{"); + trajectoryMsg.append(System.currentTimeMillis()).append(";"); + trajectoryMsg.append(location.getLongitude()).append(";"); + trajectoryMsg.append(location.getLatitude()).append(";"); + trajectoryMsg.append(location.getAltitude()).append(";"); + trajectoryMsg.append(location.getBearing()).append(";"); + trajectoryMsg.append(location.getSpeed()).append(";"); + for (int i = 0; i < items.size(); i++) { + // 临时解决车尾拖线问题,丢弃距离车最近的几个经纬度,原因是惯性导航的中心靠近车尾,会导致经纬度靠近尾部,且两个数据不同频 + MessagePad.TrajectoryPoint a = items.get(i); + double lon = a.getLongitude(); + double lat = a.getLatitude(); + trajectoryMsg.append(lon).append(","); + trajectoryMsg.append(lat).append(","); + } + trajectoryMsg.append("}"); + Log.d(M_OLD_ROUTE + TAG, "receive router data:" + items.size()); + Log.d(M_OLD_ROUTE + TAG, trajectoryMsg.toString()); + } else { + Log.d(M_OLD_ROUTE + TAG, "receive router data:" + items.size()); + } + } finally { + Log.d(M_OLD_ROUTE + TAG, "--- onAutopilotTrajectory -- cost:" + (SystemClock.elapsedRealtime() - start) + " ms"); } - - mTrajectoryList = mogoLatLngs; - builder.append("}"); } @Override public void onAutopilotRotting(MessagePad.GlobalPathResp globalPathResp) { - if (globalPathResp == null || globalPathResp.getWayPointsList().size() == 0) { - return; - } - List latLngList = new ArrayList<>(); - for (MessagePad.Location routeModel : globalPathResp.getWayPointsList()) { - latLngList.add(new MogoLatLng(routeModel.getLatitude(), routeModel.getLongitude())); - } - int listSize = latLngList.size(); - mEnding = latLngList.get(listSize - 1); +// if (globalPathResp == null || globalPathResp.getWayPointsList().size() == 0) { +// return; +// } +// List latLngList = new ArrayList<>(); +// for (MessagePad.Location routeModel : globalPathResp.getWayPointsList()) { +// latLngList.add(new MogoLatLng(routeModel.getLatitude(), routeModel.getLongitude())); +// } +// int listSize = latLngList.size(); +// mEnding = latLngList.get(listSize - 1); // RouteOverlayDrawer.getInstance(mContext).addEndingMarker(latLngList.get(listSize - 1).lat,latLngList.get(listSize - 1).lon); } @@ -113,9 +147,13 @@ public class MogoRouteOverlayManager implements @Override public void onAutopilotStatusResponse(@NotNull AutopilotStatusInfo autoPilotStatusInfo) { if (FunctionBuildConfig.isIgnoreConditionsDrawAutopilotTrajectoryData) { + isArriveAtStation.set(false); return; } this.STATUS_AUTOPILOT = autoPilotStatusInfo.getPilotmode(); + if (this.STATUS_AUTOPILOT == 1) { + isArriveAtStation.set(false); + } //CallerLogger.INSTANCE.d(M_OLD_ROUTE + TAG ,"onAutopilotStatusResponse:"+STATUS_AUTOPILOT); // if (STATUS_AUTOPILOT == 1 ){ // if (mEnding != null){ @@ -136,9 +174,15 @@ public class MogoRouteOverlayManager implements if (arrivalNotification == null) { return; } - CallerLogger.INSTANCE.d(M_OLD_ROUTE + TAG, "onArriveAt data : " + arrivalNotification.toString()); + CallerLogger.INSTANCE.d(M_OLD_ROUTE + TAG, "onArriveAt data : " + arrivalNotification); // //演示模式下 到达终点将忽略 引导线绘制 选项关闭 // FunctionBuildConfig.isIgnoreConditionsDrawAutopilotTrajectoryData = false; + + if (!isArriveAtStation.get()) { + isArriveAtStation.set(true); + RouteOverlayDrawer.getInstance(mContext).clearEndingMarker(); + RouteOverlayDrawer.getInstance(mContext).clearMogoRouteOverlay(); + } } @@ -148,67 +192,26 @@ public class MogoRouteOverlayManager implements } @Override - public void onLocationChanged(@Nullable MogoLocation location) { -// mLocation = location; -// if (mTrajectoryList.isEmpty()) { -// return; -// } -// CallerLogger.INSTANCE.d(M_OLD_ROUTE + TAG , "onLocationChanged : " + mTrajectoryList.size()); -// ArrayList list = new ArrayList(); -// for (MogoLatLng latLng : mTrajectoryList) { -// if (!isPointOnCarFront(mLocation, latLng)) { -// list.add(latLng); -// } -// } -// -// StringBuilder builder = new StringBuilder(); -// for (int i = 0; i < list.size(); i++) { -// MogoLatLng latLng = (MogoLatLng) list.get(i); -// builder.append(latLng.getLon()).append(","); -// builder.append(latLng.getLat()).append(","); -// } -// CallerLogger.INSTANCE.d(M_OLD_ROUTE + TAG , "onLocationChanged : " + GsonUtils.toJson(builder.toString())); -// CallerLogger.INSTANCE.d(M_OLD_ROUTE + TAG ,"onLocationChanged size = " + list.size() + "---TrajectoryData = " + FunctionBuildConfig.isIgnoreConditionsDrawAutopilotTrajectoryData + "----" + STATUS_AUTOPILOT); -// if (FunctionBuildConfig.isIgnoreConditionsDrawAutopilotTrajectoryData || STATUS_AUTOPILOT == 1) { -// RouteOverlayDrawer.getInstance(mContext).drawTrajectoryList(list); -// } - - mLocation = location; - List temp = mTrajectoryList; - if (temp.isEmpty()) { + public void onLocationChanged(@Nullable MogoLocation location, int from) { + if (from != 1) { return; } -// CallerLogger.INSTANCE.d(M_OLD_ROUTE + TAG , "onLocationChanged: size = "+ mTrajectoryList.size()+" ----- "+mLocation.getLongitude()+"-"+mLocation.getLatitude()); - ArrayList list = new ArrayList(); - MogoLatLng carlatLng = new MogoLatLng(CallerAutoPilotStatusListenerManager.INSTANCE.getCurWgs84Lat(),CallerAutoPilotStatusListenerManager.INSTANCE.getCurWgs84Lon()); - list.add(carlatLng); - for (MogoLatLng latLng : temp) { -// if(!isPointOnCarFront(mLocation,latLng)){ - list.add(latLng); -// } - } -// CallerLogger.INSTANCE.d(M_OLD_ROUTE + TAG, "TrajectoryData = " + FunctionBuildConfig.isIgnoreConditionsDrawAutopilotTrajectoryData + "---status = " + STATUS_AUTOPILOT + "----size = " + list.size()); - if (FunctionBuildConfig.isIgnoreConditionsDrawAutopilotTrajectoryData || STATUS_AUTOPILOT == 1) { - RouteOverlayDrawer.getInstance(mContext).drawTrajectoryList(list); - } - } - - - public boolean isPointOnCarFront(MogoLocation carLocal, MogoLatLng pointLocal) { - double carLon = carLocal.getLongitude(); - double carLat = carLocal.getLatitude(); - double poiLon = pointLocal.lon; - double poiLat = pointLocal.lat; - float carAngle = carLocal.getBearing(); - - // 计算车辆与点之间的夹角 - int diffAngle = DrivingDirectionUtils.getDegreeOfCar2Poi( - carLon, carLat, poiLon, poiLat, (int) carAngle); -// CallerLogger.INSTANCE.d(M_OLD_ROUTE + TAG,"diffAngle:"+diffAngle); - if (diffAngle <= 90) { - return true; - } else { - return false; + long start = SystemClock.elapsedRealtime(); + boolean isExcept = false; + try { + if (location == null) { + isExcept = true; + return; + } + if (FunctionBuildConfig.isIgnoreConditionsDrawAutopilotTrajectoryData || STATUS_AUTOPILOT == 1) { + RouteOverlayDrawer.getInstance(mContext).drawTrajectoryList(location, mTrajectoryList); + } + } finally { + mLocation = location; + if (isExcept) { + RouteOverlayDrawer.getInstance(mContext).setVisible(false); + } + Log.d(M_OLD_ROUTE + TAG, "--- onLocationChanged -- cost:" + (SystemClock.elapsedRealtime() - start) + " ms"); } } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/routeoverlay/RouteOverlayDrawer.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/routeoverlay/RouteOverlayDrawer.java index a8f04250de..e1d8c28da5 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/routeoverlay/RouteOverlayDrawer.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/routeoverlay/RouteOverlayDrawer.java @@ -1,13 +1,18 @@ package com.mogo.module.service.routeoverlay; import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_OLD_ROUTE; - +import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; - +import android.os.Handler; +import android.os.HandlerThread; +import android.os.SystemClock; +import android.util.Log; +import androidx.core.util.Pools; import com.mogo.eagle.core.data.map.MogoLatLng; +import com.mogo.eagle.core.data.map.MogoLocation; import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager; import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger; import com.mogo.eagle.core.utilcode.util.ColorUtils; @@ -18,22 +23,23 @@ import com.mogo.map.marker.MogoMarkerOptions; import com.mogo.map.overlay.IMogoOverlayManager; import com.mogo.map.overlay.IMogoPolyline; import com.mogo.map.overlay.MogoPolylineOptions; +import com.mogo.module.common.utils.DrivingDirectionUtils; import com.mogo.module.service.R; - import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; +import mogo.telematics.pad.MessagePad; public class RouteOverlayDrawer { private static final String TAG = "MogoRouteOverlayManager"; - private IMogoPolyline mMoGoPolyline; + private volatile IMogoPolyline mMoGoPolyline; // 连接线参数 private final MogoPolylineOptions mPolylineOptions; - // 线路径集合 - private final List mPolylinePointList; - // 渐变色 - private final List mPolylineColors; + + private Handler mRenderHandler; + private final Bitmap endingBitmap; private final Context mContext; IMogoOverlayManager mogoOverlayManager; @@ -46,14 +52,28 @@ public class RouteOverlayDrawer { mPolylineOptions = new MogoPolylineOptions(); mPolylineOptions.zIndex(75000f); mPolylineOptions.setGps(true); - // 绘制路径集合 - mPolylinePointList = new ArrayList<>(); // 引导线颜色, - mPolylineColors = new ArrayList<>(); + // 渐变色 mContext = context; mogoOverlayManager = MogoOverlayManager.getInstance(); endingBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_route_ending); + + List list = new ArrayList<>(); + int[] startColor = ColorUtils.hexToArgb("#CC64C3EA"); + int[] endColor = ColorUtils.hexToArgb("#0064C3EA"); + list.add(Color.argb(startColor[0], startColor[1], startColor[2], startColor[3])); + list.add(Color.argb(endColor[0], endColor[1], endColor[2], endColor[3])); + // 线条粗细,渐变,渐变色值 + mPolylineOptions.width(20).useGradient(true).colorValues(list); + HandlerThread renderTask = new HandlerThread("routing_render") { + @Override + protected void onLooperPrepared() { + super.onLooperPrepared(); + mRenderHandler = new Handler(getLooper()); + } + }; + renderTask.start(); } public static RouteOverlayDrawer getInstance(Context context) { @@ -103,8 +123,10 @@ public class RouteOverlayDrawer { if (mMoGoPolyline != null) { mMoGoPolyline.remove(); mMoGoPolyline = null; - mPolylinePointList.clear(); - mPolylineColors.clear(); + } + + if (mRenderTask != null) { + mRenderHandler.removeCallbacks(mRenderTask); } } @@ -114,57 +136,191 @@ public class RouteOverlayDrawer { MogoMarkerManager.getInstance(mContext).removeMarkers(markerType); } + private class RenderTask implements Runnable { + private volatile List routeList; + private volatile MogoLocation location; - public void drawTrajectoryList(List routeList) { -// clearMogoRouteOverlay(); - mPolylinePointList.clear(); - if (routeList != null && routeList.size() > 0) { - for (MogoLatLng latLng : routeList) { - mPolylinePointList.add(latLng); + private final Pools.Pool pools; + private final LinkedList points; + + public RenderTask() { + this.pools = new Pools.SimplePool<>(500); + this.points = new LinkedList<>(); + } + + public void setData(MogoLocation location, List routeList) { + this.location = location; + this.routeList = routeList; + } + + + @SuppressLint("LongLogTag") + @Override + public void run() { + LinkedList points = this.points; + points.clear(); + try { + long drawStart = SystemClock.elapsedRealtime(); + List routes = this.routeList; + if (routes == null || routes.size() < 2) { + setVisible(false); + return; + } + for (int i = 0; i < routes.size(); i++) { + MessagePad.TrajectoryPoint route = routes.get(i); + if (route == null) { + continue; + } + MogoLatLng acquire = pools.acquire(); + double latitude = route.getLatitude(); + double longitude = route.getLongitude(); + if (acquire == null) { + acquire = new MogoLatLng(latitude, longitude); + } else { + acquire.lon = longitude; + acquire.lat = latitude; + } + points.add(acquire); + } + MogoLocation location = this.location; + double lon = CallerAutoPilotStatusListenerManager.INSTANCE.getCurWgs84Lon(); + double lat = CallerAutoPilotStatusListenerManager.INSTANCE.getCurWgs84Lat(); + if (lon == 0.0 || lat == 0.0) { + return; + } + if (location != null && points.size() > 0) { + int i = 0; + int max = Math.min(20, points.size() / 2); + MogoLatLng top = null; + int remove = 0; + long angle; + while (i++ < max) { + MogoLatLng first = points.peek(); + if (first == null) { + continue; + } + if (first == top) { + break; + } + angle = isPointOnCarFront(lon, lat, location.getBearing(), first.lon, first.lat); + if (angle >= 90) { + Log.d(M_OLD_ROUTE + TAG, "render - removeCount:" + (++remove)); + points.poll(); + } + top = first; + } + //distance +// if (top != null) { +// double distance = DrivingDirectionUtils.distance(top.lon, top.lat, lon, lat) * 10_0000; +// angle = isPointOnCarFront(lon, lat, location.getBearing(), top.lon, top.lat); +// Log.d(M_OLD_ROUTE + TAG, "render - distance:" + distance + ",angle:" + angle); +// if (distance > 4.0 && angle >= 80) { +// float bearing = location.getBearing(); +// Pair p_car_f = DrivingDirectionUtils.calculateNewPoint(lon, lat, bearing, 5); +// Pair p_rout_f = DrivingDirectionUtils.calculateNewPoint(top.lon, top.lat, bearing, 5); +// if (p_car_f != null && p_rout_f != null) { +// Stack stack = new Stack<>(); +// stack.add(new MogoLatLng(p_car_f.second, p_car_f.first)); +// double new_bear = bearing + 90; +// while (distance > 0.1) { +// distance /= 2; +// Pair p = DrivingDirectionUtils.calculateNewPoint(p_car_f.first, p_car_f.second, new_bear, distance); +// if (p == null) { +// break; +// } +// stack.push(new MogoLatLng(p.second, p.first)); +// } +// Log.d("XXXX", "----stack:" + stack.size()); +// long newAngle = DrivingDirectionUtils.getDegreeOfCar2Poi2(p_rout_f.first, p_rout_f.second, top.lon, top.lat, bearing); +// Log.d("XXXX", "----newAngle:" + newAngle); +// while (newAngle > 90) { +// Log.d("XXXX", "----newAngle:" + newAngle); +// points.poll(); +// MogoLatLng peek = points.peek(); +// if (peek == null) { +// points.poll(); +// continue; +// } +// newAngle = DrivingDirectionUtils.getDegreeOfCar2Poi2(p_rout_f.first, p_rout_f.second, peek.lon, peek.lat, bearing); +// } +// while (!stack.isEmpty()) { +// MogoLatLng pop = stack.pop(); +// points.addFirst(pop); +// } +// } +// } +// } + + MogoLatLng self = pools.acquire(); + if (self == null) { + self = new MogoLatLng(lat, lon); + } else { + self.lat = lat; + self.lon = lon; + } + points.addFirst(self); + if (mMoGoPolyline == null || mMoGoPolyline.isDestroyed()) { + mPolylineOptions.points(points); + mMoGoPolyline = mogoOverlayManager.addPolyline(mPolylineOptions); + } else { + mPolylineOptions.points(points); + mMoGoPolyline.setOption(mPolylineOptions); + } + if (mMoGoPolyline != null && !mMoGoPolyline.isDestroyed() && !mMoGoPolyline.isVisible()) { + mMoGoPolyline.setVisible(true); + } + } else { + if(mMoGoPolyline != null) { + mMoGoPolyline.setVisible(false); + } + } + long drawEnd = SystemClock.elapsedRealtime(); + Log.d(M_OLD_ROUTE + TAG, "drawTrajectoryList cost : " + (drawEnd - drawStart)); + } catch (Throwable t) { + Log.d(M_OLD_ROUTE + TAG, "drawTrajectoryList error : " + t); + } finally { + if (points.size() > 0) { + for (int i = 0; i < points.size(); i++) { + MogoLatLng latLng = points.get(i); + if (latLng == null) { + continue; + } + pools.release(latLng); + } + } } - mPolylineColors.clear(); -// mPolylineColors.addAll(ColorUtils.gradientAlpha_("#FF2AAFFD", "#7b2965ED", "#002965ED", mPolylinePointList.size())); - List list = new ArrayList<>(); -// list = ColorUtils.gradientAlpha("#FF2AAFFD", "#002965ED", mPolylinePointList.size()); - int[] startColor = ColorUtils.hexToArgb("#CC64C3EA"); - int[] endColor = ColorUtils.hexToArgb("#0064C3EA"); - list.add(Color.argb(startColor[0], startColor[1], startColor[2], startColor[3])); - list.add(Color.argb(endColor[0], endColor[1], endColor[2], endColor[3])); + } - mPolylineColors.addAll(list); - // 线条粗细,渐变,渐变色值 - mPolylineOptions.width(20).useGradient(true).colorValues(mPolylineColors); - if (mMoGoPolyline == null || mMoGoPolyline.isDestroyed()) { - mPolylineOptions.points(mPolylinePointList); - mMoGoPolyline = mogoOverlayManager.addPolyline(mPolylineOptions); - } else { - mPolylineOptions.points(mPolylinePointList); - mMoGoPolyline.setOption(mPolylineOptions); + private long isPointOnCarFront(double car_lon, double car_lat, double car_head, double lon, double lat) { + long start = SystemClock.elapsedRealtime(); + try { + // 计算车辆与点之间的夹角 + long diffAngle = DrivingDirectionUtils.getDegreeOfCar2Poi2( + car_lon, car_lat, lon, lat, car_head); + CallerLogger.INSTANCE.d(M_OLD_ROUTE + TAG, "isPointOnCarFront: angle->" + diffAngle); + return diffAngle; + } finally { + CallerLogger.INSTANCE.d(M_OLD_ROUTE + TAG, "isPointOnCarFront cost:" + (SystemClock.elapsedRealtime() - start) + "ms"); } } } - public void initDraw() { - mPolylinePointList.clear(); - MogoLatLng latLng = new MogoLatLng( - CallerAutoPilotStatusListenerManager.INSTANCE.getCurWgs84Lat(), - CallerAutoPilotStatusListenerManager.INSTANCE.getCurWgs84Lon()); - mPolylinePointList.add(latLng); - mPolylinePointList.add(latLng); - mPolylineColors.clear(); - long start = System.currentTimeMillis(); - List list = new ArrayList<>(); - list = ColorUtils.gradientAlpha("#FF2AAFFD", "#002965ED", mPolylinePointList.size()); + private volatile RenderTask mRenderTask; - mPolylineColors.addAll(list); - // 线条粗细,渐变,渐变色值 - mPolylineOptions.width(12).useGradient(true).colorValues(mPolylineColors); - if (mMoGoPolyline == null || mMoGoPolyline.isDestroyed()) { - mPolylineOptions.points(mPolylinePointList); - mMoGoPolyline = mogoOverlayManager.addPolyline(mPolylineOptions); - } else { - mPolylineOptions.points(mPolylinePointList); - mMoGoPolyline.setOption(mPolylineOptions); + public void drawTrajectoryList(MogoLocation carLoc, List routeList) { + if (mRenderTask == null) { + mRenderTask = new RenderTask(); + } + mRenderTask.setData(carLoc, routeList); + if (mRenderHandler != null) { + mRenderHandler.removeCallbacks(mRenderTask); + mRenderHandler.post(mRenderTask); + } + } + + public void setVisible(boolean isVisible) { + if (mMoGoPolyline != null && !mMoGoPolyline.isDestroyed()) { + mMoGoPolyline.setVisible(isVisible); } } }