fix bug and add note

This commit is contained in:
zhongchao
2021-04-15 11:02:40 +08:00
parent 679e183859
commit 88886e9fcf
4 changed files with 162 additions and 178 deletions

View File

@@ -29,12 +29,12 @@ import java.util.Set;
import static java.lang.Math.PI;
public
/**
* @author congtaowang
* @since 2020/10/30
* <p>
* 描述
*/
/*
* @author congtaowang
* @since 2020/10/30
* <p>
* 描述
*/
class BaseDrawer {
/**
@@ -48,11 +48,11 @@ class BaseDrawer {
public void showSpeed() {
try {
showSelfSpeed( context,
showSelfSpeed(context,
marker,
speed,
MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() );
} catch ( Exception e ) {
MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode());
} catch (Exception e) {
e.printStackTrace();
}
}
@@ -79,12 +79,12 @@ class BaseDrawer {
/**
* 地图内部资源md5缓存便于资源复用
*/
protected static final Map< String, String > mMarkerCachesResMd5Values = new HashMap<>();
protected static final Map<String, String> mMarkerCachesResMd5Values = new HashMap<>();
/**
* 上一帧数据的缓存
*/
protected Map< String, IMogoMarker > mMarkersCaches = new HashMap<>();
protected Map<String, IMogoMarker> mMarkersCaches = new HashMap<>();
protected final Context mContext;
@@ -101,38 +101,38 @@ class BaseDrawer {
* 处理 marker 移除的线程
*/
private static void initWorkThreadHandler() {
if ( mWorkThreadHandler == null ) {
mWorkThreadHandler = new Handler( WorkThreadHandler.newInstance( "3d-marker-work-thread" ).getLooper() ) {
if (mWorkThreadHandler == null) {
mWorkThreadHandler = new Handler(WorkThreadHandler.newInstance("3d-marker-work-thread").getLooper()) {
@Override
public void handleMessage( Message msg ) {
super.handleMessage( msg );
if ( msg.what == MSG_REMOVE_DIRTY_MARKERS ) {
if ( msg.obj instanceof Map ) {
removeDirtyMarkers( ( ( Map ) msg.obj ) );
Set< String > key = ( ( Map ) msg.obj ).keySet();
for ( String id : key ) {
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == MSG_REMOVE_DIRTY_MARKERS) {
if (msg.obj instanceof Map) {
removeDirtyMarkers(((Map) msg.obj));
Set<String> key = ((Map) msg.obj).keySet();
for (String id : key) {
// 清除道路缓存
clearRoadCacheById( id );
clearRoadCacheById(id);
}
} else if ( msg.obj instanceof String ) {
} else if (msg.obj instanceof String) {
MogoApisHandler.getInstance().getApis()
.getMapServiceApi()
.getMarkerManager( AbsMogoApplication.getApp() )
.removeMarkers( ( ( String ) msg.obj ) );
.getMarkerManager(AbsMogoApplication.getApp())
.removeMarkers(((String) msg.obj));
}
}
}
};
}
if ( mRenderThreadHandler == null ) {
mRenderThreadHandler = new Handler( WorkThreadHandler.newInstance( "render-thread-" + new Random().nextLong() ).getLooper() ) {
if (mRenderThreadHandler == null) {
mRenderThreadHandler = new Handler(WorkThreadHandler.newInstance("render-thread-" + new Random().nextLong()).getLooper()) {
@Override
public void handleMessage( Message msg ) {
super.handleMessage( msg );
if ( msg.what == MSG_DISPLAY_SPEED ) {
if ( msg.obj instanceof SpeedData ) {
showSpeed( ( SpeedData ) msg.obj );
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == MSG_DISPLAY_SPEED) {
if (msg.obj instanceof SpeedData) {
showSpeed((SpeedData) msg.obj);
}
}
}
@@ -143,10 +143,10 @@ class BaseDrawer {
/**
* 显示速度
*
* @param data
* @param data {@link SpeedData}
*/
private static void showSpeed( SpeedData data ) {
if ( data == null ) {
private static void showSpeed(SpeedData data) {
if (data == null) {
return;
}
data.showSpeed();
@@ -156,13 +156,13 @@ class BaseDrawer {
* 清除无效[为 null 或者 已被销毁]的 marker
*/
protected void removeUselessMarker() {
if ( mMarkersCaches == null || mMarkersCaches.isEmpty() ) {
if (mMarkersCaches == null || mMarkersCaches.isEmpty()) {
return;
}
Iterator< IMogoMarker > iterator = mMarkersCaches.values().iterator();
while ( iterator.hasNext() ) {
Iterator<IMogoMarker> iterator = mMarkersCaches.values().iterator();
while (iterator.hasNext()) {
IMogoMarker marker = iterator.next();
if ( marker == null || marker.isDestroyed() ) {
if (marker == null || marker.isDestroyed()) {
iterator.remove();
}
}
@@ -171,66 +171,60 @@ class BaseDrawer {
/**
* 发送消息
*
* @param msg
* @param data
* @param msg 消息类型
* @param data 数据体
*/
public void sendMessage( int msg, Object data ) {
public void sendMessage(int msg, Object data) {
Message message = Message.obtain();
message.what = msg;
message.obj = data;
mWorkThreadHandler.sendMessage( message );
mWorkThreadHandler.sendMessage(message);
}
/**
* 判断是否是绘制内容
*
* @param type
* @return
* @param type {@link AdasRecognizedType}
* @return render
*/
public boolean isRenderType( int type ) {
AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom( type );
if ( recognizedType == AdasRecognizedType.classIdCar
public boolean isRenderType(int type) {
AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom(type);
return recognizedType == AdasRecognizedType.classIdCar
|| recognizedType == AdasRecognizedType.classIdMoto
|| recognizedType == AdasRecognizedType.classIdBicycle
|| recognizedType == AdasRecognizedType.classIdPerson
|| recognizedType == AdasRecognizedType.classIdTrafficBus
|| recognizedType == AdasRecognizedType.classIdTrafficTruck ) {
return true;
}
return false;
|| recognizedType == AdasRecognizedType.classIdTrafficTruck;
}
/**
* 是否展示车速
*
* @param type
* @return
* @param type {@link AdasRecognizedType}
* @return showSpeed
*/
public boolean shouldShowSpeed( int type ) {
AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom( type );
if ( recognizedType == AdasRecognizedType.classIdBicycle
|| recognizedType == AdasRecognizedType.classIdMoto
|| recognizedType == AdasRecognizedType.classIdPerson ) {
return false;
}
return true;
public boolean shouldShowSpeed(int type) {
AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom(type);
return recognizedType != AdasRecognizedType.classIdBicycle
&& recognizedType != AdasRecognizedType.classIdMoto
&& recognizedType != AdasRecognizedType.classIdPerson;
}
/**
* 获取3D锚点模型资源
*
* @param type {@link AdasRecognizedType}
* @return
* @return modelRes
*/
public int getModelRes( int type ) {
AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom( type );
if ( recognizedType == AdasRecognizedType.classIdCar
|| recognizedType == AdasRecognizedType.classIdTrafficTruck ) {
public int getModelRes(int type) {
AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom(type);
if (recognizedType == AdasRecognizedType.classIdCar
|| recognizedType == AdasRecognizedType.classIdTrafficTruck) {
return R.raw.othercar;
} else if ( recognizedType == AdasRecognizedType.classIdTrafficBus ) {
} else if (recognizedType == AdasRecognizedType.classIdTrafficBus) {
return R.raw.bus;
} else if ( recognizedType == AdasRecognizedType.classIdBicycle
|| recognizedType == AdasRecognizedType.classIdMoto ) {
} else if (recognizedType == AdasRecognizedType.classIdBicycle
|| recognizedType == AdasRecognizedType.classIdMoto) {
return R.raw.motorbike;
}
return R.raw.people;
@@ -244,18 +238,18 @@ class BaseDrawer {
* @param lat 纬度
* @return 实际车辆颜色
*/
protected String getModelRenderColor( int type, double speed, double lon, double lat, double angle ) {
protected String getModelRenderColor(int type, double speed, double lon, double lat, double angle) {
AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom( type );
if ( recognizedType == AdasRecognizedType.classIdTrafficBus ) {
AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom(type);
if (recognizedType == AdasRecognizedType.classIdTrafficBus) {
return "#D8D8D8FF";
}
// 距离策略
double coordinates[] = getCurCoordinates();
double distance = CoordinateUtils.calculateLineDistance( lon, lat, coordinates[0], coordinates[1] ) * 100;
if ( distance < 50 ) {
double[] coordinates = getCurCoordinates();
double distance = CoordinateUtils.calculateLineDistance(lon, lat, coordinates[0], coordinates[1]) * 100;
if (distance < 50) {
return Car3DModelColor.Dangerous.color;
} else if ( distance < 100 && distance >= 50 ) {
} else if (distance < 100 && distance >= 50) {
return Car3DModelColor.Warming.color;
}
@@ -263,11 +257,11 @@ class BaseDrawer {
// 自车速度 >= 50% 危险
// 10% < 自车速度 < 50% 警告
double curSpeed = getCurSpeed();
if ( curSpeed > 0 && speed > curSpeed ) {
double rate = ( ( speed - curSpeed ) / curSpeed ) * 100;
if ( rate >= 50 ) {
if (curSpeed > 0 && speed > curSpeed) {
double rate = ((speed - curSpeed) / curSpeed) * 100;
if (rate >= 50) {
return Car3DModelColor.Dangerous.color;
} else if ( rate > 10 && rate < 50 ) {
} else if (rate > 10 && rate < 50) {
return Car3DModelColor.Warming.color;
}
}
@@ -279,11 +273,11 @@ class BaseDrawer {
/**
* 返回当前自车速度
*
* @return
* @return isCurSpeed
*/
private double getCurSpeed() {
double speed = MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastSpeed();
if ( speed <= 0 ) {
if (speed <= 0) {
speed = SnapshotLocationController.getInstance().getCurSpeed();
}
return speed;
@@ -295,11 +289,11 @@ class BaseDrawer {
* @return
*/
private double[] getCurCoordinates() {
double coordinates[] = {
double[] coordinates = {
MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLon(),
MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLat(),
};
if ( coordinates[0] <= 0 ) {
if (coordinates[0] <= 0) {
coordinates[0] = SnapshotLocationController.getInstance().getCurLon();
coordinates[1] = SnapshotLocationController.getInstance().getCurLat();
}
@@ -312,13 +306,13 @@ class BaseDrawer {
*/
public enum Car3DModelColor {
Normal( "#D8D8D8FF" ),
Warming( "#FFD53EFF" ),
Dangerous( "#FF3C45FF" );
Normal("#D8D8D8FF"),
Warming("#FFD53EFF"),
Dangerous("#FF3C45FF");
private String color;
private final String color;
Car3DModelColor( String color ) {
Car3DModelColor(String color) {
this.color = color;
}
}
@@ -328,59 +322,59 @@ class BaseDrawer {
/**
* 展示车辆速度
*
* @param context
* @param mogoMarker
* @param speed
* @param isVrMode
* @param context 上下文
* @param mogoMarker {@link IMogoMarker}
* @param speed 是否显示速度
* @param isVrMode 是否是vrMode
*/
public void showSelfSpeed( Context context, IMogoMarker mogoMarker, double speed, boolean isVrMode ) {
if ( mogoMarker == null || mogoMarker.isDestroyed() ) {
public void showSelfSpeed(Context context, IMogoMarker mogoMarker, double speed, boolean isVrMode) {
if (mogoMarker == null || mogoMarker.isDestroyed()) {
return;
}
if ( !isVrMode ) {
if (!isVrMode) {
mogoMarker.hideInfoWindow();
return;
}
int speedIntVal = ( int ) ( speed * 3.6 );
if ( speedIntVal <= 0 ) {
int speedIntVal = (int) (speed * 3.6);
if (speedIntVal <= 0) {
mogoMarker.hideInfoWindow();
return;
}
String speedVal = speedIntVal + "";
String infoResName = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().getMarkerInfoResName( speedVal );
mogoMarker.setInfoWindowOffset( 0, 20 );
if ( TextUtils.isEmpty( infoResName ) ) {
if ( mSpeedView == null ) {
mSpeedView = new TextView( context );
mSpeedView.setTextColor( Color.WHITE );
mSpeedView.setTypeface( Typeface.defaultFromStyle( Typeface.BOLD ) );
mSpeedView.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT ) );
String infoResName = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().getMarkerInfoResName(speedVal);
mogoMarker.setInfoWindowOffset(0, 20);
if (TextUtils.isEmpty(infoResName)) {
if (mSpeedView == null) {
mSpeedView = new TextView(context);
mSpeedView.setTextColor(Color.WHITE);
mSpeedView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
mSpeedView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
mSpeedView.setText( speedVal );
mogoMarker.updateInfoWindowView( mSpeedView );
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().setMarkerInfoResName( speedVal, mogoMarker.getMarkerInfoResName() );
mSpeedView.setText(speedVal);
mogoMarker.updateInfoWindowView(mSpeedView);
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().setMarkerInfoResName(speedVal, mogoMarker.getMarkerInfoResName());
} else {
mogoMarker.updateInfoWindowView( infoResName );
mogoMarker.updateInfoWindowView(infoResName);
}
}
/**
* 移除markers
*
* @param dirtyMarkers
* @param dirtyMarkers 缓存marker数据
*/
protected static void removeDirtyMarkers( Map< String, IMogoMarker > dirtyMarkers ) {
if ( dirtyMarkers == null || dirtyMarkers.isEmpty() ) {
protected static void removeDirtyMarkers(Map<String, IMogoMarker> dirtyMarkers) {
if (dirtyMarkers == null || dirtyMarkers.isEmpty()) {
return;
}
final Collection< IMogoMarker > dirSet = dirtyMarkers.values();
for ( IMogoMarker value : dirSet ) {
if ( value == null || value.isDestroyed() ) {
final Collection<IMogoMarker> dirSet = dirtyMarkers.values();
for (IMogoMarker value : dirSet) {
if (value == null || value.isDestroyed()) {
continue;
}
try {
value.destroy();
} catch ( Exception e ) {
} catch (Exception e) {
e.printStackTrace();
}
}
@@ -393,15 +387,15 @@ class BaseDrawer {
* @param id
* @param marker
*/
protected static void cacheMarkerIconResMd5Val( String id, IMogoMarker marker ) {
if ( marker == null || marker.isDestroyed() ) {
protected static void cacheMarkerIconResMd5Val(String id, IMogoMarker marker) {
if (marker == null || marker.isDestroyed()) {
return;
}
String md5 = marker.getMarkerResName();
if ( TextUtils.isEmpty( md5 ) || TextUtils.isEmpty( id ) ) {
if (TextUtils.isEmpty(md5) || TextUtils.isEmpty(id)) {
return;
}
mMarkerCachesResMd5Values.put( id, md5 );
mMarkerCachesResMd5Values.put(id, md5);
}
/**
@@ -413,14 +407,14 @@ class BaseDrawer {
* @param isRtk
* @return
*/
public double[] matchRoad( String id, double lon, double lat, double angle, boolean isRtk ) {
public double[] matchRoad(String id, double lon, double lat, double angle, boolean isRtk) {
final long start = System.currentTimeMillis();
double[] matchRoad = MogoApisHandler.getInstance()
.getApis()
.getMapServiceApi()
.getMapUIController()
.matchRoad( id, lon, lat, angle, true, isRtk );
Log.i( "timer-matchRoad", "cost " + ( System.currentTimeMillis() - start ) + "ms" );
.matchRoad(id, lon, lat, angle, true, isRtk);
Log.i("timer-matchRoad", "cost " + (System.currentTimeMillis() - start) + "ms");
return matchRoad;
}
@@ -429,8 +423,8 @@ class BaseDrawer {
*
* @param id
*/
public static void clearRoadCacheById( String id ) {
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().clearRoadCacheById( id );
public static void clearRoadCacheById(String id) {
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().clearRoadCacheById(id);
}
/**
@@ -442,11 +436,11 @@ class BaseDrawer {
* @param curSatelliteTime
* @return
*/
public long computeAnimDuration( long lastSystemTime, long curSystemTime, long lastSatelliteTime, long curSatelliteTime ) {
public long computeAnimDuration(long lastSystemTime, long curSystemTime, long lastSatelliteTime, long curSatelliteTime) {
long systemTimeInterval = curSystemTime - lastSystemTime;
long satelliteTimeInterval = curSatelliteTime - lastSatelliteTime;
long interval = systemTimeInterval < satelliteTimeInterval || satelliteTimeInterval == 0 ? systemTimeInterval : satelliteTimeInterval;
if ( interval < 45 ) {
if (interval < 45) {
interval = 45;
}
return interval;
@@ -463,37 +457,37 @@ class BaseDrawer {
* @param lastLat
* @return
*/
protected double[] getMatchLonLat( String id, double lon, double lat, double heading, double lastLon, double lastLat ) {
double[] matchedPoint = matchRoad( id, lon,
protected double[] getMatchLonLat(String id, double lon, double lat, double heading, double lastLon, double lastLat) {
double[] matchedPoint = matchRoad(id, lon,
lat,
heading,
true
);
boolean match = false;
if ( matchedPoint != null ) {
if (matchedPoint != null) {
// Logger.d( TAG, "matchPoint %s distance = %s",lineCounter, matchedPoint[2] );
match = matchedPoint[2] < 1 && matchedPoint[2] > 0;
if ( lastLon != -1 ) {
if (lastLon != -1) {
double clearAngle;
if ( heading > 0 && heading <= 90 ) {
if (heading > 0 && heading <= 90) {
clearAngle = heading;
} else if ( heading > 90 && heading <= 180 ) {
} else if (heading > 90 && heading <= 180) {
clearAngle = 180 - heading;
} else if ( heading > 180 && heading <= 270 ) {
} else if (heading > 180 && heading <= 270) {
clearAngle = heading - 180;
} else {
clearAngle = 360 - heading;
}
double _angle = Math.atan2( Math.abs( matchedPoint[0] - lastLon ), Math.abs( matchedPoint[1] - lastLat ) ) * ( 180 / PI );
_angle = Math.abs( clearAngle - _angle );
double _angle = Math.atan2(Math.abs(matchedPoint[0] - lastLon), Math.abs(matchedPoint[1] - lastLat)) * (180 / PI);
_angle = Math.abs(clearAngle - _angle);
// Logger.d(TAG, "matchPoint %s angel = %s", lineCounter, _angle);
if ( _angle > 22.5 ) {
if (_angle > 22.5) {
match = false;
}
}
if ( match ) {
if (match) {
lon = matchedPoint[0];
lat = matchedPoint[1];
}

View File

@@ -10,11 +10,11 @@ import java.util.ArrayList;
import java.util.List;
public
/**
/*
* @author congtaowang
* @since 2020/12/14
*
* 实时坐标
* 实时坐标数据处理中心
*/
class SnapshotLocationController {
@@ -40,16 +40,15 @@ class SnapshotLocationController {
sInstance = null;
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return sInstance;
}
private CloudLocationInfo mLastLocationInfo = null;
private List< CloudLocationInfo > mLocationList = new ArrayList<>();
private int mDataAccuracy = 0;
// GPS(1s1次) RTK(OS侧)缓存数据,
private final List< CloudLocationInfo > mLocationList = new ArrayList<>();
// adda 工控机数据缓存
private final List< CloudLocationInfo > mMachineCacheList = new ArrayList<>();
private int mDataAccuracy = 0;
private double mCurSpeed;
private double mCurLon;
private double mCurLat;
@@ -57,26 +56,23 @@ class SnapshotLocationController {
/**
* 同步从定位来的数据也可能是rtk
*
* @param cli
* @param cli {@link CloudLocationInfo}
*/
public void syncLocationInfo( CloudLocationInfo cli ) {
if ( cli == null ) {
return;
}
mLastLocationInfo = cli;
mCurSpeed = mLastLocationInfo.getSpeed();
mCurLon = mLastLocationInfo.getLon();
mCurLat = mLastLocationInfo.getLat();
mCurSpeed = cli.getSpeed();
mCurLon = cli.getLon();
mCurLat = cli.getLat();
mLocationList.add( cli );
}
// adda 工控机数据缓存
private List< CloudLocationInfo > mMachineCacheList = new ArrayList<>();
/**
* 同步从工控机来的数据
*
* @param data
* @param data JSON结构化数据
*/
public void syncAdasLocationInfo( JSONObject data ) {
if ( data == null ) {
@@ -113,7 +109,7 @@ class SnapshotLocationController {
/**
* 获取某一段时间内的坐标集合
*
* @return
* @return 坐标合集
*/
public List< CloudLocationInfo > getSendLocationData() {
@@ -144,7 +140,7 @@ class SnapshotLocationController {
/**
* 数据精度类型,目前按照数据来源标志
*
* @return
* @return 精度
*/
public int getDataAccuracy() {
Logger.d( TAG, "upload loc accuracy = %s", mDataAccuracy );