[Change]
迁移 IdentifyDataDrawer.java到MoGoEagleEye.core.function-impl.mogo-core-function-map。 地图相关的功能进行聚合,为后续融合做准备。如果需要对数据进行拦截处理,也在这里添加拦截器,不要直接修改IdentifyDataDrawer Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
@@ -1,188 +0,0 @@
|
||||
package com.mogo.module.common.drawer;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.eagle.core.data.config.FunctionBuildConfig;
|
||||
import com.mogo.eagle.core.data.enums.TrafficTypeEnum;
|
||||
import com.mogo.eagle.core.data.traffic.TrafficData;
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
|
||||
import com.mogo.map.MogoMarkerManager;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
/**
|
||||
* @author xiaoyuzhou
|
||||
* @date 2021/10/19 10:45 上午
|
||||
* 域控制器识别信息绘制
|
||||
*/
|
||||
public class IdentifyDataDrawer {
|
||||
private static final String TAG = "IdentifyDataDrawer";
|
||||
|
||||
protected final Context mContext;
|
||||
private static volatile IdentifyDataDrawer sInstance;
|
||||
|
||||
/**
|
||||
* 上一帧数据的缓存
|
||||
*/
|
||||
private static final ConcurrentHashMap<String, TrafficData> mMarkersCaches = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 已经感知不到的脏数据
|
||||
*/
|
||||
private final ConcurrentHashMap<String, TrafficData> mDirtyPositions = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* 记录每次实际绘制的交通元素UUID
|
||||
*/
|
||||
private final ArrayList<String> trafficDataUuidList = new ArrayList<>();
|
||||
/**
|
||||
* 过滤后的数据集合
|
||||
*/
|
||||
private final ArrayList<MessagePad.TrackedObject> mFilterTrafficData = new ArrayList<>();
|
||||
|
||||
private IdentifyDataDrawer() {
|
||||
mContext = AbsMogoApplication.getApp();
|
||||
addPreVehicleModel();
|
||||
}
|
||||
|
||||
public static IdentifyDataDrawer getInstance() {
|
||||
if (sInstance == null) {
|
||||
synchronized (IdentifyDataDrawer.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new IdentifyDataDrawer();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染 adas 识别的数据
|
||||
*
|
||||
* @param resultList adas感知融合数据
|
||||
*/
|
||||
public void renderAdasRecognizedResult(List<MessagePad.TrackedObject> resultList) {
|
||||
if (resultList == null || resultList.isEmpty()) {
|
||||
clearOldMarker();
|
||||
CallerLogger.INSTANCE.w(TAG, "感知数据为空无需渲染……");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) {
|
||||
clearOldMarker();
|
||||
CallerLogger.INSTANCE.w(TAG, "渲染 adas 识别的数据 当前不是VR模式");
|
||||
return;
|
||||
}
|
||||
|
||||
// 循环将集合中的数据提取记录
|
||||
|
||||
for (MessagePad.TrackedObject trafficData : resultList) {
|
||||
// 过滤掉未知感知数据
|
||||
if (!FunctionBuildConfig.isDrawUnknownIdentifyData &&
|
||||
trafficData.getType() == TrafficTypeEnum.TYPE_TRAFFIC_ID_WEI_ZHI.getType()) {
|
||||
//CallerLogger.INSTANCE.w(TAG, "未知感知类型数据,丢弃,不渲染");
|
||||
continue;
|
||||
}
|
||||
trafficDataUuidList.add("" + trafficData.getUuid());
|
||||
}
|
||||
// // 找出上一针数据中已经不在本次数据中存在的数据
|
||||
// for (String uuid : mMarkersCaches.keySet()) {
|
||||
// if (!trafficDataUuidList.contains(uuid)) {
|
||||
// mDirtyPositions.put(uuid, mMarkersCaches.get(uuid));
|
||||
// }
|
||||
// }
|
||||
// // 移除脏数据
|
||||
// for (String uuid : mDirtyPositions.keySet()) {
|
||||
// MogoApisHandler.getInstance().getApis()
|
||||
// .getMapServiceApi()
|
||||
// .getMarkerManager(mContext)
|
||||
// .removeMarker(uuid);
|
||||
// }
|
||||
|
||||
// 绘制新数据
|
||||
MogoMarkerManager.getInstance(mContext)
|
||||
.updateBatchMarkerPosition(filterTrafficData(resultList));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据过滤器
|
||||
*
|
||||
* @return 过滤后的数据集合
|
||||
*/
|
||||
private ArrayList<MessagePad.TrackedObject> filterTrafficData(List<MessagePad.TrackedObject> trafficData) {
|
||||
mFilterTrafficData.clear();
|
||||
for (MessagePad.TrackedObject data : trafficData) {
|
||||
// 过滤掉未知感知数据
|
||||
if (data.getType() == TrafficTypeEnum.TYPE_TRAFFIC_ID_WEI_ZHI.getType()) {
|
||||
//CallerLogger.INSTANCE.w(TAG, "未知感知类型数据,丢弃,不渲染");
|
||||
continue;
|
||||
}
|
||||
mFilterTrafficData.add(data);
|
||||
}
|
||||
return mFilterTrafficData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 清除旧的 marker 数据
|
||||
*/
|
||||
public void clearOldMarker() {
|
||||
for (String uuid : trafficDataUuidList) {
|
||||
MogoMarkerManager.getInstance(mContext)
|
||||
.removeMarker(uuid);
|
||||
}
|
||||
trafficDataUuidList.clear();
|
||||
}
|
||||
|
||||
private void addPreVehicleModel() {
|
||||
CallerLogger.INSTANCE.d(TAG, "添加感知模型到地图中……");
|
||||
addPreVehicleModelWeiZhi(TrafficTypeEnum.TYPE_TRAFFIC_ID_WEI_ZHI, "添加感知模型到地图中……preVehicleStrWeiZhi=");
|
||||
|
||||
addPreVehicleModelWeiZhi(TrafficTypeEnum.TYPE_TRAFFIC_ID_PEOPLE, "添加感知模型到地图中……preVehicleStrPeople=");
|
||||
|
||||
addPreVehicleModelWeiZhi(TrafficTypeEnum.TYPE_TRAFFIC_ID_BICYCLE, "添加感知模型到地图中……preVehicleStrBicycle=");
|
||||
|
||||
addPreVehicleModelWeiZhi(TrafficTypeEnum.TYPE_TRAFFIC_ID_TA_CHE, "添加感知模型到地图中……preVehicleStrTaChe=");
|
||||
|
||||
addPreVehicleModelWeiZhi(TrafficTypeEnum.TYPE_TRAFFIC_ID_MOTO, "添加感知模型到地图中……preVehicleStrMoto=");
|
||||
|
||||
addPreVehicleModelWeiZhi(TrafficTypeEnum.TYPE_TRAFFIC_ID_BUS, "添加感知模型到地图中……preVehicleStrBus=");
|
||||
|
||||
addPreVehicleModelWeiZhi(TrafficTypeEnum.TYPE_TRAFFIC_ID_TRUCK, "添加感知模型到地图中……preVehicleStrTruck=");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加模型到地图中
|
||||
*
|
||||
* @param typeTrafficIdWeiZhi
|
||||
* @param s
|
||||
*/
|
||||
private void addPreVehicleModelWeiZhi(TrafficTypeEnum typeTrafficIdWeiZhi, String s) {
|
||||
String preVehicleStrWeiZhi = MogoMarkerManager.getInstance(mContext)
|
||||
.addPreVehicleModel(typeTrafficIdWeiZhi.getType(),
|
||||
typeTrafficIdWeiZhi.getTraffic3DIconId());
|
||||
CallerLogger.INSTANCE.d(TAG, s + preVehicleStrWeiZhi);
|
||||
|
||||
if (preVehicleStrWeiZhi == null) {
|
||||
UiThreadHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CallerLogger.INSTANCE.w(TAG, "添加感知模型到地图中失败,尝试重复添加……");
|
||||
addPreVehicleModelWeiZhi(typeTrafficIdWeiZhi, s);
|
||||
}
|
||||
}, 1000L);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,14 +25,13 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/10/28
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
class MarkerDrawer {
|
||||
public class MarkerDrawer {
|
||||
|
||||
public static final int MARKER_Z_INDEX_HIGH = 100;
|
||||
public static final int MARKER_Z_INDEX_LOW = 2;
|
||||
|
||||
@@ -1,515 +0,0 @@
|
||||
package com.mogo.module.common.drawer;
|
||||
|
||||
import static com.mogo.module.common.constants.DataTypes.TYPE_MARKER_CLOUD_DATA;
|
||||
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.mogo.cloud.commons.utils.CoordinateUtils;
|
||||
import com.mogo.cloud.socket.entity.SocketDownData;
|
||||
import com.mogo.cloud.socket.entity.SocketDownDataHelper;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
|
||||
import com.mogo.eagle.core.utilcode.util.ViewUtils;
|
||||
import com.mogo.map.MogoMarkerManager;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.R;
|
||||
import com.mogo.module.common.constants.DataTypes;
|
||||
import com.mogo.module.common.utils.Trigonometric;
|
||||
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
|
||||
import com.mogo.service.statusmanager.StatusDescriptor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/10/28
|
||||
* <p>
|
||||
* 云端数据绘制
|
||||
*/
|
||||
public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClickListener, IMogoStatusChangedListener {
|
||||
|
||||
private static final String TAG = "SnapshotSetDataDrawer";
|
||||
|
||||
private static volatile SnapshotSetDataDrawer sInstance;
|
||||
|
||||
private boolean mChangeCarModeStatus;
|
||||
|
||||
private SnapshotSetDataDrawer() {
|
||||
super();
|
||||
MogoApisHandler.getInstance().getApis()
|
||||
.getStatusManagerApi()
|
||||
.registerStatusChangedListener(TAG, StatusDescriptor.VR_MODE, this);
|
||||
}
|
||||
|
||||
public static SnapshotSetDataDrawer getInstance() {
|
||||
if (sInstance == null) {
|
||||
synchronized (SnapshotSetDataDrawer.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new SnapshotSetDataDrawer();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上一帧数据的缓存
|
||||
*/
|
||||
private static final Map<String, IMogoMarker> mMarkersCaches = new ConcurrentHashMap<>();
|
||||
|
||||
private final Map<String, SocketDownData.CloudRoadDataProto> mLastPositions = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 注册StatusDescriptor.VR_MODE类型,VR_MODE状态改变回调
|
||||
*
|
||||
* @param descriptor 状态类型
|
||||
* @param isTrue true - accOn、adas ui show、voice ui show、push ui show、v2x ui show
|
||||
*/
|
||||
@Override
|
||||
public void onStatusChanged(StatusDescriptor descriptor, boolean isTrue) {
|
||||
mChangeCarModeStatus = true;
|
||||
sendMessage(MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches);
|
||||
removeUselessMarker(mMarkersCaches);
|
||||
mLastPositions.clear();
|
||||
}
|
||||
|
||||
public boolean isChangeCarModeStatus() {
|
||||
return mChangeCarModeStatus;
|
||||
}
|
||||
|
||||
public void setChangeCarModeStatus(boolean mChangeCarModeStatus) {
|
||||
this.mChangeCarModeStatus = mChangeCarModeStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除旧数据操作
|
||||
*
|
||||
* @param data 自车周边数据
|
||||
* @return 清除结果
|
||||
*/
|
||||
private boolean clear(SocketDownData.LauncherSnapshotProto data) {
|
||||
if (!MogoApisHandler.getInstance().getApis().getStatusManagerApi().isMainPageLaunched()) {
|
||||
if (mMarkersCaches == null) {
|
||||
return false;
|
||||
}
|
||||
mMarkersCaches.clear();
|
||||
mLastPositions.clear();
|
||||
sendMessage(MSG_REMOVE_DIRTY_MARKERS, DataTypes.TYPE_MARKER_CLOUD_DATA);
|
||||
return true;
|
||||
}
|
||||
if (data == null || (
|
||||
(data.getAllListList() == null || data.getAllListList().isEmpty()) &&
|
||||
(data.getNearListList() == null || data.getNearListList().isEmpty()))) {
|
||||
if (mMarkersCaches != null) {
|
||||
mMarkersCaches.clear();
|
||||
}
|
||||
mLastPositions.clear();
|
||||
sendMessage(MSG_REMOVE_DIRTY_MARKERS, DataTypes.TYPE_MARKER_CLOUD_DATA);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制来自云端的 mogo 他车、mogo 他车识别的社会车辆、路边单元识别的车辆
|
||||
*
|
||||
* @param data 自车周边数据
|
||||
*/
|
||||
// @ChainLog(linkCode = CHAIN_LINK_CLOUD_SHOW,
|
||||
// endpoint = TracingConstants.Endpoint.PAD,
|
||||
// nodeAliasCode = "PAD_YINGYAN_SHOW",
|
||||
// paramIndexes = {0},
|
||||
// clientPkFileName = "sn")
|
||||
public void renderSnapshotData(SocketDownData.LauncherSnapshotProto data) {
|
||||
final long start = System.nanoTime();
|
||||
if (clear(data)) {
|
||||
return;
|
||||
}
|
||||
if (!MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<SocketDownData.CloudRoadDataProto> allDatumsList = new ArrayList<>();
|
||||
prepareData(data.getAllListList(), allDatumsList);
|
||||
|
||||
Map<String, IMogoMarker> newMarkersCaches = new ConcurrentHashMap<>(allDatumsList.size());
|
||||
List<SocketDownData.CloudRoadDataProto> newDiffSet = new ArrayList<>();
|
||||
for (SocketDownData.CloudRoadDataProto cloudRoadData : allDatumsList) {
|
||||
|
||||
if (isUselessValue(cloudRoadData)) {
|
||||
continue;
|
||||
}
|
||||
String uniqueKey = cloudRoadData.getUuid();
|
||||
IMogoMarker marker = mMarkersCaches.remove(uniqueKey);
|
||||
if (marker != null && !marker.isDestroyed()) {
|
||||
updateCacheMarkerRes(marker, cloudRoadData);
|
||||
renderSnapshotOneFrame(marker, uniqueKey, cloudRoadData, newMarkersCaches);
|
||||
} else {
|
||||
newDiffSet.add(cloudRoadData);
|
||||
}
|
||||
}
|
||||
// 需要新增的 marker 数量
|
||||
int newDiffSetSize = newDiffSet.size();
|
||||
// 复用过期 marker
|
||||
if (newDiffSetSize > 0) {
|
||||
// 复用过后还需新增的 marker
|
||||
for (int i = 0; i < newDiffSetSize; i++) {
|
||||
SocketDownData.CloudRoadDataProto cloudRoadData = newDiffSet.get(i);
|
||||
String uniqueKey = cloudRoadData.getUuid();
|
||||
IMogoMarker marker = drawSnapshotDataMarker(cloudRoadData);
|
||||
if (marker == null) {
|
||||
continue;
|
||||
}
|
||||
renderSnapshotOneFrame(marker, uniqueKey, cloudRoadData, newMarkersCaches);
|
||||
}
|
||||
}
|
||||
mMarkersCaches.putAll(newMarkersCaches);
|
||||
// 移除超时 marker
|
||||
delayRemoveUselessMarker();
|
||||
removeUselessLastRecord();
|
||||
CallerLogger.INSTANCE.d("云端数据延时绘制", "render 接收数据 -> 处理结束 " + TimeUnit.NANOSECONDS.toMillis((System.nanoTime() - start)) + "ms");
|
||||
}
|
||||
|
||||
/**
|
||||
* todo 后面涉及到此类变化的数据均改动
|
||||
*
|
||||
* @param marker {@link IMogoMarker}
|
||||
* @param cloudRoadDataProto {@link SocketDownData.CloudRoadDataProto}
|
||||
*/
|
||||
private void updateCacheMarkerRes(IMogoMarker marker, SocketDownData.CloudRoadDataProto cloudRoadDataProto) {
|
||||
String resIdVal;
|
||||
int resId = getModelRes(cloudRoadDataProto.getType());
|
||||
resIdVal = resId + "";
|
||||
String resName = mMarkerCachesResMd5Values.get(resIdVal);
|
||||
if (!TextUtils.isEmpty(resName)) {
|
||||
if (!TextUtils.equals(resName, marker.getMarkerResName())) {
|
||||
marker.use3DResource(resName);
|
||||
}
|
||||
} else {
|
||||
resName = marker.use3DResource(resId);
|
||||
mMarkerCachesResMd5Values.put(resIdVal, resName);
|
||||
}
|
||||
}
|
||||
|
||||
private void delayRemoveUselessMarker() {
|
||||
if (mMarkersCaches.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Iterator<IMogoMarker> iterator = mMarkersCaches.values().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
IMogoMarker result = iterator.next();
|
||||
SocketDownData.CloudRoadDataProto proto = ((SocketDownData.CloudRoadDataProto) result.getObject());
|
||||
if (proto == null) { // 后续有业务数据在操作,更新数据,不做处理
|
||||
continue;
|
||||
}
|
||||
long internal = getCurSatelliteTime() - proto.getSatelliteTime();
|
||||
CallerLogger.INSTANCE.d("MogoArrow", "delayRemoveUselessMarker uuid : " + proto.getUuid()
|
||||
+ " localTime : " + getCurSatelliteTime()
|
||||
+ " originTime : " + proto.getSatelliteTime()
|
||||
+ " internal : " + internal);
|
||||
if (internal > 5000) {
|
||||
iterator.remove();
|
||||
result.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeUselessLastRecord() { // todo 最好重新设计一个数据结构,用于多线程数据过期失效的场景,参见redis数据过期
|
||||
if (mLastPositions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Iterator<SocketDownData.CloudRoadDataProto> iterator = mLastPositions.values().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
SocketDownData.CloudRoadDataProto result = iterator.next();
|
||||
long internal = getCurSatelliteTime() - result.getSatelliteTime();
|
||||
if (internal > 3000) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断类型、uuid 等
|
||||
*
|
||||
* @param cloudRoadData {@link SocketDownData.CloudRoadDataProto}
|
||||
* @return isUselessValue
|
||||
*/
|
||||
private boolean isUselessValue(SocketDownData.CloudRoadDataProto cloudRoadData) {
|
||||
if (cloudRoadData == null) {
|
||||
return true;
|
||||
}
|
||||
if (nonRenderType(cloudRoadData.getType())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String uniqueKey = cloudRoadData.getUuid();
|
||||
return TextUtils.isEmpty(uniqueKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制某个物体的一个数据
|
||||
*
|
||||
* @param cloudRoadData {@link SocketDownData.CloudRoadDataProto}
|
||||
* @param newSnapshotCaches 缓存数据
|
||||
*/
|
||||
private void renderSnapshotOneFrame(IMogoMarker marker, String uniqueKey, SocketDownData.CloudRoadDataProto cloudRoadData, Map<String, IMogoMarker> newSnapshotCaches) {
|
||||
final long start = System.nanoTime();
|
||||
SocketDownData.CloudRoadDataProto lastPosition = mLastPositions.remove(uniqueKey);
|
||||
// 道路吸附
|
||||
// double lastLon = -1;
|
||||
// double lastLat = -1;
|
||||
// if (lastPosition != null) {
|
||||
// lastLon = lastPosition.getWgslon();
|
||||
// lastLat = lastPosition.getWgslat();
|
||||
// }
|
||||
// double[] matchLonLat = getMatchLonLat(cloudRoadData.getUuid(), cloudRoadData.getWgslon(), cloudRoadData.getWgslat(), cloudRoadData.getHeading(), lastLon, lastLat);
|
||||
// SocketDownData.CloudRoadDataProto.Builder builder = cloudRoadData.toBuilder();
|
||||
// builder.setWgslon(matchLonLat[0]);
|
||||
// builder.setWgslat(matchLonLat[1]);
|
||||
// cloudRoadData = builder.build();
|
||||
|
||||
mLastPositions.put(uniqueKey, cloudRoadData);
|
||||
long interval = 45;
|
||||
if (lastPosition != null) {
|
||||
interval = computeAnimDuration(lastPosition.getSatelliteTime(), cloudRoadData.getSatelliteTime());
|
||||
}
|
||||
final MogoLatLng point = new MogoLatLng(cloudRoadData.getWgslat(), cloudRoadData.getWgslon());
|
||||
long cost = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
|
||||
final long intervalRef = interval - cost;
|
||||
marker.addDynamicAnchorPosition(point, (float) cloudRoadData.getHeading(), intervalRef);
|
||||
marker.setAnchorColor(getModelRenderColor(cloudRoadData.getType(), cloudRoadData.getFromType(), 1));
|
||||
newSnapshotCaches.put(uniqueKey, marker);
|
||||
// if (shouldShowSpeed(cloudRoadData.getType())) {
|
||||
// Message msg = mRenderThreadHandler.obtainMessage();
|
||||
// msg.obj = new SpeedData(marker
|
||||
// , cloudRoadData.getSpeed()
|
||||
// , cloudRoadData.getUuid()
|
||||
// , cloudRoadData.getType()
|
||||
// , cloudRoadData.getHeading()
|
||||
// , MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode());
|
||||
// msg.what = MSG_DISPLAY_SPEED;
|
||||
// msg.sendToTarget();
|
||||
// }
|
||||
CallerLogger.INSTANCE.d("云端数据延时", "render 刷新一台车 cost : " + TimeUnit.NANOSECONDS.toMillis((System.nanoTime() - start)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤数据,对数据补点
|
||||
*
|
||||
* @param in 输入集合
|
||||
* @param out 输出集合
|
||||
*/
|
||||
private void prepareData(List<SocketDownData.CloudRoadDataProto> in, List<SocketDownData.CloudRoadDataProto> out) {
|
||||
// foreCastPoint(in, out);
|
||||
out.addAll(in);
|
||||
}
|
||||
|
||||
private final static String FORECAST = "snapshotForecast";
|
||||
|
||||
/**
|
||||
* 基于云平台下发的数据点速度预测当前位置和距离自车距离
|
||||
*
|
||||
* @param in 数据源
|
||||
*/
|
||||
private void foreCastPoint(List<SocketDownData.CloudRoadDataProto> in, List<SocketDownData.CloudRoadDataProto> out) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
for (SocketDownData.CloudRoadDataProto proto : in) {
|
||||
SocketDownData.CloudRoadDataProto.Builder builder = proto.toBuilder();
|
||||
CallerLogger.INSTANCE.d(FORECAST, "ready to foreCast current uuid : " + proto.getUuid());
|
||||
long internal = getCurSatelliteTime() - builder.getSatelliteTime();
|
||||
if (internal <= 0) {
|
||||
CallerLogger.INSTANCE.d(FORECAST, "time internal less than 0 , uuid : " + proto.getUuid());
|
||||
out.add(proto);
|
||||
continue;
|
||||
}
|
||||
long startTime = System.currentTimeMillis();
|
||||
// 预测点
|
||||
CallerLogger.INSTANCE.d(FORECAST, "time internal : " + internal + " speed : " + proto.getSpeed());
|
||||
double foreCastDistance = proto.getSpeed() * internal / 1000;
|
||||
CallerLogger.INSTANCE.d(FORECAST, "foreCastDistance : " + foreCastDistance);
|
||||
MogoLatLng mogoLatLng = new MogoLatLng(proto.getWgslat(), proto.getWgslon());
|
||||
MogoLatLng foreCastMogoLatLon = Trigonometric.getNewLocation(mogoLatLng, foreCastDistance, proto.getHeading());
|
||||
|
||||
// 计算与自车距离
|
||||
float distanceFromSelf = CoordinateUtils.calculateLineDistance(getCurCoordinates()[0], getCurCoordinates()[1]
|
||||
, foreCastMogoLatLon.getLon(), foreCastMogoLatLon.getLat());
|
||||
|
||||
long foreCastInternal = System.currentTimeMillis() - startTime;
|
||||
CallerLogger.INSTANCE.d(FORECAST, "foreCastInternal :" + foreCastInternal); //todo 耗时1~2毫秒 需要测试是否由于补点算法造成
|
||||
|
||||
builder.setWgslat(foreCastMogoLatLon.getLat());
|
||||
builder.setWgslon(foreCastMogoLatLon.getLon());
|
||||
builder.setSatelliteTime(getCurSatelliteTime() - foreCastInternal);
|
||||
builder.setDistance(distanceFromSelf);
|
||||
proto = builder.build();
|
||||
out.add(proto);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定点击事件
|
||||
*/
|
||||
public void bindClickListener(IMogoMarker marker) {
|
||||
if (marker == null || marker.isDestroyed()) {
|
||||
return;
|
||||
}
|
||||
marker.setOnMarkerClickListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制 marker
|
||||
*
|
||||
* @param data 道路数据
|
||||
* @return {@link IMogoMarker}
|
||||
*/
|
||||
public IMogoMarker drawSnapshotDataMarker(SocketDownData.CloudRoadDataProto data) {
|
||||
long start = System.nanoTime();
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MogoMarkerOptions options = new MogoMarkerOptions()
|
||||
.owner(TYPE_MARKER_CLOUD_DATA)
|
||||
.anchor(0.5f, 0.5f)
|
||||
.rotate((float) data.getHeading())
|
||||
.data(data)
|
||||
.gps(true)
|
||||
.controlAngle(true)
|
||||
.position(new MogoLatLng(data.getWgslat(), data.getWgslon()));
|
||||
String resIdVal;
|
||||
if (MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) {
|
||||
options.set3DMode(true);
|
||||
options.anchorColor(getModelRenderColor(data.getType(), data.getFromType(), 1));
|
||||
int resId = getModelRes(data.getType());
|
||||
resIdVal = resId + "";
|
||||
options.resName(mMarkerCachesResMd5Values.get(resIdVal));
|
||||
options.icon3DRes(resId);
|
||||
} else {
|
||||
options.set3DMode(false);
|
||||
View view = inflateView(data);
|
||||
options.icon(view);
|
||||
resIdVal = view.getId() + "";
|
||||
}
|
||||
IMogoMarker marker = MogoMarkerManager.getInstance(mContext).addMarker(TYPE_MARKER_CLOUD_DATA, options);
|
||||
cacheMarkerIconResMd5Val(resIdVal, marker);
|
||||
|
||||
if (!TextUtils.isEmpty(data.getSn())) {
|
||||
bindClickListener(marker);
|
||||
}
|
||||
CallerLogger.INSTANCE.d("云端数据延时", "创建一个新 marker cost : " + TimeUnit.NANOSECONDS.toMillis((System.nanoTime() - start)));
|
||||
return marker;
|
||||
}
|
||||
|
||||
public String get3DCacheId(String resIdVal) {
|
||||
return mMarkerCachesResMd5Values.get(resIdVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 2d marker 资源
|
||||
*
|
||||
* @param data 道路数据
|
||||
* @return marker
|
||||
*/
|
||||
public View inflateView(SocketDownData.CloudRoadDataProto data) {
|
||||
View rootView = LayoutInflater.from(AbsMogoApplication.getApp()).inflate(R.layout.module_commons_layout_car, null);
|
||||
ImageView iv = rootView.findViewById(R.id.module_commons_marker_car_model);
|
||||
int viewIdLike = get2DModel(data);
|
||||
iv.setImageResource(viewIdLike);
|
||||
rootView.setId(viewIdLike);
|
||||
return rootView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取车辆2d贴图
|
||||
*
|
||||
* @param data 道路数据
|
||||
* @return 2D贴图id
|
||||
*/
|
||||
private int get2DModel(SocketDownData.CloudRoadDataProto data) {
|
||||
switch (data.getFromType()) {
|
||||
case SocketDownDataHelper.FROM_ADAS:
|
||||
case SocketDownDataHelper.FROM_ROAD_UNIT:
|
||||
case SocketDownDataHelper.FROM_MY_LOCATION:
|
||||
default:
|
||||
return R.drawable.icon_map_marker_car_gray;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMarkerClicked(IMogoMarker marker) {
|
||||
if (marker != null && !marker.isDestroyed()) {
|
||||
if (marker.getObject() instanceof SocketDownData.CloudRoadDataProto) {
|
||||
showCarCallPanel(((SocketDownData.CloudRoadDataProto) marker.getObject()));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示用户信息面版
|
||||
*
|
||||
* @param data 道路数据
|
||||
*/
|
||||
private void showCarCallPanel(SocketDownData.CloudRoadDataProto data) {
|
||||
|
||||
/* MogoDriverInfo driverInfo = new MogoDriverInfo();
|
||||
driverInfo.setLat(data.getLat());
|
||||
driverInfo.setLon(data.getLon());
|
||||
driverInfo.setSn(data.getSn());
|
||||
ICarsChattingProvider carChatting = CallChatApi.getInstance().getApiProvider();
|
||||
|
||||
if (carChatting != null) {
|
||||
try {
|
||||
carChatting.showUserWindow(TAG, driverInfo, mContext);
|
||||
} catch (Exception e) {
|
||||
CallerLogger.INSTANCE.e(TAG, e, "showCarCallPanel");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public void changeIconResourceIfNecessary(SocketDownData.CloudRoadDataProto cloudRoadData, IMogoMarker marker) {
|
||||
if (isChangeCarModeStatus()) {
|
||||
setChangeCarModeStatus(false);
|
||||
if (MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) {
|
||||
marker.getMogoMarkerOptions().set3DMode(true);
|
||||
int resId = getModelRes(cloudRoadData.getType());
|
||||
String resName = get3DCacheId(resId + "");
|
||||
if (TextUtils.isEmpty(resName)) {
|
||||
marker.use3DResource(resId);
|
||||
cacheMarkerIconResMd5Val(resId + "", marker);
|
||||
} else {
|
||||
marker.use3DResource(resName);
|
||||
}
|
||||
} else {
|
||||
marker.getMogoMarkerOptions().set3DMode(false);
|
||||
View view = inflateView(cloudRoadData);
|
||||
int resId = view.getId();
|
||||
String resName = get3DCacheId(resId + "");
|
||||
if (TextUtils.isEmpty(resName)) {
|
||||
marker.setIcon(ViewUtils.fromView(view));
|
||||
cacheMarkerIconResMd5Val(resId + "", marker);
|
||||
} else {
|
||||
marker.use2DResource(resName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user