This commit is contained in:
wangcongtao
2020-04-13 11:18:35 +08:00
parent 45e480cefa
commit 798df646bf
7 changed files with 221 additions and 38 deletions

View File

@@ -14,7 +14,6 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Interpolator;
import com.alibaba.idst.nls.internal.utils.L;
import com.amap.api.maps.AMap;
import com.amap.api.maps.AMapUtils;
import com.amap.api.maps.CameraUpdateFactory;
@@ -47,6 +46,7 @@ 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.MapControlResult;
@@ -87,6 +87,11 @@ public class AMapNaviViewWrapper implements IMogoMapView,
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 AMapNaviViewWrapper( AMapNaviView mapView ) {
this.mMapView = mapView;
@@ -113,8 +118,7 @@ public class AMapNaviViewWrapper implements IMogoMapView,
// 设置路线相关的配置属性,如:路线的路况颜色,路线上是否显示摄像头气泡等。
// options.setRouteOverlayOptions( MapStyleUtils.getRouteOverlayOptions() );
// 设置自车的图片对象
options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(),
R.drawable.ic_amap_navi_cursor ) );
options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(), DEFAULT_OPTION.getNaviCursorRes() ) );
// 设置指南针图标否在导航界面显示默认显示。true显示false隐藏。
options.setCompassEnabled( false );
// 黑夜模式
@@ -463,10 +467,10 @@ public class AMapNaviViewWrapper implements IMogoMapView,
break;
case NorthUP_2D:
mMapView.setNaviMode( AMapNaviView.NORTH_UP_MODE );
break;
break;
}
Logger.d(TAG,"mCurrentUIMode--->"+mCurrentUIMode.name());
Logger.d( TAG, "mCurrentUIMode--->" + mCurrentUIMode.name() );
if ( options == null ) {
return;
}
@@ -517,7 +521,7 @@ public class AMapNaviViewWrapper implements IMogoMapView,
style.showMyLocation( visible );
if ( visible ) {
// 强制刷新一遍车标
style.myLocationIcon( BitmapDescriptorFactory.fromResource( R.drawable.map_api_ic_current_location2 ) );
style.myLocationIcon( BitmapDescriptorFactory.fromResource( mCarCursorOption.getCarCursorRes() ) );
}
mMapView.getMap().setMyLocationStyle( style );
}
@@ -840,4 +844,37 @@ public class AMapNaviViewWrapper implements IMogoMapView,
public synchronized boolean isCarLocked() {
return mIsCarLocked;
}
@Override
public void setCarCursorOption( CarCursorOption option ) {
if ( mCarCursorOption != null ) {
mCarCursorOption.destroy();
}
try {
mCarCursorOption = option.clone();
} catch ( CloneNotSupportedException e ) {
mCarCursorOption = DEFAULT_OPTION;
}
if ( !checkAMapView() ) {
return;
}
AMapNaviViewOptions options = mMapView.getViewOptions();
if ( options != null && mCarCursorOption.getNaviCursorRes() != 0 ) {
options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(), mCarCursorOption.getNaviCursorRes() ) );
mMapView.setViewOptions( options );
}
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() ) );
}
}
mMapView.getMap().setMyLocationStyle( style );
}
}

View File

@@ -9,6 +9,7 @@ import android.view.animation.Interpolator;
import com.mogo.map.MogoLatLng;
import com.mogo.map.MogoMap;
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.MapControlResult;
@@ -252,4 +253,11 @@ public class AMapUIController implements IMogoMapUIController {
}
return false;
}
@Override
public void setCarCursorOption( CarCursorOption option ) {
if ( mClient != null ) {
mClient.setCarCursorOption( option );
}
}
}

View File

@@ -0,0 +1,125 @@
package com.mogo.map.uicontroller;
import android.graphics.Bitmap;
import androidx.annotation.DrawableRes;
import com.mogo.map.IDestroyable;
/**
* @author congtaowang
* @since 2020-04-13
* <p>
* 设置自车图标
*/
public class CarCursorOption implements Cloneable, IDestroyable {
private CarCursorOption() {
}
/**
* 自车图标资源
*/
@DrawableRes
private int mCarCursorRes = 0;
/**
* 自车图标图片,优先使用
*/
private Bitmap mCarCursorBmp;
/**
* 导航图标资源
*/
@DrawableRes
private int mNaviCursorRes = 0;
public int getCarCursorRes() {
return mCarCursorRes;
}
public void setCarCursorRes( int carCursorRes ) {
this.mCarCursorRes = carCursorRes;
}
public Bitmap getCarCursorBmp() {
return mCarCursorBmp;
}
public void setCarCursorBmp( Bitmap carCursorBmp ) {
this.mCarCursorBmp = carCursorBmp;
}
public int getNaviCursorRes() {
return mNaviCursorRes;
}
public void setNaviCursorRes( int naviCursorRes ) {
this.mNaviCursorRes = naviCursorRes;
}
public static class Builder {
private CarCursorOption target;
public Builder() {
target = new CarCursorOption();
}
/**
* 自车图标资源
*/
public Builder carCursorRes( @DrawableRes int redId ) {
target.mCarCursorRes = redId;
return this;
}
/**
* 自车图标图片,优先使用
*/
public Builder carCursorBmp( Bitmap bmp ) {
target.mCarCursorBmp = bmp;
return this;
}
/**
* 导航图标资源
*
* @param naviCursorRes
* @return
*/
public Builder naviCursorRes( int naviCursorRes ) {
target.mNaviCursorRes = naviCursorRes;
return this;
}
public CarCursorOption build() {
return target;
}
}
@Override
public CarCursorOption clone() throws CloneNotSupportedException {
CarCursorOption option = ( CarCursorOption ) super.clone();
if ( mCarCursorBmp != null && !mCarCursorBmp.isRecycled() ) {
try {
option.mCarCursorBmp = Bitmap.createBitmap( mCarCursorBmp );
} catch ( Exception e ) {
option.mCarCursorBmp = null;
}
}
option.mCarCursorRes = mCarCursorRes;
option.mNaviCursorRes = mNaviCursorRes;
return option;
}
@Override
public void destroy() {
if ( mCarCursorBmp != null && !mCarCursorBmp.isRecycled() ) {
mCarCursorBmp.recycle();
}
mCarCursorBmp = null;
mCarCursorRes = 0;
mNaviCursorRes = 0;
}
}

View File

@@ -6,6 +6,8 @@ import android.location.Location;
import android.view.View;
import android.view.animation.Interpolator;
import androidx.annotation.DrawableRes;
import com.mogo.map.MogoLatLng;
import com.mogo.map.marker.IMogoMarker;
@@ -56,7 +58,6 @@ public interface IMogoMapUIController {
void showMyLocation( boolean visible );
/**
*
* @param view
*/
void showMyLocation( View view );
@@ -183,7 +184,15 @@ public interface IMogoMapUIController {
/**
* 锁车状态
*
* @return
*/
boolean isCarLocked();
/**
* 配置自车图标样式
*
* @param option
*/
void setCarCursorOption( CarCursorOption option );
}

View File

@@ -8,6 +8,7 @@ import android.view.animation.Interpolator;
import com.mogo.map.impl.amap.uicontroller.AMapUIController;
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.MapControlResult;
@@ -245,4 +246,11 @@ public class MogoMapUIController implements IMogoMapUIController {
}
return false;
}
@Override
public void setCarCursorOption( CarCursorOption option ) {
if ( mDelegate != null ) {
mDelegate.setCarCursorOption( option );
}
}
}