[8.0.0][Opt]优化决策、预测地图渲染

This commit is contained in:
chenfufeng
2025-05-21 19:03:28 +08:00
parent 74dffcb288
commit 57a62699be
13 changed files with 556 additions and 226 deletions

View File

@@ -2,6 +2,7 @@ package com.mogo.eagle.core.function.business.identify
import android.util.Log
import com.mogo.eagle.core.data.config.FunctionBuildConfig
import com.mogo.eagle.core.data.map.MogoLatLng
import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.data.traffic.TrafficData
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotIdentifyListener
@@ -9,11 +10,14 @@ import com.mogo.eagle.core.function.api.base.IMoGoSubscriber
import com.mogo.eagle.core.function.api.datacenter.obu.IMoGoObuStatusListener
import com.mogo.eagle.core.function.business.routeoverlay.PredictionOverlayDrawer
import com.mogo.eagle.core.function.business.routeoverlay.PredictionOverlayDrawer2
import com.mogo.eagle.core.function.business.routeoverlay.PredictionOverlayDrawer3
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotIdentifyListenerManager
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager.getLocationHeading
import com.mogo.eagle.core.function.call.obu.CallerObuWarningListenerManager
import com.mogo.eagle.core.utilcode.util.ThreadUtils
import com.mogo.map.MogoMap
import com.mogo.map.MogoMap.Companion.mapInstance
import com.mogo.map.identify.MogoIdentifyManager
import com.mogo.map.utils.LocationUtils
import mogo.telematics.pad.MessagePad
@@ -78,19 +82,20 @@ class MapIdentifySubscriber private constructor() : IMoGoSubscriber,
if (FunctionBuildConfig.isDrawPreIdentifyData) {
try {
ThreadUtils.getSinglePool().execute {
// // 渲染它车
// IdentifyFactory.renderPredictionResult(predictionObjects.objsAppList)
val mogoMap = mapInstance.getMogoMap(MogoMap.DEFAULT)
val pointsList: ArrayList<List<MogoLatLng>> = ArrayList()
var arr: DoubleArray?
// 渲染自车
predictionObjects.objsAppList.forEach { preObj ->
val points = ArrayList<MogoLatLng>()
if (preObj.mNid == 800000L) {
// 自车有2条轨迹一条概率大、一条概率小
if (preObj.predictionTrajectoryList == null || preObj.predictionTrajectoryList.size < 2) return@forEach
carPoiList1 = preObj.predictionTrajectoryList[0].trajectoryPointsList
carPoiList2 = preObj.predictionTrajectoryList[1].trajectoryPointsList
val largeType: Int
val heading = getChassisLocationWGS84().heading
location1 = LocationUtils.generateLocation(carPoiList1!![0].x, carPoiList1!![0].y, heading)
location2 = LocationUtils.generateLocation(carPoiList2!![0].x, carPoiList2!![0].y, heading)
location1 = LocationUtils.generateLocation(carPoiList1!![0].x, carPoiList1!![0].y, getLocationHeading())
location2 = LocationUtils.generateLocation(carPoiList2!![0].x, carPoiList2!![0].y, getLocationHeading())
if (location1 == null || location2 == null) return@forEach
probability1 = preObj.predictionTrajectoryList[0].predictionProbability
probability2 = preObj.predictionTrajectoryList[1].predictionProbability
@@ -102,12 +107,24 @@ class MapIdentifySubscriber private constructor() : IMoGoSubscriber,
MogoIdentifyManager.getInstance().updateGps(location2!!, MogoMap.SMALL_PRED_MAP)
largeType = 3
}
PredictionOverlayDrawer.getInstance().drawPredictionList(carPoiList1, heading, false, 2, largeType)
PredictionOverlayDrawer2.getInstance().drawPredictionList(carPoiList2, heading, false, 3, largeType)
PredictionOverlayDrawer2.getInstance().drawPredictionList(carPoiList1, getLocationHeading(), false, 2, largeType)
PredictionOverlayDrawer3.getInstance().drawPredictionList(carPoiList2, getLocationHeading(), false, 3, largeType)
MogoIdentifyManager.getInstance().updateGps(location1!!, MogoMap.SMALL_PRED_MAP2)
MogoIdentifyManager.getInstance().updateGps(location2!!, MogoMap.SMALL_PRED_MAP3)
} else {
if (preObj.predictionTrajectoryList.isNullOrEmpty() || mogoMap == null) return@forEach
preObj.predictionTrajectoryList[0].trajectoryPointsList.forEachIndexed { index, point ->
if (index % 2 == 0) {// 步长为2减少点
arr = mogoMap.switchData(point.x, point.y, false)
arr?.let { lonLatArr ->
points.add(MogoLatLng(lonLatArr[1], lonLatArr[0]))
}
}
}
pointsList.add(points)
}
}
PredictionOverlayDrawer.getInstance().drawPredictionList(pointsList, getLocationHeading())
}
} catch (e: Exception) {
e.printStackTrace()

View File

@@ -131,16 +131,16 @@ public class MogoRouteOverlayManager implements
// Log.d(TAG, "-- onChassisLocationGCJ02 -- 1 ---" + ":auto-mode:" + autoPilotState + ", isArriveAtStation: " + isArriveAtStation);
if (isArriveAtStation && autoPilotState != 2) {
RouteOverlayDrawer.getInstance().clearMogoRouteOverlay();
PredictionOverlayDrawer.getInstance().clearPreRouteOverlay();
PredictionOverlayDrawer2.getInstance().clearPreRouteOverlay();
PredictionOverlayDrawer3.getInstance().clearPreRouteOverlay();
return;
}
// Log.d(TAG, "-- onChassisLocationGCJ02 -- 2 ---" + "auto-mode:" + autoPilotState + ", isDemoMode:" + FunctionBuildConfig.isDemoMode + ", force:" + FunctionBuildConfig.isForceDrawAutopilotTrajectoryByDebugSettingView);
boolean force = hasGreenWave.get() || FunctionBuildConfig.isForceDrawAutopilotTrajectoryByDebugSettingView || FunctionBuildConfig.isDemoMode && FunctionBuildConfig.isIgnoreConditionsDrawAutopilotTrajectoryData;
if (!force && autoPilotState != 2) {
RouteOverlayDrawer.getInstance().clearMogoRouteOverlay();
PredictionOverlayDrawer.getInstance().clearPreRouteOverlay();
PredictionOverlayDrawer2.getInstance().clearPreRouteOverlay();
PredictionOverlayDrawer3.getInstance().clearPreRouteOverlay();
return;
}
// Log.d(TAG, "-- onChassisLocationGCJ02 -- 3 ---");

View File

@@ -1,10 +1,6 @@
package com.mogo.eagle.core.function.business.routeoverlay;
import static com.mogo.map.MogoMap.DEFAULT;
import static com.mogo.map.MogoMap.SMALL_DES_MAP;
import static com.mogo.map.MogoMap.SMALL_PRED_MAP;
import static com.mogo.map.MogoMap.SMALL_PRED_MAP2;
import static com.mogo.map.MogoMap.SMALL_PRED_MAP3;
import android.annotation.SuppressLint;
import android.graphics.Color;
@@ -16,24 +12,19 @@ import androidx.core.util.Pools;
import com.mogo.eagle.core.data.config.FunctionBuildConfig;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.eagle.core.data.map.MogoLocation;
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager;
import com.mogo.eagle.core.function.call.map.CallerMapIdentifyManager;
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager;
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils;
import com.mogo.eagle.core.utilcode.util.DrivingDirectionUtils;
import com.mogo.map.IMogoMap;
import com.mogo.map.MogoMap;
import com.mogo.map.overlay.IMoGoOverlayManager;
import com.mogo.map.overlay.core.Level;
import com.mogo.map.overlay.line.Polyline;
import com.zhidaoauto.map.sdk.open.common.tools.MapTools;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import kotlin.Pair;
import mogo.telematics.pad.MessagePad;
public class PredictionOverlayDrawer {
@@ -46,14 +37,12 @@ public class PredictionOverlayDrawer {
private static final byte[] obj = new byte[0];
private static final int COLOR_LIGHT = Color.parseColor("#BAEBF5");
private final List<Integer> greenWaveColors = new ArrayList<>();
private PredictionOverlayDrawer() {
// 渐变色
mogoOverlayManager = CallerMapUIServiceManager.INSTANCE.getOverlayManager();
if (mogoOverlayManager != null) {
// 线条粗细,渐变,渐变色值
HandlerThread renderTask = new HandlerThread("prediction_render") {
HandlerThread renderTask = new HandlerThread("pred_render") {
@Override
protected void onLooperPrepared() {
super.onLooperPrepared();
@@ -61,17 +50,6 @@ public class PredictionOverlayDrawer {
}
};
renderTask.start();
ArrayList<Pair<Integer, Integer>> temps = new ArrayList<>();
temps.add(new Pair<>(0, 51));
temps.add(new Pair<>(10, 102));
temps.add(new Pair<>(30, 51));
temps.add(new Pair<>(100, 0));
List<Integer> alphas = MapTools.INSTANCE.getColorAlpha(temps);
if (alphas != null && !alphas.isEmpty()) {
for (int i : alphas) {
greenWaveColors.add(Color.argb(i, 48, 163, 255));
}
}
}
}
@@ -96,36 +74,31 @@ public class PredictionOverlayDrawer {
}
private class RenderTask implements Runnable {
private volatile List<MogoLatLng> predictionList;
// 对象池
private final Pools.Pool<MogoLatLng> pools;
private final LinkedList<MogoLatLng> points;
private double bearing;
private boolean hasGreenWave;
private int preViewType;
private int largeType;
private Polyline.Options mPolylineOptions;
//用于taxi乘客屏渐变颜色集合
private List<Integer> colors = null;
private volatile List<List<MogoLatLng>> mPredPointsList;
private final List<LinkedList<MogoLatLng>> mPointsList;
private List<Polyline.Options> mLineOptList;
public RenderTask() {
this.pools = new Pools.SimplePool<>(500);
this.points = new LinkedList<>();
mPolylineOptions = new Polyline.Options.Builder("prediction_overlay" + preViewType, Level.GUIDE_ROUTE_LINE)
this.pools = new Pools.SimplePool<>(1000);
this.mPointsList = new ArrayList<>();
mPolylineOptions = new Polyline.Options.Builder("pred_overlay", Level.GUIDE_ROUTE_LINE)
.setUseGps(true)
.setWidth(20)
.setWidth(10)
.setIsGradient(true)
.build();
}
public void setPreData(List<MogoLatLng> data, double bearing, boolean hasGreenWave, int preType, int largeType) {
predictionList = data;
public void setPreDataList(List<List<MogoLatLng>> data, double bearing) {
mPredPointsList = data;
this.bearing = bearing;
this.hasGreenWave = hasGreenWave;
preViewType = preType;
this.largeType = largeType;
}
@SuppressLint("LongLogTag")
@@ -135,168 +108,127 @@ public class PredictionOverlayDrawer {
if (overlayManager == null) {
return;
}
LinkedList<MogoLatLng> pps = this.points;
List<LinkedList<MogoLatLng>> poiList = mPointsList;
List<LinkedList<MogoLatLng>> ppsList = new ArrayList<>();
boolean isExcept = false;
int total;
try {
pps.clear();
List<MogoLatLng> routes = this.predictionList;
if (routes == null || (total = routes.size()) < 2) {
isExcept = true;
poiList.clear();
List<List<MogoLatLng>> routes1 = this.mPredPointsList;
if (mLineOptList == null) {
mLineOptList = new ArrayList<>();
}
for (List<MogoLatLng> latLngList : routes1) {
if (latLngList == null || (total = latLngList.size()) < 2) {
return;
}
boolean isColorfulStrategy = !hasGreenWave && !AppIdentityModeUtils.isTaxi(FunctionBuildConfig.appIdentityMode) || !AppIdentityModeUtils.isPassenger(FunctionBuildConfig.appIdentityMode);
if (isColorfulStrategy) {
RouteStrategy.INSTANCE.start();
} else {
if (colors == null || colors.isEmpty()) {
ArrayList<Pair<Integer, Integer>> temps = new ArrayList<>();
temps.add(new Pair<>(0, 51));
temps.add(new Pair<>(10, 102));
temps.add(new Pair<>(30, 51));
temps.add(new Pair<>(100, 0));
List<Integer> alphas = MapTools.INSTANCE.getColorAlpha(temps);
if (alphas != null && !alphas.isEmpty()) {
colors = new CopyOnWriteArrayList<>();
for (int i : alphas) {
colors.add(Color.argb(i, 48, 163, 255));
LinkedList<MogoLatLng> pps = null;
try {
pps = new LinkedList<>();
for (int i = 0; i < total; i++) {
MogoLatLng route = null;
try {
route = latLngList.get(i);
if (route == null) {
continue;
}
} catch (Throwable t) {
Log.d("Route", "render-error:" + t.getMessage());
}
}
}
for (int i = 0; i < total; i++) {
MogoLatLng route = null;
try {
route = routes.get(i);
if (route == null) {
continue;
}
} catch (Throwable t) {
Log.d("Route", "render-error:" + t.getMessage());
}
if (route == null) {
//数组越界了,结束循环
break;
}
MogoLatLng acquire = pools.acquire();
double latitude = route.getLat();
double longitude = route.getLon();
if (acquire == null) {
acquire = new MogoLatLng(latitude, longitude);
} else {
acquire.lon = longitude;
acquire.lat = latitude;
}
acquire.acc = 0.0;// 加速度
acquire.speed = 0.0;// 速度
pps.add(acquire);
if (isColorfulStrategy) {
RouteStrategy.INSTANCE.check(0.0, 0.0, predictionList.size());
}
}
double lon = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLongitude();
double lat = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLatitude();
if (!points.isEmpty()) {
MogoLatLng top = null;
while (!points.isEmpty()) {
MogoLatLng first = points.peek();
if (first == null) {
continue;
}
if (first == top) {
//数组越界了,结束循环
break;
}
lon = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLongitude();
lat = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLatitude();
long angle = isPointOnCarFront(lon, lat, bearing, first.lon, first.lat);
if (angle >= 90) {
if (isColorfulStrategy) {
RouteStrategy.INSTANCE.remove(first.acc);
}
pools.release(first);
points.poll();
}
top = first;
}
if (points.isEmpty()) {
isExcept = true;
return;
}
MogoLatLng self = pools.acquire();
if (self == null) {
self = new MogoLatLng(lat, lon);
} else {
self.lat = lat;
self.lon = lon;
}
points.addFirst(self);
Polyline.Options.Builder builder;
if (mPolylineOptions == null) {
builder = new Polyline.Options.Builder("prediction_overlay" + preViewType, Level.GUIDE_ROUTE_LINE)
.setUseGps(true)
.setWidth(20)
.setIsGradient(true);
} else {
builder = mPolylineOptions.builder();
}
if (isColorfulStrategy) {
RouteStrategy.INSTANCE.end();
Strategy strategy = RouteStrategy.INSTANCE.getStrategy();
List<Integer> colors = strategy.getColors();
boolean isLightOn = strategy instanceof ColorfulStrategy && ((ColorfulStrategy) strategy).isLightOn();
builder.colors(colors);
builder.setLightOn(isLightOn);
builder.setLightColor(COLOR_LIGHT);
builder.setLightSpeed(0.3f);
} else {
if (!hasGreenWave) {
if (colors != null && !colors.isEmpty()) {
builder.colors(colors);
builder.setIsGradient(true);
builder.setLightOn(true);
builder.isShowArrow(false);
builder.setLightColor(COLOR_LIGHT);
builder.setLightSpeed(0.3f);
}
MogoLatLng acquire = pools.acquire();
double latitude = route.getLat();
double longitude = route.getLon();
if (acquire == null) {
acquire = new MogoLatLng(latitude, longitude);
} else {
builder.colors(greenWaveColors)
.setIsGradient(true)
.setLightOn(false)
.isShowArrow(true);
acquire.lon = longitude;
acquire.lat = latitude;
}
acquire.acc = 0.0;// 加速度
acquire.speed = 0.0;// 速度
pps.add(acquire);
}
builder.points(points);
builder.setVisible(true);
Polyline.Options options = builder.build();
if (mPolylineOptions == null) {
mPolylineOptions = options;
}
if (FunctionBuildConfig.isDrawPreIdentifyData) {
if (preViewType == 2) {
overlayManager.showOrUpdateLine(options, SMALL_PRED_MAP2);
} else if (preViewType == 3) {
overlayManager.showOrUpdateLine(options, SMALL_PRED_MAP3);
ppsList.add(pps);
MogoLocation location = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84();
double lon = location.getLongitude();
double lat = location.getLatitude();
if (!pps.isEmpty()) {
MogoLatLng top = null;
while (!pps.isEmpty()) {
MogoLatLng first = pps.peek();
if (first == null) {
continue;
}
if (first == top) {
break;
}
lon = location.getLongitude();
lat = location.getLatitude();
long angle = isPointOnCarFront(lon, lat, bearing, first.lon, first.lat);
if (angle >= 90) {
pools.release(first);
pps.poll();
}
top = first;
}
}
} else {
isExcept = true;
}
} catch (Throwable t) {
t.printStackTrace();
} finally {
if (isExcept) {
setVisible(false);
}
if (!points.isEmpty()) {
for (int i = 0; i < points.size(); i++) {
MogoLatLng latLng = points.get(i);
if (latLng == null) {
continue;
if (pps.isEmpty()) {
isExcept = true;
return;
}
MogoLatLng self = pools.acquire();
if (self == null) {
self = new MogoLatLng(lat, lon);
} else {
self.lat = lat;
self.lon = lon;
}
pps.addFirst(self);
// 线的配置
Polyline.Options.Builder builder;
if (mPolylineOptions == null) {
builder = new Polyline.Options.Builder("pred_overlay", Level.GUIDE_ROUTE_LINE)
.setUseGps(true)
.setWidth(5)
.setIsGradient(true);
} else {
builder = mPolylineOptions.builder();
}
builder.color(Color.rgb(196, 196, 196));
builder.setIsGradient(false);
builder.setLightOn(false);
builder.setIsDottedLine(true);
builder.isShowArrow(false);
builder.points(pps);
builder.setVisible(true);
Polyline.Options options = builder.build();
if (mPolylineOptions == null) {
mPolylineOptions = options;
}
if (FunctionBuildConfig.isDrawPreIdentifyData && CallerMapIdentifyManager.INSTANCE.isPreViewLoaded()) {
overlayManager.showOrUpdateLine(options, SMALL_PRED_MAP);
}
} else {
isExcept = true;
}
poiList.add(pps);
} catch (Throwable t) {
t.printStackTrace();
} finally {
if (isExcept) {
setVisible(false);
}
if (pps != null && !pps.isEmpty()) {
for (int i = 0; i < pps.size(); i++) {
MogoLatLng latLng = pps.get(i);
if (latLng == null) {
continue;
}
pools.release(latLng);
}
pools.release(latLng);
}
}
}
@@ -309,21 +241,13 @@ public class PredictionOverlayDrawer {
private volatile RenderTask mPreRenderTask;
public void drawPredictionList(List<geometry.Geometry.Point> dataList, double bearing, boolean hasGreenWave, int preType, int largeType) {
IMogoMap iMogoMap = MogoMap.Companion.getMapInstance().getMogoMap(DEFAULT);
double[] arr;
if (mogoOverlayManager != null && iMogoMap != null) {
public void drawPredictionList(List<List<MogoLatLng>> dataList, double bearing) {
if (dataList.isEmpty()) return;
if (mogoOverlayManager != null) {
if (mPreRenderTask == null) {
mPreRenderTask = new RenderTask();
}
List<MogoLatLng> latLngList = new ArrayList<>();
for (geometry.Geometry.Point point : dataList) {
arr = iMogoMap.switchData(point.getX(), point.getY(), false);
if (arr == null || arr.length < 2) continue;
latLngList.add(new MogoLatLng(arr[1], arr[0]));
}
if (latLngList.isEmpty()) return;
mPreRenderTask.setPreData(latLngList, bearing, hasGreenWave, preType, largeType);
mPreRenderTask.setPreDataList(dataList, bearing);
if (mRenderHandler != null) {
mRenderHandler.removeCallbacks(mPreRenderTask);
mRenderHandler.post(mPreRenderTask);

View File

@@ -1,7 +1,6 @@
package com.mogo.eagle.core.function.business.routeoverlay;
import static com.mogo.map.MogoMap.DEFAULT;
import static com.mogo.map.MogoMap.SMALL_PRED_MAP;
import static com.mogo.map.MogoMap.SMALL_PRED_MAP2;
import static com.mogo.map.MogoMap.SMALL_PRED_MAP3;
@@ -16,6 +15,7 @@ import androidx.core.util.Pools;
import com.mogo.eagle.core.data.config.FunctionBuildConfig;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager;
import com.mogo.eagle.core.function.call.map.CallerMapIdentifyManager;
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager;
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils;
import com.mogo.eagle.core.utilcode.util.DrivingDirectionUtils;
@@ -32,6 +32,7 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import kotlin.Pair;
import mogo.telematics.pad.MessagePad;
public class PredictionOverlayDrawer2 {
@@ -51,7 +52,7 @@ public class PredictionOverlayDrawer2 {
mogoOverlayManager = CallerMapUIServiceManager.INSTANCE.getOverlayManager();
if (mogoOverlayManager != null) {
// 线条粗细,渐变,渐变色值
HandlerThread renderTask = new HandlerThread("prediction_render2") {
HandlerThread renderTask = new HandlerThread("prediction_render") {
@Override
protected void onLooperPrepared() {
super.onLooperPrepared();
@@ -144,7 +145,7 @@ public class PredictionOverlayDrawer2 {
isExcept = true;
return;
}
boolean isColorfulStrategy = !hasGreenWave && !AppIdentityModeUtils.isTaxi(FunctionBuildConfig.appIdentityMode) || !AppIdentityModeUtils.isPassenger(FunctionBuildConfig.appIdentityMode);
boolean isColorfulStrategy = false;
if (isColorfulStrategy) {
RouteStrategy.INSTANCE.start();
} else {
@@ -209,9 +210,6 @@ public class PredictionOverlayDrawer2 {
lat = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLatitude();
long angle = isPointOnCarFront(lon, lat, bearing, first.lon, first.lat);
if (angle >= 90) {
if (isColorfulStrategy) {
RouteStrategy.INSTANCE.remove(first.acc);
}
pools.release(first);
points.poll();
}
@@ -272,10 +270,10 @@ public class PredictionOverlayDrawer2 {
if (mPolylineOptions == null) {
mPolylineOptions = options;
}
if (FunctionBuildConfig.isDrawDecIdentifyData) {
if (preViewType == 2) {
if (FunctionBuildConfig.isDrawPreIdentifyData) {
if (preViewType == 2 && CallerMapIdentifyManager.INSTANCE.isPreView2Loaded()) {
overlayManager.showOrUpdateLine(options, SMALL_PRED_MAP2);
} else if (preViewType == 3) {
} else if (preViewType == 3 && CallerMapIdentifyManager.INSTANCE.isPreView3Loaded()) {
overlayManager.showOrUpdateLine(options, SMALL_PRED_MAP3);
}
}
@@ -309,7 +307,7 @@ public class PredictionOverlayDrawer2 {
public void drawPredictionList(List<geometry.Geometry.Point> dataList, double bearing, boolean hasGreenWave, int preType, int largeType) {
IMogoMap iMogoMap = MogoMap.Companion.getMapInstance().getMogoMap(DEFAULT);
double[] arr = null;
double[] arr;
if (mogoOverlayManager != null && iMogoMap != null) {
if (mPreRenderTask == null) {
mPreRenderTask = new RenderTask();

View File

@@ -0,0 +1,341 @@
package com.mogo.eagle.core.function.business.routeoverlay;
import static com.mogo.map.MogoMap.DEFAULT;
import static com.mogo.map.MogoMap.SMALL_PRED_MAP2;
import static com.mogo.map.MogoMap.SMALL_PRED_MAP3;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Handler;
import android.os.HandlerThread;
import android.util.Log;
import androidx.core.util.Pools;
import com.mogo.eagle.core.data.config.FunctionBuildConfig;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager;
import com.mogo.eagle.core.function.call.map.CallerMapIdentifyManager;
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager;
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils;
import com.mogo.eagle.core.utilcode.util.DrivingDirectionUtils;
import com.mogo.map.IMogoMap;
import com.mogo.map.MogoMap;
import com.mogo.map.overlay.IMoGoOverlayManager;
import com.mogo.map.overlay.core.Level;
import com.mogo.map.overlay.line.Polyline;
import com.zhidaoauto.map.sdk.open.common.tools.MapTools;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import kotlin.Pair;
public class PredictionOverlayDrawer3 {
private static final String TAG = "PredictionOverlayDrawer3";
// 连接线参数
private Handler mRenderHandler;
private final IMoGoOverlayManager mogoOverlayManager;
private static volatile PredictionOverlayDrawer3 sInstance;
private static final byte[] obj = new byte[0];
private static final int COLOR_LIGHT = Color.parseColor("#BAEBF5");
private final List<Integer> greenWaveColors = new ArrayList<>();
private PredictionOverlayDrawer3() {
// 渐变色
mogoOverlayManager = CallerMapUIServiceManager.INSTANCE.getOverlayManager();
if (mogoOverlayManager != null) {
// 线条粗细,渐变,渐变色值
HandlerThread renderTask = new HandlerThread("prediction_render2") {
@Override
protected void onLooperPrepared() {
super.onLooperPrepared();
mRenderHandler = new Handler(getLooper());
}
};
renderTask.start();
ArrayList<Pair<Integer, Integer>> temps = new ArrayList<>();
temps.add(new Pair<>(0, 51));
temps.add(new Pair<>(10, 102));
temps.add(new Pair<>(30, 51));
temps.add(new Pair<>(100, 0));
List<Integer> alphas = MapTools.INSTANCE.getColorAlpha(temps);
if (alphas != null && !alphas.isEmpty()) {
for (int i : alphas) {
greenWaveColors.add(Color.argb(i, 48, 163, 255));
}
}
}
}
public static PredictionOverlayDrawer3 getInstance() {
if (sInstance == null) {
synchronized (obj) {
if (sInstance == null) {
sInstance = new PredictionOverlayDrawer3();
}
}
}
return sInstance;
}
public void clearPreRouteOverlay() {
if (mogoOverlayManager != null) {
if (mPreRenderTask != null) {
mRenderHandler.removeCallbacks(mPreRenderTask);
}
mogoOverlayManager.hideAllLinesInLevel(Level.GUIDE_ROUTE_LINE);
}
}
private class RenderTask implements Runnable {
private volatile List<MogoLatLng> predictionList;
private final Pools.Pool<MogoLatLng> pools;
private final LinkedList<MogoLatLng> points;
private double bearing;
private boolean hasGreenWave;
private int preViewType;
private int largeType;
private Polyline.Options mPolylineOptions;
//用于taxi乘客屏渐变颜色集合
private List<Integer> colors = null;
public RenderTask() {
this.pools = new Pools.SimplePool<>(500);
this.points = new LinkedList<>();
mPolylineOptions = new Polyline.Options.Builder("prediction_overlay" + preViewType, Level.GUIDE_ROUTE_LINE)
.setUseGps(true)
.setWidth(20)
.setIsGradient(true)
.build();
}
public void setPreData(List<MogoLatLng> data, double bearing, boolean hasGreenWave, int preType, int largeType) {
predictionList = data;
this.bearing = bearing;
this.hasGreenWave = hasGreenWave;
preViewType = preType;
this.largeType = largeType;
}
@SuppressLint("LongLogTag")
@Override
public void run() {
IMoGoOverlayManager overlayManager = mogoOverlayManager;
if (overlayManager == null) {
return;
}
LinkedList<MogoLatLng> pps = this.points;
boolean isExcept = false;
int total;
try {
pps.clear();
List<MogoLatLng> routes = this.predictionList;
if (routes == null || (total = routes.size()) < 2) {
isExcept = true;
return;
}
boolean isColorfulStrategy = false;
if (isColorfulStrategy) {
RouteStrategy.INSTANCE.start();
} else {
if (colors == null || colors.isEmpty()) {
ArrayList<Pair<Integer, Integer>> temps = new ArrayList<>();
temps.add(new Pair<>(0, 51));
temps.add(new Pair<>(10, 102));
temps.add(new Pair<>(30, 51));
temps.add(new Pair<>(100, 0));
List<Integer> alphas = MapTools.INSTANCE.getColorAlpha(temps);
if (alphas != null && !alphas.isEmpty()) {
colors = new CopyOnWriteArrayList<>();
for (int i : alphas) {
colors.add(Color.argb(i, 48, 163, 255));
}
}
}
}
for (int i = 0; i < total; i++) {
MogoLatLng route = null;
try {
route = routes.get(i);
if (route == null) {
continue;
}
} catch (Throwable t) {
Log.d("Route", "render-error:" + t.getMessage());
}
if (route == null) {
//数组越界了,结束循环
break;
}
MogoLatLng acquire = pools.acquire();
double latitude = route.getLat();
double longitude = route.getLon();
if (acquire == null) {
acquire = new MogoLatLng(latitude, longitude);
} else {
acquire.lon = longitude;
acquire.lat = latitude;
}
acquire.acc = 0.0;// 加速度
acquire.speed = 0.0;// 速度
pps.add(acquire);
if (isColorfulStrategy) {
RouteStrategy.INSTANCE.check(0.0, 0.0, predictionList.size());
}
}
double lon = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLongitude();
double lat = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLatitude();
if (!points.isEmpty()) {
MogoLatLng top = null;
while (!points.isEmpty()) {
MogoLatLng first = points.peek();
if (first == null) {
continue;
}
if (first == top) {
break;
}
lon = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLongitude();
lat = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLatitude();
long angle = isPointOnCarFront(lon, lat, bearing, first.lon, first.lat);
if (angle >= 90) {
if (isColorfulStrategy) {
RouteStrategy.INSTANCE.remove(first.acc);
}
pools.release(first);
points.poll();
}
top = first;
}
if (points.isEmpty()) {
isExcept = true;
return;
}
MogoLatLng self = pools.acquire();
if (self == null) {
self = new MogoLatLng(lat, lon);
} else {
self.lat = lat;
self.lon = lon;
}
points.addFirst(self);
Polyline.Options.Builder builder;
if (mPolylineOptions == null) {
builder = new Polyline.Options.Builder("prediction_overlay" + preViewType, Level.GUIDE_ROUTE_LINE)
.setUseGps(true)
.setWidth(20)
.setIsGradient(true);
} else {
builder = mPolylineOptions.builder();
}
if (isColorfulStrategy) {
RouteStrategy.INSTANCE.end();
Strategy strategy = RouteStrategy.INSTANCE.getStrategy();
List<Integer> colors = strategy.getColors();
boolean isLightOn = strategy instanceof ColorfulStrategy && ((ColorfulStrategy) strategy).isLightOn();
builder.colors(colors);
builder.setLightOn(isLightOn);
builder.setLightColor(COLOR_LIGHT);
builder.setLightSpeed(0.3f);
} else {
if (!hasGreenWave) {
if (colors != null && !colors.isEmpty()) {
builder.colors(colors);
builder.setIsGradient(true);
builder.setLightOn(true);
builder.isShowArrow(false);
builder.setLightColor(COLOR_LIGHT);
builder.setLightSpeed(0.3f);
}
} else {
builder.colors(greenWaveColors)
.setIsGradient(true)
.setLightOn(false)
.isShowArrow(true);
}
}
builder.points(points);
builder.setVisible(true);
Polyline.Options options = builder.build();
if (mPolylineOptions == null) {
mPolylineOptions = options;
}
if (FunctionBuildConfig.isDrawDecIdentifyData) {
if (preViewType == 2 && CallerMapIdentifyManager.INSTANCE.isPreView2Loaded()) {
overlayManager.showOrUpdateLine(options, SMALL_PRED_MAP2);
} else if (preViewType == 3 && CallerMapIdentifyManager.INSTANCE.isPreView3Loaded()) {
overlayManager.showOrUpdateLine(options, SMALL_PRED_MAP3);
}
}
} else {
isExcept = true;
}
} catch (Throwable t) {
t.printStackTrace();
} finally {
if (isExcept) {
setVisible(false);
}
if (!points.isEmpty()) {
for (int i = 0; i < points.size(); i++) {
MogoLatLng latLng = points.get(i);
if (latLng == null) {
continue;
}
pools.release(latLng);
}
}
}
}
private long isPointOnCarFront(double car_lon, double car_lat, double car_head, double lon, double lat) {
return DrivingDirectionUtils.getDegreeOfCar2Poi2(car_lon, car_lat, lon, lat, car_head);
}
}
private volatile RenderTask mPreRenderTask;
public void drawPredictionList(List<geometry.Geometry.Point> dataList, double bearing, boolean hasGreenWave, int preType, int largeType) {
IMogoMap iMogoMap = MogoMap.Companion.getMapInstance().getMogoMap(DEFAULT);
double[] arr = null;
if (mogoOverlayManager != null && iMogoMap != null) {
if (mPreRenderTask == null) {
mPreRenderTask = new RenderTask();
}
List<MogoLatLng> latLngList = new ArrayList<>();
for (geometry.Geometry.Point point : dataList) {
arr = iMogoMap.switchData(point.getX(), point.getY(), false);
if (arr == null || arr.length < 2) continue;
latLngList.add(new MogoLatLng(arr[1], arr[0]));
}
if (latLngList.isEmpty()) return;
mPreRenderTask.setPreData(latLngList, bearing, hasGreenWave, preType, largeType);
if (mRenderHandler != null) {
mRenderHandler.removeCallbacks(mPreRenderTask);
mRenderHandler.post(mPreRenderTask);
}
}
}
public void setVisible(boolean isVisible) {
if (mogoOverlayManager != null) {
if (isVisible) {
mogoOverlayManager.showAllLinesInLevel(Level.GUIDE_ROUTE_LINE);
} else {
mogoOverlayManager.hideAllLinesInLevel(Level.GUIDE_ROUTE_LINE);
}
}
}
}

View File

@@ -13,6 +13,7 @@ import androidx.core.util.Pools;
import com.mogo.eagle.core.data.config.FunctionBuildConfig;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager;
import com.mogo.eagle.core.function.call.map.CallerMapIdentifyManager;
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager;
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils;
import com.mogo.eagle.core.utilcode.util.DrivingDirectionUtils;
@@ -187,8 +188,8 @@ public class RouteOverlayDrawer {
RouteStrategy.INSTANCE.check(route.getVelocity(), route.getAcceleration(), routeList.size());
}
}
double lon = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLongitude();
double lat = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLatitude();
double lon = CallerChassisLocationWGS84ListenerManager.INSTANCE.getWgs84Lon();
double lat = CallerChassisLocationWGS84ListenerManager.INSTANCE.getWgs84Lat();
if (!points.isEmpty()) {
MogoLatLng top = null;
while (!points.isEmpty()) {
@@ -199,8 +200,8 @@ public class RouteOverlayDrawer {
if (first == top) {
break;
}
lon = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLongitude();
lat = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLatitude();
lon = CallerChassisLocationWGS84ListenerManager.INSTANCE.getWgs84Lon();
lat = CallerChassisLocationWGS84ListenerManager.INSTANCE.getWgs84Lat();
long angle = isPointOnCarFront(lon, lat, bearing, first.lon, first.lat);
if (angle >= 90) {
if (isColorfulStrategy) {
@@ -267,7 +268,7 @@ public class RouteOverlayDrawer {
mPolylineOptions = options;
}
overlayManager.showOrUpdateLine(options,DEFAULT);
if (FunctionBuildConfig.isDrawDecIdentifyData) {
if (FunctionBuildConfig.isDrawDecIdentifyData && CallerMapIdentifyManager.INSTANCE.isDecViewLoaded()) {
overlayManager.showOrUpdateLine(options,SMALL_DES_MAP);
}
} else {

View File

@@ -11,6 +11,7 @@ import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationWGS84Listener
import com.mogo.eagle.core.function.api.map.road.IMoGoMapRoadListener
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager
import com.mogo.eagle.core.function.call.map.CallerMapIdentifyManager.isDecViewLoaded
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_MAP
@@ -92,6 +93,11 @@ class DecisionMapView(context: Context?, attrs: AttributeSet?) : MogoMapView(con
override fun onMapInit() {}
override fun onDestroy() {
isDecViewLoaded = false
super.onDestroy()
}
override fun onMapLoaded() {
(mMapView.mapView as MapAutoView).getMapView()?.getMapEngine()?.setHDTypeVisible(
intArrayOf(
@@ -101,6 +107,7 @@ class DecisionMapView(context: Context?, attrs: AttributeSet?) : MogoMapView(con
HDTypes.regional.type
)
)
isDecViewLoaded = true
}
override fun onChassisLocationWGS84(gnssInfo: MogoLocation) {

View File

@@ -11,6 +11,7 @@ import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationWGS84Listener
import com.mogo.eagle.core.function.api.map.road.IMoGoMapRoadListener
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager
import com.mogo.eagle.core.function.call.map.CallerMapIdentifyManager
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_MAP
@@ -96,6 +97,11 @@ class PredictionMap2View(context: Context, attrs: AttributeSet) : MogoMapView(co
override fun onMapInit() {}
override fun onDestroy() {
CallerMapIdentifyManager.isPreView2Loaded = false
super.onDestroy()
}
override fun onMapLoaded() {
(mMapView.mapView as MapAutoView).getMapView()?.getMapEngine()?.setHDTypeVisible(
intArrayOf(
@@ -105,6 +111,7 @@ class PredictionMap2View(context: Context, attrs: AttributeSet) : MogoMapView(co
HDTypes.regional.type
)
)
CallerMapIdentifyManager.isPreView2Loaded = true
}
override fun onChassisLocationWGS84(gnssInfo: MogoLocation) {

View File

@@ -11,6 +11,7 @@ import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationWGS84Listener
import com.mogo.eagle.core.function.api.map.road.IMoGoMapRoadListener
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager
import com.mogo.eagle.core.function.call.map.CallerMapIdentifyManager
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_MAP
@@ -96,6 +97,11 @@ class PredictionMap3View(context: Context, attrs: AttributeSet) : MogoMapView(co
override fun onMapInit() {}
override fun onDestroy() {
CallerMapIdentifyManager.isPreView3Loaded = false
super.onDestroy()
}
override fun onMapLoaded() {
(mMapView.mapView as MapAutoView).getMapView()?.getMapEngine()?.setHDTypeVisible(
intArrayOf(
@@ -105,6 +111,7 @@ class PredictionMap3View(context: Context, attrs: AttributeSet) : MogoMapView(co
HDTypes.regional.type
)
)
CallerMapIdentifyManager.isPreView3Loaded = true
}
override fun onChassisLocationWGS84(gnssInfo: MogoLocation) {

View File

@@ -11,6 +11,7 @@ import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationWGS84Listener
import com.mogo.eagle.core.function.api.map.road.IMoGoMapRoadListener
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager
import com.mogo.eagle.core.function.call.map.CallerMapIdentifyManager
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_MAP
@@ -118,6 +119,12 @@ class PredictionMapView(context: Context, attrs: AttributeSet) : MogoMapView(con
HDTypes.regional.type
)
)
CallerMapIdentifyManager.isPreViewLoaded = true
}
override fun onDestroy() {
CallerMapIdentifyManager.isPreViewLoaded = false
super.onDestroy()
}
override fun onChassisLocationWGS84(gnssInfo: MogoLocation) {