@@ -0,0 +1,778 @@
package com.mogo.map.impl.amap ;
import android.content.Context ;
import android.graphics.Color ;
import android.graphics.Point ;
import android.graphics.Rect ;
import android.location.Location ;
import android.os.Bundle ;
import android.os.SystemClock ;
import android.os.Trace ;
import android.util.Log ;
import android.view.MotionEvent ;
import android.view.View ;
import android.view.animation.Interpolator ;
import com.amap.api.maps.AMap ;
import com.amap.api.maps.AMapUtils ;
import com.amap.api.maps.CameraUpdateFactory ;
import com.amap.api.maps.MapView ;
import com.amap.api.maps.model.BitmapDescriptorFactory ;
import com.amap.api.maps.model.CameraPosition ;
import com.amap.api.maps.model.LatLng ;
import com.amap.api.maps.model.LatLngBounds ;
import com.amap.api.maps.model.Marker ;
import com.amap.api.maps.model.MyLocationStyle ;
import com.amap.api.maps.model.Poi ;
import com.amap.api.maps.model.Polyline ;
import com.amap.api.maps.model.animation.Animation ;
import com.amap.api.maps.model.animation.TranslateAnimation ;
import com.amap.api.navi.AMapNaviViewOptions ;
import com.amap.api.navi.model.NaviInfo ;
import com.mogo.commons.debug.DebugConfig ;
import com.mogo.map.IMogoMap ;
import com.mogo.map.IMogoMapView ;
import com.mogo.map.MogoLatLng ;
import com.mogo.map.impl.amap.hook.BnHooker ;
import com.mogo.map.impl.amap.marker.AMapMarkerWrapper ;
import com.mogo.map.impl.amap.message.AMapMessageListener ;
import com.mogo.map.impl.amap.message.AMapMessageManager ;
import com.mogo.map.impl.amap.navi.NaviClient ;
import com.mogo.map.impl.amap.utils.MogoMapUtils ;
import com.mogo.map.impl.amap.utils.ObjectUtils ;
import com.mogo.map.listener.MogoMapListenerHandler ;
import com.mogo.map.marker.IMogoMarker ;
import com.mogo.map.uicontroller.CarCursorOption ;
import com.mogo.map.uicontroller.EnumMapUI ;
import com.mogo.map.uicontroller.IMogoMapUIController ;
import com.mogo.map.uicontroller.MapCameraPosition ;
import com.mogo.map.uicontroller.MapControlResult ;
import com.mogo.utils.WindowUtils ;
import com.mogo.utils.logger.Logger ;
import java.util.List ;
/**
* @author congtaowang
* @since 2019-12-18
* <p>
* 代理高德导航地图
*/
public class AMapViewWrapper implements IMogoMapView ,
IMogoMapUIController ,
AMap . OnMarkerClickListener ,
AMap . OnMapLoadedListener ,
AMap . OnMapTouchListener ,
AMap . OnPOIClickListener ,
AMap . OnMapClickListener ,
AMap . OnPolylineClickListener ,
AMapMessageListener ,
AMap . OnCameraChangeListener ,
AMap . OnMyLocationChangeListener {
private static final String TAG = " AMapNaviViewWrapper " ;
private final MapView mMapView ;
private IMogoMap mIMap ;
private AMapMarkerClickHandler mMarkerClickHandler ;
private EnumMapUI mCurrentUIMode ;
private boolean mIsCarLocked = false ;
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 )
. build ( ) ;
private CarCursorOption mCarCursorOption = DEFAULT_OPTION ;
public AMapViewWrapper ( MapView mapView ) {
this . mMapView = mapView ;
this . mIMap = new AMapWrapper ( mMapView . getMap ( ) , mMapView . getContext ( ) , this ) ;
try {
new BnHooker ( mMapView . getMap ( ) , mapView . getContext ( ) ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
}
private void initMapView ( ) {
if ( mMapView = = null ) {
return ;
}
// AMapNaviViewOptions options = mMapView.getViewOptions();
// if ( options != null ) {
// // 设置是否开启自动黑夜模式切换, 默认为false, 不自动切换
// options.setAutoNaviViewNightMode( false );
// // 设置6秒后是否自动锁车
// options.setAutoLockCar( false );
// // 设置路线上的摄像头气泡是否显示
// options.setCameraBubbleShow( true );
// // 设置路线相关的配置属性,如:路线的路况颜色,路线上是否显示摄像头气泡等。
// // options.setRouteOverlayOptions( MapStyleUtils.getRouteOverlayOptions() );
// // 设置自车的图片对象
// options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(), DEFAULT_OPTION.getNaviCursorRes() ) );
// // 设置指南针图标否在导航界面显示, 默认显示。true, 显示; false, 隐藏。
// options.setCompassEnabled( false );
// // 黑夜模式
// options.setNaviNight( true );
// //设置路况光柱条是否显示(只适用于驾车导航,需要联网)。
// options.setTrafficBarEnabled( false );
// // 设置[实时交通图层开关按钮]是否显示(只适用于驾车导航,需要联网)。
// options.setTrafficLayerEnabled( false );
// // 设置导航界面是否显示路线全览按钮。
// options.setRouteListButtonShow( false );
// // 设置屏幕是否常亮,默认开启
// options.setScreenAlwaysBright( false );
// // 设置交通播报是否打开(只适用于驾车导航,需要联网)。
// options.setTrafficInfoUpdateEnabled( true );
// // 设置摄像头播报是否打开(只适用于驾车导航)。
// options.setCameraInfoUpdateEnabled( true );
// // 设置菜单按钮是否在导航界面显示。
// options.setSettingMenuEnabled( false );
// // 设置是否绘制显示交通路况的线路(彩虹线),拥堵-红色,畅通-绿色,缓慢-黄色,未知-蓝色。默认不绘制彩虹线。
// options.setTrafficLine( true );
// // 设置是否绘制牵引线(当前位置到目的地的指引线)。默认不绘制牵引线。
// options.setLeaderLineEnabled( -1 );
// // 设置导航界面UI是否显示。
// options.setLayoutVisible( false );
// // 设置是否自动画路
// options.setAutoDrawRoute( false );
// // 设置是否显示路口放大图(实景图)
// options.setRealCrossDisplayShow( false );
// // 设置是否显示路口放大图(路口模型图)
// options.setModeCrossDisplayShow( false );
// // 设置是否显示道路信息view
// options.setLaneInfoShow( false );
// // 设置是否自动改变缩放等级
// options.setAutoChangeZoom( false );
// // 设置是否自动全览模式,即在算路成功后自动进入全览模式
// options.setAutoDisplayOverview( false );
// // 设置路线转向箭头隐藏和显示
// options.setNaviArrowVisible( false );
// // 通过路线是否自动置灰,仅支持驾车导航
// options.setAfterRouteAutoGray( true );
// options.setZoom( ( ( int ) mDefaultZoomLevel ) );
// options.setPointToCenter( 0.7D, 0.5D );
// // 2D模式
// options.setTilt( 0 );
// mMapView.setViewOptions( options );
// }
// mMapView.setRouteOverlayVisible( false );
// mMapView.setCarOverlayVisible( false );
changeMapMode ( EnumMapUI . CarUp_2D ) ;
changeMapMode ( EnumMapUI . Type_Night ) ;
setTrafficEnabled ( true ) ;
mMapView . getMap ( ) . moveCamera ( CameraUpdateFactory . zoomTo ( mDefaultZoomLevel ) ) ;
}
private void initListeners ( ) {
mMarkerClickHandler = new AMapMarkerClickHandler ( ) ;
final AMap aMap = mMapView . getMap ( ) ;
if ( aMap ! = null ) {
aMap . setOnMarkerClickListener ( this ) ;
aMap . setOnMapLoadedListener ( this ) ;
aMap . setOnMapTouchListener ( this ) ;
aMap . setOnPolylineClickListener ( this ) ;
aMap . setOnCameraChangeListener ( this ) ;
aMap . setOnPOIClickListener ( this ) ;
aMap . setOnMapClickListener ( this ) ;
aMap . setOnCameraChangeListener ( this ) ;
aMap . setOnMyLocationChangeListener ( this ) ;
}
AMapMessageManager . getInstance ( ) . registerAMapMessageListener ( this ) ;
}
private Context getContext ( ) {
return mMapView . getContext ( ) ;
}
@Override
public View getMapView ( ) {
return mMapView ;
}
@Override
public IMogoMap getMap ( ) {
return mIMap ;
}
@Override
public void onCreate ( Bundle bundle ) {
if ( mMapView ! = null ) {
mMapView . onCreate ( bundle ) ;
Logger . d ( TAG , " map onCreate " ) ;
initMapView ( ) ;
initListeners ( ) ;
initMyLocation ( ) ;
}
}
@Override
public void onResume ( ) {
if ( mMapView ! = null ) {
mMapView . onResume ( ) ;
Logger . d ( TAG , " map onResume " ) ;
}
}
@Override
public void onPause ( ) {
if ( mMapView ! = null ) {
mMapView . onPause ( ) ;
Logger . d ( TAG , " map onPause " ) ;
}
}
@Override
public void onDestroy ( ) {
if ( mMapView ! = null ) {
mMapView . onDestroy ( ) ;
Logger . d ( TAG , " map onDestroy " ) ;
}
}
@Override
public void onSaveInstanceState ( Bundle outState ) {
if ( mMapView ! = null ) {
mMapView . onSaveInstanceState ( outState ) ;
Logger . d ( TAG , " map onSaveInstanceState " ) ;
}
}
@Override
public void onLowMemory ( ) {
Logger . d ( TAG , " map onLowMemory " ) ;
}
/**
* 地图marker点击
*/
@Override
public boolean onMarkerClick ( Marker marker ) {
return mMarkerClickHandler . handleMarkerClicked ( marker ) ;
}
/**
* 地图加载完毕
*/
@Override
public void onMapLoaded ( ) {
MogoMapListenerHandler . getInstance ( ) . onMapLoaded ( ) ;
}
/**
* 地图点击回调
*/
@Override
public void onTouch ( MotionEvent motionEvent ) {
MogoMapListenerHandler . getInstance ( ) . onTouch ( motionEvent ) ;
if ( mIsCarLocked ) {
loseLockMode ( ) ;
}
}
/**
* POI 点击
*/
@Override
public void onPOIClick ( Poi poi ) {
if ( InterceptorHandler . getInstance ( ) . ignorePoiClicked ( getContext ( ) ) ) {
return ;
}
MogoMapListenerHandler . getInstance ( ) . onPOIClick ( ObjectUtils . fromAMap ( poi ) ) ;
}
@Override
public void onMapClick ( LatLng latLng ) {
if ( InterceptorHandler . getInstance ( ) . ignoreMapClicked ( getContext ( ) ) ) {
return ;
}
MogoMapListenerHandler . getInstance ( ) . onMapClick ( ObjectUtils . fromAMap ( latLng ) ) ;
}
@Override
public void onPolylineClick ( Polyline polyline ) {
if ( ! NaviClient . getInstance ( getContext ( ) ) . isNaviing ( ) ) {
NaviClient . getInstance ( getContext ( ) ) . handleClickedPolyline ( polyline ) ;
}
}
@Override
public void setTrafficEnabled ( boolean visible ) {
if ( checkMapView ( ) ) {
mMapView . getMap ( ) . setTrafficEnabled ( true ) ;
}
}
@Override
public MapControlResult changeZoom ( boolean zoom ) {
if ( checkMapView ( ) ) {
mDefaultZoomLevel = ( int ) ( getMap ( ) . getZoomLevel ( ) + 0 . 5f ) ;
if ( zoom ) {
if ( mDefaultZoomLevel > = 20 ) {
return MapControlResult . TARGET ;
}
} else {
if ( mDefaultZoomLevel < = 3 ) {
return MapControlResult . TARGET ;
}
}
if ( zoom ) {
mDefaultZoomLevel + = 2f ;
if ( mDefaultZoomLevel > 20 ) {
mDefaultZoomLevel = 20 ;
}
} else {
mDefaultZoomLevel - = 2f ;
if ( mDefaultZoomLevel < 1 ) {
mDefaultZoomLevel = 1 ;
}
}
changeZoom ( ( int ) mDefaultZoomLevel ) ;
}
return MapControlResult . SUCCESS ;
}
@Override
public MapControlResult changeZoom ( float zoom ) {
Logger . d ( TAG , " changeZoom %s " , zoom ) ;
if ( DebugConfig . isDebug ( ) ) {
Logger . d ( TAG , Log . getStackTraceString ( new Throwable ( ) ) ) ;
}
getMap ( ) . changeZoom ( zoom ) ;
return MapControlResult . SUCCESS ;
}
@Override
public void changeMapMode ( EnumMapUI ui ) {
if ( ui = = null ) {
return ;
}
if ( checkMapView ( ) ) {
switch ( ui ) {
case CarUp_3D :
mMapView . getMap ( ) . moveCamera ( CameraUpdateFactory . changeTilt ( 60 ) ) ;
break ;
case NorthUP_2D :
case CarUp_2D :
mMapView . getMap ( ) . moveCamera ( CameraUpdateFactory . changeTilt ( 0 ) ) ;
break ;
case Type_Light :
mMapView . getMap ( ) . setMapType ( AMap . MAP_TYPE_NORMAL ) ;
break ;
case Type_Night :
mMapView . getMap ( ) . setMapType ( AMap . MAP_TYPE_NIGHT ) ;
break ;
case Type_AUTO_LIGHT_Night :
break ;
}
}
}
private boolean checkMapView ( ) {
if ( mMapView = = null ) {
Logger . e ( TAG , " 高德mapView实例为空, 请检查 " ) ;
return false ;
}
return true ;
}
@Override
public void moveToCenter ( MogoLatLng latLng , boolean animate ) {
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 ( ) ) ) ;
}
loseLockMode ( ) ;
if ( animate ) {
mMapView . getMap ( ) . animateCamera ( CameraUpdateFactory . newLatLng ( new LatLng ( latLng . lat , latLng . lng ) ) ) ;
} else {
mMapView . getMap ( ) . moveCamera ( CameraUpdateFactory . newLatLng ( new LatLng ( latLng . lat , latLng . lng ) ) ) ;
}
}
@Override
public void showMyLocation ( boolean visible ) {
Logger . d ( TAG , " showMyLocation1 %s " , visible ) ;
if ( visible & & NaviClient . getInstance ( getContext ( ) ) . isNaviing ( ) ) {
return ;
}
if ( DebugConfig . isDebug ( ) ) {
Logger . d ( TAG , Log . getStackTraceString ( new Throwable ( ) ) ) ;
}
if ( checkMapView ( ) ) {
MyLocationStyle style = mMapView . getMap ( ) . getMyLocationStyle ( ) ;
if ( style = = null ) {
style = new MyLocationStyle ( ) ;
}
style . showMyLocation ( visible ) ;
if ( visible ) {
// 强制刷新一遍车标
style . myLocationIcon ( BitmapDescriptorFactory . fromResource ( mCarCursorOption . getCarCursorRes ( ) ) ) ;
}
mMapView . getMap ( ) . setMyLocationStyle ( style ) ;
}
}
@Override
public void showMyLocation ( View view ) {
if ( NaviClient . getInstance ( getContext ( ) ) . isNaviing ( ) ) {
return ;
}
if ( DebugConfig . isDebug ( ) ) {
Logger . d ( TAG , Log . getStackTraceString ( new Throwable ( ) ) ) ;
}
if ( checkMapView ( ) ) {
MyLocationStyle style = mMapView . getMap ( ) . getMyLocationStyle ( ) ;
if ( style = = null ) {
style = new MyLocationStyle ( ) ;
}
style . showMyLocation ( true ) ;
style . myLocationIcon ( BitmapDescriptorFactory . fromView ( view ) ) ;
mMapView . getMap ( ) . setMyLocationStyle ( style ) ;
}
}
public void initMyLocation ( ) {
if ( checkMapView ( ) ) {
mMapView . getMap ( ) . setMyLocationEnabled ( true ) ;
MyLocationStyle style = mMapView . getMap ( ) . getMyLocationStyle ( ) ;
style . myLocationType ( MyLocationStyle . LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER ) ;
style . interval ( 1000 ) ;
style . anchor ( 0 . 5F , 0 . 5F ) ;
style . strokeColor ( Color . TRANSPARENT ) ;
style . strokeWidth ( 0 ) ;
style . radiusFillColor ( Color . TRANSPARENT ) ;
mMapView . getMap ( ) . setMyLocationStyle ( style ) ;
}
}
@Override
public void recoverLockMode ( ) {
if ( checkMapView ( ) ) {
if ( DebugConfig . isDebug ( ) ) {
Logger . d ( TAG , Log . getStackTraceString ( new Throwable ( ) ) ) ;
}
Logger . d ( TAG , " 锁车 " ) ;
MyLocationStyle style = mMapView . getMap ( ) . getMyLocationStyle ( ) ;
style . myLocationType ( MyLocationStyle . LOCATION_TYPE_FOLLOW ) ;
mMapView . getMap ( ) . setMyLocationStyle ( style ) ;
mIsCarLocked = true ;
}
}
@Override
public void loseLockMode ( ) {
if ( DebugConfig . isDebug ( ) ) {
Logger . d ( TAG , Log . getStackTraceString ( new Throwable ( ) ) ) ;
}
Logger . d ( TAG , " 解锁锁车 " ) ;
MyLocationStyle style = mMapView . getMap ( ) . getMyLocationStyle ( ) ;
style . myLocationType ( MyLocationStyle . LOCATION_TYPE_FOLLOW_NO_CENTER ) ;
mMapView . getMap ( ) . setMyLocationStyle ( style ) ;
mIsCarLocked = false ;
}
/**
* 模拟点击事件,达到锁车->普通事件
*/
private void mockTouchEvent ( ) {
long downTime = SystemClock . uptimeMillis ( ) ;
long eventTime = downTime + 1 ;
int metaState = 0 ;
MotionEvent motionEvent = MotionEvent . obtain ( downTime , eventTime , MotionEvent . ACTION_DOWN , 0 , 0 , metaState ) ;
mMapView . dispatchTouchEvent ( motionEvent ) ;
MotionEvent upEvent = MotionEvent . obtain ( downTime + 1 , eventTime + 2 , MotionEvent . ACTION_UP , 0 , 0 , metaState ) ;
mMapView . dispatchTouchEvent ( upEvent ) ;
}
@Override
public void setLockZoom ( int var1 ) {
if ( checkMapView ( ) ) {
if ( DebugConfig . isDebug ( ) ) {
Logger . d ( TAG , Log . getStackTraceString ( new Throwable ( ) ) ) ;
}
Logger . d ( TAG , " Zoom锁定锁车比例尺 %s " , var1 ) ;
// TODO: 2020/8/27 设置锁车比例尺
// mMapView.setLockZoom( var1 );
}
}
@Override
public void displayOverview ( Rect bounds ) {
if ( checkMapView ( ) ) {
if ( NaviClient . getInstance ( getContext ( ) ) . isNaviing ( ) ) {
loseLockMode ( ) ;
NaviClient . getInstance ( getContext ( ) ) . displayOverview ( bounds ) ;
}
}
}
@Override
public float getScalePerPixel ( ) {
return getMap ( ) . getScalePerPixel ( ) ;
}
@Override
public float getZoomLevel ( ) {
return getMap ( ) . getZoomLevel ( ) ;
}
@Override
public void onNaviStarted ( ) {
if ( checkMapView ( ) ) {
showMyLocation ( false ) ;
}
}
@Override
public void onNaviStopped ( ) {
if ( checkMapView ( ) ) {
showMyLocation ( true ) ;
NaviClient . getInstance ( getContext ( ) ) . startAimlessMode ( ) ;
}
}
@Override
public void onNaviInfoUpdat ( NaviInfo naviInfo ) {
}
@Override
public void onCalculateSuccess ( ) {
loseLockMode ( ) ;
}
@Override
public void onCameraChange ( CameraPosition cameraPosition ) {
}
@Override
public void onCameraChangeFinish ( CameraPosition cameraPosition ) {
if ( cameraPosition ! = null ) {
Trace . beginSection ( " timer.onCameraChangeFinish " ) ;
MogoMapListenerHandler . getInstance ( ) . onMapChanged ( ObjectUtils . fromAMap ( cameraPosition . target ) ,
cameraPosition . zoom ,
cameraPosition . tilt ,
cameraPosition . bearing ) ;
Trace . endSection ( ) ;
}
}
@Override
public MogoLatLng getCameraNorthEastPosition ( ) {
try {
return ObjectUtils . fromAMap ( mMapView . getMap ( ) . getProjection ( ) . getVisibleRegion ( ) . latLngBounds . northeast ) ;
} catch ( Exception e ) {
}
return null ;
}
@Override
public MogoLatLng getCameraSouthWestPosition ( ) {
try {
return ObjectUtils . fromAMap ( mMapView . getMap ( ) . getProjection ( ) . getVisibleRegion ( ) . latLngBounds . southwest ) ;
} catch ( Exception e ) {
}
return null ;
}
@Override
public MogoLatLng getWindowCenterLocation ( ) {
try {
return ObjectUtils . fromAMap ( mMapView . getMap ( ) . getCameraPosition ( ) . target ) ;
} catch ( Exception e ) {
}
return null ;
}
@Override
public void setPointToCenter ( double mapCenterX , double mapCenterY ) {
if ( checkMapView ( ) ) {
if ( DebugConfig . isDebug ( ) ) {
Logger . d ( TAG , Log . getStackTraceString ( new Throwable ( ) ) ) ;
}
Logger . d ( TAG , " setPointToCenter(%s, %s) " , mapCenterX , mapCenterY ) ;
mMapView . getMap ( ) . setPointToCenter ( ( ( int ) ( mapCenterX * WindowUtils . getScreenWidth ( getContext ( ) ) ) ) ,
( ( int ) ( mapCenterY * WindowUtils . getScreenHeight ( getContext ( ) ) ) ) ) ;
}
}
@Override
public Point getLocationPointInScreen ( MogoLatLng latLng ) {
if ( checkMapView ( ) ) {
try {
return mMapView . getMap ( )
. getProjection ( )
. toScreenLocation ( ObjectUtils . fromMogo2 ( latLng ) ) ;
} catch ( Exception e ) {
return null ;
}
}
return null ;
}
@Override
public MogoLatLng getLocationMogoLatLngInScreen ( Point point ) {
if ( checkMapView ( ) ) {
try {
return ObjectUtils . fromAMap (
mMapView . getMap ( ) . getProjection ( ) . fromScreenLocation ( point ) ) ;
} catch ( Exception e ) {
return null ;
}
}
return null ;
}
@Override
public void startJumpAnimation ( IMogoMarker marker , float high , Interpolator interpolator ,
long duration ) {
if ( marker = = null | | high < = 0 . 0f | | interpolator = = null | | duration < 0 ) {
return ;
}
try {
final LatLng latLng = ObjectUtils . fromMogo2 ( marker . getPosition ( ) ) ;
Point point = mMapView . getMap ( ) . getProjection ( ) . toScreenLocation ( latLng ) ;
point . y - = WindowUtils . dip2px ( getContext ( ) , high ) ;
LatLng target = mMapView . getMap ( ) . getProjection ( ) . fromScreenLocation ( point ) ;
//使用TranslateAnimation,填写一个需要移动的目标点
Animation animation = new TranslateAnimation ( target ) ;
animation . setInterpolator ( interpolator ) ;
//整个移动所需要的时间
animation . setDuration ( duration ) ;
//设置动画
if ( marker instanceof AMapMarkerWrapper ) {
( ( AMapMarkerWrapper ) marker ) . getMarker ( ) . setAnimation ( animation ) ;
( ( AMapMarkerWrapper ) marker ) . getMarker ( ) . startAnimation ( ) ;
}
} catch ( Exception e ) {
Logger . e ( TAG , e , " error. " ) ;
}
}
@Override
public void setRenderFps ( int fps ) {
if ( checkMapView ( ) ) {
if ( mMapView . getMap ( ) ! = null ) {
mMapView . getMap ( ) . setRenderFps ( fps ) ;
Logger . d ( TAG , " 设置刷新帧率 fps = %s " , fps ) ;
}
}
}
@Override
public void showBounds ( String tag , MogoLatLng carPosition , List < MogoLatLng > lonLats , Rect bound , boolean lockCarPosition ) {
if ( ! checkMapView ( ) ) {
return ;
}
try {
if ( DebugConfig . isDebug ( ) ) {
Logger . d ( TAG , Log . getStackTraceString ( new Throwable ( ) ) ) ;
}
LatLngBounds latLngBounds = MogoMapUtils . getLatLngBounds ( carPosition , lonLats , lockCarPosition ) ;
if ( ! lockCarPosition ) {
loseLockMode ( ) ;
}
mMapView . getMap ( ) . moveCamera ( CameraUpdateFactory . newLatLngBoundsRect ( latLngBounds , bound . left , bound . right , bound . top , bound . bottom ) ) ;
} catch ( Exception e ) {
Logger . e ( TAG , e , " %s error. " , tag ) ;
}
}
@Override
public void forceRender ( ) {
if ( checkMapView ( ) ) {
mMapView . getMap ( ) . runOnDrawFrame ( ) ;
}
}
@Override
public float calculateLineDistance ( MogoLatLng p1 , MogoLatLng p2 ) throws Exception {
if ( p1 = = null | | p2 = = null ) {
throw new Exception ( " 计算距离的点不能为 null " ) ;
}
return AMapUtils . calculateLineDistance ( ObjectUtils . fromMogo2 ( p1 ) , ObjectUtils . fromMogo2 ( p2 ) ) ;
}
@Override
public void onMyLocationChange ( Location location ) {
NaviClient . getInstance ( getContext ( ) ) . syncCarLocation ( location ) ;
}
@Override
public EnumMapUI getCurrentUiMode ( ) {
return mCurrentUIMode ;
}
@Override
public void changeMyLocation ( Location location ) {
}
@Override
public synchronized boolean isCarLocked ( ) {
return mIsCarLocked ;
}
@Override
public void setCarCursorOption ( CarCursorOption option ) {
if ( mCarCursorOption ! = null & & mCarCursorOption ! = DEFAULT_OPTION ) {
mCarCursorOption . destroy ( ) ;
}
if ( option ! = null ) {
try {
mCarCursorOption = option . clone ( ) ;
} catch ( Exception e ) {
mCarCursorOption = DEFAULT_OPTION ;
}
} else {
mCarCursorOption = DEFAULT_OPTION ;
}
if ( ! checkMapView ( ) ) {
return ;
}
if ( mMapView . getMap ( ) = = null ) {
return ;
}
MyLocationStyle style = mMapView . getMap ( ) . getMyLocationStyle ( ) ;
if ( mCarCursorOption . getCarCursorBmp ( ) ! = null & & ! mCarCursorOption . getCarCursorBmp ( ) . isRecycled ( ) ) {
style . myLocationIcon ( BitmapDescriptorFactory . fromBitmap ( mCarCursorOption . getCarCursorBmp ( ) ) ) ;
} else {
if ( mCarCursorOption . getCarCursorRes ( ) ! = 0 ) {
style . myLocationIcon ( BitmapDescriptorFactory . fromResource ( mCarCursorOption . getCarCursorRes ( ) ) ) ;
} else {
style . myLocationIcon ( BitmapDescriptorFactory . fromResource ( DEFAULT_OPTION . getCarCursorRes ( ) ) ) ;
}
}
mMapView . getMap ( ) . setMyLocationStyle ( style ) ;
}
@Override
public MapCameraPosition getMapCameraPosition ( ) {
if ( checkMapView ( ) ) {
CameraPosition cameraPosition = mMapView . getMap ( ) . getCameraPosition ( ) ;
return ObjectUtils . fromAMap ( cameraPosition ) ;
}
return null ;
}
@Override
public void changeBearing ( float bearing ) {
if ( checkMapView ( ) ) {
mMapView . getMap ( ) . moveCamera ( CameraUpdateFactory . changeBearing ( bearing ) ) ;
}
}
}