This commit is contained in:
wangcongtao
2020-02-21 20:33:38 +08:00
parent 58fc32b0aa
commit 50d4463ac6

View File

@@ -5,6 +5,7 @@ import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Point;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Interpolator;
@@ -23,6 +24,7 @@ import com.amap.api.maps.model.animation.TranslateAnimation;
import com.amap.api.navi.AMapNaviView;
import com.amap.api.navi.AMapNaviViewListener;
import com.amap.api.navi.AMapNaviViewOptions;
import com.amap.api.navi.enums.AMapNaviViewShowMode;
import com.amap.api.navi.enums.AimLessMode;
import com.amap.api.navi.model.NaviInfo;
import com.mogo.map.IMogoMap;
@@ -49,16 +51,16 @@ import retrofit2.http.HEAD;
* 代理高德导航地图
*/
public class AMapNaviViewWrapper implements IMogoMapView,
IMogoMapUIController,
AMap.OnMarkerClickListener,
AMap.OnMapLoadedListener,
AMap.OnMapTouchListener,
AMap.OnPOIClickListener,
AMap.OnMapClickListener,
AMap.OnPolylineClickListener,
AMapNaviViewListener,
AMapMessageListener,
AMap.OnCameraChangeListener {
IMogoMapUIController,
AMap.OnMarkerClickListener,
AMap.OnMapLoadedListener,
AMap.OnMapTouchListener,
AMap.OnPOIClickListener,
AMap.OnMapClickListener,
AMap.OnPolylineClickListener,
AMapNaviViewListener,
AMapMessageListener,
AMap.OnCameraChangeListener {
private static final String TAG = "AMapNaviViewWrapper";
@@ -67,95 +69,95 @@ public class AMapNaviViewWrapper implements IMogoMapView,
private AMapMarkerClickHandler mMarkerClickHandler;
public AMapNaviViewWrapper(AMapNaviView mapView) {
public AMapNaviViewWrapper( AMapNaviView mapView ) {
this.mMapView = mapView;
this.mIMap = new AMapWrapper(mMapView.getMap(), mMapView, this);
this.mIMap = new AMapWrapper( mMapView.getMap(), mMapView, this );
}
private void initMapView() {
if (mMapView != null) {
if ( mMapView != null ) {
AMapNaviViewOptions options = mMapView.getViewOptions();
if (options != null) {
if ( options != null ) {
// 设置是否开启自动黑夜模式切换默认为false不自动切换
options.setAutoNaviViewNightMode(false);
options.setAutoNaviViewNightMode( false );
// 设置6秒后是否自动锁车
options.setAutoLockCar(false);
options.setAutoLockCar( false );
// 设置路线上的摄像头气泡是否显示
options.setCameraBubbleShow(true);
options.setCameraBubbleShow( true );
// 设置路线相关的配置属性,如:路线的路况颜色,路线上是否显示摄像头气泡等。
// options.setRouteOverlayOptions( MapStyleUtils.getRouteOverlayOptions() );
// 设置自车的图片对象
options.setCarBitmap(BitmapFactory.decodeResource(getContext().getResources(),
R.drawable.ic_amap_navi_cursor));
options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(),
R.drawable.ic_amap_navi_cursor ) );
// 设置指南针图标否在导航界面显示默认显示。true显示false隐藏。
options.setCompassEnabled(false);
options.setCompassEnabled( false );
// 黑夜模式
options.setNaviNight(true);
options.setNaviNight( true );
//设置路况光柱条是否显示(只适用于驾车导航,需要联网)。
options.setTrafficBarEnabled(false);
options.setTrafficBarEnabled( false );
// 设置[实时交通图层开关按钮]是否显示(只适用于驾车导航,需要联网)。
options.setTrafficLayerEnabled(false);
options.setTrafficLayerEnabled( false );
// 设置导航界面是否显示路线全览按钮。
options.setRouteListButtonShow(false);
options.setRouteListButtonShow( false );
// 设置导航状态下屏幕是否一直开启。
options.setScreenAlwaysBright(true);
options.setScreenAlwaysBright( true );
// 设置交通播报是否打开(只适用于驾车导航,需要联网)。
options.setTrafficInfoUpdateEnabled(true);
options.setTrafficInfoUpdateEnabled( true );
// 设置摄像头播报是否打开(只适用于驾车导航)。
options.setCameraInfoUpdateEnabled(true);
options.setCameraInfoUpdateEnabled( true );
// 设置菜单按钮是否在导航界面显示。
options.setSettingMenuEnabled(false);
options.setSettingMenuEnabled( false );
// 设置是否绘制显示交通路况的线路(彩虹线),拥堵-红色,畅通-绿色,缓慢-黄色,未知-蓝色。默认不绘制彩虹线。
options.setTrafficLine(true);
options.setTrafficLine( true );
// 设置是否绘制牵引线(当前位置到目的地的指引线)。默认不绘制牵引线。
options.setLeaderLineEnabled(-1);
options.setLeaderLineEnabled( -1 );
// 设置导航界面UI是否显示。
options.setLayoutVisible(false);
options.setLayoutVisible( false );
// 设置是否自动画路
options.setAutoDrawRoute(false);
options.setAutoDrawRoute( false );
// 设置是否显示路口放大图(实景图)
options.setRealCrossDisplayShow(false);
options.setRealCrossDisplayShow( false );
// 设置是否显示路口放大图(路口模型图)
options.setModeCrossDisplayShow(false);
options.setModeCrossDisplayShow( false );
// 设置是否显示道路信息view
options.setLaneInfoShow(false);
options.setLaneInfoShow( false );
// 设置是否自动改变缩放等级
options.setAutoChangeZoom(true);
options.setAutoChangeZoom( true );
// 设置是否自动全览模式,即在算路成功后自动进入全览模式
options.setAutoDisplayOverview(false);
options.setAutoDisplayOverview( false );
// 设置路线转向箭头隐藏和显示
options.setNaviArrowVisible(false);
options.setNaviArrowVisible( false );
// 通过路线是否自动置灰,仅支持驾车导航
options.setAfterRouteAutoGray(true);
options.setZoom(16);
options.setPointToCenter(0.5D, 0.5D);
options.setAfterRouteAutoGray( true );
options.setZoom( 16 );
options.setPointToCenter( 0.5D, 0.5D );
// 2D模式
options.setTilt(0);
mMapView.setViewOptions(options);
options.setTilt( 0 );
mMapView.setViewOptions( options );
}
mMapView.setRouteOverlayVisible(false);
mMapView.setCarOverlayVisible(false);
mMapView.setNaviMode(AMapNaviView.CAR_UP_MODE);
mMapView.setRouteOverlayVisible( false );
mMapView.setCarOverlayVisible( false );
mMapView.setNaviMode( AMapNaviView.CAR_UP_MODE );
}
}
private void initListeners() {
mMapView.setOnMarkerClickListener(this);
mMapView.setOnMarkerClickListener( this );
mMarkerClickHandler = new AMapMarkerClickHandler();
mMapView.setOnMapLoadedListener(this);
mMapView.setOnMapTouchListener(this);
mMapView.setOnPolylineClickListener(this);
mMapView.setAMapNaviViewListener(this);
mMapView.setOnCameraChangeListener(this);
mMapView.setOnMapLoadedListener( this );
mMapView.setOnMapTouchListener( this );
mMapView.setOnPolylineClickListener( this );
mMapView.setAMapNaviViewListener( this );
mMapView.setOnCameraChangeListener( this );
final AMap aMap = mMapView.getMap();
if (aMap != null) {
aMap.setOnPOIClickListener(this);
aMap.setOnMapClickListener(this);
aMap.setOnCameraChangeListener(this);
if ( aMap != null ) {
aMap.setOnPOIClickListener( this );
aMap.setOnMapClickListener( this );
aMap.setOnCameraChangeListener( this );
}
AMapMessageManager.getInstance().registerAMapMessageListener(this);
AMapMessageManager.getInstance().registerAMapMessageListener( this );
}
private Context getContext() {
@@ -173,10 +175,10 @@ public class AMapNaviViewWrapper 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" );
initMapView();
initListeners();
initMyLocation();
@@ -185,47 +187,47 @@ public class AMapNaviViewWrapper implements IMogoMapView,
@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();
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" );
}
}
@Override
public void onLowMemory() {
Logger.d(TAG, "map onLowMemory");
Logger.d( TAG, "map onLowMemory" );
}
/**
* 地图marker点击
*/
@Override
public boolean onMarkerClick(Marker marker) {
return mMarkerClickHandler.handleMarkerClicked(marker);
public boolean onMarkerClick( Marker marker ) {
return mMarkerClickHandler.handleMarkerClicked( marker );
}
/**
@@ -240,32 +242,32 @@ public class AMapNaviViewWrapper implements IMogoMapView,
* 地图点击回调
*/
@Override
public void onTouch(MotionEvent motionEvent) {
MogoMapListenerHandler.getInstance().onTouch(motionEvent);
public void onTouch( MotionEvent motionEvent ) {
MogoMapListenerHandler.getInstance().onTouch( motionEvent );
}
/**
* POI 点击
*/
@Override
public void onPOIClick(Poi poi) {
if (InterceptorHandler.getInstance().ignorePoiClicked(getContext())) {
public void onPOIClick( Poi poi ) {
if ( InterceptorHandler.getInstance().ignorePoiClicked( getContext() ) ) {
return;
}
MogoMapListenerHandler.getInstance().onPOIClick(ObjectUtils.fromAMap(poi));
MogoMapListenerHandler.getInstance().onPOIClick( ObjectUtils.fromAMap( poi ) );
}
@Override
public void onMapClick(LatLng latLng) {
if (InterceptorHandler.getInstance().ignoreMapClicked(getContext())) {
public void onMapClick( LatLng latLng ) {
if ( InterceptorHandler.getInstance().ignoreMapClicked( getContext() ) ) {
return;
}
MogoMapListenerHandler.getInstance().onMapClick(ObjectUtils.fromAMap(latLng));
MogoMapListenerHandler.getInstance().onMapClick( ObjectUtils.fromAMap( latLng ) );
}
@Override
public void onPolylineClick(Polyline polyline) {
NaviClient.getInstance(getContext()).handleClickedPolyline(polyline);
public void onPolylineClick( Polyline polyline ) {
NaviClient.getInstance( getContext() ).handleClickedPolyline( polyline );
}
@Override
@@ -287,8 +289,8 @@ public class AMapNaviViewWrapper implements IMogoMapView,
* @param mode 0:车头朝上状态1:正北朝上模式
*/
@Override
public void onNaviMapMode(int mode) {
Logger.i(TAG, "mode=" + mode);
public void onNaviMapMode( int mode ) {
Logger.i( TAG, "mode=" + mode );
}
@Override
@@ -307,8 +309,9 @@ public class AMapNaviViewWrapper implements IMogoMapView,
}
@Override
public void onLockMap(boolean isLock) {
MogoMapListenerHandler.getInstance().onLockMap(isLock);
public void onLockMap( boolean isLock ) {
Logger.d( TAG, "lock status = %s", isLock );
MogoMapListenerHandler.getInstance().onLockMap( isLock );
}
@Override
@@ -317,138 +320,152 @@ public class AMapNaviViewWrapper implements IMogoMapView,
}
@Override
public void onMapTypeChanged(int type) {
if (type == 4) {
MogoMapListenerHandler.getInstance().onMapModeChanged(EnumMapUI.Type_Light);
} else if (type == 3) {
MogoMapListenerHandler.getInstance().onMapModeChanged(EnumMapUI.Type_Night);
public void onMapTypeChanged( int type ) {
if ( type == 4 ) {
MogoMapListenerHandler.getInstance().onMapModeChanged( EnumMapUI.Type_Light );
} else if ( type == 3 ) {
MogoMapListenerHandler.getInstance().onMapModeChanged( EnumMapUI.Type_Night );
}
}
@Override
public void onNaviViewShowMode(int i) {
public void onNaviViewShowMode( int i ) {
}
@Override
public void setTrafficEnabled(boolean visible) {
if (checkAMapView()) {
mMapView.setTrafficLine(visible);
long delay = mMapView.getViewOptions().getLockMapDelayed();
switch ( i ) {
case AMapNaviViewShowMode.SHOW_MODE_DEFAULT:
Logger.d( TAG, "普通模式" );
break;
case AMapNaviViewShowMode.SHOW_MODE_DISPLAY_OVERVIEW:
Logger.d( TAG, "全览模式" );
break;
case AMapNaviViewShowMode.SHOW_MODE_LOCK_CAR:
Logger.d( TAG, "锁车模式: %s", delay );
break;
}
}
@Override
public void changeZoom(boolean zoom) {
if (checkAMapView()) {
if (zoom) {
public void setTrafficEnabled( boolean visible ) {
if ( checkAMapView() ) {
mMapView.setTrafficLine( visible );
}
}
@Override
public void changeZoom( boolean zoom ) {
if ( checkAMapView() ) {
if ( zoom ) {
mMapView.zoomIn();
} else {
mMapView.zoomOut();
}
Logger.i(TAG, "mapview zoom = " + mMapView.getMap().getCameraPosition().zoom);
Logger.i(TAG, "scalePerPixel = " + getMap().getScalePerPixel());
Logger.i( TAG, "mapview zoom = " + mMapView.getMap().getCameraPosition().zoom );
Logger.i( TAG, "scalePerPixel = " + getMap().getScalePerPixel() );
}
}
@Override
public void changeZoom(float zoom) {
public void changeZoom( float zoom ) {
Logger.d( TAG, "changeZoom %s", zoom );
getMap().changeZoom(zoom);
mockTouchEvent();
getMap().changeZoom( zoom );
}
@Override
public void changeMapMode(EnumMapUI ui) {
if (ui == null) {
public void changeMapMode( EnumMapUI ui ) {
if ( ui == null ) {
return;
}
if (checkAMapView()) {
if ( checkAMapView() ) {
AMapNaviViewOptions options = mMapView.getViewOptions();
if (options == null) {
if ( options == null ) {
options = new AMapNaviViewOptions();
}
switch (ui) {
switch ( ui ) {
case CarUp_2D:
options.setTilt(0);
mMapView.setNaviMode(AMapNaviView.CAR_UP_MODE);
options.setTilt( 0 );
mMapView.setNaviMode( AMapNaviView.CAR_UP_MODE );
break;
case CarUp_3D:
options.setTilt(60);
mMapView.setNaviMode(AMapNaviView.CAR_UP_MODE);
options.setTilt( 60 );
mMapView.setNaviMode( AMapNaviView.CAR_UP_MODE );
break;
case NorthUP_2D:
options.setTilt(0);
mMapView.setNaviMode(AMapNaviView.NORTH_UP_MODE);
options.setTilt( 0 );
mMapView.setNaviMode( AMapNaviView.NORTH_UP_MODE );
break;
case Type_Light:
options.setNaviNight(false);
options.setNaviNight( false );
break;
case Type_Night:
options.setNaviNight(true);
options.setNaviNight( true );
break;
case Type_AUTO_LIGHT_Night:
options.setNaviNight(false);
options.setAutoNaviViewNightMode(true);
options.setNaviNight( false );
options.setAutoNaviViewNightMode( true );
break;
}
mMapView.setViewOptions(options);
mMapView.setViewOptions( options );
}
}
private boolean checkAMapView() {
if (mMapView == null) {
Logger.e(TAG, "高德mapView实例为空请检查");
if ( mMapView == null ) {
Logger.e( TAG, "高德mapView实例为空请检查" );
return false;
}
return true;
}
@Override
public void moveToCenter(MogoLatLng latLng) {
public void moveToCenter( MogoLatLng latLng ) {
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");
if ( latLng == null || latLng.lat == 0.0d || latLng.lng == 0.0d ) {
Logger.e( TAG, "latlng = null or is illegal" );
return;
}
mockTouchEvent();
mMapView.getMap()
.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(latLng.lat, latLng.lng)));
.moveCamera( CameraUpdateFactory.newLatLng( new LatLng( latLng.lat, latLng.lng ) ) );
}
@Override
public void showMyLocation(boolean visible) {
if (checkAMapView()) {
public void showMyLocation( boolean visible ) {
if ( checkAMapView() ) {
MyLocationStyle style = mMapView.getMap().getMyLocationStyle();
style.showMyLocation(visible);
mMapView.getMap().setMyLocationStyle(style);
style.showMyLocation( visible );
mMapView.getMap().setMyLocationStyle( style );
}
}
public void initMyLocation() {
if (checkAMapView()) {
mMapView.getMap().setMyLocationEnabled(true);
if ( checkAMapView() ) {
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.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 );
style.myLocationIcon(
BitmapDescriptorFactory.fromResource(R.drawable.map_api_ic_current_location2));
mMapView.getMap().setMyLocationStyle(style);
BitmapDescriptorFactory.fromResource( R.drawable.map_api_ic_current_location2 ) );
mMapView.getMap().setMyLocationStyle( style );
}
}
@Override
public void recoverLockMode() {
if (checkAMapView()) {
if ( checkAMapView() ) {
mMapView.recoverLockMode();
}
}
@Override
public void displayOverview() {
if (checkAMapView()) {
if (NaviClient.getInstance(getContext()).isNaviing()) {
if ( checkAMapView() ) {
if ( NaviClient.getInstance( getContext() ).isNaviing() ) {
mMapView.displayOverview();
}
}
@@ -466,37 +483,37 @@ public class AMapNaviViewWrapper implements IMogoMapView,
@Override
public void onNaviStarted() {
if (checkAMapView()) {
mMapView.setCarOverlayVisible(true);
if ( checkAMapView() ) {
mMapView.setCarOverlayVisible( true );
showMyLocation( false );
}
}
@Override
public void onNaviStopped() {
if (checkAMapView()) {
mMapView.setCarOverlayVisible(false);
showMyLocation(true);
NaviClient.getInstance(getContext()).startAimlessMode(AimLessMode.CAMERA_AND_SPECIALROAD_DETECTED);
if ( checkAMapView() ) {
mMapView.setCarOverlayVisible( false );
showMyLocation( true );
NaviClient.getInstance( getContext() ).startAimlessMode( AimLessMode.CAMERA_AND_SPECIALROAD_DETECTED );
}
}
@Override
public void onNaviInfoUpdat(NaviInfo naviInfo) {
public void onNaviInfoUpdat( NaviInfo naviInfo ) {
}
@Override
public void onCameraChange(CameraPosition cameraPosition) {
public void onCameraChange( CameraPosition cameraPosition ) {
}
@Override
public void onCameraChangeFinish(CameraPosition cameraPosition) {
if (cameraPosition != null) {
public void onCameraChangeFinish( CameraPosition cameraPosition ) {
if ( cameraPosition != null ) {
MogoMapListenerHandler.getInstance()
.onMapChanged(ObjectUtils.fromAMap(cameraPosition.target), cameraPosition.zoom,
cameraPosition.tilt, cameraPosition.bearing);
.onMapChanged( ObjectUtils.fromAMap( cameraPosition.target ), cameraPosition.zoom,
cameraPosition.tilt, cameraPosition.bearing );
}
}
@@ -504,8 +521,8 @@ public class AMapNaviViewWrapper implements IMogoMapView,
public MogoLatLng getCameraNorthEastPosition() {
try {
return ObjectUtils.fromAMap(
mMapView.getMap().getProjection().getVisibleRegion().latLngBounds.northeast);
} catch (Exception e) {
mMapView.getMap().getProjection().getVisibleRegion().latLngBounds.northeast );
} catch ( Exception e ) {
}
return null;
@@ -515,8 +532,8 @@ public class AMapNaviViewWrapper implements IMogoMapView,
public MogoLatLng getCameraSouthWestPosition() {
try {
return ObjectUtils.fromAMap(
mMapView.getMap().getProjection().getVisibleRegion().latLngBounds.southwest);
} catch (Exception e) {
mMapView.getMap().getProjection().getVisibleRegion().latLngBounds.southwest );
} catch ( Exception e ) {
}
return null;
@@ -525,30 +542,30 @@ public class AMapNaviViewWrapper implements IMogoMapView,
@Override
public MogoLatLng getWindowCenterLocation() {
try {
return ObjectUtils.fromAMap(mMapView.getMap().getCameraPosition().target);
} catch (Exception e) {
return ObjectUtils.fromAMap( mMapView.getMap().getCameraPosition().target );
} catch ( Exception e ) {
}
return null;
}
@Override
public void setPointToCenter(double mapCenterX, double mapCenterY) {
if (checkAMapView()) {
public void setPointToCenter( double mapCenterX, double mapCenterY ) {
if ( checkAMapView() ) {
AMapNaviViewOptions options = mMapView.getViewOptions();
options.setPointToCenter(mapCenterX, mapCenterY);
mMapView.setViewOptions(options);
options.setPointToCenter( mapCenterX, mapCenterY );
mMapView.setViewOptions( options );
}
}
@Override
public Point getLocationPointInScreen(MogoLatLng latLng) {
if (checkAMapView()) {
public Point getLocationPointInScreen( MogoLatLng latLng ) {
if ( checkAMapView() ) {
try {
return mMapView.getMap()
.getProjection()
.toScreenLocation(ObjectUtils.fromMogo2(latLng));
} catch (Exception e) {
.getProjection()
.toScreenLocation( ObjectUtils.fromMogo2( latLng ) );
} catch ( Exception e ) {
return null;
}
}
@@ -556,12 +573,12 @@ public class AMapNaviViewWrapper implements IMogoMapView,
}
@Override
public MogoLatLng getLocationMogoLatLngInScreen(Point point) {
if (checkAMapView()) {
public MogoLatLng getLocationMogoLatLngInScreen( Point point ) {
if ( checkAMapView() ) {
try {
return ObjectUtils.fromAMap(
mMapView.getMap().getProjection().fromScreenLocation(point));
} catch (Exception e) {
mMapView.getMap().getProjection().fromScreenLocation( point ) );
} catch ( Exception e ) {
return null;
}
}
@@ -569,28 +586,41 @@ public class AMapNaviViewWrapper 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 {
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);
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 animation = new TranslateAnimation( target );
animation.setInterpolator( interpolator );
//整个移动所需要的时间
animation.setDuration(duration);
animation.setDuration( duration );
//设置动画
if (marker instanceof AMapMarkerWrapper) {
((AMapMarkerWrapper) marker).getMarker().setAnimation(animation);
((AMapMarkerWrapper) marker).getMarker().startAnimation();
if ( marker instanceof AMapMarkerWrapper ) {
( ( 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." );
}
}
/**
* 模拟点击事件,达到锁车->普通事件
*/
private void mockTouchEvent(){
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 100;
int metaState = 0;
MotionEvent motionEvent = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, 0, 0, metaState);
mMapView.dispatchTouchEvent(motionEvent);
MotionEvent upEvent = MotionEvent.obtain(downTime + 100, eventTime + 100, MotionEvent.ACTION_UP, 0,0, metaState);
mMapView.dispatchTouchEvent(upEvent);
}
}