渐变色绘制线(目前手动添加一个点,后续根据算法动态扩展点)
This commit is contained in:
@@ -2,6 +2,8 @@ package com.mogo.module.v2x.entity.model;
|
||||
|
||||
import com.mogo.map.MogoLatLng;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
@@ -14,9 +16,13 @@ public class DrawLineInfo {
|
||||
|
||||
// 起点位置
|
||||
private MogoLatLng startLocation;
|
||||
|
||||
//结束点位置
|
||||
private MogoLatLng endLocation;
|
||||
|
||||
//绘制线的多个点位置
|
||||
private List<MogoLatLng> locations;
|
||||
|
||||
private double heading;
|
||||
|
||||
private float width;
|
||||
@@ -70,4 +76,12 @@ public class DrawLineInfo {
|
||||
public void setDirection(int direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
public List<MogoLatLng> getLocations() {
|
||||
return locations;
|
||||
}
|
||||
|
||||
public void setLocations(List<MogoLatLng> locations) {
|
||||
this.locations = locations;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.overlay.IMogoPolyline;
|
||||
import com.mogo.map.overlay.MogoPolylineOptions;
|
||||
import com.mogo.module.v2x.MoGoV2XServicePaths;
|
||||
@@ -13,6 +14,7 @@ import com.mogo.module.v2x.entity.model.DrawLineInfo;
|
||||
import com.mogo.module.v2x.manager.IMoGoPersonWarnPolylineManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -39,17 +41,17 @@ public class MoGoPersonWarnPolylineManager implements IMoGoPersonWarnPolylineMan
|
||||
|
||||
// 渐变色
|
||||
List<Integer> colors = new ArrayList<>();
|
||||
colors.add(0xFFE32F46);
|
||||
colors.add(0xFFE32F46);
|
||||
colors.add(0x0DE32F46);
|
||||
colors.add(0xD9E32F46);
|
||||
colors.add(0x0DE32F46);
|
||||
|
||||
// 线条粗细,渐变,渐变色值
|
||||
Log.d(V2XConst.LOG_NAME_WARN, "MoGoPersonWarnPolylineManager width = " + info.getWidth());
|
||||
options.width(info.getWidth()).useGradient(true).colorValues(colors);
|
||||
// 当前车辆位置
|
||||
options.add(info.getStartLocation());
|
||||
// 目标车辆位置
|
||||
options.add(info.getEndLocation());
|
||||
|
||||
List<MogoLatLng> locations = info.getLocations();
|
||||
for (int i = 0; i < locations.size(); i++) {
|
||||
options.add(locations.get(i));
|
||||
}
|
||||
// 绘制线的对象
|
||||
mMogoPolyline = V2XServiceManager.getMogoOverlayManager().addPolyline(options);
|
||||
mMogoPolyline.setTransparency(0.5f);
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.overlay.IMogoPolyline;
|
||||
import com.mogo.map.overlay.MogoPolylineOptions;
|
||||
import com.mogo.module.v2x.MoGoV2XServicePaths;
|
||||
@@ -38,17 +39,18 @@ public class MoGoStopPolylineManager implements IMoGoStopPolylineManager {
|
||||
// 连接线参数
|
||||
MogoPolylineOptions options = new MogoPolylineOptions();
|
||||
List<Integer> colors = new ArrayList<>();
|
||||
colors.add(0xFFE32F46);
|
||||
colors.add(0xFFE32F46);
|
||||
colors.add(0x0DE32F46);
|
||||
colors.add(0xD9E32F46);
|
||||
colors.add(0x0DE32F46);
|
||||
|
||||
Log.d(V2XConst.LOG_NAME_WARN, "MoGoStopPolylineManager roadWidth = " + info.getWidth());
|
||||
// 线条粗细,渐变,渐变色值
|
||||
// 当前车辆位置
|
||||
options.width(info.getWidth() == 0.0 ? 60 : info.getWidth()).useGradient(true).colorValues(colors);
|
||||
options.add(info.getStartLocation());
|
||||
// 目标车辆位置
|
||||
options.add(info.getEndLocation());
|
||||
|
||||
List<MogoLatLng> locations = info.getLocations();
|
||||
for (int i = 0; i < locations.size(); i++) {
|
||||
options.add(locations.get(i));
|
||||
}
|
||||
// 绘制线的对象
|
||||
mMogoPolyline = V2XServiceManager.getMogoOverlayManager().addPolyline(options);
|
||||
mMogoPolyline.setTransparency(0.5f);
|
||||
|
||||
@@ -7,15 +7,10 @@ import android.util.Log;
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.cloud.commons.utils.CoordinateUtils;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.map.navi.IMogoCarLocationChangedListener2;
|
||||
import com.mogo.map.overlay.IMogoPolyline;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.drawer.MarkerDrawer;
|
||||
import com.mogo.module.common.drawer.V2XWarnDataDrawer;
|
||||
import com.mogo.module.common.drawer.marker.EmptyMarkerView;
|
||||
import com.mogo.module.common.drawer.marker.SimpleWindow3DAdapter;
|
||||
import com.mogo.module.common.entity.V2XWarningEntity;
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
import com.mogo.module.service.receiver.MogoReceiver;
|
||||
@@ -24,18 +19,15 @@ 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.marker.V2XFrontTargetMarkerView;
|
||||
import com.mogo.module.v2x.utils.LocationUtils;
|
||||
import com.mogo.utils.UiThreadHandler;
|
||||
import com.mogo.utils.ViewUtils;
|
||||
import com.mogo.utils.ViewUtils;x
|
||||
import com.mogo.utils.WorkThreadHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mogo.module.common.constants.DataTypes.TYPE_MARKER_CLOUD_STOP_LINE_DATA;
|
||||
import static com.mogo.module.v2x.V2XConst.V2X_FRONT_WARNING_MARKER;
|
||||
import static com.mogo.module.v2x.V2XServiceManager.getContext;
|
||||
|
||||
/**
|
||||
@@ -48,7 +40,8 @@ public class MoGoV2XCloundDataManager implements IMoGoV2XCloundDataManager, IMog
|
||||
private boolean isSelfLineClear;
|
||||
private List fillPoints = new ArrayList();//停止线经纬度合集
|
||||
private boolean isFirstLocation = false;
|
||||
private MogoLatLng mNewLocation;
|
||||
private MogoLatLng carLocation;
|
||||
|
||||
private static long showTime = 0;
|
||||
|
||||
@Override
|
||||
@@ -73,8 +66,6 @@ public class MoGoV2XCloundDataManager implements IMoGoV2XCloundDataManager, IMog
|
||||
MogoLatLng newLocation = LocationUtils.getNewLocation((MogoLatLng) fillPoints.get(0), 80, cloundWarningInfo.getAngle());
|
||||
//停止线前方画线
|
||||
WorkThreadHandler.getInstance().postDelayed(() -> {
|
||||
//添加停止线
|
||||
drawStopLineWith2Resource();
|
||||
//二轮车和行人的渲染和移动
|
||||
V2XWarnDataDrawer.getInstance().renderWarnData(cloundWarningInfo);
|
||||
//绘制识别物与交汇点连线,并且更新连线数据
|
||||
@@ -121,54 +112,30 @@ public class MoGoV2XCloundDataManager implements IMoGoV2XCloundDataManager, IMog
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 2D资源绘制停止线
|
||||
* */
|
||||
private void drawStopLineWith2Resource() {
|
||||
MogoLatLng carlo = mCloundWarningInfo.getCarLocation();
|
||||
if (carlo == null) {
|
||||
double lon = MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLon();
|
||||
double lat = MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLat();
|
||||
carlo = new MogoLatLng(lat, lon);
|
||||
}
|
||||
//自车行驶方向的前方*米的经纬度,该经纬度在停止线上
|
||||
MogoLatLng drawStopLineLon = LocationUtils.getNewLocation(carlo, mCloundWarningInfo.getStopLineDistance(), mCloundWarningInfo.getAngle());
|
||||
Log.d(TAG, "2D资源绘制停止线" + drawStopLineLon);
|
||||
MogoMarkerOptions optionsRipple = new MogoMarkerOptions()
|
||||
.latitude(drawStopLineLon.getLat())
|
||||
.longitude(drawStopLineLon.getLon())
|
||||
.anchor(1.0f, 1.0f)
|
||||
.zIndex(MarkerDrawer.MARKER_Z_INDEX_HIGH);
|
||||
|
||||
optionsRipple
|
||||
.icon(ViewUtils.fromView(new EmptyMarkerView(V2XServiceManager.getContext())));
|
||||
IMogoMarker stopLine = V2XServiceManager.getMarkerManager().addMarker(TYPE_MARKER_CLOUD_STOP_LINE_DATA, optionsRipple);
|
||||
stopLine.setInfoWindowAdapter(new SimpleWindow3DAdapter(new V2XFrontTargetMarkerView(V2XServiceManager.getContext())));
|
||||
stopLine.showInfoWindow();
|
||||
UiThreadHandler.postDelayed(() -> {
|
||||
stopLine.hideInfoWindow();
|
||||
}, showTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制停止线前方线 TODO 需要实时给行人当前位置
|
||||
* 绘制红色区域(停止线继续前行的预警区域) TODO 需要实时给行人当前位置
|
||||
*/
|
||||
private void drawStopLine(V2XWarningEntity info, MogoLatLng mogoLatLng) {
|
||||
IMogoPolyline polyLine = V2XServiceManager.getMoGoStopPolylineManager().getMogoStopPolyline();
|
||||
if (info != null) {
|
||||
if (polyLine != null) {
|
||||
Log.d(V2XConst.LOG_NAME_WARN, "drawStopLine polyLine != null");
|
||||
polyLine.setPoints(Arrays.asList(new MogoLatLng(mNewLocation.lat, mNewLocation.lon),
|
||||
polyLine.setPoints(Arrays.asList(new MogoLatLng(carLocation.lat, carLocation.lon),
|
||||
new MogoLatLng(mogoLatLng.lat, mogoLatLng.lon)));
|
||||
polyLine.setTransparency(0.5f);
|
||||
} else {
|
||||
DrawLineInfo lineInfo = new DrawLineInfo();
|
||||
MogoLatLng startLatlng = new MogoLatLng(mNewLocation.lat, mNewLocation.lon);
|
||||
MogoLatLng startLatlng = new MogoLatLng(carLocation.lat, carLocation.lon);
|
||||
MogoLatLng endLatlng = new MogoLatLng(mogoLatLng.lat, mogoLatLng.lon);
|
||||
Log.d(V2XConst.LOG_NAME_WARN, " drawStopLine endLatlng lon =" + endLatlng.lon + "--lat =" + endLatlng.lat
|
||||
+ "--startLatlng lon = " + startLatlng.lon + "-lat = " + startLatlng.lat);
|
||||
lineInfo.setStartLocation(startLatlng);
|
||||
lineInfo.setEndLocation(endLatlng);
|
||||
float distance = CoordinateUtils.calculateLineDistance(startLatlng.lon, startLatlng.lat, endLatlng.lon, endLatlng.lat);
|
||||
MogoLatLng addMiddleLoc = LocationUtils.getNewLocation(startLatlng, distance / 2, mCloundWarningInfo.getAngle());
|
||||
List locations = new ArrayList();
|
||||
locations.add(startLatlng);
|
||||
locations.add(addMiddleLoc);
|
||||
locations.add(endLatlng);
|
||||
lineInfo.setLocations(locations);
|
||||
lineInfo.setHeading(info.heading);
|
||||
Log.d(V2XConst.LOG_NAME_WARN, "drawStopLine width = " + info.getRoadwidth());
|
||||
lineInfo.setWidth(info.getRoadwidth() * 10 + 5);
|
||||
@@ -182,7 +149,7 @@ public class MoGoV2XCloundDataManager implements IMoGoV2XCloundDataManager, IMog
|
||||
|
||||
|
||||
/**
|
||||
* 绘制行人和二轮车连线,并且更新数据 TODO 需要实时给行人当前位置
|
||||
* 目标物与预碰撞点连线,并且更新数据 TODO 需要实时给行人当前位置
|
||||
*/
|
||||
private void drawOtherObjectLine(V2XWarningEntity info) {
|
||||
IMogoPolyline polyLine = V2XServiceManager.getMoGoPersonWarnPolylineManager().getMogoPersonWarnPolyline();
|
||||
@@ -196,8 +163,14 @@ public class MoGoV2XCloundDataManager implements IMoGoV2XCloundDataManager, IMog
|
||||
DrawLineInfo lineInfo = new DrawLineInfo();
|
||||
MogoLatLng startLatlng = new MogoLatLng(info.getLat(), info.getLon());
|
||||
MogoLatLng endLatlng = new MogoLatLng(info.getCollisionLat(), info.getCollisionLon());
|
||||
lineInfo.setStartLocation(startLatlng);
|
||||
lineInfo.setEndLocation(endLatlng);
|
||||
float distance = CoordinateUtils.calculateLineDistance(startLatlng.lon, startLatlng.lat, endLatlng.lon, endLatlng.lat);
|
||||
MogoLatLng addMiddleLoc = LocationUtils.getNewLocation(startLatlng, distance / 2, mCloundWarningInfo.getAngle());
|
||||
Log.d(TAG,"目标物与预碰撞点画线点为"+"起点:"+startLatlng+"中间点:"+addMiddleLoc+"终点:"+endLatlng);
|
||||
List locations = new ArrayList();
|
||||
locations.add(startLatlng);
|
||||
locations.add(addMiddleLoc);
|
||||
locations.add(endLatlng);
|
||||
lineInfo.setLocations(locations);
|
||||
lineInfo.setHeading(info.heading);
|
||||
Log.d(V2XConst.LOG_NAME_WARN, "drawOtherObjectLine width = " + info.getRoadwidth());
|
||||
lineInfo.setWidth(info.getRoadwidth() * 10 + 5);
|
||||
@@ -231,30 +204,36 @@ public class MoGoV2XCloundDataManager implements IMoGoV2XCloundDataManager, IMog
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制自车连线
|
||||
* 绘制安全区域,自车与碰撞点之间的蓝色线
|
||||
*/
|
||||
private void drawSlefCarLine(Location latLng) {
|
||||
if (!isSelfLineClear) {
|
||||
IMogoPolyline mogoPolyline = V2XServiceManager.getMoGoWarnPolylineManager().getMogoWarnPolyline();
|
||||
if (mCloundWarningInfo != null) {
|
||||
if (!isFirstLocation) {
|
||||
mNewLocation = getMogoLat(new MogoLatLng(latLng.getLatitude(), latLng.getLongitude()));
|
||||
Log.d(V2XConst.LOG_NAME_WARN, "drawSlefCarLine lon = " + mNewLocation.lon + "---lat = " + mNewLocation.lat);
|
||||
carLocation = getMogoLat(new MogoLatLng(latLng.getLatitude(), latLng.getLongitude()));
|
||||
Log.d(V2XConst.LOG_NAME_WARN, "drawSlefCarLine lon = " + carLocation.lon + "---lat = " + carLocation.lat);
|
||||
isFirstLocation = true;
|
||||
}
|
||||
if (mogoPolyline != null) {
|
||||
mogoPolyline.setPoints(Arrays.asList(new MogoLatLng(latLng.getLatitude(), latLng.getLongitude()),
|
||||
new MogoLatLng(mCloundWarningInfo.getDirection() == 1 ? mNewLocation.lat : mCloundWarningInfo.getCollisionLat(),
|
||||
mCloundWarningInfo.getDirection() == 1 ? mNewLocation.lon : mCloundWarningInfo.getCollisionLon())));
|
||||
new MogoLatLng(mCloundWarningInfo.getDirection() == 1 ? carLocation.lat : mCloundWarningInfo.getCollisionLat(),
|
||||
mCloundWarningInfo.getDirection() == 1 ? carLocation.lon : mCloundWarningInfo.getCollisionLon())));
|
||||
mogoPolyline.setTransparency(0.5f);
|
||||
} else {
|
||||
DrawLineInfo info = new DrawLineInfo(); // 对象
|
||||
MogoLatLng startLatlng = new MogoLatLng(latLng.getLatitude(), latLng.getLongitude());
|
||||
MogoLatLng endLatlng = new MogoLatLng(mCloundWarningInfo.getDirection() == 1 ? mNewLocation.lat : mCloundWarningInfo.getCollisionLat(),
|
||||
mCloundWarningInfo.getDirection() == 1 ? mNewLocation.lon : mCloundWarningInfo.getCollisionLon());
|
||||
MogoLatLng 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);
|
||||
MogoLatLng addMiddleLoc = LocationUtils.getNewLocation(startLatlng, distance / 2, mCloundWarningInfo.getAngle());
|
||||
Log.d(TAG,"安全区域的画线点为"+"起点:"+startLatlng+"中间点:"+addMiddleLoc+"终点:"+endLatlng);
|
||||
List locations = new ArrayList();
|
||||
locations.add(startLatlng);
|
||||
locations.add(addMiddleLoc);
|
||||
locations.add(endLatlng);
|
||||
info.setLocations(locations);
|
||||
info.setHeading(latLng.getBearing());
|
||||
info.setStartLocation(startLatlng);
|
||||
info.setEndLocation(endLatlng);
|
||||
info.setWidth(mCloundWarningInfo.getRoadwidth() * 10 + 5);
|
||||
info.setDirection(mCloundWarningInfo.getDirection());
|
||||
V2XServiceManager.getMoGoWarnPolylineManager().drawWarnPolyline(getContext(), info);
|
||||
|
||||
@@ -43,11 +43,13 @@ public class MoGoWarnPolylineManager implements IMoGoWarnPolylineManager {
|
||||
List<Integer> colors = new ArrayList<>();
|
||||
|
||||
if (info.getDirection() == 1) {
|
||||
colors.add(0xFF3036FF);
|
||||
colors.add(0xFF3036FF);
|
||||
colors.add(0x0D3036FF);
|
||||
colors.add(0xD93036FF);
|
||||
colors.add(0x0D3036FF);
|
||||
} else {
|
||||
colors.add(0xFFE32F46);
|
||||
colors.add(0xFFE32F46);
|
||||
colors.add(0x0DE32F46);
|
||||
colors.add(0xD9E32F46);
|
||||
colors.add(0x0DE32F46);
|
||||
}
|
||||
|
||||
Log.d(V2XConst.LOG_NAME_WARN, "MoGoWarnPolylineManager roadWidth = " + info.getWidth());
|
||||
@@ -55,10 +57,10 @@ public class MoGoWarnPolylineManager implements IMoGoWarnPolylineManager {
|
||||
// 当前车辆位置
|
||||
options.width(info.getWidth() == 0.0 ? 60 : info.getWidth()).useGradient(true).colorValues(colors);
|
||||
// options.width(60).useGradient(true).colorValues(colors);
|
||||
options.add(info.getStartLocation());
|
||||
// 目标车辆位置
|
||||
options.add(info.getEndLocation());
|
||||
|
||||
List<MogoLatLng> locations = info.getLocations();
|
||||
for (int i = 0; i < locations.size(); i++) {
|
||||
options.add(locations.get(i));
|
||||
}
|
||||
// 绘制线的对象
|
||||
mMogoPolyline = V2XServiceManager.getMogoOverlayManager().addPolyline(options);
|
||||
mMogoPolyline.setTransparency(0.5f);
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.mogo.utils.WorkThreadHandler;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mogo.module.common.constants.DataTypes.TYPE_MARKER_CLOUD_STOP_LINE_DATA;
|
||||
import static com.mogo.module.v2x.V2XConst.V2X_FRONT_WARNING_MARKER;
|
||||
import static com.mogo.module.v2x.V2XConst.V2X_OPTIMAL_SPEED_MARKER;
|
||||
|
||||
@@ -86,4 +87,33 @@ public class V2XWarningMarker implements IV2XMarker {
|
||||
V2XServiceManager.getMoGoWarnPolylineManager().clearLine();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 2D资源绘制停止线
|
||||
* */
|
||||
private void drawStopLineWith2Resource() {
|
||||
MogoLatLng carlo = mMarkerEntity.getCarLocation();
|
||||
if (carlo == null) {
|
||||
double lon = MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLon();
|
||||
double lat = MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLat();
|
||||
carlo = new MogoLatLng(lat, lon);
|
||||
}
|
||||
//自车行驶方向的前方*米的经纬度,该经纬度在停止线上
|
||||
MogoLatLng drawStopLineLon = LocationUtils.getNewLocation(carlo, mMarkerEntity.getStopLineDistance(), mMarkerEntity.getAngle());
|
||||
Log.d(TAG, "2D资源绘制停止线" + drawStopLineLon);
|
||||
MogoMarkerOptions optionsRipple = new MogoMarkerOptions()
|
||||
.latitude(drawStopLineLon.getLat())
|
||||
.longitude(drawStopLineLon.getLon())
|
||||
.anchor(1.0f, 1.0f)
|
||||
.zIndex(MarkerDrawer.MARKER_Z_INDEX_HIGH);
|
||||
|
||||
optionsRipple
|
||||
.icon(ViewUtils.fromView(new EmptyMarkerView(V2XServiceManager.getContext())));
|
||||
IMogoMarker stopLine = V2XServiceManager.getMarkerManager().addMarker(TYPE_MARKER_CLOUD_STOP_LINE_DATA, optionsRipple);
|
||||
stopLine.setInfoWindowAdapter(new SimpleWindow3DAdapter(new V2XFrontTargetMarkerView(V2XServiceManager.getContext())));
|
||||
stopLine.showInfoWindow();
|
||||
UiThreadHandler.postDelayed(() -> {
|
||||
stopLine.hideInfoWindow();
|
||||
}, 8000);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user