add draw line and show

This commit is contained in:
lixiaopeng
2021-04-25 17:58:14 +08:00
parent b87d8f38ff
commit 707fa23eef
13 changed files with 177 additions and 175 deletions

View File

@@ -7,6 +7,7 @@ import com.mogo.map.location.IMogoLocationClient;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.IMogoMarkerManager;
import com.mogo.map.navi.IMogoNavi;
import com.mogo.map.overlay.IMogoOverlayManager;
import com.mogo.map.uicontroller.IMogoMapUIController;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.drawer.MarkerDrawer;
@@ -61,6 +62,7 @@ public class MarkerServiceHandler {
private static IMogoFragmentManager sFragmentManager;
private static ICarsChattingProvider sCarChatting;
private static IV2XProvider sIV2XProvider;
private static IMogoOverlayManager sIMogoOverlayManager;
// private static IMogoGpsSimulatorManager sGpsSimulatorManager;
@@ -77,6 +79,7 @@ public class MarkerServiceHandler {
sMogoSocketManager = sApis.getSocketManagerApi( context );
sMogoAnalytics = sApis.getAnalyticsApi();
sMarkerManager = sMapService.getMarkerManager( context );
sIMogoOverlayManager = sMapService.getOverlayManager(context);
sNavi = sMapService.getNavi( context );
sMapUIController = sMapService.getMapUIController();
sLocationClient = sMapService.getSingletonLocationClient( context );
@@ -87,7 +90,6 @@ public class MarkerServiceHandler {
sADASController = sApis.getAdasControllerApi();
sLauncher = sApis.getLauncherApi();
sFragmentManager = sApis.getFragmentManagerApi();
sCarChatting = ( ICarsChattingProvider ) ARouter.getInstance().build( CallChattingProviderConstant.CAR_CALL_PROVIDER ).navigation( context );
sIV2XProvider = sApis.getV2XListenerManager();
@@ -172,7 +174,15 @@ public class MarkerServiceHandler {
return sCarChatting;
}
// public static IMogoGpsSimulatorManager getGpsSimulatorManager() {
public static IMogoOverlayManager getsIMogoOverlayManager() {
return sIMogoOverlayManager;
}
public static void setsIMogoOverlayManager(IMogoOverlayManager sIMogoOverlayManager) {
MarkerServiceHandler.sIMogoOverlayManager = sIMogoOverlayManager;
}
// public static IMogoGpsSimulatorManager getGpsSimulatorManager() {
// return sGpsSimulatorManager;
// }

View File

@@ -8,6 +8,7 @@ import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import com.mogo.cloud.commons.utils.CoordinateUtils;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.map.MogoLatLng;
@@ -16,6 +17,7 @@ import com.mogo.map.marker.IMogoMarkerClickListener;
import com.mogo.map.marker.IMogoMarkerManager;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.map.navi.IMogoCarLocationChangedListener2;
import com.mogo.map.overlay.IMogoPolyline;
import com.mogo.map.uicontroller.EnumMapUI;
import com.mogo.map.uicontroller.IMogoMapUIController;
import com.mogo.module.common.ModuleNames;
@@ -36,12 +38,15 @@ import com.mogo.module.common.entity.MarkerLocation;
import com.mogo.module.common.entity.MarkerOnlineCar;
import com.mogo.module.common.entity.MarkerResponse;
import com.mogo.module.common.entity.MarkerShowEntity;
import com.mogo.module.common.entity.V2XWarningEntity;
import com.mogo.module.common.utils.CloudPoiManager;
import com.mogo.module.common.utils.Trigonometric;
import com.mogo.module.service.MarkerServiceHandler;
import com.mogo.module.service.R;
import com.mogo.module.service.ServiceConst;
import com.mogo.module.service.network.RefreshCallback;
import com.mogo.module.service.network.RefreshModel;
import com.mogo.module.service.polyline.LimberCollisionPolyline;
import com.mogo.realtime.api.MoGoAiCloudRealTime;
import com.mogo.realtime.entity.ADASRecognizedResult;
import com.mogo.realtime.entity.MogoSnapshotSetData;
@@ -62,6 +67,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -161,24 +167,58 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
msg.sendToTarget();
}
} );
// adas 每隔一秒传递的数据
MarkerServiceHandler.getApis().getAdasControllerApi().addAdasRecognizedDataCallback( resultList -> {
// 绘制近景识别到的车辆
AdasRecognizedResultDrawer.getInstance().renderAdasRecognizedResult( resultList );
//绘制他车的线 liyz
//添加自车的定位图标,碰撞只有一个预警 TODO
//添加自车的定位图标,碰撞只有一个预警,还需要和adas 联调,还需要改 liyz
// ADASRecognizedResult result = null;
// for (int i = 0; i < resultList.size(); i++) {
// result = resultList.get(i);
// if (result.type) { //找出可能碰撞的车
// result = resultList.get(i);
// }
//绘制他车的线,从列表中查出可能碰撞的车的经纬度(没有或者只有一个)然后预设20米的长度
//绘制碰撞的他车指引线,需要实时给数据更新 TODO
// drawLimberCollisionPolyline(result);
// }
//
// //通过这个传值 ADASRecognizedResult
// MarkerServiceHandler.getApis().getMapServiceApi().getMapUIController().setAdasRecognizedResult(GsonUtil.jsonFromObject(result));
// //通过这个传值到 AMapViewWrapper根据数据更新自车的模型数据 ADASRecognizedResult
// MarkerServiceHandler.getApis().getMapServiceApi().getMapUIController().setAdasRecognizedResult(result);
} );
}
/**
* 实时绘制连线
* @param result
*/
private void drawLimberCollisionPolyline(ADASRecognizedResult result) {
if (result != null) {
IMogoPolyline polyLine = LimberCollisionPolyline.getInstance().getPolyLine();
MogoLatLng startLatLng = new MogoLatLng(result.lat, result.lon);
MogoLatLng endLatlng = Trigonometric.getNewLocation(startLatLng, 20, result.heading);
Log.d(TAG, "红色区域起始点 = " + startLatLng.lon + "," + startLatLng.lat
+ "终点" + endLatlng.lon + "," + endLatlng.lat + "--heading =" + result.heading);
if (polyLine != null) {
Log.d(TAG, "drawStopLine polyLine != null");
polyLine.setPoints(Arrays.asList(startLatLng, endLatlng));
} else {
List<MogoLatLng> latLngs = new ArrayList<>();
latLngs.add(startLatLng);
latLngs.add(endLatlng);
LimberCollisionPolyline.getInstance().draw((float) result.roadWidth, latLngs);
}
} else {
LimberCollisionPolyline.getInstance().clearLine();
}
}
private Handler mSnapshotHandler = new Handler( WorkThreadHandler.newInstance( "snapshot-thread" ).getLooper() ) {
@Override
public void handleMessage( Message msg ) {

View File

@@ -0,0 +1,88 @@
package com.mogo.module.service.polyline;
import com.mogo.map.MogoLatLng;
import com.mogo.map.overlay.IMogoPolyline;
import com.mogo.map.overlay.MogoPolylineOptions;
import com.mogo.module.service.MarkerServiceHandler;
import java.util.ArrayList;
import java.util.List;
/**
* @author lixiaopeng
* @description 前车碰撞的画线
* @since 2021/4/25
*/
public class LimberCollisionPolyline {
private volatile static LimberCollisionPolyline mInstance = null;
private IMogoPolyline mMoGoPolyline;
// 连接线参数
private MogoPolylineOptions mPolylineOptions;
// 线路径集合
private List<MogoLatLng> mPolylinePointList;
public static LimberCollisionPolyline getInstance() {
if (mInstance == null) {
synchronized (LimberCollisionPolyline.class) {
if (mInstance == null) {
mInstance = new LimberCollisionPolyline();
}
}
}
return mInstance;
}
protected LimberCollisionPolyline() {
mPolylineOptions = new MogoPolylineOptions();
// 绘制路径集合
mPolylinePointList = new ArrayList<>();
}
public IMogoPolyline draw(float width, List<MogoLatLng> polylinePoint) {
try {
if (mMoGoPolyline != null) {
mMoGoPolyline.remove();
mPolylinePointList.clear();
}
// 连接线参数
MogoPolylineOptions options = new MogoPolylineOptions();
// 渐变色
List<Integer> colors = new ArrayList<>();
// colors.add(0x0DE32F46);
colors.add(0xD9E32F46);
colors.add(0x0DE32F46);
// 线条粗细,渐变,渐变色值 TODO liyz 宽度需要传过来
options.width(60).useGradient(true).colorValues(colors);
for (int i = 0; i < polylinePoint.size(); i++) {
options.add(polylinePoint.get(i));
}
// 绘制线的对象
mMoGoPolyline = MarkerServiceHandler.getsIMogoOverlayManager().addPolyline(options);
} catch (Exception e) {
e.printStackTrace();
}
return mMoGoPolyline;
}
public IMogoPolyline getPolyLine() {
return mMoGoPolyline;
}
public void clearLine() {
if (mMoGoPolyline != null) {
mMoGoPolyline.remove();
mMoGoPolyline = null;
}
}
}