merge
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
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 android.util.Log;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
@@ -17,6 +19,7 @@ import com.mogo.realtime.entity.ADASRecognizedResult;
|
||||
import com.mogo.utils.WorkThreadHandler;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -58,11 +61,11 @@ 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 ){
|
||||
} else if ( msg.what == MSG_SET_SPEED ) {
|
||||
if ( msg.obj instanceof SpeedData ) {
|
||||
showSpeed( ( SpeedData ) msg.obj );
|
||||
showSpeed( ( SpeedData ) msg.obj );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,7 +83,12 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
Message msg = Message.obtain();
|
||||
msg.what = MSG_SET_POINT;
|
||||
msg.obj = points.get( i );
|
||||
mPointSettingHandler.sendMessageDelayed( msg, ( i + 1 ) * 10 );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,14 +97,14 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
*
|
||||
* @param pointData
|
||||
*/
|
||||
private void moveMarker( MovingPoint pointData ) {
|
||||
private void moveMarker( MovingPoint pointData, int drId ) {
|
||||
if ( pointData == null ) {
|
||||
return;
|
||||
}
|
||||
pointData.move();
|
||||
}
|
||||
|
||||
private void showSpeed(SpeedData data){
|
||||
private void showSpeed( SpeedData data ) {
|
||||
if ( data == null ) {
|
||||
return;
|
||||
}
|
||||
@@ -126,7 +134,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
}
|
||||
|
||||
// adas marker 缓存
|
||||
private Map< String, IMogoMarker > mAdasRecognizedMarkersCaches = new ConcurrentHashMap<>();
|
||||
private Map< String, IMogoMarker > mAdasRecognizedMarkersCaches = new HashMap<>();
|
||||
|
||||
public boolean hasCached( String uniqueKey ) {
|
||||
return mAdasRecognizedMarkersCaches.containsKey( uniqueKey );
|
||||
@@ -143,7 +151,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
return;
|
||||
}
|
||||
|
||||
Map< String, IMogoMarker > newAdasRecognizedMarkersCaches = new ConcurrentHashMap<>();
|
||||
Map< String, IMogoMarker > newAdasRecognizedMarkersCaches = new HashMap<>();
|
||||
for ( ADASRecognizedResult recognizedListResult : resultList ) {
|
||||
if ( recognizedListResult == null ) {
|
||||
continue;
|
||||
@@ -158,6 +166,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
|
||||
/**
|
||||
* 绘制某个物体的一个数据
|
||||
*
|
||||
* @param recognizedListResult
|
||||
* @param newAdasRecognizedMarkersCaches
|
||||
*/
|
||||
@@ -171,7 +180,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
if ( TextUtils.isEmpty( uniqueKey ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
final long start = System.currentTimeMillis();
|
||||
double[] matchedPoint = SnapshotSetDataDrawer.getInstance().matchRoad( recognizedListResult.uuid, recognizedListResult.lon,
|
||||
recognizedListResult.lat,
|
||||
recognizedListResult.heading,
|
||||
@@ -210,29 +219,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 );
|
||||
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.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,6 +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 + i ) * MAP_RENDER_FRAME_FREQUENCY;
|
||||
pd.angle = ( float ) _angle;
|
||||
pd.marker = start.marker;
|
||||
arrayList.add( pd );
|
||||
@@ -273,6 +285,7 @@ class BaseDrawer {
|
||||
public MogoLatLng point;
|
||||
public float angle;
|
||||
public IMogoMarker marker;
|
||||
public long delay;
|
||||
|
||||
public void move() {
|
||||
try {
|
||||
|
||||
@@ -60,14 +60,18 @@ class MarkerDrawer {
|
||||
}
|
||||
|
||||
public IMogoMarker drawMapMarkerImpl( MarkerShowEntity markerShowEntity, int zIndex, IMogoMarkerClickListener listener ) {
|
||||
return drawMapMarkerImpl(markerShowEntity, zIndex, 0, listener);
|
||||
return drawMapMarkerImpl( markerShowEntity, false, zIndex, 0, listener );
|
||||
}
|
||||
|
||||
public IMogoMarker drawMapMarkerImpl( MarkerShowEntity markerShowEntity, int zIndex, int icon3DRes, IMogoMarkerClickListener listener ) {
|
||||
public IMogoMarker drawMapMarkerImpl( MarkerShowEntity markerShowEntity, boolean matchRoadSide, int zIndex, IMogoMarkerClickListener listener ) {
|
||||
return drawMapMarkerImpl( markerShowEntity, matchRoadSide, zIndex, 0, listener );
|
||||
}
|
||||
|
||||
public IMogoMarker drawMapMarkerImpl( MarkerShowEntity markerShowEntity, boolean matchRoadSide, int zIndex, int icon3DRes, IMogoMarkerClickListener listener ) {
|
||||
if ( markerShowEntity == null || markerShowEntity.getMarkerLocation() == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoMarkerOptions options = new MogoMarkerOptions().icon3DRes( icon3DRes ).owner( markerShowEntity.getMarkerType() ).zIndex( zIndex ).object( markerShowEntity ).latitude( markerShowEntity.getMarkerLocation().getLat() ).longitude( markerShowEntity.getMarkerLocation().getLon() );
|
||||
MogoMarkerOptions options = new MogoMarkerOptions().icon3DRes( icon3DRes ).matchOnRoadSide( matchRoadSide ).owner( markerShowEntity.getMarkerType() ).zIndex( zIndex ).object( markerShowEntity ).latitude( markerShowEntity.getMarkerLocation().getLat() ).longitude( markerShowEntity.getMarkerLocation().getLon() );
|
||||
IMarkerView markerView = MapMarkerAdapter.getMarkerView( AbsMogoApplication.getApp(), markerShowEntity, options );
|
||||
if ( markerView instanceof OnlineCarMarkerView ) {
|
||||
try {
|
||||
|
||||
@@ -105,7 +105,7 @@ class OnlineCarDrawer {
|
||||
String sn = MarkerDrawer.getInstance().getPrimaryKeyFromEntity( markerOnlineCar );
|
||||
IMogoMarker mogoMarker = existCarMap.get( sn );
|
||||
if ( mogoMarker == null || mogoMarker.isDestroyed() ) {
|
||||
mogoMarker = MarkerDrawer.getInstance().drawMapMarkerImpl( markerShowEntity, MarkerDrawer.MARKER_Z_INDEX_LOW, R.raw.taxi, listener );
|
||||
mogoMarker = MarkerDrawer.getInstance().drawMapMarkerImpl( markerShowEntity, false, MarkerDrawer.MARKER_Z_INDEX_LOW, R.raw.taxi, listener );
|
||||
}
|
||||
if ( mogoMarker != null ) {
|
||||
mogoMarker.setVisible( true );
|
||||
|
||||
@@ -86,14 +86,14 @@ class RoadConditionDrawer {
|
||||
Logger.d( TAG, "draw road condition, sn = %s", sn );
|
||||
try {
|
||||
if ( MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() ) {
|
||||
mogoMarker = MarkerDrawer.getInstance().drawMapMarkerImpl( markerShowEntity, MarkerDrawer.MARKER_Z_INDEX_HIGH, listener );
|
||||
mogoMarker = MarkerDrawer.getInstance().drawMapMarkerImpl( markerShowEntity, true, MarkerDrawer.MARKER_Z_INDEX_HIGH, listener );
|
||||
mogoMarker.setInfoWindowAdapter( new RoadConditionInfoWindow3DAdapter( markerShowEntity, AbsMogoApplication.getApp(), mogoMarker.getMogoMarkerOptions() ) );
|
||||
mogoMarker.showInfoWindow();
|
||||
} else {
|
||||
if ( DebugConfig.isRoadEventAnimated() ) {
|
||||
post2AddAndStartAnimation( markerShowEntity, i * 100L, listener );
|
||||
} else {
|
||||
mogoMarker = MarkerDrawer.getInstance().drawMapMarkerImpl( markerShowEntity, MarkerDrawer.MARKER_Z_INDEX_HIGH, listener );
|
||||
mogoMarker = MarkerDrawer.getInstance().drawMapMarkerImpl( markerShowEntity, false, MarkerDrawer.MARKER_Z_INDEX_HIGH, listener );
|
||||
}
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.SystemClock;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
@@ -66,7 +67,23 @@ public class SimpleHandlerThreadPool {
|
||||
Message msg = Message.obtain();
|
||||
msg.what = MSG_SET_POINT;
|
||||
msg.obj = points.get( i );
|
||||
renderHandler.sendMessageDelayed( msg, ( i + 1 ) * 10 );
|
||||
renderHandler.sendMessageDelayed( msg, points.get(i).delay );
|
||||
}
|
||||
}
|
||||
|
||||
private long startMove = 0;
|
||||
private int lastIndex = 0;
|
||||
|
||||
private void slowTest(){
|
||||
if (startMove == 0) {
|
||||
startMove = SystemClock.uptimeMillis();
|
||||
} else {
|
||||
long diff = SystemClock.uptimeMillis() - startMove;
|
||||
int index = (int) (diff / 30);
|
||||
if (index - lastIndex > 1) {
|
||||
Logger.e("MapRenderSlow", "miss " + (index - lastIndex) + " diff: " + diff);
|
||||
}
|
||||
lastIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,10 +92,11 @@ public class SimpleHandlerThreadPool {
|
||||
*
|
||||
* @param pointData
|
||||
*/
|
||||
private void moveMarker( BaseDrawer.MovingPoint pointData ) {
|
||||
if ( pointData == null ) {
|
||||
private void moveMarker(BaseDrawer.MovingPoint pointData) {
|
||||
if (pointData == null) {
|
||||
return;
|
||||
}
|
||||
// slowTest();
|
||||
pointData.move();
|
||||
}
|
||||
|
||||
@@ -175,6 +193,8 @@ public class SimpleHandlerThreadPool {
|
||||
return;
|
||||
}
|
||||
|
||||
final long start = System.currentTimeMillis();
|
||||
|
||||
IMogoMarker marker = markerCache.get( uniqueKey );
|
||||
CloudRoadData lastPosition = roadDataCache.put( uniqueKey, cloudRoadData );
|
||||
if ( marker == null || marker.isDestroyed() ) {
|
||||
@@ -218,25 +238,28 @@ public class SimpleHandlerThreadPool {
|
||||
|
||||
SnapshotSetDataDrawer.getInstance().changeIconResourceIfNecessary( cloudRoadData, marker );
|
||||
|
||||
// final IMogoMarker finalMarker = marker;
|
||||
final IMogoMarker finalMarker = marker;
|
||||
Logger.d( TAG, "work in " + Thread.currentThread().getName() );
|
||||
|
||||
if ( lastPosition != null ) {
|
||||
MogoLatLng endLatLon = new MogoLatLng( cloudRoadData.getWgslat(),cloudRoadData.getWgslon() );
|
||||
long interval = SnapshotSetDataDrawer.getInstance().computeAnimDuration( lastPosition.getSystemTime(), cloudRoadData.getSystemTime(), lastPosition.getSatelliteTime(), cloudRoadData.getSatelliteTime() );
|
||||
|
||||
long cost = System.currentTimeMillis() - start;
|
||||
interval -= cost;
|
||||
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;
|
||||
endPoint.delay = interval;
|
||||
endPoint.angle = ( float ) cloudRoadData.getHeading();
|
||||
|
||||
BaseDrawer.MovingPoint startPoint = new BaseDrawer.MovingPoint();
|
||||
startPoint.point = lastPoint;
|
||||
startPoint.marker = marker;
|
||||
startPoint.delay = 0;
|
||||
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;
|
||||
@@ -261,6 +284,7 @@ public class SimpleHandlerThreadPool {
|
||||
// // 由于地图现在不支持addDynamicAnchorPosition并发,所以工作线程仅做相关计算,真正绘制发送到另外一条绘制线程中做
|
||||
// if ( lastPosition != null && !lastPosition.equals( cloudRoadData ) ) {
|
||||
// long interval = SystemClock.uptimeMillis() - lastExecutionTimeCache.get( uniqueKey );
|
||||
// interval = cloudRoadData.getSystemTime() - lastPosition.getSystemTime();
|
||||
// finalMarker.addDynamicAnchorPosition( new MogoLatLng( cloudRoadData.getWgslat(), cloudRoadData.getWgslon() ), interval );
|
||||
// Logger.d( TAG, "anim duration: %s in thread: %s", interval, Thread.currentThread().getName() );
|
||||
// } else {
|
||||
|
||||
Reference in New Issue
Block a user