优化显示逻辑
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
package com.mogo.module.common.drawer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
@@ -26,8 +24,6 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static java.lang.Math.PI;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -167,19 +163,14 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
}
|
||||
renderAdasOneFrame( recognizedListResult, newAdasRecognizedMarkersCaches );
|
||||
}
|
||||
for (String id : mAdasRecognizedMarkersCaches.keySet()) {
|
||||
for ( String id : mAdasRecognizedMarkersCaches.keySet() ) {
|
||||
// 清除道路缓存
|
||||
clearRoadCacheById(id);
|
||||
clearRoadCacheById( id );
|
||||
}
|
||||
sendMessage( MSG_REMOVE_DIRTY_MARKERS, mAdasRecognizedMarkersCaches );
|
||||
mAdasRecognizedMarkersCaches = newAdasRecognizedMarkersCaches;
|
||||
}
|
||||
|
||||
private final Map< String, Boolean > mIsMatchStatusCache = new ArrayMap<>();
|
||||
|
||||
private String markerRes;
|
||||
private String markerRes2;
|
||||
|
||||
/**
|
||||
* 绘制某个物体的一个数据
|
||||
*
|
||||
@@ -198,14 +189,15 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
}
|
||||
|
||||
final long start = System.currentTimeMillis();
|
||||
|
||||
ADASRecognizedResult lastPosition = mLastPositions.remove( uniqueKey );
|
||||
double lastLon = -1;
|
||||
double lastLat = -1;
|
||||
if (lastPosition != null) {
|
||||
if ( lastPosition != null ) {
|
||||
lastLon = lastPosition.lon;
|
||||
lastLat = lastPosition.lat;
|
||||
}
|
||||
double[] matchLonLat = getMatchLonLat(recognizedListResult.uuid, recognizedListResult.lon, recognizedListResult.lat, recognizedListResult.heading, lastLon, lastLat);
|
||||
double[] matchLonLat = getMatchLonLat( recognizedListResult.uuid, recognizedListResult.lon, recognizedListResult.lat, recognizedListResult.heading, lastLon, lastLat );
|
||||
|
||||
recognizedListResult.lon = matchLonLat[0];
|
||||
recognizedListResult.lat = matchLonLat[1];
|
||||
@@ -224,70 +216,13 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
if ( lastPosition != null ) {
|
||||
long interval = computeAnimDuration( lastPosition.systemTime, recognizedListResult.systemTime, lastPosition.satelliteTime, recognizedListResult.satelliteTime );
|
||||
|
||||
MovingPoint startPoint = new MovingPoint();
|
||||
startPoint.point = new MogoLatLng( lastPosition.lat, lastPosition.lon );
|
||||
startPoint.marker = marker;
|
||||
startPoint.delay = 0L;
|
||||
startPoint.angle = ( float ) lastPosition.heading;
|
||||
|
||||
long cost = System.currentTimeMillis() - start;
|
||||
final MovingPoint endPoint = new MovingPoint();
|
||||
endPoint.point = new MogoLatLng( recognizedListResult.lat, recognizedListResult.lon );
|
||||
endPoint.marker = marker;
|
||||
endPoint.angle = ( float ) recognizedListResult.heading;
|
||||
interval -= cost;
|
||||
endPoint.delay = interval;
|
||||
|
||||
// method 1
|
||||
final IMogoMarker renderRef = marker;
|
||||
final long intervalRef = interval;
|
||||
final MogoLatLng renderLoc = new MogoLatLng( recognizedListResult.lat, recognizedListResult.lon );
|
||||
long cost = System.currentTimeMillis() - start;
|
||||
final long intervalRef = interval - cost;
|
||||
SimpleHandlerThreadPool.getInstance().postRender( () -> {
|
||||
renderRef.addDynamicAnchorPosition( endPoint.point, endPoint.angle, intervalRef );
|
||||
//
|
||||
// // 原坐标
|
||||
// MogoMarkerOptions options2 = new MogoMarkerOptions();
|
||||
// options2.gps( true )
|
||||
// .position( new MogoLatLng( lat, lon ) )
|
||||
// .anchor( 0.5f, 0.5f )
|
||||
// .rotate( endPoint.angle );
|
||||
// if ( TextUtils.isEmpty( markerRes2 ) ) {
|
||||
// options2.icon( BitmapFactory.decodeResource( mContext.getResources(), R.drawable.sy ) );
|
||||
// } else {
|
||||
// options2.resName( markerRes2 );
|
||||
// }
|
||||
// IMogoMarker marker2 = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).addMarker( TAG, options2 );
|
||||
// if ( TextUtils.isEmpty( markerRes2 ) ) {
|
||||
// markerRes2 = marker2.getMarkerResName();
|
||||
// }
|
||||
//
|
||||
// // 匹配坐标
|
||||
// MogoMarkerOptions options = new MogoMarkerOptions();
|
||||
// options.gps( true )
|
||||
// .position( endPoint.point )
|
||||
// .anchor( 0.5f, 0.5f )
|
||||
// .rotate( endPoint.angle );
|
||||
// if ( TextUtils.isEmpty( markerRes ) ) {
|
||||
// options.icon( BitmapFactory.decodeResource( mContext.getResources(), R.drawable.sr ) );
|
||||
// } else {
|
||||
// options.resName( markerRes );
|
||||
// }
|
||||
// IMogoMarker marker1 = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).addMarker( TAG, options );
|
||||
// if ( TextUtils.isEmpty( markerRes ) ) {
|
||||
// markerRes = marker1.getMarkerResName();
|
||||
// }
|
||||
|
||||
renderRef.addDynamicAnchorPosition( renderLoc, ( float ) recognizedListResult.heading, 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() );
|
||||
|
||||
} else {
|
||||
marker.setRotateAngle( ( ( float ) recognizedListResult.heading ) );
|
||||
marker.setPosition( recognizedListResult.lat, recognizedListResult.lon );
|
||||
@@ -296,8 +231,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
SpeedData obj = new SpeedData();
|
||||
obj.context = mContext;
|
||||
obj.marker = marker;
|
||||
// obj.speed = match ? 1.0 : 0.0;
|
||||
obj.speed = recognizedListResult.speed;//;lineCounter++
|
||||
obj.speed = recognizedListResult.speed;
|
||||
msg.obj = obj;
|
||||
msg.what = MSG_DISPLAY_SPEED;
|
||||
mRenderThreadHandler.sendMessage( msg );
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.util.Log;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mogo.cloud.commons.utils.CoordinateUtils;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
@@ -61,6 +62,7 @@ class BaseDrawer {
|
||||
if ( mWorkThreadHandler == null ) {
|
||||
initWorkThreadHandler();
|
||||
}
|
||||
init();
|
||||
}
|
||||
|
||||
private static Handler mWorkThreadHandler;
|
||||
@@ -144,6 +146,9 @@ class BaseDrawer {
|
||||
return R.raw.people;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fromType {@link com.mogo.realtime.entity.CloudRoadData}
|
||||
* @return
|
||||
@@ -155,7 +160,7 @@ class BaseDrawer {
|
||||
|| recognizedType == AdasRecognizedType.classIdTrafficTruck ) {
|
||||
if ( fromType == CloudRoadData.FROM_ADAS ) {
|
||||
// 灰色
|
||||
return "#D8D8D8FF";
|
||||
return "#5A8DFFFF";
|
||||
} else if ( fromType == CloudRoadData.FROM_ROAD_UNIT ) {
|
||||
// 绿色
|
||||
return "#3FE792FF";
|
||||
@@ -172,6 +177,58 @@ class BaseDrawer {
|
||||
return "#D8D8D8FF";
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据速度、经纬度计算距离判断车辆颜色
|
||||
*
|
||||
* @param speed 车速
|
||||
* @param lon 经度
|
||||
* @param lat 纬度
|
||||
* @return 实际车辆颜色
|
||||
*/
|
||||
protected String getModelRenderColor( double speed, double lon, double lat, double angle ) {
|
||||
|
||||
// 距离策略
|
||||
double curLon = MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLon();
|
||||
double curLat = MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLat();
|
||||
double distance = CoordinateUtils.calculateLineDistance( lon, lat, curLon, curLat ) * 100;
|
||||
if ( distance < 50 ) {
|
||||
return Car3DModelColor.Dangerous.color;
|
||||
} else if ( distance < 100 && distance >= 50 ) {
|
||||
return Car3DModelColor.Warming.color;
|
||||
}
|
||||
|
||||
// 速度策略
|
||||
double curSpeed = MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastSpeed();
|
||||
if ( curSpeed > 0 && speed > curSpeed ) {
|
||||
double rate = ( ( speed - curSpeed ) / curSpeed ) * 100;
|
||||
if ( rate >= 50 ) {
|
||||
return Car3DModelColor.Dangerous.color;
|
||||
} else if ( rate > 10 && rate < 50 ) {
|
||||
return Car3DModelColor.Warming.color;
|
||||
}
|
||||
}
|
||||
|
||||
// 默认颜色
|
||||
return Car3DModelColor.Normal.color;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 模型颜色
|
||||
*/
|
||||
public enum Car3DModelColor {
|
||||
|
||||
Normal( "#D8D8D8FF" ),
|
||||
Warming( "#FFD53EFF" ),
|
||||
Dangerous( "#FF3C45FF" );
|
||||
|
||||
private String color;
|
||||
|
||||
Car3DModelColor( String color ) {
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
private TextView mSpeedView = null;
|
||||
|
||||
/**
|
||||
@@ -273,8 +330,8 @@ class BaseDrawer {
|
||||
return matchRoad;
|
||||
}
|
||||
|
||||
public void clearRoadCacheById(String id) {
|
||||
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().clearRoadCacheById(id);
|
||||
public void clearRoadCacheById( String id ) {
|
||||
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().clearRoadCacheById( id );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,15 +369,11 @@ class BaseDrawer {
|
||||
if ( duration % MAP_RENDER_FRAME_FREQUENCY < MAP_RENDER_FRAME_FREQUENCY / 2 ) {
|
||||
interpolateFrame -= 1;
|
||||
}
|
||||
// if ( interpolateFrame == 0 ) {
|
||||
// interpolateFrame = 1;
|
||||
// }
|
||||
List< MovingPoint > arrayList = new ArrayList<>();
|
||||
double _angle = ( end.angle + start.angle ) / 2;
|
||||
if ( Math.abs( end.angle - start.angle ) > 5 ) {
|
||||
_angle = Math.atan2( Math.abs( start.point.lon - end.point.lon ), Math.abs( start.point.lat - end.point.lat ) ) * ( 180 / PI );
|
||||
}
|
||||
// arrayList.add( start );
|
||||
if ( interpolateFrame > 0 ) {
|
||||
double lonStep = ( end.point.lon - start.point.lon ) / ( interpolateFrame + 1 );
|
||||
double latStep = ( end.point.lat - start.point.lat ) / ( interpolateFrame + 1 );
|
||||
@@ -388,7 +441,7 @@ class BaseDrawer {
|
||||
}
|
||||
|
||||
protected double[] getMatchLonLat(String id,double lon,double lat,double heading,double lastLon,double lastLat){
|
||||
double[] matchedPoint = SnapshotSetDataDrawer.getInstance().matchRoad( id, lon,
|
||||
double[] matchedPoint = matchRoad( id, lon,
|
||||
lat,
|
||||
heading,
|
||||
true
|
||||
|
||||
Reference in New Issue
Block a user