优化显示逻辑
This commit is contained in:
@@ -67,7 +67,7 @@ dependencies {
|
||||
implementation project(':foudations:mogo-commons')
|
||||
}
|
||||
|
||||
implementation 'com.zhidaoauto.machine:map:1.0.0-vr-8.1.8'
|
||||
implementation 'com.zhidaoauto.machine:map:1.0.0-vr-8.2.0'
|
||||
// implementation 'com.zhidaoauto.machine:map:1.0.0-vr-test-3.4'
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
@@ -13,7 +13,6 @@ import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.R;
|
||||
import com.mogo.module.common.constants.DataTypes;
|
||||
import com.mogo.module.common.kt.ScopeManager;
|
||||
import com.mogo.realtime.entity.ADASRecognizedResult;
|
||||
import com.mogo.utils.WorkThreadHandler;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
@@ -38,6 +37,8 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
private final Context mContext;
|
||||
|
||||
private Handler pointSettingHandler = null;
|
||||
public static final int MSG_POINTS_SETTING = 9;
|
||||
public static final int MSG_SET_POINT = 10;
|
||||
|
||||
private AdasRecognizedResultDrawer() {
|
||||
super();
|
||||
@@ -45,33 +46,51 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
initHandler();
|
||||
}
|
||||
|
||||
private class SettingData {
|
||||
public IMogoMarker marker;
|
||||
public List< PointData > points;
|
||||
}
|
||||
|
||||
private void initHandler() {
|
||||
pointSettingHandler = new Handler( WorkThreadHandler.newInstance( "point-setting-thread" ).getLooper() ) {
|
||||
@Override
|
||||
public void handleMessage( Message msg ) {
|
||||
super.handleMessage( msg );
|
||||
if ( msg.obj instanceof SettingData ) {
|
||||
List< PointData > points = ( ( SettingData ) msg.obj ).points;
|
||||
IMogoMarker marker = ( ( SettingData ) msg.obj ).marker;
|
||||
for ( int i = 0; i < points.size(); i++ ) {
|
||||
marker.setRotateAngle( points.get( i ).angle );
|
||||
marker.setPosition( points.get( i ).point.lat, points.get( i ).point.lon );
|
||||
try {
|
||||
Thread.sleep( 10 );
|
||||
} catch ( InterruptedException e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if ( msg.what == MSG_POINTS_SETTING ) {
|
||||
if ( msg.obj instanceof SettingData ) {
|
||||
startSettingPointLooper( ( ( SettingData ) msg.obj ) );
|
||||
}
|
||||
} else if ( msg.what == MSG_SET_POINT ) {
|
||||
if ( msg.obj instanceof PointData ) {
|
||||
moveMarker( ( ( PointData ) msg.obj ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启设置位置的循环
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
private void startSettingPointLooper( SettingData data ) {
|
||||
List< 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 );
|
||||
pointSettingHandler.sendMessageDelayed( msg, ( i + 1 ) * 10 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 marker 的点到新的位置
|
||||
*
|
||||
* @param pointData
|
||||
*/
|
||||
private void moveMarker( PointData pointData ) {
|
||||
if ( pointData == null ) {
|
||||
return;
|
||||
}
|
||||
pointData.move();
|
||||
}
|
||||
|
||||
private final Map< String, ADASRecognizedResult > mLastPositions = new ConcurrentHashMap<>();
|
||||
|
||||
public static AdasRecognizedResultDrawer getInstance() {
|
||||
@@ -117,17 +136,14 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
if ( recognizedListResult == null ) {
|
||||
continue;
|
||||
}
|
||||
ScopeManager.INSTANCE.adasScope( () -> {
|
||||
renderAdasOneFrame( recognizedListResult, newAdasRecognizedMarkersCaches );
|
||||
} );
|
||||
renderAdasOneFrame( recognizedListResult, newAdasRecognizedMarkersCaches );
|
||||
}
|
||||
|
||||
ScopeManager.INSTANCE.adasScope( () -> {
|
||||
sendMessage( MSG_REMOVE_DIRTY_MARKERS, mAdasRecognizedMarkersCaches );
|
||||
mAdasRecognizedMarkersCaches = newAdasRecognizedMarkersCaches;
|
||||
} );
|
||||
sendMessage( MSG_REMOVE_DIRTY_MARKERS, mAdasRecognizedMarkersCaches );
|
||||
mAdasRecognizedMarkersCaches = newAdasRecognizedMarkersCaches;
|
||||
}
|
||||
|
||||
private final Map< String, Boolean > isMatchStatusCache = new ArrayMap<>();
|
||||
|
||||
private void renderAdasOneFrame( ADASRecognizedResult recognizedListResult, Map< String, IMogoMarker > newAdasRecognizedMarkersCaches ) {
|
||||
// 暂时只显示车辆
|
||||
if ( !isCarType( recognizedListResult.type ) ) {
|
||||
@@ -139,17 +155,32 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
return;
|
||||
}
|
||||
|
||||
// final long start = System.currentTimeMillis();
|
||||
// double[] matchedPoint = matchRoad( recognizedListResult.lon,
|
||||
// recognizedListResult.lat,
|
||||
// recognizedListResult.heading,
|
||||
// recognizedListResult.dataAccuracy == 1
|
||||
// );
|
||||
// Log.i( "match-road-timer", "cost " + ( System.currentTimeMillis() - start ) + "ms" );
|
||||
// if ( matchedPoint != null ) {
|
||||
// recognizedListResult.lon = matchedPoint[0];
|
||||
// recognizedListResult.lat = matchedPoint[1];
|
||||
// }
|
||||
double[] matchedPoint = SnapshotSetDataDrawer.getInstance().matchRoad( recognizedListResult.lon,
|
||||
recognizedListResult.lat,
|
||||
recognizedListResult.heading,
|
||||
true
|
||||
);
|
||||
Boolean isMatch = isMatchStatusCache.get( uniqueKey );
|
||||
if ( matchedPoint != null ) {
|
||||
if ( ( isMatch == null || !isMatch ) ) {
|
||||
if ( matchedPoint[2] < 0.5 ) {
|
||||
isMatch = true;
|
||||
}
|
||||
} else {
|
||||
if ( matchedPoint[2] > 1 ) {
|
||||
isMatch = false;
|
||||
}
|
||||
}
|
||||
if ( isMatch == null ) {
|
||||
isMatch = false;
|
||||
}
|
||||
isMatchStatusCache.put( uniqueKey, isMatch );
|
||||
|
||||
if ( isMatch ) {
|
||||
recognizedListResult.lon = matchedPoint[0];
|
||||
recognizedListResult.lat = matchedPoint[1];
|
||||
}
|
||||
}
|
||||
|
||||
IMogoMarker marker = mAdasRecognizedMarkersCaches.remove( uniqueKey );
|
||||
ADASRecognizedResult lastPosition = mLastPositions.put( uniqueKey, recognizedListResult );
|
||||
@@ -169,17 +200,19 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
endLatLon.setTime( recognizedListResult.satelliteTime );
|
||||
PointData endPoint = new PointData();
|
||||
endPoint.point = endLatLon;
|
||||
endPoint.angle = (float)recognizedListResult.heading;
|
||||
endPoint.marker = marker;
|
||||
endPoint.angle = ( float ) recognizedListResult.heading;
|
||||
|
||||
PointData startPoint = new PointData();
|
||||
startPoint.point = lastPoint;
|
||||
startPoint.angle = (float)lastPosition.heading;
|
||||
startPoint.marker = marker;
|
||||
startPoint.angle = ( float ) lastPosition.heading;
|
||||
List< PointData > points = interpolate( startPoint, endPoint, 30, interval );
|
||||
Message msg = new Message();
|
||||
SettingData obj = new SettingData();
|
||||
obj.marker = marker;
|
||||
obj.points = points;
|
||||
msg.obj = obj;
|
||||
msg.what = MSG_POINTS_SETTING;
|
||||
pointSettingHandler.sendMessage( msg );
|
||||
// marker.startSmoothInMs( points, interval );
|
||||
// marker.addDynamicAnchorPosition( endLatLon, interval );
|
||||
|
||||
@@ -248,6 +248,7 @@ class BaseDrawer {
|
||||
PointData pd = new PointData();
|
||||
pd.point = new MogoLatLng( lat, lon );
|
||||
pd.angle = ( float ) _angle;
|
||||
pd.marker = start.marker;
|
||||
arrayList.add( pd );
|
||||
}
|
||||
}
|
||||
@@ -255,8 +256,24 @@ class BaseDrawer {
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
/**
|
||||
* marker 单个点移动的对象
|
||||
*/
|
||||
public static class PointData {
|
||||
public MogoLatLng point;
|
||||
public float angle;
|
||||
public IMogoMarker marker;
|
||||
|
||||
public void move() {
|
||||
marker.setRotateAngle( angle );
|
||||
marker.setPosition( point.lat, point.lon );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* marker 平滑移动的对象
|
||||
*/
|
||||
public static class SettingData {
|
||||
public List< PointData > points;
|
||||
}
|
||||
}
|
||||
|
||||
8316
modules/mogo-module-service/src/main/assets/adas-loc.txt
Normal file
8316
modules/mogo-module-service/src/main/assets/adas-loc.txt
Normal file
File diff suppressed because it is too large
Load Diff
1
modules/mogo-module-service/src/main/assets/loc2.txt
Normal file
1
modules/mogo-module-service/src/main/assets/loc2.txt
Normal file
File diff suppressed because one or more lines are too long
@@ -560,6 +560,7 @@ public class MockIntentHandler implements IntentHandler {
|
||||
// mLocationMockHandler.sendEmptyMessageDelayed( 2, 0 );
|
||||
// mLocationMockHandler.sendEmptyMessageDelayed( 21, 200 );
|
||||
mLocationMockHandler.sendEmptyMessageDelayed( 3, 0L );
|
||||
// mLocationMockHandler.sendEmptyMessageDelayed( 5, 0L );
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -613,18 +614,18 @@ public class MockIntentHandler implements IntentHandler {
|
||||
}
|
||||
br2 = null;
|
||||
}
|
||||
} else if( msg.what == 21 ) {
|
||||
} else if ( msg.what == 21 ) {
|
||||
try {
|
||||
handleMockSnapshotIntent2();
|
||||
} catch (Exception e) {
|
||||
} catch ( Exception e ) {
|
||||
try {
|
||||
br4.close();
|
||||
} catch (IOException ex) {
|
||||
} catch ( IOException ex ) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}else if ( msg.what == 3 ) {
|
||||
} else if ( msg.what == 3 ) {
|
||||
try {
|
||||
handleMockAdasIntent();
|
||||
} catch ( Exception e ) {
|
||||
@@ -635,6 +636,17 @@ public class MockIntentHandler implements IntentHandler {
|
||||
}
|
||||
br3 = null;
|
||||
}
|
||||
} else if ( msg.what == 5 ) {
|
||||
try {
|
||||
handleMockAdasLocIntent();
|
||||
} catch ( Exception e ) {
|
||||
try {
|
||||
br5.close();
|
||||
} catch ( IOException ex ) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
br5 = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -653,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, 100L );
|
||||
mLocationMockHandler.sendEmptyMessageDelayed( 1, 50L );
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -703,7 +715,7 @@ public class MockIntentHandler implements IntentHandler {
|
||||
return false;
|
||||
}
|
||||
// double[] coor = CoordinateUtils.transformWgsToGcj( cloudRoadData.getLat(), cloudRoadData.getLon() );
|
||||
cloudRoadData.setUuid("1_21");
|
||||
cloudRoadData.setUuid( "1_21" );
|
||||
// cloudRoadData.setLon( coor[0] );
|
||||
// cloudRoadData.setLat( coor[1] );
|
||||
allList.add( cloudRoadData );
|
||||
@@ -743,4 +755,22 @@ public class MockIntentHandler implements IntentHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
private BufferedReader br5;
|
||||
|
||||
private boolean handleMockAdasLocIntent() throws Exception {
|
||||
if ( br5 == null ) {
|
||||
br5 = new BufferedReader( new InputStreamReader( AbsMogoApplication.getApp().getAssets().open( "adas-loc.txt" ) ) );
|
||||
}
|
||||
String line = br5.readLine();
|
||||
if ( line == null ) {
|
||||
throw new Exception( "end of file 3." );
|
||||
}
|
||||
MogoApisHandler.getInstance()
|
||||
.getApis()
|
||||
.getAdasControllerApi()
|
||||
.mockAdasLoc( line );
|
||||
mLocationMockHandler.sendEmptyMessageDelayed( 5, 50L );
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -174,4 +174,6 @@ public interface IMogoADASController extends IProvider {
|
||||
* 结束自动驾驶
|
||||
*/
|
||||
void cancelAutopilot();
|
||||
|
||||
void mockAdasLoc(String json);
|
||||
}
|
||||
|
||||
@@ -711,4 +711,15 @@ public class MogoADASController implements IMogoADASController {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mockAdasLoc( String json ) {
|
||||
ADASCarStateInfo stateInf = GsonUtil.objectFromJson( json, ADASCarStateInfo.class );
|
||||
if ( stateInf == null ) {
|
||||
return;
|
||||
}
|
||||
if ( mMogoAdasCarDataCallback != null ) {
|
||||
mMogoAdasCarDataCallback.onAdasCarDataCallback( stateInf );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user