This commit is contained in:
zhongchao
2021-03-10 12:23:44 +08:00
12 changed files with 4395 additions and 79 deletions

View File

@@ -67,7 +67,7 @@ dependencies {
implementation project(':foudations:mogo-commons')
}
implementation 'com.zhidaoauto.machine:map:1.0.0-vr-8.2.4'
implementation 'com.zhidaoauto.machine:map:1.0.0-vr-8.2.6'
// implementation 'com.zhidaoauto.machine:map:1.0.0-vr-test-3.4'
}

View File

@@ -468,7 +468,7 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
return;
}
List< LonLatPoint > newPoints = new ArrayList<>();
ArrayList< LonLatPoint > newPoints = new ArrayList<>();
for ( int i = 0; i < points.size(); i++ ) {
LonLatPoint point = ObjectUtils.fromMogo( points.get( i ) );
if ( point == null ) {
@@ -480,6 +480,35 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
return;
}
// MarkerTranslateAnimation animation = new MarkerTranslateAnimation( newPoints );
// animation.setDuration( duration );
// animation.setAnimationListener( new MarkerAnimationListener() {
// @Override
// public void onAnimationStart( @NotNull Animation animation ) {
//
// }
//
// @Override
// public void onAnimationEnd( @NotNull Animation animation ) {
//
// }
//
// long lastTime = 0L;
//
// @Override
// public void onAnimationRepeat( @NotNull Animation animation ) {
// if ( lastTime == 0L ) {
// lastTime = System.currentTimeMillis();
// return;
// }
// Logger.d( TAG, "frame cost = %s", System.currentTimeMillis() - lastTime );
// lastTime = System.currentTimeMillis();
// }
// } );
// mMarker.setTranslateAnimation( animation );
// mMarker.startAnimation();
mMarker.startSmooth( newPoints, ( int ) duration );
// mMarker.addDynamicAnchorPostion( newPoints.get( newPoints.size() - 1 ), ( int ) duration );
}

View File

