优化显示逻辑
This commit is contained in:
@@ -563,9 +563,16 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
|
||||
}
|
||||
}
|
||||
|
||||
private String mLastAnchorColor = "";
|
||||
|
||||
@Override
|
||||
public void setAnchorColor( String anchorColor ) {
|
||||
mMarker.setMarkerOptions( mMarker.getMarkeOptions().anchorColor( anchorColor ) );
|
||||
if ( TextUtils.equals( mLastAnchorColor, anchorColor ) ) {
|
||||
return;
|
||||
}
|
||||
mMogoMarkerOptions.anchorColor( anchorColor );
|
||||
mMarker.setAnchorColor( anchorColor );
|
||||
mLastAnchorColor = anchorColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -50,6 +50,9 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
initHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化清理marker的线程
|
||||
*/
|
||||
private void initHandler() {
|
||||
mRenderThreadHandler = new Handler( WorkThreadHandler.newInstance( "render-thread-" + new Random().nextLong() ).getLooper() ) {
|
||||
@Override
|
||||
@@ -133,11 +136,8 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
// adas marker 缓存
|
||||
private Map< String, IMogoMarker > mAdasRecognizedMarkersCaches = new HashMap<>();
|
||||
|
||||
public boolean hasCached( String uniqueKey ) {
|
||||
return mAdasRecognizedMarkersCaches.containsKey( uniqueKey );
|
||||
return mMarkersCaches.containsKey( uniqueKey );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,12 +163,8 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
}
|
||||
renderAdasOneFrame( recognizedListResult, newAdasRecognizedMarkersCaches );
|
||||
}
|
||||
for ( String id : mAdasRecognizedMarkersCaches.keySet() ) {
|
||||
// 清除道路缓存
|
||||
clearRoadCacheById( id );
|
||||
}
|
||||
sendMessage( MSG_REMOVE_DIRTY_MARKERS, mAdasRecognizedMarkersCaches );
|
||||
mAdasRecognizedMarkersCaches = newAdasRecognizedMarkersCaches;
|
||||
sendMessage( MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches );
|
||||
mMarkersCaches = newAdasRecognizedMarkersCaches;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,7 +200,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
|
||||
mLastPositions.put( uniqueKey, recognizedListResult );
|
||||
Logger.d( "matchRoad", "cost = %s", System.currentTimeMillis() - start );
|
||||
IMogoMarker marker = mAdasRecognizedMarkersCaches.remove( uniqueKey );
|
||||
IMogoMarker marker = mMarkersCaches.remove( uniqueKey );
|
||||
|
||||
if ( marker == null || marker.isDestroyed() ) {
|
||||
marker = drawAdasRecognizedDataMarker( recognizedListResult );
|
||||
@@ -223,6 +219,8 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
SimpleHandlerThreadPool.getInstance().postRender( () -> {
|
||||
renderRef.addDynamicAnchorPosition( renderLoc, ( float ) recognizedListResult.heading, intervalRef );
|
||||
} );
|
||||
|
||||
marker.setAnchorColor( getModelRenderColor(recognizedListResult.speed, recognizedListResult.lon, recognizedListResult.lat, recognizedListResult.heading) );
|
||||
} else {
|
||||
marker.setRotateAngle( ( ( float ) recognizedListResult.heading ) );
|
||||
marker.setPosition( recognizedListResult.lat, recognizedListResult.lon );
|
||||
@@ -237,8 +235,6 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
mRenderThreadHandler.sendMessage( msg );
|
||||
}
|
||||
|
||||
int lineCounter = 0;
|
||||
|
||||
/**
|
||||
* 绘制 marker
|
||||
*
|
||||
@@ -258,7 +254,8 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
.anchor( 0.5f, 0.5f )
|
||||
.set3DMode( true )
|
||||
.gps( true )
|
||||
.anchorColor( getModelRenderColor( CloudRoadData.FROM_ADAS, recognizedListResult.type ) )
|
||||
// .anchorColor( getModelRenderColor( CloudRoadData.FROM_ADAS, recognizedListResult.type ) )
|
||||
.anchorColor( getModelRenderColor(recognizedListResult.speed, recognizedListResult.lon, recognizedListResult.lat, recognizedListResult.heading) )
|
||||
.controlAngle( true )
|
||||
.resName( mMarkerCachesResMd5Values.get( resIdVal ) )
|
||||
.icon3DRes( resId )
|
||||
@@ -280,8 +277,8 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
* 清除旧的 marker 数据
|
||||
*/
|
||||
public void clearOldMarker() {
|
||||
if ( mAdasRecognizedMarkersCaches != null ) {
|
||||
mAdasRecognizedMarkersCaches.clear();
|
||||
if ( mMarkersCaches != null ) {
|
||||
mMarkersCaches.clear();
|
||||
}
|
||||
if ( mLastPositions != null ) {
|
||||
mLastPositions.clear();
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.lang.Math.PI;
|
||||
|
||||
@@ -39,6 +40,54 @@ public
|
||||
*/
|
||||
class BaseDrawer {
|
||||
|
||||
/**
|
||||
* marker 单个点移动的对象
|
||||
*/
|
||||
public static class MovingPoint {
|
||||
|
||||
public MogoLatLng point;
|
||||
public float angle;
|
||||
public IMogoMarker marker;
|
||||
public long delay;
|
||||
|
||||
public void move() {
|
||||
try {
|
||||
marker.setRotateAngle( angle );
|
||||
marker.setPosition( point.lat, point.lon );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* marker 平滑移动的对象
|
||||
*/
|
||||
public static class MovingPoints {
|
||||
public List< MovingPoint > points;
|
||||
}
|
||||
|
||||
/**
|
||||
* 速度显示对象
|
||||
*/
|
||||
public class SpeedData {
|
||||
|
||||
public IMogoMarker marker;
|
||||
public Context context;
|
||||
double speed;
|
||||
|
||||
public void showSpeed() {
|
||||
try {
|
||||
showSelfSpeed( context,
|
||||
marker,
|
||||
speed,
|
||||
MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 移除过期的 marker
|
||||
public static final int MSG_REMOVE_DIRTY_MARKERS = 9990;
|
||||
public static final int MSG_REMOVE_ADAS_MARKERS = 9992;
|
||||
@@ -58,6 +107,11 @@ class BaseDrawer {
|
||||
*/
|
||||
protected static final Map< String, String > mMarkerCachesResMd5Values = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 上一帧数据的缓存
|
||||
*/
|
||||
protected Map< String, IMogoMarker > mMarkersCaches = new HashMap<>();
|
||||
|
||||
public BaseDrawer() {
|
||||
if ( mWorkThreadHandler == null ) {
|
||||
initWorkThreadHandler();
|
||||
@@ -81,6 +135,11 @@ class BaseDrawer {
|
||||
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 );
|
||||
}
|
||||
} else if ( msg.obj instanceof String ) {
|
||||
MogoApisHandler.getInstance().getApis()
|
||||
.getMapServiceApi()
|
||||
@@ -197,7 +256,9 @@ class BaseDrawer {
|
||||
return Car3DModelColor.Warming.color;
|
||||
}
|
||||
|
||||
// 速度策略
|
||||
// 他车车速和自车车速对比速度策略
|
||||
// 自车速度 >= 50% 危险
|
||||
// 10% < 自车速度 < 50% 警告
|
||||
double curSpeed = MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastSpeed();
|
||||
if ( curSpeed > 0 && speed > curSpeed ) {
|
||||
double rate = ( ( speed - curSpeed ) / curSpeed ) * 100;
|
||||
@@ -330,7 +391,11 @@ class BaseDrawer {
|
||||
return matchRoad;
|
||||
}
|
||||
|
||||
public void clearRoadCacheById( String id ) {
|
||||
/**
|
||||
* 清理缓存路段数据
|
||||
* @param id
|
||||
*/
|
||||
public static void clearRoadCacheById( String id ) {
|
||||
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().clearRoadCacheById( id );
|
||||
}
|
||||
|
||||
@@ -393,54 +458,16 @@ class BaseDrawer {
|
||||
}
|
||||
|
||||
/**
|
||||
* marker 单个点移动的对象
|
||||
* 根据位置信息、车头朝向计算道路吸附
|
||||
* @param id
|
||||
* @param lon
|
||||
* @param lat
|
||||
* @param heading
|
||||
* @param lastLon
|
||||
* @param lastLat
|
||||
* @return
|
||||
*/
|
||||
public static class MovingPoint {
|
||||
|
||||
public MogoLatLng point;
|
||||
public float angle;
|
||||
public IMogoMarker marker;
|
||||
public long delay;
|
||||
|
||||
public void move() {
|
||||
try {
|
||||
marker.setRotateAngle( angle );
|
||||
marker.setPosition( point.lat, point.lon );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* marker 平滑移动的对象
|
||||
*/
|
||||
public static class MovingPoints {
|
||||
public List< MovingPoint > points;
|
||||
}
|
||||
|
||||
/**
|
||||
* 速度显示对象
|
||||
*/
|
||||
public class SpeedData {
|
||||
|
||||
public IMogoMarker marker;
|
||||
public Context context;
|
||||
double speed;
|
||||
|
||||
public void showSpeed() {
|
||||
try {
|
||||
showSelfSpeed( context,
|
||||
marker,
|
||||
speed,
|
||||
MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected double[] getMatchLonLat(String id,double lon,double lat,double heading,double lastLon,double lastLat){
|
||||
protected double[] getMatchLonLat( String id, double lon, double lat, double heading, double lastLon, double lastLat ) {
|
||||
double[] matchedPoint = matchRoad( id, lon,
|
||||
lat,
|
||||
heading,
|
||||
@@ -454,17 +481,17 @@ class BaseDrawer {
|
||||
|
||||
if ( lastLon != -1 ) {
|
||||
double clearAngle;
|
||||
if (heading > 0 && heading <= 90) {
|
||||
if ( heading > 0 && heading <= 90 ) {
|
||||
clearAngle = heading;
|
||||
} else if (heading > 90 && heading <= 180) {
|
||||
clearAngle = 180 - heading ;
|
||||
} else if (heading > 180 && heading <= 270) {
|
||||
} else if ( heading > 90 && heading <= 180 ) {
|
||||
clearAngle = 180 - heading;
|
||||
} else if ( heading > 180 && heading <= 270 ) {
|
||||
clearAngle = heading - 180;
|
||||
}else{
|
||||
} 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 ) {
|
||||
match = false;
|
||||
@@ -476,6 +503,6 @@ class BaseDrawer {
|
||||
}
|
||||
}
|
||||
|
||||
return new double[]{lon,lat};
|
||||
return new double[]{lon, lat};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,46 +160,34 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
|
||||
prepareData( data.getAllList(), allDatumsList );
|
||||
Map< String, IMogoMarker > newMarkersCaches = new ArrayMap<>( allDatumsList.size() );
|
||||
for ( CloudRoadData cloudRoadData : allDatumsList ) {
|
||||
// cloudKeyCache.remove( cloudRoadData.getUniqueKey() );
|
||||
// newMarkersCaches.put( cloudRoadData.getUniqueKey(), cloudRoadData.getUniqueKey() );
|
||||
// SimpleHandlerThreadPool.getInstance().post( cloudRoadData );
|
||||
renderSnapshotOneFrame(cloudRoadData,newMarkersCaches);
|
||||
}
|
||||
sendMessage(MSG_REMOVE_DIRTY_MARKERS,mAdasRecognizedMarkersCaches);
|
||||
mAdasRecognizedMarkersCaches = newMarkersCaches;
|
||||
sendMessage(MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches );
|
||||
mMarkersCaches = newMarkersCaches;
|
||||
|
||||
|
||||
// SimpleHandlerThreadPool.getInstance().removeDirtyMarker( cloudKeyCache.values() );
|
||||
// cloudKeyCache = newMarkersCaches;
|
||||
}
|
||||
private final Map< String, Boolean > mIsMatchStatusCache = new ArrayMap<>();
|
||||
private Map< String, IMogoMarker > mAdasRecognizedMarkersCaches = new HashMap<>();
|
||||
|
||||
public boolean hasCached( String uniqueKey ) {
|
||||
return mAdasRecognizedMarkersCaches.containsKey( uniqueKey );
|
||||
}
|
||||
/**
|
||||
* 绘制某个物体的一个数据
|
||||
*
|
||||
* @param recognizedListResult
|
||||
* @param cloudRoadData
|
||||
* @param newAdasRecognizedMarkersCaches
|
||||
*/
|
||||
private void renderSnapshotOneFrame(CloudRoadData recognizedListResult, Map< String, IMogoMarker > newAdasRecognizedMarkersCaches ) {
|
||||
private void renderSnapshotOneFrame(final CloudRoadData cloudRoadData, Map< String, IMogoMarker > newAdasRecognizedMarkersCaches ) {
|
||||
// 暂时只显示车辆
|
||||
if ( !isRenderType( recognizedListResult.getType() ) ) {
|
||||
if ( !isRenderType( cloudRoadData.getType() ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
String uniqueKey = recognizedListResult.getUniqueKey();
|
||||
String uniqueKey = cloudRoadData.getUniqueKey();
|
||||
if ( TextUtils.isEmpty( uniqueKey ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
final long start = System.currentTimeMillis();
|
||||
// Logger.d( "matchRoad", "cost = %s", System.currentTimeMillis() - start );
|
||||
|
||||
IMogoMarker marker = mAdasRecognizedMarkersCaches.remove( uniqueKey );
|
||||
CloudRoadData lastPosition = mLastPositions.put( uniqueKey, recognizedListResult );
|
||||
IMogoMarker marker = mMarkersCaches.remove( uniqueKey );
|
||||
CloudRoadData lastPosition = mLastPositions.put( uniqueKey, cloudRoadData );
|
||||
|
||||
double lastLon = -1;
|
||||
double lastLat = -1;
|
||||
@@ -207,59 +195,39 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
|
||||
lastLon = lastPosition.getWgslon();
|
||||
lastLat = lastPosition.getWgslat();
|
||||
}
|
||||
double[] matchLonLat = getMatchLonLat(recognizedListResult.getUniqueKey(), recognizedListResult.getWgslon(), recognizedListResult.getWgslat(), recognizedListResult.getHeading(), lastLon, lastLat);
|
||||
recognizedListResult.setWgslon(matchLonLat[0]);
|
||||
recognizedListResult.setWgslat(matchLonLat[1]);
|
||||
double[] matchLonLat = getMatchLonLat(cloudRoadData.getUniqueKey(), cloudRoadData.getWgslon(), cloudRoadData.getWgslat(), cloudRoadData.getHeading(), lastLon, lastLat);
|
||||
cloudRoadData.setWgslon(matchLonLat[0]);
|
||||
cloudRoadData.setWgslat(matchLonLat[1]);
|
||||
|
||||
if ( marker == null || marker.isDestroyed() ) {
|
||||
marker = drawSnapshotDataMarker( recognizedListResult );
|
||||
marker = drawSnapshotDataMarker( cloudRoadData );
|
||||
if ( marker == null ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
newAdasRecognizedMarkersCaches.put( uniqueKey, marker );
|
||||
if ( lastPosition != null ) {
|
||||
long interval = computeAnimDuration( lastPosition.getSystemTime(), recognizedListResult.getSystemTime(), lastPosition.getSatelliteTime(), recognizedListResult.getSatelliteTime() );
|
||||
|
||||
MovingPoint startPoint = new MovingPoint();
|
||||
startPoint.point = new MogoLatLng( lastPosition.getWgslat(), lastPosition.getWgslon() );
|
||||
startPoint.marker = marker;
|
||||
startPoint.delay = 0L;
|
||||
startPoint.angle = ( float ) lastPosition.getHeading();
|
||||
|
||||
long cost = System.currentTimeMillis() - start;
|
||||
final MovingPoint endPoint = new MovingPoint();
|
||||
endPoint.point = new MogoLatLng( recognizedListResult.getWgslat(), recognizedListResult.getWgslon() );
|
||||
endPoint.marker = marker;
|
||||
endPoint.angle = ( float ) recognizedListResult.getHeading();
|
||||
interval -= cost;
|
||||
endPoint.delay = interval;
|
||||
long interval = computeAnimDuration( lastPosition.getSystemTime(), cloudRoadData.getSystemTime(), lastPosition.getSatelliteTime(), cloudRoadData.getSatelliteTime() );
|
||||
|
||||
// method 1
|
||||
final IMogoMarker renderRef = marker;
|
||||
final long intervalRef = interval;
|
||||
final MogoLatLng point = new MogoLatLng( cloudRoadData.getWgslat(), cloudRoadData.getWgslon() );
|
||||
long cost = System.currentTimeMillis() - start;
|
||||
final long intervalRef = interval - cost;
|
||||
|
||||
SimpleHandlerThreadPool.getInstance().postRender( () -> {
|
||||
renderRef.addDynamicAnchorPosition( endPoint.point, endPoint.angle, intervalRef );
|
||||
renderRef.addDynamicAnchorPosition( point, (float)cloudRoadData.getHeading(), intervalRef );
|
||||
} );
|
||||
|
||||
// method 2
|
||||
// List< MovingPoint > points = interpolate( startPoint, endPoint, interval );
|
||||
// Message msg = new Message();
|
||||
// MovingPoints obj = new MovingPoints();
|
||||
// obj.points = points;
|
||||
// msg.obj = obj;
|
||||
// msg.what = MSG_MOVE_POINTS;
|
||||
// mRenderThreadHandler.sendMessage( msg );
|
||||
// Logger.d( TAG, "anim duration: %s, points size = %s", interval, points.size() );
|
||||
|
||||
marker.setAnchorColor( getModelRenderColor(cloudRoadData.getSpeed(), cloudRoadData.getWgslon(), cloudRoadData.getWgslat(), cloudRoadData.getHeading()) );
|
||||
} else {
|
||||
marker.setRotateAngle( ( ( float ) recognizedListResult.getHeading() ) );
|
||||
marker.setPosition( recognizedListResult.getWgslat(), recognizedListResult.getWgslon() );
|
||||
marker.setRotateAngle( ( ( float ) cloudRoadData.getHeading() ) );
|
||||
marker.setPosition( cloudRoadData.getWgslat(), cloudRoadData.getWgslon() );
|
||||
}
|
||||
SpeedData obj = new SpeedData();
|
||||
obj.context = mContext;
|
||||
obj.marker = marker;
|
||||
obj.speed = recognizedListResult.getSpeed();
|
||||
obj.speed = cloudRoadData.getSpeed();
|
||||
SimpleHandlerThreadPool.getInstance().postRender(obj::showSpeed);
|
||||
|
||||
}
|
||||
@@ -330,7 +298,8 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
|
||||
String resIdVal = null;
|
||||
if ( MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() ) {
|
||||
options.set3DMode( true );
|
||||
options.anchorColor( getModelRenderColor( data.getFromType(), data.getType() ) );
|
||||
// options.anchorColor( getModelRenderColor( data.getFromType(), data.getType() ) );
|
||||
options.anchorColor( getModelRenderColor( data.getSpeed(), data.getWgslon(), data.getWgslat(), data.getHeading() ) );
|
||||
int resId = getModelRes( data.getType() );
|
||||
resIdVal = resId + "";
|
||||
options.resName( mMarkerCachesResMd5Values.get( resIdVal ) );
|
||||
|
||||
Reference in New Issue
Block a user