diff --git a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java index 9326d048ba..dee9ee8373 100644 --- a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java +++ b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java @@ -9,6 +9,7 @@ import android.location.Location; import android.os.Bundle; import android.os.Trace; import android.text.TextUtils; +import android.util.ArrayMap; import android.util.Log; import android.view.MotionEvent; import android.view.View; @@ -16,7 +17,6 @@ import android.view.ViewGroup; import android.view.animation.Interpolator; import android.widget.TextView; -import com.mogo.cloud.commons.utils.CoordinateUtils; import com.mogo.commons.debug.DebugConfig; import com.mogo.map.IMogoMap; import com.mogo.map.IMogoMapView; @@ -55,11 +55,7 @@ import com.zhidaoauto.map.sdk.open.location.MyLocationStyle; import com.zhidaoauto.map.sdk.open.location.RTKAutopilotLocationBean; import com.zhidaoauto.map.sdk.open.marker.BitmapDescriptorFactory; import com.zhidaoauto.map.sdk.open.marker.Marker; -import com.zhidaoauto.map.sdk.open.marker.MarkerOptions; -import com.zhidaoauto.map.sdk.open.marker.MultiPointOverlayOptions; -import com.zhidaoauto.map.sdk.open.marker.OnInfoWindowClickListener; import com.zhidaoauto.map.sdk.open.marker.OnMarkClickListener; -import com.zhidaoauto.map.sdk.open.poyline.PolylineOptions; import com.zhidaoauto.map.sdk.open.query.LonLatPoint; import com.zhidaoauto.map.sdk.open.tools.MapTools; import com.zhidaoauto.map.sdk.open.view.MapAutoView; @@ -69,7 +65,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.json.JSONObject; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -98,8 +93,8 @@ public class AMapViewWrapper implements IMogoMapView, private float mDefaultZoomLevel = 16.0f; private final CarCursorOption DEFAULT_OPTION = new CarCursorOption.Builder() - .carCursorRes( R.drawable.map_api_ic_current_location2 ) - .naviCursorRes( R.drawable.ic_amap_navi_cursor ) + .carCursorRes(R.drawable.map_api_ic_current_location2) + .naviCursorRes(R.drawable.ic_amap_navi_cursor) .build(); private CarCursorOption mCarCursorOption = DEFAULT_OPTION; @@ -111,16 +106,16 @@ public class AMapViewWrapper implements IMogoMapView, private boolean mIsDelayed = false; private Marker mSelfMarker; - public AMapViewWrapper( MapAutoView mMapView ) { + public AMapViewWrapper(MapAutoView mMapView) { startTime = System.currentTimeMillis(); - Logger.i( TAG, "autoop--AMapViewWrapper: init" ); + Logger.i(TAG, "autoop--AMapViewWrapper: init"); this.mMapView = mMapView; - if ( DebugConfig.isDebug() ) { - GpsTester.getInstance().init( mMapView ); + if (DebugConfig.isDebug()) { + GpsTester.getInstance().init(mMapView); } initViews(); initListeners(); - this.mIMap = new AMapWrapper( this.mMapView.getMapAutoViewHelper(), this.mMapView, this ); + this.mIMap = new AMapWrapper(this.mMapView.getMapAutoViewHelper(), this.mMapView, this); } private void initViews() { @@ -128,12 +123,12 @@ public class AMapViewWrapper implements IMogoMapView, } private void initMapView() { - if ( mMapView == null ) { + if (mMapView == null) { return; } MapAutoViewHelper options = mMapView.getMapAutoViewHelper(); - if ( options != null ) { - options.setZoomGesturesEnabled( true ); + if (options != null) { + options.setZoomGesturesEnabled(true); // 设置是否开启自动黑夜模式切换,默认为false,不自动切换 // options.setAutoSwitchStyle(false); // 设置6秒后是否自动锁车 @@ -143,7 +138,7 @@ public class AMapViewWrapper implements IMogoMapView, // 设置路线相关的配置属性,如:路线的路况颜色,路线上是否显示摄像头气泡等。 // options.setRouteOverlayOptions( MapStyleUtils.getRouteOverlayOptions() ); // 设置自车的图片对象 - options.setMyLocationStyle( options.getMyLocationStyle().myLocationIcon( DEFAULT_OPTION.getCarCursorRes() ) ); + options.setMyLocationStyle(options.getMyLocationStyle().myLocationIcon(DEFAULT_OPTION.getCarCursorRes())); // 设置指南针图标否在导航界面显示,默认显示。true,显示;false,隐藏。 // options.hiddenDirection(); // 黑夜模式 @@ -197,19 +192,19 @@ public class AMapViewWrapper implements IMogoMapView, private void initListeners() { - mMapView.setOnMarkClickListener( this ); + mMapView.setOnMarkClickListener(this); mMarkerClickHandler = AMapMarkerClickHandler.getInstance(); - mMapView.setOnMapLoadedListener( this ); - mMapView.setOnMapTouchListener( this ); - mMapView.setOnMapClickListener( this ); - mMapView.getLocationClient().registerListener( this ); + mMapView.setOnMapLoadedListener(this); + mMapView.setOnMapTouchListener(this); + mMapView.setOnMapClickListener(this); + mMapView.getLocationClient().registerListener(this); // mMapView.getLocationClient().registerGpsListener( this ); - mMapView.registerListener( this, MapAutoApi.LISTENER_TYPE_ZOOM ); - mMapView.registerListener( this, MapAutoApi.LISTENER_TYPE_ROTATE ); - mMapView.registerListener( this, MapAutoApi.LISTENER_TYPE_3D ); - mMapView.setMOnCameraChangeListener( this ); - mMapView.setOnMapStyleListener( this ); - Logger.d( TAG, "styleop - initListeners - setOnMapStyleListener - view %s", mMapView ); + mMapView.registerListener(this, MapAutoApi.LISTENER_TYPE_ZOOM); + mMapView.registerListener(this, MapAutoApi.LISTENER_TYPE_ROTATE); + mMapView.registerListener(this, MapAutoApi.LISTENER_TYPE_3D); + mMapView.setMOnCameraChangeListener(this); + mMapView.setOnMapStyleListener(this); + Logger.d(TAG, "styleop - initListeners - setOnMapStyleListener - view %s", mMapView); // mMapView.setOnPolylineClickListener( this ); // mMapView.setAMapNaviViewListener( this ); @@ -239,49 +234,49 @@ public class AMapViewWrapper implements IMogoMapView, } @Override - public void onCreate( Bundle bundle ) { - if ( mMapView != null ) { - mMapView.onCreate( bundle ); - Logger.d( TAG, "map onCreate" ); + public void onCreate(Bundle bundle) { + if (mMapView != null) { + mMapView.onCreate(bundle); + Logger.d(TAG, "map onCreate"); } } @Override public void onResume() { - if ( mMapView != null ) { + if (mMapView != null) { mMapView.onResume(); - Logger.d( TAG, "map onResume" ); + Logger.d(TAG, "map onResume"); } } @Override public void onPause() { - if ( mMapView != null ) { + if (mMapView != null) { mMapView.onPause(); - Logger.d( TAG, "map onPause" ); + Logger.d(TAG, "map onPause"); } } @Override public void onDestroy() { - if ( mMapView != null ) { + if (mMapView != null) { mMapView.onDestroy(); - mMapView.setOnMarkClickListener( null ); - mMapView.setOnMapLoadedListener( null ); - mMapView.setOnMapTouchListener( null ); - mMapView.setOnMapClickListener( null ); - mMapView.getLocationClient().unRegisterListener( this ); - mMapView.setMOnCameraChangeListener( null ); + mMapView.setOnMarkClickListener(null); + mMapView.setOnMapLoadedListener(null); + mMapView.setOnMapTouchListener(null); + mMapView.setOnMapClickListener(null); + mMapView.getLocationClient().unRegisterListener(this); + mMapView.setMOnCameraChangeListener(null); mSelfMarker = null; - Logger.d( TAG, "map onDestroy" ); + Logger.d(TAG, "map onDestroy"); } } @Override - public void onSaveInstanceState( Bundle outState ) { - if ( mMapView != null ) { - mMapView.onSaveInstanceState( outState ); - Logger.d( TAG, "map onSaveInstanceState" ); + public void onSaveInstanceState(Bundle outState) { + if (mMapView != null) { + mMapView.onSaveInstanceState(outState); + Logger.d(TAG, "map onSaveInstanceState"); } } @@ -291,83 +286,83 @@ public class AMapViewWrapper implements IMogoMapView, } @Override - public void setTrafficEnabled( boolean visible ) { - if ( checkAMapView() ) { + public void setTrafficEnabled(boolean visible) { + if (checkAMapView()) { // mMapView.getMapAutoViewHelper().setTraffic( visible ); } } @Override - public MapControlResult changeZoom( boolean zoom ) { - if ( checkAMapView() ) { - mDefaultZoomLevel = ( getMap().getZoomLevel() + 0.5f ); - if ( zoom ) { - if ( mDefaultZoomLevel >= 20f ) { + public MapControlResult changeZoom(boolean zoom) { + if (checkAMapView()) { + mDefaultZoomLevel = (getMap().getZoomLevel() + 0.5f); + if (zoom) { + if (mDefaultZoomLevel >= 20f) { return MapControlResult.TARGET; } } else { - if ( mDefaultZoomLevel <= 7f ) { + if (mDefaultZoomLevel <= 7f) { return MapControlResult.TARGET; } } - if ( zoom ) { + if (zoom) { mDefaultZoomLevel += 1f; - if ( mDefaultZoomLevel > 19f ) { + if (mDefaultZoomLevel > 19f) { mDefaultZoomLevel = 19f; } } else { mDefaultZoomLevel -= 1f; - if ( mDefaultZoomLevel < 8f ) { + if (mDefaultZoomLevel < 8f) { mDefaultZoomLevel = 8f; } } - changeZoom( mDefaultZoomLevel ); + changeZoom(mDefaultZoomLevel); } return MapControlResult.SUCCESS; } @Override - public MapControlResult changeZoom( float zoom ) { - if ( mCurrentUI == EnumMapUI.Type_VR ) { + public MapControlResult changeZoom(float zoom) { + if (mCurrentUI == EnumMapUI.Type_VR) { return MapControlResult.ERROR; } - Logger.d( TAG, "changeZoom %s", zoom ); - if ( DebugConfig.isDebug() ) { - Logger.d( TAG, Log.getStackTraceString( new Throwable() ) ); + Logger.d(TAG, "changeZoom %s", zoom); + if (DebugConfig.isDebug()) { + Logger.d(TAG, Log.getStackTraceString(new Throwable())); } - getMap().changeZoom( zoom ); + getMap().changeZoom(zoom); return MapControlResult.SUCCESS; } @Override - public void changeMapMode( EnumMapUI ui ) { - if ( ui == null ) { + public void changeMapMode(EnumMapUI ui) { + if (ui == null) { return; } - Logger.d( TAG, "设置的样式 = %s", ui ); - if ( checkAMapView() ) { - switch ( ui ) { + Logger.d(TAG, "设置的样式 = %s", ui); + if (checkAMapView()) { + switch (ui) { case CarUp_2D: case CarUp_3D: case NorthUP_2D: - setUIMode( ui ); + setUIMode(ui); break; case Type_VR: - mMapView.getMapAutoViewHelper().setMapStyle( MapAutoApi.MAP_STYLE_VR ); + mMapView.getMapAutoViewHelper().setMapStyle(MapAutoApi.MAP_STYLE_VR); return; case Type_Light: - mMapView.getMapAutoViewHelper().setAutoSwitchStyle( false ); - mMapView.getMapAutoViewHelper().setMapStyle( MapAutoApi.MAP_STYLE_DAY ); + mMapView.getMapAutoViewHelper().setAutoSwitchStyle(false); + mMapView.getMapAutoViewHelper().setMapStyle(MapAutoApi.MAP_STYLE_DAY); mIsLightStyle = true; break; case Type_Night: - mMapView.getMapAutoViewHelper().setAutoSwitchStyle( false ); - mMapView.getMapAutoViewHelper().setMapStyle( MapAutoApi.MAP_STYLE_NIGHT ); + mMapView.getMapAutoViewHelper().setAutoSwitchStyle(false); + mMapView.getMapAutoViewHelper().setMapStyle(MapAutoApi.MAP_STYLE_NIGHT); mIsLightStyle = false; break; case Type_AUTO_LIGHT_Night: - mMapView.getMapAutoViewHelper().setAutoSwitchStyle( true ); + mMapView.getMapAutoViewHelper().setAutoSwitchStyle(true); break; } @@ -375,140 +370,140 @@ public class AMapViewWrapper implements IMogoMapView, } @Override - public void moveToCenter( MogoLatLng latLng ) { - moveToCenter( latLng, true ); + public void moveToCenter(MogoLatLng latLng) { + moveToCenter(latLng, true); } - private void setUIMode( EnumMapUI ui ) { + private void setUIMode(EnumMapUI ui) { this.mCurrentCarUIMode = ui; - if ( mMapView.getMapAutoViewHelper() != null ) { - switch ( ui ) { + if (mMapView.getMapAutoViewHelper() != null) { + switch (ui) { case CarUp_2D: case CarUp_3D: - mMapView.getMapAutoViewHelper().setMapViewPerspective( MapAutoApi.MAP_PERSPECTIVE_UP_CAR ); + mMapView.getMapAutoViewHelper().setMapViewPerspective(MapAutoApi.MAP_PERSPECTIVE_UP_CAR); break; case NorthUP_2D: - if ( mCurrentUI == EnumMapUI.Type_VR ) { + if (mCurrentUI == EnumMapUI.Type_VR) { return; } - mMapView.getMapAutoViewHelper().setMapViewPerspective( MapAutoApi.MAP_PERSPECTIVE_UP_NORTH ); + mMapView.getMapAutoViewHelper().setMapViewPerspective(MapAutoApi.MAP_PERSPECTIVE_UP_NORTH); break; } } } private boolean checkAMapView() { - if ( mMapView == null || mMapView.getMapAutoViewHelper() == null ) { - Logger.e( TAG, "自研mapView实例为空,请检查" ); + if (mMapView == null || mMapView.getMapAutoViewHelper() == null) { + Logger.e(TAG, "自研mapView实例为空,请检查"); return false; } return true; } @Override - public void moveToCenter( MogoLatLng latLng, boolean animate ) { - if ( mCurrentUI == EnumMapUI.Type_VR ) { + public void moveToCenter(MogoLatLng latLng, boolean animate) { + if (mCurrentUI == EnumMapUI.Type_VR) { return; } - Logger.d( TAG, "move to center %s", latLng ); - if ( latLng == null || latLng.lat == 0.0d || latLng.lng == 0.0d ) { - Logger.e( TAG, "latlng = null or is illegal" ); + Logger.d(TAG, "move to center %s", latLng); + if (latLng == null || latLng.lat == 0.0d || latLng.lng == 0.0d) { + Logger.e(TAG, "latlng = null or is illegal"); return; } - if ( DebugConfig.isDebug() ) { - Logger.d( TAG, Log.getStackTraceString( new Throwable() ) ); + if (DebugConfig.isDebug()) { + Logger.d(TAG, Log.getStackTraceString(new Throwable())); } loseLockMode(); - mMapView.getMapAutoViewHelper().animateCamera( new LonLatPoint( latLng.lon, latLng.lat ) ); + mMapView.getMapAutoViewHelper().animateCamera(new LonLatPoint(latLng.lon, latLng.lat)); } @Override - public void showMyLocation( boolean visible ) { - Logger.d( TAG, "showMyLocation1 %s", visible ); + public void showMyLocation(boolean visible) { + Logger.d(TAG, "showMyLocation1 %s", visible); - if ( mCurrentUI == EnumMapUI.Type_VR ) { + if (mCurrentUI == EnumMapUI.Type_VR) { return; } - if ( visible && NaviClient.getInstance( getContext() ).isNaviing() ) { + if (visible && NaviClient.getInstance(getContext()).isNaviing()) { return; } // if (DebugConfig.isDebug()) { // Logger.d(TAG, Log.getStackTraceString(new Throwable())); // } - if ( checkAMapView() ) { + if (checkAMapView()) { MyLocationStyle style = mMapView.getMapAutoViewHelper().getMyLocationStyle(); - if ( visible ) { + if (visible) { // 强制刷新一遍车标 - style.myLocationIcon( mCarCursorOption.getCarCursorRes() ); + style.myLocationIcon(mCarCursorOption.getCarCursorRes()); } - mMapView.getMapAutoViewHelper().setMyLocationStyle( style ); + mMapView.getMapAutoViewHelper().setMyLocationStyle(style); } } @Override - public void showMyLocation( View view ) { - Logger.d( TAG, "showMyLocation %s", "view" ); - if ( NaviClient.getInstance( getContext() ).isNaviing() ) { + public void showMyLocation(View view) { + Logger.d(TAG, "showMyLocation %s", "view"); + if (NaviClient.getInstance(getContext()).isNaviing()) { return; } - if ( DebugConfig.isDebug() ) { - Logger.d( TAG, Log.getStackTraceString( new Throwable() ) ); + if (DebugConfig.isDebug()) { + Logger.d(TAG, Log.getStackTraceString(new Throwable())); } - if ( checkAMapView() ) { + if (checkAMapView()) { MyLocationStyle style = mMapView.getMapAutoViewHelper().getMyLocationStyle(); - style.myLocationIcon( BitmapDescriptorFactory.INSTANCE.convertViewToBitmap( view ) ); - mMapView.getMapAutoViewHelper().setMyLocationStyle( style ); + style.myLocationIcon(BitmapDescriptorFactory.INSTANCE.convertViewToBitmap(view)); + mMapView.getMapAutoViewHelper().setMyLocationStyle(style); } } public void initMyLocation() { - if ( checkAMapView() ) { - mMapView.getMapAutoViewHelper().setMyLocationEnabled( true ); + if (checkAMapView()) { + mMapView.getMapAutoViewHelper().setMyLocationEnabled(true); MyLocationStyle style = mMapView.getMapAutoViewHelper().getMyLocationStyle(); - style.setLocationType( MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER ); - style.interval( 1000 ); + style.setLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER); + style.interval(1000); // style.anchor( 0.5F, 0.5F ); // style.strokeColor( Color.TRANSPARENT ); // style.strokeWidth( 0 ); // style.radiusFillColor( Color.TRANSPARENT ); - mMapView.getMapAutoViewHelper().setMyLocationStyle( style ); + mMapView.getMapAutoViewHelper().setMyLocationStyle(style); } } @Override public void recoverLockMode() { - if ( checkAMapView() ) { + if (checkAMapView()) { // if ( DebugConfig.isDebug() ) { // Logger.d( TAG, Log.getStackTraceString( new Throwable() ) ); // } - if ( mCurrentUI == EnumMapUI.Type_VR ) { + if (mCurrentUI == EnumMapUI.Type_VR) { return; } - Logger.d( TAG, "锁车" ); + Logger.d(TAG, "锁车"); // mMapView.getMapAutoViewHelper().setZoom(mLockZoom); - mMapView.getMapAutoViewHelper().setLockMode( true ); + mMapView.getMapAutoViewHelper().setLockMode(true); mIsCarLocked = true; } } @Override public void loseLockMode() { - if ( mCurrentUI == EnumMapUI.Type_VR ) { + if (mCurrentUI == EnumMapUI.Type_VR) { return; } - Logger.d( TAG, "解锁锁车" ); - mMapView.getMapAutoViewHelper().setLockMode( false ); + Logger.d(TAG, "解锁锁车"); + mMapView.getMapAutoViewHelper().setLockMode(false); mIsCarLocked = false; } @Override - public void setLockZoom( int var1 ) { + public void setLockZoom(int var1) { mLockZoom = var1; } @Override - public void displayOverview( Rect bounds ) { + public void displayOverview(Rect bounds) { } @@ -524,14 +519,14 @@ public class AMapViewWrapper implements IMogoMapView, @Override public MogoLatLng getCameraNorthEastPosition() { - return ObjectUtils.fromAMap( MapTools.INSTANCE.getVisibleRegion().getRightTopPoint() ); + return ObjectUtils.fromAMap(MapTools.INSTANCE.getVisibleRegion().getRightTopPoint()); } @Override public MogoLatLng getCameraSouthWestPosition() { try { - return ObjectUtils.fromAMap( MapTools.INSTANCE.getVisibleRegion().getLeftBottomPoint() ); - } catch ( Exception e ) { + return ObjectUtils.fromAMap(MapTools.INSTANCE.getVisibleRegion().getLeftBottomPoint()); + } catch (Exception e) { } return null; @@ -540,30 +535,30 @@ public class AMapViewWrapper implements IMogoMapView, @Override public MogoLatLng getWindowCenterLocation() { try { - return ObjectUtils.fromAMap( mMapView.getMapAutoViewHelper().getCenter() ); - } catch ( Exception e ) { + return ObjectUtils.fromAMap(mMapView.getMapAutoViewHelper().getCenter()); + } catch (Exception e) { } return null; } @Override - public void setPointToCenter( double mapCenterX, double mapCenterY ) { - if ( checkAMapView() ) { - if ( mCurrentUI == EnumMapUI.Type_VR ) { + public void setPointToCenter(double mapCenterX, double mapCenterY) { + if (checkAMapView()) { + if (mCurrentUI == EnumMapUI.Type_VR) { return; } - Logger.d( TAG, "setPointToCenter(%s, %s)", mapCenterX, mapCenterY ); - mMapView.getMapAutoViewHelper().setPointToCenter( ( float ) mapCenterX, ( float ) mapCenterY ); + Logger.d(TAG, "setPointToCenter(%s, %s)", mapCenterX, mapCenterY); + mMapView.getMapAutoViewHelper().setPointToCenter((float) mapCenterX, (float) mapCenterY); } } @Override - public Point getLocationPointInScreen( MogoLatLng latLng ) { - if ( checkAMapView() ) { + public Point getLocationPointInScreen(MogoLatLng latLng) { + if (checkAMapView()) { try { - return MapTools.INSTANCE.toScreenLocation( ObjectUtils.fromMogo( latLng ) ); - } catch ( Exception e ) { + return MapTools.INSTANCE.toScreenLocation(ObjectUtils.fromMogo(latLng)); + } catch (Exception e) { return null; } } @@ -571,12 +566,12 @@ public class AMapViewWrapper implements IMogoMapView, } @Override - public MogoLatLng getLocationMogoLatLngInScreen( Point point ) { - if ( checkAMapView() ) { + public MogoLatLng getLocationMogoLatLngInScreen(Point point) { + if (checkAMapView()) { try { return ObjectUtils.fromAMap( - MapTools.INSTANCE.fromScreenLocation( point ) ); - } catch ( Exception e ) { + MapTools.INSTANCE.fromScreenLocation(point)); + } catch (Exception e) { return null; } } @@ -584,9 +579,9 @@ public class AMapViewWrapper implements IMogoMapView, } @Override - public void startJumpAnimation( IMogoMarker marker, float high, Interpolator interpolator, - long duration ) { - if ( marker == null || high <= 0.0f || interpolator == null || duration < 0 ) { + public void startJumpAnimation(IMogoMarker marker, float high, Interpolator interpolator, + long duration) { + if (marker == null || high <= 0.0f || interpolator == null || duration < 0) { return; } try { @@ -604,56 +599,56 @@ public class AMapViewWrapper implements IMogoMapView, // ( ( AMapMarkerWrapper ) marker ).getMarker().setAnimation( animation ); // ( ( AMapMarkerWrapper ) marker ).getMarker().startAnimation(); // } - } catch ( Exception e ) { - Logger.e( TAG, e, "error." ); + } catch (Exception e) { + Logger.e(TAG, e, "error."); } } @Override - public void setRenderFps( int fps ) { - if ( checkAMapView() ) { - if ( mMapView.getMapAutoViewHelper() != null ) { - mMapView.getMapAutoViewHelper().setRenderFps( fps ); - Logger.d( TAG, "设置刷新帧率 fps = %s", fps ); + public void setRenderFps(int fps) { + if (checkAMapView()) { + if (mMapView.getMapAutoViewHelper() != null) { + mMapView.getMapAutoViewHelper().setRenderFps(fps); + Logger.d(TAG, "设置刷新帧率 fps = %s", fps); } } } @Override - public void showBounds( String tag, MogoLatLng carPosition, List< MogoLatLng > lonLats, Rect bound, boolean lockCarPosition ) { - if ( !checkAMapView() ) { + public void showBounds(String tag, MogoLatLng carPosition, List lonLats, Rect bound, boolean lockCarPosition) { + if (!checkAMapView()) { return; } - if ( mCurrentUI == EnumMapUI.Type_VR ) { - Logger.w( TAG, "vr 模式下忽略该设置" ); + if (mCurrentUI == EnumMapUI.Type_VR) { + Logger.w(TAG, "vr 模式下忽略该设置"); return; } - Logger.i( TAG, "showBounds:%s -%s-%s- %b ", tag, carPosition.toString(), bound.toShortString(), lockCarPosition ); + Logger.i(TAG, "showBounds:%s -%s-%s- %b ", tag, carPosition.toString(), bound.toShortString(), lockCarPosition); try { - LatLngBounds latLngBounds = MogoMapUtils.getLatLngBounds( carPosition, lonLats, lockCarPosition ); - if ( !lockCarPosition ) { + LatLngBounds latLngBounds = MogoMapUtils.getLatLngBounds(carPosition, lonLats, lockCarPosition); + if (!lockCarPosition) { loseLockMode(); } - mMapView.getMapAutoViewHelper().setCenter( ObjectUtils.fromMogo( carPosition ) ); - mMapView.getMapAutoViewHelper().moveCamera( CameraUpdateFactory.INSTANCE.newLatLngBounds( latLngBounds, bound.left, bound.right, bound.top, bound.bottom ) ); - } catch ( Exception e ) { - Logger.e( TAG, e, "%s error.", tag ); + mMapView.getMapAutoViewHelper().setCenter(ObjectUtils.fromMogo(carPosition)); + mMapView.getMapAutoViewHelper().moveCamera(CameraUpdateFactory.INSTANCE.newLatLngBounds(latLngBounds, bound.left, bound.right, bound.top, bound.bottom)); + } catch (Exception e) { + Logger.e(TAG, e, "%s error.", tag); } } @Override public void forceRender() { - if ( checkAMapView() ) { + if (checkAMapView()) { mMapView.getMapAutoViewHelper().runOnDrawFrame(); } } @Override - public float calculateLineDistance( MogoLatLng p1, MogoLatLng p2 ) throws Exception { - if ( p1 == null || p2 == null ) { - throw new Exception( "计算距离的点不能为 null" ); + public float calculateLineDistance(MogoLatLng p1, MogoLatLng p2) throws Exception { + if (p1 == null || p2 == null) { + throw new Exception("计算距离的点不能为 null"); } - return MogoMapUtils.calculateLineDistance( ObjectUtils.fromMogo( p1 ), ObjectUtils.fromMogo( p2 ) ); + return MogoMapUtils.calculateLineDistance(ObjectUtils.fromMogo(p1), ObjectUtils.fromMogo(p2)); } @@ -663,7 +658,7 @@ public class AMapViewWrapper implements IMogoMapView, } @Override - public void changeMyLocation( Location location ) { + public void changeMyLocation(Location location) { } @Override @@ -672,168 +667,168 @@ public class AMapViewWrapper implements IMogoMapView, } @Override - public void setCarCursorOption( CarCursorOption option ) { - if ( mCurrentUI == EnumMapUI.Type_VR ) { + public void setCarCursorOption(CarCursorOption option) { + if (mCurrentUI == EnumMapUI.Type_VR) { return; } - if ( mCarCursorOption != null && mCarCursorOption != DEFAULT_OPTION ) { + if (mCarCursorOption != null && mCarCursorOption != DEFAULT_OPTION) { mCarCursorOption.destroy(); } - if ( option != null ) { + if (option != null) { try { mCarCursorOption = option.clone(); - } catch ( Exception e ) { + } catch (Exception e) { mCarCursorOption = DEFAULT_OPTION; } } else { mCarCursorOption = DEFAULT_OPTION; } - if ( !checkAMapView() ) { + if (!checkAMapView()) { return; } - if ( mMapView.getMapAutoViewHelper() == null ) { + if (mMapView.getMapAutoViewHelper() == null) { return; } MyLocationStyle style = mMapView.getMapAutoViewHelper().getMyLocationStyle(); - if ( mCarCursorOption.getCarCursorBmp() != null && !mCarCursorOption.getCarCursorBmp().isRecycled() ) { - style.myLocationIcon( mCarCursorOption.getCarCursorBmp() ); + if (mCarCursorOption.getCarCursorBmp() != null && !mCarCursorOption.getCarCursorBmp().isRecycled()) { + style.myLocationIcon(mCarCursorOption.getCarCursorBmp()); } else { - if ( mCarCursorOption.getCarCursorRes() != 0 ) { - style.myLocationIcon( mCarCursorOption.getCarCursorRes() ); + if (mCarCursorOption.getCarCursorRes() != 0) { + style.myLocationIcon(mCarCursorOption.getCarCursorRes()); } else { - style.myLocationIcon( mCarCursorOption.getCarCursorRes() ); + style.myLocationIcon(mCarCursorOption.getCarCursorRes()); } } - mMapView.getMapAutoViewHelper().setMyLocationStyle( style ); + mMapView.getMapAutoViewHelper().setMyLocationStyle(style); } @Override public MapCameraPosition getMapCameraPosition() { - if ( checkAMapView() ) { + if (checkAMapView()) { CameraPosition cameraPosition = mMapView.getMapAutoViewHelper().getCameraPosition(); - return ObjectUtils.fromAMap( cameraPosition ); + return ObjectUtils.fromAMap(cameraPosition); } return null; } @Override - public void changeBearing( float bearing ) { - if ( checkAMapView() ) { - mMapView.getMapAutoViewHelper().setMapViewRotation( bearing ); + public void changeBearing(float bearing) { + if (checkAMapView()) { + mMapView.getMapAutoViewHelper().setMapViewRotation(bearing); } } @Override - public void onLocationChanged( @NotNull com.zhidaoauto.map.sdk.open.location.MogoLocation location ) { - Location sysLocation = new Location( location.getProvider() ); - sysLocation.setAltitude( location.getAltitude() ); - sysLocation.setLatitude( location.getLat() ); - sysLocation.setLongitude( location.getLon() ); - sysLocation.setProvider( location.getProvider() ); - sysLocation.setAccuracy( location.getAcceleration() ); - sysLocation.setTime( location.getDuration() ); - sysLocation.setBearing( location.getHeading() ); - sysLocation.setSpeed( location.getSpeed() ); + public void onLocationChanged(@NotNull com.zhidaoauto.map.sdk.open.location.MogoLocation location) { + Location sysLocation = new Location(location.getProvider()); + sysLocation.setAltitude(location.getAltitude()); + sysLocation.setLatitude(location.getLat()); + sysLocation.setLongitude(location.getLon()); + sysLocation.setProvider(location.getProvider()); + sysLocation.setAccuracy(location.getAcceleration()); + sysLocation.setTime(location.getDuration()); + sysLocation.setBearing(location.getHeading()); + sysLocation.setSpeed(location.getSpeed()); - if ( sysLocation.getSpeed() > 0 ) { + if (sysLocation.getSpeed() > 0) { mLastDriveLocationShadow = sysLocation; } else { - if ( ( int ) sysLocation.getBearing() == 0 - && mLastDriveLocationShadow != null ) { + if ((int) sysLocation.getBearing() == 0 + && mLastDriveLocationShadow != null) { // TODO: 2020/12/12 停车时自车图标方向调整 } } - NaviClient.getInstance( getContext() ).syncCarLocation( sysLocation ); - if ( checkAMapView() && mMapLoaded ) { + NaviClient.getInstance(getContext()).syncCarLocation(sysLocation); + if (checkAMapView() && mMapLoaded) { // 地图初始化完成后,每隔5s自动判断当前地图的模式 - if ( mIsFirstLocated ) { - if ( !mIsDelayed ) { + if (mIsFirstLocated) { + if (!mIsDelayed) { mIsDelayed = true; - UiThreadHandler.postDelayed( () -> { - Logger.d( TAG, "倒计时结束" ); + UiThreadHandler.postDelayed(() -> { + Logger.d(TAG, "倒计时结束"); mIsFirstLocated = false; - }, 5_000L ); + }, 5_000L); } } else { mIsFirstLocated = true; mIsDelayed = false; - Logger.d( TAG, "同步定位" ); - MapStyleController.getInstance().onLocationChanged( location, this ); + Logger.d(TAG, "同步定位"); + MapStyleController.getInstance().onLocationChanged(location, this); } } - if ( mSelfMarker == null ) { + if (mSelfMarker == null) { try { mSelfMarker = mMapView.getMapAutoViewHelper().getMyLocationStyle().getSelfMarker(); - mSelfMarker.setInfoWindowEnable( true ); - } catch ( Exception e ) { + mSelfMarker.setInfoWindowEnable(true); + } catch (Exception e) { } } - showSelfSpeed( location.getSpeed() ); + showSelfSpeed(location.getSpeed()); } private TextView mSpeedView = null; - private void showSelfSpeed( float speed ) { + private void showSelfSpeed(float speed) { - if ( !checkAMapView() ) { + if (!checkAMapView()) { return; } - if ( mSelfMarker == null ) { + if (mSelfMarker == null) { return; } - if ( mCurrentUI != EnumMapUI.Type_VR ) { + if (mCurrentUI != EnumMapUI.Type_VR) { mSelfMarker.hideInfoWindow(); return; } - int speedIntVal = ( int ) ( speed * 3.6 ); - if ( speedIntVal <= 0 ) { + int speedIntVal = (int) (speed * 3.6); + if (speedIntVal <= 0) { mSelfMarker.hideInfoWindow(); return; } - String speedVal = String.valueOf( speedIntVal ); - String infoResName = ResIdCache.getVal( speedVal ); - if ( TextUtils.isEmpty( infoResName ) ) { - if ( mSpeedView == null ) { - mSpeedView = new TextView( mMapView.getContext() ); - mSpeedView.setTextColor( Color.WHITE ); - mSpeedView.setTypeface( Typeface.defaultFromStyle( Typeface.BOLD ) ); - mSpeedView.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT ) ); + String speedVal = String.valueOf(speedIntVal); + String infoResName = ResIdCache.getVal(speedVal); + if (TextUtils.isEmpty(infoResName)) { + if (mSpeedView == null) { + mSpeedView = new TextView(mMapView.getContext()); + mSpeedView.setTextColor(Color.WHITE); + mSpeedView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); + mSpeedView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } - mSpeedView.setText( speedVal ); - mSelfMarker.setInfoWindowOffset( 0, 20 ); - mSelfMarker.setInfoWindowView( mSpeedView ); - ResIdCache.putVal( speedVal, mSelfMarker.getMarkeOptions().getMarkerInfoName() ); + mSpeedView.setText(speedVal); + mSelfMarker.setInfoWindowOffset(0, 20); + mSelfMarker.setInfoWindowView(mSpeedView); + ResIdCache.putVal(speedVal, mSelfMarker.getMarkeOptions().getMarkerInfoName()); } else { - mSelfMarker.setMarkerInfoName( infoResName ); + mSelfMarker.setMarkerInfoName(infoResName); } } @Override - public void onMapClick( @Nullable LonLatPoint lonLatPoint ) { - if ( InterceptorHandler.getInstance().ignoreMapClicked( getContext() ) ) { + public void onMapClick(@Nullable LonLatPoint lonLatPoint) { + if (InterceptorHandler.getInstance().ignoreMapClicked(getContext())) { return; } - MogoMapListenerHandler.getInstance().onMapClick( ObjectUtils.fromAMap( lonLatPoint ) ); + MogoMapListenerHandler.getInstance().onMapClick(ObjectUtils.fromAMap(lonLatPoint)); } @Override public void onMapLoaded() { - Logger.i( TAG, "autoop--onMapLoaded: " ); + Logger.i(TAG, "autoop--onMapLoaded: "); MogoMapListenerHandler.getInstance().onMapLoaded(); mMapLoaded = true; CameraPosition cameraPosition = mMapView.getMapAutoViewHelper().getCameraPosition(); - if ( cameraPosition != null ) { - Trace.beginSection( "timer.onCameraChangeFinish" ); - MogoMapListenerHandler.getInstance().onMapChanged( ObjectUtils.fromAMap( cameraPosition.getTarget() ), + if (cameraPosition != null) { + Trace.beginSection("timer.onCameraChangeFinish"); + MogoMapListenerHandler.getInstance().onMapChanged(ObjectUtils.fromAMap(cameraPosition.getTarget()), cameraPosition.getZoom(), cameraPosition.getTilt(), - cameraPosition.getBearing() ); + cameraPosition.getBearing()); Trace.endSection(); } initMapView(); @@ -841,52 +836,52 @@ public class AMapViewWrapper implements IMogoMapView, } @Override - public boolean onTouch( @Nullable MotionEvent motionEvent ) { - MogoMapListenerHandler.getInstance().onTouch( motionEvent ); + public boolean onTouch(@Nullable MotionEvent motionEvent) { + MogoMapListenerHandler.getInstance().onTouch(motionEvent); return false; } @Override - public void onMarkClick( @NotNull Marker markerInfo ) { - mMarkerClickHandler.handleMarkerClicked( markerInfo ); + public void onMarkClick(@NotNull Marker markerInfo) { + mMarkerClickHandler.handleMarkerClicked(markerInfo); } @Override - public void onRoadLoaded( @Nullable String s ) { + public void onRoadLoaded(@Nullable String s) { } @Override - public void onMapStatusChanged( int type, int value ) { + public void onMapStatusChanged(int type, int value) { // Logger.i( TAG, "mapop--onMapStatusChanged-: " + type + "," + value ); } @Override - public void onCameraChange( int type, int value ) { + public void onCameraChange(int type, int value) { // Logger.i( TAG, "mapop--onCameraChange-: " + type + "," + value ); } @Override - public void onCameraChangeFinish( @Nullable CameraPosition cameraPosition ) { + public void onCameraChangeFinish(@Nullable CameraPosition cameraPosition) { // Logger.i( TAG, "mapop--onCameraChangeFinish-: " + cameraPosition + "cost:" + ( System.currentTimeMillis() - startTime ) ); - if ( cameraPosition != null ) { - Trace.beginSection( "timer.onCameraChangeFinish" ); - MogoMapListenerHandler.getInstance().onMapChanged( ObjectUtils.fromAMap( cameraPosition.getTarget() ), + if (cameraPosition != null) { + Trace.beginSection("timer.onCameraChangeFinish"); + MogoMapListenerHandler.getInstance().onMapChanged(ObjectUtils.fromAMap(cameraPosition.getTarget()), cameraPosition.getZoom(), cameraPosition.getTilt(), - cameraPosition.getBearing() ); + cameraPosition.getBearing()); Trace.endSection(); } } @Override - public void setAnchorScale( float x, float y ) { - mMapView.getMapAutoViewHelper().setAnchorScale( x, y ); + public void setAnchorScale(float x, float y) { + mMapView.getMapAutoViewHelper().setAnchorScale(x, y); } @Override - public void setAnchorRate( float rate ) { - mMapView.getMapAutoViewHelper().setAnchorRate( rate ); + public void setAnchorRate(float rate) { + mMapView.getMapAutoViewHelper().setAnchorRate(rate); } @Override @@ -898,18 +893,18 @@ public class AMapViewWrapper implements IMogoMapView, // private boolean mVrModeAutoChangedFlag = false; @Override - public void onChangeMapStyle( int i ) { + public void onChangeMapStyle(int i) { EnumMapUI last = mCurrentUI; - Logger.d( TAG, "currentMapStyle = %s", i ); + Logger.d(TAG, "currentMapStyle = %s", i); - if ( i == MapAutoApi.MAP_STYLE_DAY - || i == MapAutoApi.MAP_STYLE_DAY_NAV ) { + if (i == MapAutoApi.MAP_STYLE_DAY + || i == MapAutoApi.MAP_STYLE_DAY_NAV) { mCurrentUI = EnumMapUI.Type_Light; - } else if ( i == MapAutoApi.MAP_STYLE_NIGHT - || i == MapAutoApi.MAP_STYLE_NIGHT_NAV ) { + } else if (i == MapAutoApi.MAP_STYLE_NIGHT + || i == MapAutoApi.MAP_STYLE_NIGHT_NAV) { mCurrentUI = EnumMapUI.Type_Night; - } else if ( i == MapAutoApi.MAP_STYLE_VR ) { + } else if (i == MapAutoApi.MAP_STYLE_VR) { mCurrentUI = EnumMapUI.Type_VR; } // else if ( i == MapAutoApi.MAP_PERSPECTIVE_2D ) { @@ -918,17 +913,17 @@ public class AMapViewWrapper implements IMogoMapView, // mCurrentUI = EnumMapUI.CarUp_3D; // } - if ( last == mCurrentUI ) { - Logger.d( TAG, "currentUI is same as last = %s", mCurrentUI ); + if (last == mCurrentUI) { + Logger.d(TAG, "currentUI is same as last = %s", mCurrentUI); return; } // vr 模式切换到普通模式下,保持之前的白天模式 wtf. - if ( last == EnumMapUI.Type_VR + if (last == EnumMapUI.Type_VR && mCurrentUI != last - && mCurrentUI != EnumMapUI.Type_Light ) { - if ( mIsLightStyle ) { - changeMapMode( EnumMapUI.Type_Light ); + && mCurrentUI != EnumMapUI.Type_Light) { + if (mIsLightStyle) { + changeMapMode(EnumMapUI.Type_Light); return; } // if ( mVrModeAutoChangedFlag ) { @@ -936,16 +931,16 @@ public class AMapViewWrapper implements IMogoMapView, // return; // } } - Logger.d( TAG, Log.getStackTraceString( new Throwable() ) ); - if ( mCurrentUI != null ) { - UiThreadHandler.post( () -> { + Logger.d(TAG, Log.getStackTraceString(new Throwable())); + if (mCurrentUI != null) { + UiThreadHandler.post(() -> { try { - Logger.d( TAG, "currentUI = %s", mCurrentUI ); - MogoMapListenerHandler.getInstance().onMapModeChanged( mCurrentUI ); - } catch ( Exception e ) { + Logger.d(TAG, "currentUI = %s", mCurrentUI); + MogoMapListenerHandler.getInstance().onMapModeChanged(mCurrentUI); + } catch (Exception e) { e.printStackTrace(); } - } ); + }); } } @@ -955,20 +950,20 @@ public class AMapViewWrapper implements IMogoMapView, } @Override - public void onStyleAutoChanged( boolean isVrMode ) { - if ( isVrMode ) { - if ( mCurrentUI != EnumMapUI.Type_VR ) { - Logger.d( TAG, "自动切换为vr模式" ); + public void onStyleAutoChanged(boolean isVrMode) { + if (isVrMode) { + if (mCurrentUI != EnumMapUI.Type_VR) { + Logger.d(TAG, "自动切换为vr模式"); // mVrModeAutoChangedFlag = true; - changeMapMode( EnumMapUI.Type_VR ); + changeMapMode(EnumMapUI.Type_VR); } } else { - if ( mCurrentUI == EnumMapUI.Type_VR ) { - Logger.d( TAG, "自动切换为2D模式" ); - if ( mIsLightStyle ) { - changeMapMode( EnumMapUI.Type_Light ); + if (mCurrentUI == EnumMapUI.Type_VR) { + Logger.d(TAG, "自动切换为2D模式"); + if (mIsLightStyle) { + changeMapMode(EnumMapUI.Type_Light); } else { - changeMapMode( EnumMapUI.Type_Night ); + changeMapMode(EnumMapUI.Type_Night); } } } @@ -977,77 +972,108 @@ public class AMapViewWrapper implements IMogoMapView, private boolean mRtkEnable = false; @Override - public void rtkEnable( boolean enable ) { + public void rtkEnable(boolean enable) { try { mRtkEnable = !mRtkEnable; - TipToast.shortTip( mRtkEnable ? "已开启rtk道路匹配" : "已开启gps道路匹配" ); - mMapView.getLocationClient().rtkEnable( mRtkEnable ); - } catch ( Exception e ) { - Logger.e( TAG, e, "rtkEnable" ); + TipToast.shortTip(mRtkEnable ? "已开启rtk道路匹配" : "已开启gps道路匹配"); + mMapView.getLocationClient().rtkEnable(mRtkEnable); + } catch (Exception e) { + Logger.e(TAG, e, "rtkEnable"); } } @Override - public void syncLocation2Map( JSONObject data ) { - if ( !checkAMapView() ) { + public void syncLocation2Map(JSONObject data) { + if (!checkAMapView()) { return; } - if ( data == null ) { - Logger.d( TAG, "停止使用rtk定位数据" ); + if (data == null) { + Logger.d(TAG, "停止使用rtk定位数据"); mMapView.getLocationClient().stopAutoPilotRTK(); return; } - double lon = data.optDouble( "lon", -1 ); - double lat = data.optDouble( "lat", -1 ); - double alt = data.optDouble( "alt", -1 ); - double heading = data.optDouble( "heading", -1 ); - double acceleration = data.optDouble( "acceleration", -1 ); - double yawRate = data.optDouble( "yawRate", -1 ); - double speed = data.optDouble( "speed", -1 ); - long systemTime = data.optLong( "systemTime" ); - long receiverDataTime = data.optLong( "receiverDataTime" ); - if ( lon == -1 ) { + double lon = data.optDouble("lon", -1); + double lat = data.optDouble("lat", -1); + double alt = data.optDouble("alt", -1); + double heading = data.optDouble("heading", -1); + double acceleration = data.optDouble("acceleration", -1); + double yawRate = data.optDouble("yawRate", -1); + double speed = data.optDouble("speed", -1); + long systemTime = data.optLong("systemTime"); + long receiverDataTime = data.optLong("receiverDataTime"); + if (lon == -1) { return; } RTKAutopilotLocationBean bean = new RTKAutopilotLocationBean(); - bean.setYaw_rate( yawRate ); - bean.setHeading( heading ); - bean.setSystemTime( systemTime ); - bean.setReceiverDataTime( receiverDataTime ); - bean.setHeading( heading ); - bean.setAcceleration( acceleration ); - bean.setAlt( alt ); - bean.setLon( lon ); - bean.setGnss_speed( ( ( float ) speed ) ); - bean.setLat( lat ); - Logger.d( "ADASCOOR", "使用rtk定位数据%s", GsonUtil.jsonFromObject( bean ) ); - mMapView.getLocationClient().updateRTKAutoPilotLocation( bean ); + bean.setYaw_rate(yawRate); + bean.setHeading(heading); + bean.setSystemTime(systemTime); + bean.setReceiverDataTime(receiverDataTime); + bean.setHeading(heading); + bean.setAcceleration(acceleration); + bean.setAlt(alt); + bean.setLon(lon); + bean.setGnss_speed(((float) speed)); + bean.setLat(lat); + Logger.d("ADASCOOR", "使用rtk定位数据%s", GsonUtil.jsonFromObject(bean)); + mMapView.getLocationClient().updateRTKAutoPilotLocation(bean); } @Override - public void openVrMode( boolean zoomGestureEnable ) { + public void openVrMode(boolean zoomGestureEnable) { try { - mMapView.getMapAutoViewHelper().setZoomGesturesEnabled( zoomGestureEnable ); - mMapView.getMapAutoViewHelper().setMapStyle( MapAutoApi.MAP_STYLE_VR ); - } catch ( Exception e ) { + mMapView.getMapAutoViewHelper().setZoomGesturesEnabled(zoomGestureEnable); + mMapView.getMapAutoViewHelper().setMapStyle(MapAutoApi.MAP_STYLE_VR); + } catch (Exception e) { e.printStackTrace(); } } + Map roadCacheMap = new ArrayMap<>(); + @Override - public double[] matchRoad( double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) { + public double[] matchRoad(String id, double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK) { + return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK, true); + } + + private double[] matchRoad(String id, double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK, boolean usdCache) { double wgs[] = new double[]{lon, lat}; long start = System.currentTimeMillis(); - SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad( wgs[0], wgs[1], ( ( float ) angle ), isGpsLocation, isRTK ); - Log.i("timer-matchRoad-1", "cost " + (System.currentTimeMillis() - start) + "ms"); - if ( singlePointRoadInfo != null - && singlePointRoadInfo.getCoords() != null - && !singlePointRoadInfo.getCoords().isEmpty() ) { - start = System.currentTimeMillis(); - double matchedPoint[] = PointInterpolatorUtil.mergeToRoad( wgs[0], wgs[1], singlePointRoadInfo.getCoords() ); - Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms"); - return matchedPoint; + RoadCacheWrapper roadCache = roadCacheMap.get(id); + if (roadCache == null) { + SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad(((float) wgs[0]), ((float) wgs[1]), ((float) angle), isGpsLocation, isRTK); + if (singlePointRoadInfo != null && singlePointRoadInfo.getCoords() != null && !singlePointRoadInfo.getCoords().isEmpty()) { + Log.i("timer-matchRoad-4", "cost " + (System.currentTimeMillis() - start) + "ms roadId: " + singlePointRoadInfo.getRoadId()); + roadCache = new RoadCacheWrapper(singlePointRoadInfo.getCoords()); + } } + + Log.i("timer-matchRoad-1", "cost " + (System.currentTimeMillis() - start) + "ms"); + if (roadCache != null + && roadCache.getRoad() != null + && !roadCache.getRoad().isEmpty()) { + start = System.currentTimeMillis(); + double matchedPoint[] = PointInterpolatorUtil.mergeToRoad(wgs[0], wgs[1], roadCache.getRoad()); + if (matchedPoint[2] > 0 && matchedPoint[2] < 1.5) { +// if (roadCache.inCache(matchedPoint[0], matchedPoint[1])) { + roadCacheMap.put(id, roadCache); + Log.i("timer-matchRoad-3", "cost " + (System.currentTimeMillis() - start) + "ms"); + return matchedPoint; +// } +// roadCacheMap.put(id, null); +// Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms roadId: "+roadCache.getLastLat()); +// return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK,false); + }else{ + roadCacheMap.put(id, null); + Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms roadId: " + roadCache.getLastLat()); + if(usdCache) { + return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK, false); + }else{ + return null; + } + } + } + roadCacheMap.put(id, null); return null; } @@ -1057,7 +1083,7 @@ public class AMapViewWrapper implements IMogoMapView, } @Override - public void setMarkerInfoResName( String speedVal, String val ) { - ResIdCache.putVal( speedVal, val ); + public void setMarkerInfoResName(String speedVal, String val) { + ResIdCache.putVal(speedVal, val); } } diff --git a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/RoadCacheWrapper.java b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/RoadCacheWrapper.java new file mode 100644 index 0000000000..626a352d60 --- /dev/null +++ b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/RoadCacheWrapper.java @@ -0,0 +1,77 @@ +package com.mogo.map.impl.custom; + +import com.zhidaoauto.map.sdk.open.query.LonLatPoint; + +import java.util.List; + +/** + * 道路数据缓存 + * + * @author tongchenfei + */ +public class RoadCacheWrapper { + private List road; + private double lastDistanceDiff; + private int roadLength = -1; + + public RoadCacheWrapper(List road) { + setRoad(road); + } + + public List getRoad() { + return road; + } + + public void setRoad(List road) { + this.road = road; + if(road!=null) { + roadLength = road.size(); + } + } + + public double getLastDistanceDiff() { + return lastDistanceDiff; + } + + public void setLastDistanceDiff(double lastDistanceDiff) { + this.lastDistanceDiff = lastDistanceDiff; + } + + public double getLastLat(){ + if (roadLength != -1) { + return road.get(roadLength - 1).getLatitude(); + } + return 0; + } + + public double getLastLon(){ + if (roadLength != -1) { + return road.get(roadLength - 1).getLongitude(); + } + return 0; + } + + public boolean inCache(double lon, double lat) { + if (roadLength > 0) { + LonLatPoint start = road.get(0); + LonLatPoint end = road.get(roadLength - 1); + boolean latInRoad = false; + boolean lonInRoad = false; + if (start.getLatitude() > end.getLatitude()) { + latInRoad = lat <= start.getLatitude() && lat >= end.getLatitude(); + }else{ + latInRoad = lat >= start.getLatitude() && lat <= end.getLatitude(); + } + + if (start.getLongitude() > end.getLongitude()) { + lonInRoad = lon <= start.getLongitude() && lon >= end.getLongitude(); + }else{ + lonInRoad = lon >= start.getLongitude() && lon <= end.getLongitude(); + } + + return latInRoad && lonInRoad; + } + return false; + } + +} diff --git a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/uicontroller/AMapUIController.java b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/uicontroller/AMapUIController.java index 7ce8f4d8c6..fd2d79c2e1 100644 --- a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/uicontroller/AMapUIController.java +++ b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/uicontroller/AMapUIController.java @@ -315,9 +315,9 @@ public class AMapUIController implements IMogoMapUIController { } @Override - public double[] matchRoad( double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) { + public double[] matchRoad( String id, double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) { if ( mClient != null ) { - return mClient.matchRoad( lon, lat, angle, isGpsLocation, isRTK ); + return mClient.matchRoad( id, lon, lat, angle, isGpsLocation, isRTK ); } return null; } diff --git a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/utils/PointInterpolatorUtil.java b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/utils/PointInterpolatorUtil.java index 342827642c..6fbb15abc8 100644 --- a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/utils/PointInterpolatorUtil.java +++ b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/utils/PointInterpolatorUtil.java @@ -61,13 +61,15 @@ public class PointInterpolatorUtil { getCloseTwoPoint( lon, lat, road ); LonLatPoint start = road.get( closeStart ); LonLatPoint end = road.get( closeEnd ); - Logger.d( TAG, "mergeToRoad start: " + closeStart + " end: " + closeEnd ); +// Logger.d( TAG, "mergeToRoad start: " + closeStart + " end: " + closeEnd ); // return getMid(start, end); - double[] foot = getFoot( lon, lat, start, end ); +// double[] foot = getFoot( lon, lat, start, end ); - float d = CoordinateUtils.calculateLineDistance( foot[0], foot[1], lon, lat ); - Logger.d( TAG, "distance to mid line==" + d ); - return new double[]{foot[0], foot[1], d}; +// float d = CoordinateUtils.calculateLineDistance( foot[0], foot[1], lon, lat ); +// Logger.d( TAG, "distance to mid line==" + d ); +// return new double[]{foot[0], foot[1], d}; + + return getFootAndMinDistance(lon, lat, start.getLongitude(), start.getLatitude(), end.getLongitude(), end.getLatitude()); } private static int closeStart = 0; @@ -99,6 +101,57 @@ public class PointInterpolatorUtil { return new double[]{beginPt.getLongitude() + u * dy, beginPt.getLatitude() + u * dx}; } + +// un minDistance(x: Double, y: Double, x1: Double, y1: Double, x2: Double, y2: Double): Double { +// val cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1) +// println("1.cross:$cross") +// if (cross <= 0) { +// return Math.sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)) +// } +// val d2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) +// println("2.d2:$cross") +// if (cross > d2) { +// return Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2)) +// } +// val r = cross / d2 +// val px = x1 + (x2 - x1) * r +// val py = y1 + (y2 - y1) * r +// println("3.r:$r,px:$px,py:$py") +// return Math.sqrt((x - px) * (x - px) + (py - y) * (py - y)) +// } + + /** + * 计算垂足以及最短距离 + * + * @param x target point lon + * @param y target point lat + * @param x1 start point lon + * @param y1 start point lat + * @param x2 end point lon + * @param y2 end point lat + * @return double[]{footLon,footLat,minDistance} if(footLon == -1) => no foot or foot not in line + */ + private static double[] getFootAndMinDistance(double x, double y, double x1, double y1, double x2, double y2) { + double[] result = new double[]{-1, -1, -1}; + double cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1); + if (cross < 0) { + // 垂足没有在线段内,所以也无需计算最短距离 + // result[2] = Math.sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)); + return result; + } + double d2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1); + if (cross > d2) { + // 垂足没有在线段内,所以也无需计算最短距离 + // result[2] = Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2)); + return result; + } + double r = cross / d2; + result[0] = x1 + (x2 - x1) * r; + result[1] = y1 + (y2 - y1) * r; + result[2] = Math.sqrt((x - result[0]) * (x - result[0]) + (result[1] - y) * (result[1] - y)); + return result; + } + private static double[] getMid( LonLatPoint start, LonLatPoint end ) { return new double[]{( start.getLongitude() + end.getLongitude() ) / 2, ( start.getLatitude() + end.getLatitude() ) / 2}; } diff --git a/libraries/mogo-map-api/src/main/java/com/mogo/map/uicontroller/IMogoMapUIController.java b/libraries/mogo-map-api/src/main/java/com/mogo/map/uicontroller/IMogoMapUIController.java index f888406782..2edd64b0d1 100644 --- a/libraries/mogo-map-api/src/main/java/com/mogo/map/uicontroller/IMogoMapUIController.java +++ b/libraries/mogo-map-api/src/main/java/com/mogo/map/uicontroller/IMogoMapUIController.java @@ -285,7 +285,7 @@ public interface IMogoMapUIController { * @param isRTK * @return */ - default double[] matchRoad( double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) { + default double[] matchRoad(String id, double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) { return null; } diff --git a/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapUIController.java b/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapUIController.java index 18b6892bed..6060688593 100644 --- a/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapUIController.java +++ b/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapUIController.java @@ -355,10 +355,10 @@ public class MogoMapUIController implements IMogoMapUIController { } @Override - public double[] matchRoad( double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) { + public double[] matchRoad( String id, double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) { initDelegate(); if ( mDelegate != null ) { - return mDelegate.matchRoad( lon, lat, angle, isGpsLocation, isRTK ); + return mDelegate.matchRoad( id, lon, lat, angle, isGpsLocation, isRTK ); } return null; } diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/AdasRecognizedResultDrawer.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/AdasRecognizedResultDrawer.java index 255825d995..1c53fe9628 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/AdasRecognizedResultDrawer.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/AdasRecognizedResultDrawer.java @@ -188,8 +188,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer { final long start = System.currentTimeMillis(); - - double[] matchedPoint = SnapshotSetDataDrawer.getInstance().matchRoad( recognizedListResult.lon, + double[] matchedPoint = SnapshotSetDataDrawer.getInstance().matchRoad( recognizedListResult.uuid, recognizedListResult.lon, recognizedListResult.lat, recognizedListResult.heading, true diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/BaseDrawer.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/BaseDrawer.java index 2ca30509b3..cf50dafe33 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/BaseDrawer.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/BaseDrawer.java @@ -208,14 +208,14 @@ class BaseDrawer { * @param isRtk * @return */ - public double[] matchRoad( double lon, double lat, double angle, boolean isRtk ) { + public double[] matchRoad( String id, double lon, double lat, double angle, boolean isRtk ) { final long start = System.currentTimeMillis(); double[] matchRoad = MogoApisHandler.getInstance() .getApis() .getMapServiceApi() .getMapUIController() - .matchRoad( lon, lat, angle, true, isRtk ); - Log.i( "timer-matchRoad", "cost " + ( System.currentTimeMillis() - start ) + "ms" ); + .matchRoad( id, lon, lat, angle, true, isRtk ); + Log.i("timer-matchRoad", "cost " + (System.currentTimeMillis() - start) + "ms"); return matchRoad; } diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/SimpleHandlerThreadPool.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/SimpleHandlerThreadPool.java index d4f6c75781..8b24ba2358 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/SimpleHandlerThreadPool.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/SimpleHandlerThreadPool.java @@ -208,7 +208,8 @@ public class SimpleHandlerThreadPool { } } - double[] matchedPoint = SnapshotSetDataDrawer.getInstance().matchRoad( cloudRoadData.getWgslon(), + double[] matchedPoint = SnapshotSetDataDrawer.getInstance().matchRoad( cloudRoadData.getUniqueKey(), + cloudRoadData.getWgslon(), cloudRoadData.getWgslat(), cloudRoadData.getHeading(), true diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/MockIntentHandler.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/MockIntentHandler.java index b762c5df27..8b22c98493 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/MockIntentHandler.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/MockIntentHandler.java @@ -560,9 +560,9 @@ public class MockIntentHandler implements IntentHandler { break; case 47: mLocationMockHandler.sendEmptyMessageDelayed( 1, 200L ); -// mLocationMockHandler.sendEmptyMessageDelayed( 2, 0 ); + mLocationMockHandler.sendEmptyMessageDelayed( 2, 0 ); // mLocationMockHandler.sendEmptyMessageDelayed( 21, 200 ); - mLocationMockHandler.sendEmptyMessageDelayed( 3, 0L ); +// mLocationMockHandler.sendEmptyMessageDelayed( 3, 0L ); // mLocationMockHandler.sendEmptyMessageDelayed( 5, 0L ); break; case 48: @@ -763,7 +763,7 @@ public class MockIntentHandler implements IntentHandler { private boolean handleMockSnapshotIntent() throws Exception { if ( br2 == null ) { - br2 = new BufferedReader( new InputStreamReader( AbsMogoApplication.getApp().getAssets().open( "snapshot2.txt" ) ) ); + br2 = new BufferedReader( new InputStreamReader( AbsMogoApplication.getApp().getAssets().open( "snapshot.txt" ) ) ); } String line = br2.readLine(); if ( line == null ) { @@ -791,7 +791,7 @@ public class MockIntentHandler implements IntentHandler { delay = cloudRoadData.getSystemTime() - last; } last = cloudRoadData.getSystemTime(); - mLocationMockHandler.sendEmptyMessageDelayed( 2, delay ); + mLocationMockHandler.sendEmptyMessageDelayed( 2, 100L ); return true; }