优化显示逻辑
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -60,7 +61,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
}
|
||||
} else if ( msg.what == MSG_SET_POINT ) {
|
||||
if ( msg.obj instanceof MovingPoint ) {
|
||||
moveMarker( ( ( MovingPoint ) msg.obj ) );
|
||||
moveMarker( ( ( MovingPoint ) msg.obj ), msg.arg1 );
|
||||
}
|
||||
} else if ( msg.what == MSG_SET_SPEED ) {
|
||||
if ( msg.obj instanceof SpeedData ) {
|
||||
@@ -82,6 +83,11 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
Message msg = Message.obtain();
|
||||
msg.what = MSG_SET_POINT;
|
||||
msg.obj = points.get( i );
|
||||
if ( i == 0 || i == points.size() - 1 ) {
|
||||
msg.arg1 = R.drawable.sr;
|
||||
} else {
|
||||
msg.arg1 = R.drawable.sy;
|
||||
}
|
||||
mPointSettingHandler.sendMessageDelayed( msg, points.get( i ).delay );
|
||||
}
|
||||
}
|
||||
@@ -91,7 +97,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
*
|
||||
* @param pointData
|
||||
*/
|
||||
private void moveMarker( MovingPoint pointData ) {
|
||||
private void moveMarker( MovingPoint pointData, int drId ) {
|
||||
if ( pointData == null ) {
|
||||
return;
|
||||
}
|
||||
@@ -215,34 +221,29 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
}
|
||||
newAdasRecognizedMarkersCaches.put( uniqueKey, marker );
|
||||
if ( lastPosition != null ) {
|
||||
MogoLatLng endLatLon = new MogoLatLng( recognizedListResult.lat, recognizedListResult.lon );
|
||||
long interval = computeAnimDuration( lastPosition.systemTime, recognizedListResult.systemTime, lastPosition.satelliteTime, recognizedListResult.satelliteTime );
|
||||
|
||||
long cost = System.currentTimeMillis() - start;
|
||||
interval -= cost;
|
||||
MogoLatLng lastPoint = new MogoLatLng( lastPosition.lat, lastPosition.lon );
|
||||
lastPoint.setTime( lastPosition.satelliteTime );
|
||||
endLatLon.setTime( recognizedListResult.satelliteTime );
|
||||
MovingPoint endPoint = new MovingPoint();
|
||||
endPoint.point = endLatLon;
|
||||
endPoint.marker = marker;
|
||||
endPoint.delay = interval;
|
||||
endPoint.angle = ( float ) recognizedListResult.heading;
|
||||
|
||||
MovingPoint startPoint = new MovingPoint();
|
||||
startPoint.point = lastPoint;
|
||||
startPoint.point = new MogoLatLng( lastPosition.lat, lastPosition.lon );
|
||||
startPoint.marker = marker;
|
||||
startPoint.delay = 0L;
|
||||
startPoint.angle = ( float ) lastPosition.heading;
|
||||
List< MovingPoint > points = interpolate( startPoint, endPoint, 30, interval );
|
||||
|
||||
long cost = System.currentTimeMillis() - start;
|
||||
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;
|
||||
|
||||
List< MovingPoint > points = interpolate( startPoint, endPoint, interval );
|
||||
Message msg = new Message();
|
||||
MovingPoints obj = new MovingPoints();
|
||||
obj.points = points;
|
||||
msg.obj = obj;
|
||||
msg.what = MSG_POINTS_SETTING;
|
||||
mPointSettingHandler.sendMessage( msg );
|
||||
// marker.startSmoothInMs( points, interval );
|
||||
// marker.addDynamicAnchorPosition( endLatLon, interval );
|
||||
Logger.d( TAG, "anim duration: %s, points size = %s", interval, points.size() );
|
||||
} else {
|
||||
marker.setRotateAngle( ( ( float ) recognizedListResult.heading ) );
|
||||
|
||||
@@ -38,6 +38,11 @@ class BaseDrawer {
|
||||
public static final int MSG_REMOVE_DIRTY_MARKERS = 9990;
|
||||
public static final int MSG_REMOVE_ADAS_MARKERS = 9992;
|
||||
|
||||
/**
|
||||
* 地图刷新频率
|
||||
*/
|
||||
public static final int MAP_RENDER_FRAME_FREQUENCY = 25;
|
||||
|
||||
/**
|
||||
* 地图内部资源md5缓存,便于资源复用
|
||||
*/
|
||||
@@ -234,20 +239,26 @@ class BaseDrawer {
|
||||
*
|
||||
* @param start
|
||||
* @param end
|
||||
* @param frameInterval
|
||||
* @return
|
||||
*/
|
||||
public static List< MovingPoint > interpolate( MovingPoint start, MovingPoint end, long frameInterval, long duration ) {
|
||||
public static List< MovingPoint > interpolate( MovingPoint start, MovingPoint end, long duration ) {
|
||||
if ( start == null || end == null ) {
|
||||
return null;
|
||||
}
|
||||
int interpolateFrame = ( int ) ( duration / frameInterval ) - 1;
|
||||
|
||||
int interpolateFrame = ( int ) ( duration / MAP_RENDER_FRAME_FREQUENCY );
|
||||
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 );
|
||||
// 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 );
|
||||
@@ -256,7 +267,7 @@ class BaseDrawer {
|
||||
double lat = start.point.lat + latStep * ( i + 1 );
|
||||
MovingPoint pd = new MovingPoint();
|
||||
pd.point = new MogoLatLng( lat, lon );
|
||||
pd.delay = ( i + 1 ) * frameInterval;
|
||||
pd.delay = ( i + i ) * MAP_RENDER_FRAME_FREQUENCY;
|
||||
pd.angle = ( float ) _angle;
|
||||
pd.marker = start.marker;
|
||||
arrayList.add( pd );
|
||||
|
||||
@@ -224,8 +224,6 @@ public class SimpleHandlerThreadPool {
|
||||
MogoLatLng endLatLon = new MogoLatLng( cloudRoadData.getWgslat(),cloudRoadData.getWgslon() );
|
||||
long interval = SnapshotSetDataDrawer.getInstance().computeAnimDuration( lastPosition.getSystemTime(), cloudRoadData.getSystemTime(), lastPosition.getSatelliteTime(), cloudRoadData.getSatelliteTime() );
|
||||
MogoLatLng lastPoint = new MogoLatLng( lastPosition.getWgslat(), lastPosition.getWgslon() );
|
||||
lastPoint.setTime( lastPosition.getSatelliteTime() );
|
||||
endLatLon.setTime( cloudRoadData.getSatelliteTime() );
|
||||
BaseDrawer.MovingPoint endPoint = new BaseDrawer.MovingPoint();
|
||||
endPoint.point = endLatLon;
|
||||
endPoint.marker = marker;
|
||||
@@ -235,7 +233,7 @@ public class SimpleHandlerThreadPool {
|
||||
startPoint.point = lastPoint;
|
||||
startPoint.marker = marker;
|
||||
startPoint.angle = ( float ) lastPosition.getHeading();
|
||||
List< BaseDrawer.MovingPoint > points = BaseDrawer.interpolate( startPoint, endPoint, 20, interval );
|
||||
List< BaseDrawer.MovingPoint > points = BaseDrawer.interpolate( startPoint, endPoint, interval );
|
||||
Message msg = new Message();
|
||||
BaseDrawer.MovingPoints obj = new BaseDrawer.MovingPoints();
|
||||
obj.points = points;
|
||||
|
||||
Reference in New Issue
Block a user