优化云端下发数据在地图上的渲染
This commit is contained in:
@@ -13,11 +13,13 @@ import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.drawer.AdasRecognizedResultDrawer;
|
||||
import com.mogo.module.common.drawer.BaseDrawer;
|
||||
import com.mogo.module.common.drawer.SnapshotSetDataDrawer;
|
||||
import com.mogo.realtime.entity.CloudRoadData;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.mogo.module.common.drawer.BaseDrawer.MSG_REMOVE_DIRTY_MARKERS;
|
||||
@@ -29,12 +31,56 @@ import static com.mogo.module.common.drawer.BaseDrawer.MSG_REMOVE_DIRTY_MARKERS;
|
||||
*/
|
||||
public class SimpleHandlerThreadPool {
|
||||
private static final String TAG = "SimpleHandlerThreadPool";
|
||||
private HandlerThread renderThread = new HandlerThread( "one-frame-render-thread" );
|
||||
private Handler renderHandler;
|
||||
private final HandlerThread renderThread = new HandlerThread( "one-frame-render-thread" );
|
||||
private final Handler renderHandler;
|
||||
|
||||
public static final int MSG_POINTS_SETTING = 9;
|
||||
public static final int MSG_SET_POINT = 10;
|
||||
|
||||
private SimpleHandlerThreadPool() {
|
||||
renderThread.start();
|
||||
renderHandler = new Handler( renderThread.getLooper() );
|
||||
renderHandler = new Handler( renderThread.getLooper() ){
|
||||
@Override
|
||||
public void handleMessage( Message msg ) {
|
||||
super.handleMessage( msg );
|
||||
if ( msg.what == MSG_POINTS_SETTING ) {
|
||||
if ( msg.obj instanceof BaseDrawer.SettingData) {
|
||||
startSettingPointLooper( ( (BaseDrawer.SettingData) msg.obj ) );
|
||||
}
|
||||
} else if ( msg.what == MSG_SET_POINT ) {
|
||||
if ( msg.obj instanceof BaseDrawer.PointData) {
|
||||
moveMarker( ( (BaseDrawer.PointData) msg.obj ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启设置位置的循环
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
private void startSettingPointLooper( BaseDrawer.SettingData data ) {
|
||||
List<BaseDrawer.PointData> points = data.points;
|
||||
for ( int i = 0; i < points.size(); i++ ) {
|
||||
Message msg = Message.obtain();
|
||||
msg.what = MSG_SET_POINT;
|
||||
msg.obj = points.get( i );
|
||||
renderHandler.sendMessageDelayed( msg, ( i + 1 ) * 10 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 marker 的点到新的位置
|
||||
*
|
||||
* @param pointData
|
||||
*/
|
||||
private void moveMarker( BaseDrawer.PointData pointData ) {
|
||||
if ( pointData == null ) {
|
||||
return;
|
||||
}
|
||||
pointData.move();
|
||||
}
|
||||
|
||||
private static final SimpleHandlerThreadPool INSTANCE = new SimpleHandlerThreadPool();
|
||||
@@ -172,22 +218,58 @@ public class SimpleHandlerThreadPool {
|
||||
|
||||
SnapshotSetDataDrawer.getInstance().changeIconResourceIfNecessary( cloudRoadData, marker );
|
||||
|
||||
final IMogoMarker finalMarker = marker;
|
||||
// final IMogoMarker finalMarker = marker;
|
||||
Logger.d( TAG, "work in " + Thread.currentThread().getName() );
|
||||
renderHandler.post( () -> {
|
||||
// 由于地图现在不支持addDynamicAnchorPosition并发,所以工作线程仅做相关计算,真正绘制发送到另外一条绘制线程中做
|
||||
if ( lastPosition != null && !lastPosition.equals( cloudRoadData ) ) {
|
||||
long interval = SystemClock.uptimeMillis() - lastExecutionTimeCache.get( uniqueKey );
|
||||
finalMarker.addDynamicAnchorPosition( new MogoLatLng( cloudRoadData.getWgslat(), cloudRoadData.getWgslon() ), interval );
|
||||
Logger.d( TAG, "anim duration: %s in thread: %s", interval, Thread.currentThread().getName() );
|
||||
} else {
|
||||
finalMarker.setRotateAngle( ( float ) cloudRoadData.getHeading() );
|
||||
finalMarker.setPosition( cloudRoadData.getWgslat(), cloudRoadData.getWgslon() );
|
||||
Logger.d( TAG, "设置点位置 in thread: %s", Thread.currentThread().getName() );
|
||||
}
|
||||
lastExecutionTimeCache.put( uniqueKey, SystemClock.uptimeMillis() );
|
||||
SnapshotSetDataDrawer.getInstance().showSelfSpeed( AbsMogoApplication.getApp(), finalMarker, cloudRoadData.getSpeed(), MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() );
|
||||
} );
|
||||
|
||||
if ( lastPosition != null ) {
|
||||
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.PointData endPoint = new BaseDrawer.PointData();
|
||||
endPoint.point = endLatLon;
|
||||
endPoint.marker = marker;
|
||||
endPoint.angle = ( float ) cloudRoadData.getHeading();
|
||||
|
||||
BaseDrawer.PointData startPoint = new BaseDrawer.PointData();
|
||||
startPoint.point = lastPoint;
|
||||
startPoint.marker = marker;
|
||||
startPoint.angle = ( float ) lastPosition.getHeading();
|
||||
List<BaseDrawer.PointData> points = BaseDrawer.interpolate( startPoint, endPoint, 30, interval );
|
||||
Message msg = new Message();
|
||||
BaseDrawer.SettingData obj = new BaseDrawer.SettingData();
|
||||
obj.points = points;
|
||||
msg.obj = obj;
|
||||
msg.what = MSG_POINTS_SETTING;
|
||||
renderHandler.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 ) cloudRoadData.getHeading() ) );
|
||||
marker.setPosition(cloudRoadData.getWgslat(), cloudRoadData.getWgslon());
|
||||
}
|
||||
SnapshotSetDataDrawer.getInstance().showSelfSpeed( AbsMogoApplication.getApp(),
|
||||
marker,
|
||||
cloudRoadData.getSpeed(),
|
||||
MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()
|
||||
);
|
||||
|
||||
// renderHandler.post( () -> {
|
||||
// // 由于地图现在不支持addDynamicAnchorPosition并发,所以工作线程仅做相关计算,真正绘制发送到另外一条绘制线程中做
|
||||
// if ( lastPosition != null && !lastPosition.equals( cloudRoadData ) ) {
|
||||
// long interval = SystemClock.uptimeMillis() - lastExecutionTimeCache.get( uniqueKey );
|
||||
// finalMarker.addDynamicAnchorPosition( new MogoLatLng( cloudRoadData.getWgslat(), cloudRoadData.getWgslon() ), interval );
|
||||
// Logger.d( TAG, "anim duration: %s in thread: %s", interval, Thread.currentThread().getName() );
|
||||
// } else {
|
||||
// finalMarker.setRotateAngle( ( float ) cloudRoadData.getHeading() );
|
||||
// finalMarker.setPosition( cloudRoadData.getWgslat(), cloudRoadData.getWgslon() );
|
||||
// Logger.d( TAG, "设置点位置 in thread: %s", Thread.currentThread().getName() );
|
||||
// }
|
||||
// lastExecutionTimeCache.put( uniqueKey, SystemClock.uptimeMillis() );
|
||||
// SnapshotSetDataDrawer.getInstance().showSelfSpeed( AbsMogoApplication.getApp(), finalMarker, cloudRoadData.getSpeed(), MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() );
|
||||
// } );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -665,7 +665,7 @@ public class MockIntentHandler implements IntentHandler {
|
||||
JSONObject jo = new JSONObject( line );
|
||||
MarkerServiceHandler.getApis().getMapServiceApi().getMapUIController().syncLocation2Map( jo );
|
||||
Log.i( "mock-timer-loc", "cost " + ( System.currentTimeMillis() - start ) + "ms" );
|
||||
mLocationMockHandler.sendEmptyMessageDelayed( 1, 50L );
|
||||
mLocationMockHandler.sendEmptyMessageDelayed( 1, 100L );
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -688,6 +688,8 @@ public class MockIntentHandler implements IntentHandler {
|
||||
// double[] coor = CoordinateUtils.transformWgsToGcj( cloudRoadData.getLat(), cloudRoadData.getLon() );
|
||||
// cloudRoadData.setLon( coor[0] );
|
||||
// cloudRoadData.setLat( coor[1] );
|
||||
cloudRoadData.setWgslat(cloudRoadData.getLat());
|
||||
cloudRoadData.setWgslon(cloudRoadData.getLon());
|
||||
allList.add( cloudRoadData );
|
||||
data.setAllList( allList );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user