From 4d2a1d1a9190ce2168adabebfcf116148de8c303 Mon Sep 17 00:00:00 2001 From: tongchenfei Date: Thu, 11 Mar 2021 11:53:19 +0800 Subject: [PATCH] opt road cache --- libraries/map-custom/build.gradle | 2 +- .../mogo/map/impl/custom/AMapViewWrapper.java | 687 +++++++++--------- .../custom/utils/PointInterpolatorUtil.java | 63 +- 3 files changed, 404 insertions(+), 348 deletions(-) diff --git a/libraries/map-custom/build.gradle b/libraries/map-custom/build.gradle index 66f58cc70e..6537b666f1 100644 --- a/libraries/map-custom/build.gradle +++ b/libraries/map-custom/build.gradle @@ -67,7 +67,7 @@ dependencies { implementation project(':foudations:mogo-commons') } - implementation 'com.zhidaoauto.machine:map:1.0.0-vr-8.2.6' + implementation 'com.zhidaoauto.machine:map:1.0.0-vr-8.2.9' // implementation 'com.zhidaoauto.machine:map:1.0.0-vr-test-3.4' } 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 26b59a6e85..7dfd1b4941 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 @@ -17,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; @@ -56,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; @@ -70,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; @@ -99,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; @@ -112,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() { @@ -129,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秒后是否自动锁车 @@ -144,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(); // 黑夜模式 @@ -198,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 ); @@ -240,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"); } } @@ -292,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; } @@ -376,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) { } @@ -525,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; @@ -541,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; } } @@ -572,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; } } @@ -585,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 { @@ -605,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)); } @@ -664,7 +658,7 @@ public class AMapViewWrapper implements IMogoMapView, } @Override - public void changeMyLocation( Location location ) { + public void changeMyLocation(Location location) { } @Override @@ -673,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(); @@ -842,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 @@ -899,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 ) { @@ -919,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 ) { @@ -937,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(); } - } ); + }); } } @@ -956,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); } } } @@ -978,59 +972,59 @@ 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(); } } @@ -1038,12 +1032,16 @@ public class AMapViewWrapper implements IMogoMapView, Map roadCacheMap = new ArrayMap<>(); @Override - public double[] matchRoad( String id, 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(); RoadCacheWrapper roadCache = roadCacheMap.get(id); - if(roadCache == null){ - SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad( ( ( float ) wgs[0] ), ( ( float ) wgs[1] ), ( ( float ) angle ), isGpsLocation, isRTK ); + 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()); @@ -1051,23 +1049,28 @@ public class AMapViewWrapper implements IMogoMapView, } Log.i("timer-matchRoad-1", "cost " + (System.currentTimeMillis() - start) + "ms"); - if ( roadCache != null + if (roadCache != null && roadCache.getRoad() != null - && !roadCache.getRoad().isEmpty() ) { + && !roadCache.getRoad().isEmpty()) { start = System.currentTimeMillis(); - double matchedPoint[] = PointInterpolatorUtil.mergeToRoad( wgs[0], wgs[1], roadCache.getRoad() ); - if(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); + 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); - return matchedPoint; + 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); @@ -1075,12 +1078,12 @@ public class AMapViewWrapper implements IMogoMapView, } @Override - public String getMarkerInfoResName( String speedVal ) { + public String getMarkerInfoResName(String speedVal) { return null; } @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/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}; }