修改在线车辆刷新

This commit is contained in:
wangcongtao
2020-12-22 19:22:38 +08:00
parent f2ef82eba9
commit e7d4c19d8f
7 changed files with 35102 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -15,6 +15,7 @@ import com.mogo.commons.debug.DebugConfig;
import com.mogo.map.IMogoMap;
import com.mogo.map.IMogoMapView;
import com.mogo.map.MogoLatLng;
import com.mogo.map.impl.custom.location.GpsTester;
import com.mogo.map.impl.custom.navi.NaviClient;
import com.mogo.map.impl.custom.utils.MogoMapUtils;
import com.mogo.map.impl.custom.utils.ObjectUtils;
@@ -76,7 +77,7 @@ public class AMapViewWrapper implements IMogoMapView,
private float mDefaultZoomLevel = 16.0f;
private final CarCursorOption DEFAULT_OPTION = new CarCursorOption.Builder()
.carCursorRes( R.drawable.map_custom_ic_current_location2 )
.carCursorRes( R.drawable.map_api_ic_current_location2 )
.naviCursorRes( R.drawable.ic_amap_navi_cursor )
.build();
private CarCursorOption mCarCursorOption = DEFAULT_OPTION;
@@ -88,6 +89,9 @@ public class AMapViewWrapper implements IMogoMapView,
startTime = System.currentTimeMillis();
Logger.i( TAG, "autoop--AMapViewWrapper: init" );
this.mMapView = mMapView;
if ( DebugConfig.isDebug() ) {
GpsTester.getInstance().init( mMapView );
}
initListeners();
this.mIMap = new AMapWrapper( this.mMapView.getMapAutoViewHelper(), this.mMapView, this );
}
@@ -787,4 +791,9 @@ public class AMapViewWrapper implements IMogoMapView,
} );
}
}
@Override
public void testGpsData() {
GpsTester.getInstance().testGpsData();
}
}

View File

@@ -95,6 +95,7 @@ class CustomMapApiBuilder implements IMogoMapApiBuilder {
.setDebugMode( true )
.setCoordinateType( MapParams.COORDINATETYPE_GCJ02 )
.setPerspectiveMode( MapParams.MAP_PERSPECTIVE_2D )
.setCachePath( "sdcard/tiles" )
.setZoom( 16 )
.setPointToCenter( 0.734375f, 0.5f )
.setStyleMode( MapParams.MAP_STYLE_NIGHT ), NavParams.Companion.init() );

View File

@@ -0,0 +1,171 @@
package com.mogo.map.impl.custom.location;
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.view.TextureView;
import com.zhidaoauto.map.sdk.open.location.MogoLocation;
import com.zhidaoauto.map.sdk.open.view.MapAutoView;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public
/**
* @author congtaowang
* @since 2020/12/22
*
* 描述
*/
class GpsTester {
private static volatile GpsTester sInstance;
private MapAutoView mMapAutoView;
private GpsTester() {
}
public static GpsTester getInstance() {
if ( sInstance == null ) {
synchronized ( GpsTester.class ) {
if ( sInstance == null ) {
sInstance = new GpsTester();
}
}
}
return sInstance;
}
public synchronized void release() {
sInstance = null;
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return sInstance;
}
public void init( MapAutoView view ) {
mMapAutoView = view;
}
private class GpsTestThreadHandler extends Handler {
public GpsTestThreadHandler( Looper looper ) {
super( looper );
}
@Override
public void handleMessage( Message msg ) {
super.handleMessage( msg );
switch ( msg.what ) {
case 1:
try {
prepareGpsData();
sendEmptyMessageDelayed( 2, 0 );
} catch ( Exception e ) {
e.printStackTrace();
}
break;
case 2:
try {
readOneLineGpsDataAndSet2Map();
sendEmptyMessageDelayed( 2, 0 );
} catch ( Exception e ) {
e.printStackTrace();
}
break;
}
}
}
private Handler mHandler = null;
private BufferedReader br = null;
private long mLastTime = 0;
private float mLastHeading = 0;
private int step = 0;
private MogoLocation mogoLocation = new MogoLocation();
public void testGpsData() {
if ( mHandler != null ) {
return;
}
final HandlerThread ht = new HandlerThread( "gps-test-thread" );
ht.start();
mHandler = new GpsTestThreadHandler( ht.getLooper() );
mMapAutoView.getLocationClient().setIsUseExtraGPSData( true );
mHandler.sendEmptyMessage( 1 );
}
private void prepareGpsData() throws Exception {
InputStreamReader isr = new InputStreamReader( mMapAutoView.getContext().getAssets().open( "20201105_1.csv" ) );
br = new BufferedReader( isr );
}
private long readOneLineGpsDataAndSet2Map() throws Exception {
String line = br.readLine();
if ( TextUtils.isEmpty( line ) ) {
return 0;
}
int count = 0;
long duration = 3;
String datums[] = line.split( "," );
long time = Long.valueOf( datums[0] );
mogoLocation.setProvider( "GPS_SELF" );
mogoLocation.setLon( Double.valueOf( datums[1] ) );
mogoLocation.setLat( Double.valueOf( datums[2] ) );
float angle = Float.valueOf( datums[4] );
if ( mLastTime > 0 ) {
duration = time - mLastTime;
} else {
duration = 3;
}
mogoLocation.setDuration( mogoLocation.getDuration() + duration - 2 );
mLastTime = time;
float heading = angle;
if ( heading == -100f ) {
if ( mLastHeading != 400f ) {
heading = mLastHeading;
} else {
heading = 0f;
}
}
if ( mLastHeading == 400f || Math.abs( mLastHeading - heading ) > 0.5f ) {
mLastHeading = heading;
} else {
heading = mLastHeading;
}
if ( heading < 40 ) {
mogoLocation.setHeading( heading + 4f );
} else {
mogoLocation.setHeading( heading );
}
step++;
if ( step >= 50 ) {
step = 0;
count++;
long realDuration = mogoLocation.getDuration() + 75;
realDuration = realDuration / 4;
mogoLocation.setDuration( realDuration );
mMapAutoView.getLocationClient().setExtraSelfGPSData( mogoLocation );
mogoLocation.setDuration( 0L );
return realDuration;
}
return 0;
}
}