@@ -17,35 +17,6 @@ public class PointInterpolatorUtil {
private static final String TAG = "PointInterpolatorUtil";
private static final int DISTANCE_THRESHOLD = 2;
/**
* 在两点之间插值
*
* @param start
* @param end
* @param frameInterval
* @return
*/
public static List< MogoLatLng > interpolate( MogoLatLng start, MogoLatLng end, long frameInterval ) {
if ( start == null || end == null ) {
return null;
}
long locInterval = end.time - start.time;
int interpolateFrame = ( int ) ( locInterval / frameInterval ) - 1;
List< MogoLatLng > arrayList = new ArrayList<>();
arrayList.add( start );
if ( interpolateFrame > 0 ) {
double lonStep = ( end.lon - start.lon ) / ( interpolateFrame + 1 );
double latStep = ( end.lat - start.lat ) / ( interpolateFrame + 1 );
for ( int i = 0; i < interpolateFrame; i++ ) {
double lon = start.lon + lonStep * ( i + 1 );
double lat = start.lat + latStep * ( i + 1 );
arrayList.add( new MogoLatLng( lon, lat ) );
}
}
arrayList.add( end );
return arrayList;
}
/**
* 在(x1,y1) (x2,y2)中间插入一些点,使每两个点之间距离<={@link #DISTANCE_THRESHOLD},利用如下公式进行计算
* xn = x1 + (x2 - x1)*n/a

View File

@@ -17,7 +17,6 @@ public class MogoLatLng implements Parcelable {
@Deprecated
public final double lng;
public final double lon;
public long time;
public MogoLatLng( double lat, double lon ) {
this.lat = lat;
@@ -43,14 +42,6 @@ public class MogoLatLng implements Parcelable {
return lon;
}
public long getTime() {
return time;
}
public void setTime( long time ) {
this.time = time;
}
@Override
public boolean equals( Object o ) {
if ( this == o ) return true;
@@ -83,14 +74,12 @@ public class MogoLatLng implements Parcelable {
dest.writeDouble( this.lat );
dest.writeDouble( this.lng );
dest.writeDouble( this.lon );
dest.writeLong( this.time );
}
protected MogoLatLng( Parcel in ) {
this.lat = in.readDouble();
this.lng = in.readDouble();
this.lon = in.readDouble();
this.time = in.readLong();
}
public static final Creator< MogoLatLng > CREATOR = new Creator< MogoLatLng >() {

View File

@@ -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 ) );

View File

@@ -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 );

View File

@@ -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() ) {
@@ -217,25 +237,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;
@@ -260,6 +283,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 {

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -28,11 +28,14 @@ import com.mogo.map.search.geo.MogoGeocodeResult;
import com.mogo.map.search.geo.MogoRegeocodeResult;
import com.mogo.map.search.geo.query.MogoRegeocodeQuery;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.constants.DataTypes;
import com.mogo.module.common.dialog.WMDialog;
import com.mogo.module.common.drawer.AdasRecognizedResultDrawer;
import com.mogo.module.common.drawer.SnapshotSetDataDrawer;
import com.mogo.module.service.MarkerServiceHandler;
import com.mogo.module.service.R;
import com.mogo.module.service.uploadintime.SnapshotLocationController;
import com.mogo.realtime.core.SnapshotUploadInTime;
import com.mogo.realtime.entity.ADASRecognizedResult;
import com.mogo.realtime.entity.CloudRoadData;
import com.mogo.realtime.entity.MogoSnapshotSetData;
@@ -556,12 +559,29 @@ public class MockIntentHandler implements IntentHandler {
SnapshotSetDataDrawer.getInstance().renderSnapshotData( GsonUtil.objectFromJson( json, MogoSnapshotSetData.class ) );
break;
case 47:
mLocationMockHandler.sendEmptyMessageDelayed( 1, 200L );
// mLocationMockHandler.sendEmptyMessageDelayed( 2, 0 );
mLocationMockHandler.sendEmptyMessageDelayed( 1, 8200L );
mLocationMockHandler.sendEmptyMessageDelayed( 2, 0 );
// mLocationMockHandler.sendEmptyMessageDelayed( 21, 200 );
mLocationMockHandler.sendEmptyMessageDelayed( 3, 0L );
// mLocationMockHandler.sendEmptyMessageDelayed( 3, 0L );
// mLocationMockHandler.sendEmptyMessageDelayed( 5, 0L );
break;
case 48:
MogoMarkerOptions options = new MogoMarkerOptions()
.owner( DataTypes.TYPE_MARKER_ADAS )
.anchor( 0.5f, 0.5f )
.set3DMode( true )
.position( new MogoLatLng( 39.981971055705,116.41150648393 ) )
.gps( true )
.controlAngle( true )
.icon3DRes( R.raw.cargrey )
.rotate( ( float ) 358.526123 );
IMogoMarker marker = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( context ).addMarker( DataTypes.TYPE_MARKER_ADAS, options );
List<MogoLatLng> latLngs = new ArrayList<>( );
latLngs.add( new MogoLatLng( 39.981971055705,116.41150648393 ) );
latLngs.add( new MogoLatLng( 39.981990561932,116.412893641626 ) );
marker.startSmoothInMs(latLngs, 20_000L );
break;
}
}
@@ -647,6 +667,17 @@ public class MockIntentHandler implements IntentHandler {
}
br5 = null;
}
} else if ( msg.what == 48 ) {
try {
handleMockLocationIntent48();
} catch ( Exception e ) {
try {
br48.close();
} catch ( IOException ex ) {
ex.printStackTrace();
}
br48 = null;
}
}
}
};
@@ -664,16 +695,38 @@ public class MockIntentHandler implements IntentHandler {
}
JSONObject jo = new JSONObject( line );
MarkerServiceHandler.getApis().getMapServiceApi().getMapUIController().syncLocation2Map( jo );
SnapshotLocationController.getInstance().syncAdasLocationInfo( jo );
Log.i( "mock-timer-loc", "cost " + ( System.currentTimeMillis() - start ) + "ms" );
mLocationMockHandler.sendEmptyMessageDelayed( 1, 100L );
return true;
}
private BufferedReader br48;
int count = 0;
private boolean handleMockLocationIntent48() throws Exception {
if ( br48 == null ) {
br48 = new BufferedReader( new InputStreamReader( AbsMogoApplication.getApp().getAssets().open( "loc3.txt" ) ) );
}
final long start = System.currentTimeMillis();
String line = br48.readLine();
if ( line == null ) {
throw new Exception( "end of file." );
}
JSONObject jo = new JSONObject( line );
MarkerServiceHandler.getApis().getMapServiceApi().getMapUIController().syncLocation2Map( jo );
Logger.i( "mock-timer-loc", "cost " + ( System.currentTimeMillis() - start ) + "ms: count=%s", ++count );
mLocationMockHandler.sendEmptyMessageDelayed( 48, 100L );
return true;
}
private BufferedReader br2;
private long last = 0;
private boolean handleMockSnapshotIntent() throws Exception {
if ( br2 == null ) {
br2 = new BufferedReader( new InputStreamReader( AbsMogoApplication.getApp().getAssets().open( "snapshot.txt" ) ) );
br2 = new BufferedReader( new InputStreamReader( AbsMogoApplication.getApp().getAssets().open( "snapshot2.txt" ) ) );
}
String line = br2.readLine();
if ( line == null ) {
@@ -688,15 +741,20 @@ 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());
cloudRoadData.setWgslat( cloudRoadData.getLat() );
cloudRoadData.setWgslon( cloudRoadData.getLon() );
allList.add( cloudRoadData );
data.setAllList( allList );
final long start = System.currentTimeMillis();
SnapshotSetDataDrawer.getInstance().renderSnapshotData( data );
Log.i( "mock-timer-snapshot", "cost " + ( System.currentTimeMillis() - start ) + "ms" );
mLocationMockHandler.sendEmptyMessageDelayed( 2, 100L );
long delay = 100;
if (last != 0){
delay = cloudRoadData.getSystemTime() - last;
}
last = cloudRoadData.getSystemTime();
mLocationMockHandler.sendEmptyMessageDelayed( 2, delay );
return true;
}