This commit is contained in:
wangcongtao
2019-12-30 16:35:51 +08:00
parent 9b93caefda
commit 5752829cf3
128 changed files with 7092 additions and 491 deletions

View File

@@ -6,5 +6,7 @@
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="a36b9f7b086fa3951bb35338a5a06dd3" />
<!--定位服务-->
<service android:name="com.amap.api.location.APSService" />
</application>
</manifest>

View File

@@ -3,6 +3,7 @@ package com.mogo.map.impl.amap;
import com.amap.api.maps.model.Marker;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.IMogoMarkerClickListener;
import com.mogo.map.marker.MogoMarkersHandler;
/**
* @author congtaowang
@@ -17,9 +18,11 @@ public class AMapMarkerClickHandler {
return false;
}
if ( marker.getObject() instanceof IMogoMarker ) {
final IMogoMarkerClickListener listener = ( ( IMogoMarker ) marker.getObject() ).getOnMarkerClickListener();
IMogoMarker mogoMarker = ( ( IMogoMarker ) marker.getObject() );
MogoMarkersHandler.getInstance().onMarkerClicked( mogoMarker );
final IMogoMarkerClickListener listener = mogoMarker.getOnMarkerClickListener();
if ( listener != null ) {
return listener.onMarkerClicked( ( ( IMogoMarker ) marker.getObject() ) );
return listener.onMarkerClicked( mogoMarker );
}
}
return false;

View File

@@ -2,6 +2,7 @@ package com.mogo.map.impl.amap;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
@@ -17,13 +18,15 @@ import com.amap.api.maps.model.Polyline;
import com.amap.api.navi.AMapNaviView;
import com.amap.api.navi.AMapNaviViewListener;
import com.amap.api.navi.AMapNaviViewOptions;
import com.amap.api.navi.model.NaviInfo;
import com.mogo.map.IMogoMap;
import com.mogo.map.IMogoMapView;
import com.mogo.map.impl.amap.location.ALocationClient;
import com.mogo.map.MogoLatLng;
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.ObjectUtils;
import com.mogo.map.listener.MogoMapListenerHandler;
import com.mogo.map.location.MogoLocation;
import com.mogo.map.uicontroller.EnumMapUI;
import com.mogo.map.uicontroller.IMogoMapUIController;
import com.mogo.utils.logger.Logger;
@@ -41,7 +44,8 @@ public class AMapNaviViewWrapper implements IMogoMapView, IMogoMapUIController,
AMap.OnPOIClickListener,
AMap.OnMapClickListener,
AMap.OnPolylineClickListener,
AMapNaviViewListener {
AMapNaviViewListener,
AMapMessageListener {
private static final String TAG = "AMapNaviViewWrapper";
@@ -70,7 +74,7 @@ public class AMapNaviViewWrapper implements IMogoMapView, IMogoMapUIController,
// 设置路线相关的配置属性,如:路线的路况颜色,路线上是否显示摄像头气泡等。
// options.setRouteOverlayOptions( MapStyleUtils.getRouteOverlayOptions() );
// 设置自车的图片对象
options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(), R.drawable.ic_search_poi_location ) );
options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(), R.drawable.ic_amap_navi_cursor ) );
// 设置指南针图标否在导航界面显示默认显示。true显示false隐藏。
options.setCompassEnabled( false );
//设置路况光柱条是否显示(只适用于驾车导航,需要联网)。
@@ -120,6 +124,7 @@ public class AMapNaviViewWrapper implements IMogoMapView, IMogoMapUIController,
}
mMapView.setRouteOverlayVisible( false );
mMapView.setCarOverlayVisible( false );
mMapView.setNaviMode( AMapNaviView.NORTH_UP_MODE );
}
}
@@ -135,6 +140,7 @@ public class AMapNaviViewWrapper implements IMogoMapView, IMogoMapUIController,
mMapView.getMap().setOnPOIClickListener( this );
mMapView.getMap().setOnMapClickListener( this );
}
AMapMessageManager.getInstance().registerAMapMessageListener( this );
}
private Context getContext() {
@@ -324,9 +330,16 @@ public class AMapNaviViewWrapper implements IMogoMapView, IMogoMapUIController,
} else {
mMapView.zoomOut();
}
Logger.i( TAG, "mapview zoom = " + mMapView.getMap().getCameraPosition().zoom );
Logger.i( TAG, "scalePerPixel = " + getMap().getScalePerPixel() );
}
}
@Override
public void changeZoom( float zoom ) {
getMap().changeZoom( zoom );
}
@Override
public void changeMapMode( EnumMapUI ui ) {
if ( ui == null ) {
@@ -370,11 +383,12 @@ public class AMapNaviViewWrapper implements IMogoMapView, IMogoMapUIController,
}
@Override
public void moveToCurrentLocation() {
MogoLocation location = ALocationClient.getInstance( getContext() ).getLastKnowLocation();
if ( location != null ) {
mMapView.getMap().animateCamera( CameraUpdateFactory.newLatLng( new LatLng( location.getLatitude(), location.getLongitude() ) ) );
public void moveToCenter( MogoLatLng latLng ) {
if ( latLng == null ) {
Logger.e( TAG, "latlng = null" );
return;
}
mMapView.getMap().animateCamera( CameraUpdateFactory.newLatLng( new LatLng( latLng.lat, latLng.lng ) ) );
}
@Override
@@ -383,7 +397,11 @@ public class AMapNaviViewWrapper implements IMogoMapView, IMogoMapUIController,
mMapView.getMap().setMyLocationEnabled( true );
MyLocationStyle style = mMapView.getMap().getMyLocationStyle();
style.showMyLocation( visible );
style.myLocationIcon( BitmapDescriptorFactory.fromResource( R.drawable.ic_search_poi_location ) );
style.myLocationType( MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER );
style.strokeColor( Color.TRANSPARENT );
style.strokeWidth( 0 );
style.radiusFillColor( Color.TRANSPARENT );
style.myLocationIcon( BitmapDescriptorFactory.fromResource( R.drawable.ic_current_location_cursor ) );
mMapView.getMap().setMyLocationStyle( style );
}
}
@@ -401,4 +419,28 @@ public class AMapNaviViewWrapper implements IMogoMapView, IMogoMapUIController,
mMapView.displayOverview();
}
}
@Override
public float getScalePerPixel() {
return getMap().getScalePerPixel();
}
@Override
public void onNaviStarted() {
if ( checkAMapView() ) {
mMapView.setCarOverlayVisible( true );
}
}
@Override
public void onNaviStopped() {
if ( checkAMapView() ) {
mMapView.setCarOverlayVisible( false );
}
}
@Override
public void onNaviInfoUpdat( NaviInfo naviInfo ) {
}
}

View File

@@ -4,25 +4,17 @@ import android.content.Context;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.amap.api.navi.AMapNaviView;
import com.amap.api.navi.AMapNaviViewOptions;
import com.amap.api.navi.model.AMapNaviMarkerOptions;
import com.mogo.map.IMogoMap;
import com.mogo.map.IMogoUiSettings;
import com.mogo.map.impl.amap.location.ALocationClient;
import com.mogo.map.impl.amap.marker.AMapInfoWindowAdapter;
import com.mogo.map.impl.amap.marker.AMapMarkerWrapper;
import com.mogo.map.impl.amap.utils.ObjectUtils;
import com.mogo.map.location.MogoLocation;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.map.marker.MogoMarkersHandler;
import com.mogo.map.uicontroller.EnumMapUI;
import com.mogo.map.uicontroller.IMogoMapUIController;
import com.mogo.utils.logger.Logger;
@@ -83,7 +75,7 @@ public class AMapWrapper implements IMogoMap {
Logger.e( TAG, "marker参数为空" );
return null;
}
final IMogoMarker mogoMarker = new AMapMarkerWrapper( mAMap.addMarker( markerOptions ) );
final IMogoMarker mogoMarker = new AMapMarkerWrapper( mAMap.addMarker( markerOptions ), options );
MogoMarkersHandler.getInstance().add( tag, mogoMarker );
return mogoMarker;
}
@@ -124,11 +116,12 @@ public class AMapWrapper implements IMogoMap {
if ( markers == null || markers.isEmpty() ) {
return null;
}
for ( Marker marker : markers ) {
for ( int i = 0; i < markers.size(); i++ ) {
Marker marker = markers.get( i );
if ( marker == null ) {
continue;
}
mogoMarkers.add( new AMapMarkerWrapper( marker ) );
mogoMarkers.add( new AMapMarkerWrapper( marker, options.get( i ) ) );
}
MogoMarkersHandler.getInstance().add( tag, mogoMarkers );
return mogoMarkers;
@@ -197,6 +190,21 @@ public class AMapWrapper implements IMogoMap {
}
}
@Override
public float getScalePerPixel() {
if ( checkAMap() ) {
return mAMap.getScalePerPixel();
}
return 0;
}
@Override
public void changeZoom( float zoom ) {
if ( checkAMap() ) {
mAMap.moveCamera( CameraUpdateFactory.zoomTo( zoom ) );
}
}
private boolean checkAMap() {
if ( mAMap == null ) {
Logger.e( TAG, "高德map实例为空请检查" );

View File

@@ -7,8 +7,8 @@ import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.mogo.map.impl.amap.utils.ObjectUtils;
import com.mogo.map.location.IMogoLocationListener;
import com.mogo.map.location.IMogoLocationClient;
import com.mogo.map.location.IMogoLocationListener;
import com.mogo.map.location.MogoLocation;
import com.mogo.utils.logger.Logger;
@@ -26,25 +26,19 @@ public class ALocationClient implements IMogoLocationClient {
private static final String TAG = "LocationClient";
private static volatile ALocationClient sInstance;
private static Set< IMogoLocationListener > sListeners = new HashSet<>( 10 );
private static MogoLocation sLastLocation = new MogoLocation();
private Set< IMogoLocationListener > sListeners = new HashSet<>( 10 );
private MogoLocation mLastLocation;
private AMapLocationListener mListener = new InternalLocationListener();
private ALocationClient( Context context ) {
private boolean mIsDestroyed = false;
public ALocationClient( Context context ) {
mClient = new AMapLocationClient( context );
mClient.setLocationListener( new InternalLocationListener() );
sLastLocation = ObjectUtils.fromAMap( mClient.getLastKnownLocation() );
}
public static ALocationClient getInstance( Context context ) {
if ( sInstance == null ) {
synchronized ( ALocationClient.class ) {
if ( sInstance == null ) {
sInstance = new ALocationClient( context );
}
}
mClient.setLocationListener( mListener );
mLastLocation = ObjectUtils.fromAMap( mClient.getLastKnownLocation() );
if ( mLastLocation != null ) {
mLastLocation = new MogoLocation();
}
return sInstance;
}
private AMapLocationClient mClient;
@@ -56,26 +50,38 @@ public class ALocationClient implements IMogoLocationClient {
@Override
public void start( long interval ) {
stop();
AMapLocationClientOption option = new AMapLocationClientOption();
option.setLocationMode( AMapLocationClientOption.AMapLocationMode.Hight_Accuracy );
option.setNeedAddress( true );
option.setInterval( interval );
if ( mClient != null ) {
mClient.setLocationOption( option );
if ( mIsDestroyed ) {
destroyWarming();
return;
}
if ( mClient != null ) {
AMapLocationClientOption option = new AMapLocationClientOption();
option.setLocationMode( AMapLocationClientOption.AMapLocationMode.Hight_Accuracy );
option.setNeedAddress( true );
option.setGpsFirst( true );
option.setInterval( interval );
mClient.setLocationOption( option );
mClient.startLocation();
}
mClient.startLocation();
}
@Override
public void stop() {
if ( mClient != null ) {
if ( mIsDestroyed ) {
destroyWarming();
return;
}
if ( mClient != null && mClient.isStarted() ) {
mClient.stopLocation();
}
}
@Override
public void addLocationListener( IMogoLocationListener listener ) {
if ( mIsDestroyed ) {
destroyWarming();
return;
}
if ( listener != null ) {
synchronized ( sListeners ) {
sListeners.add( listener );
@@ -85,6 +91,10 @@ public class ALocationClient implements IMogoLocationClient {
@Override
public void removeLocationListener( IMogoLocationListener listener ) {
if ( mIsDestroyed ) {
destroyWarming();
return;
}
if ( listener != null ) {
synchronized ( sListeners ) {
sListeners.remove( listener );
@@ -94,25 +104,52 @@ public class ALocationClient implements IMogoLocationClient {
@Override
public MogoLocation getLastKnowLocation() {
return sLastLocation;
if ( mIsDestroyed ) {
destroyWarming();
return null;
}
return mLastLocation;
}
private static class InternalLocationListener implements AMapLocationListener {
@Override
public synchronized void destroy() {
mIsDestroyed = true;
if ( sListeners != null ) {
sListeners.clear();
}
sListeners = null;
if ( mClient != null ) {
mClient.unRegisterLocationListener( mListener );
mClient.stopLocation();
mClient.onDestroy();
}
mClient = null;
mLastLocation = null;
}
private class InternalLocationListener implements AMapLocationListener {
@Override
public void onLocationChanged( AMapLocation aMapLocation ) {
if ( mIsDestroyed ) {
destroyWarming();
return;
}
if ( aMapLocation == null ||
aMapLocation.getLatitude() == 0.0D ||
aMapLocation.getLongitude() == 0.0D ) {
return;
}
Logger.d( TAG, aMapLocation.toString() );
sLastLocation = ObjectUtils.fromAMap( aMapLocation );
mLastLocation = ObjectUtils.fromAMap( aMapLocation );
synchronized ( sListeners ) {
Iterator< IMogoLocationListener > listenerIterator = sListeners.iterator();
while ( listenerIterator.hasNext() ) {
listenerIterator.next().onLocationChanged( sLastLocation.clone() );
listenerIterator.next().onLocationChanged( mLastLocation.clone() );
}
}
}
}
private void destroyWarming() {
Logger.w( TAG, "location client has destroyed." );
}
}

View File

@@ -1,6 +1,7 @@
package com.mogo.map.impl.amap.marker;
import android.graphics.Bitmap;
import android.view.View;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
@@ -12,9 +13,12 @@ import com.mogo.map.impl.amap.utils.ObjectUtils;
import com.mogo.map.marker.IMogoInfoWindowAdapter;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.IMogoMarkerClickListener;
import com.mogo.map.marker.IMogoMarkerIconViewCreator;
import com.mogo.map.marker.MogoMarkerOptions;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
/**
* @author congtaowang
@@ -22,7 +26,7 @@ import java.util.ArrayList;
* <p>
* 高德marker
*/
public class AMapMarkerWrapper implements IMogoMarker {
public class AMapMarkerWrapper implements IMogoMarker, Observer {
private Marker mMarker;
private Object mObject;
@@ -31,16 +35,33 @@ public class AMapMarkerWrapper implements IMogoMarker {
private boolean mIsDestroy = false;
public AMapMarkerWrapper( Marker marker ) {
private MogoMarkerOptions mMogoMarkerOptions;
private String mOwner;
public AMapMarkerWrapper( Marker marker, MogoMarkerOptions mogoMarkerOptions ) {
this.mMarker = marker;
if ( marker != null ) {
// 设置高德 marker 的object对象为 IMogoMarker 实例。!!!!
marker.setObject( this );
}
this.mMogoMarkerOptions = mogoMarkerOptions;
mMogoMarkerOptions.addObserver( this );
}
@Override
public void update( Observable o, Object arg ) {
if ( isDestroyed() ) {
return;
}
setMarkerOptions( mMogoMarkerOptions );
}
@Override
public void destroy() {
if ( mMogoMarkerOptions != null ) {
mMogoMarkerOptions.deleteObservers();
mMogoMarkerOptions = null;
}
if ( mMarker != null ) {
mMarker.destroy();
mMarker.setObject( null );
@@ -236,8 +257,28 @@ public class AMapMarkerWrapper implements IMogoMarker {
return mMogoInfoWindowAdapter;
}
@Override
public void setMarkerIconView( IMogoMarkerIconViewCreator creator ) {
if ( creator != null ) {
View iconView = creator.createView( this );
if ( iconView != null ) {
mMarker.setIcon( BitmapDescriptorFactory.fromView( iconView ) );
}
}
}
@Override
public boolean isDestroyed() {
return mIsDestroy;
}
@Override
public void setOwner( String mOwner ) {
this.mOwner = mOwner;
}
@Override
public String getOwner() {
return this.mOwner == null ? mMogoMarkerOptions.getOwner() : mOwner;
}
}

View File

@@ -0,0 +1,26 @@
package com.mogo.map.impl.amap.message;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import androidx.annotation.NonNull;
/**
* @author congtaowang
* @since 2019-12-28
* <p>
* 描述
*/
public class AMapMessageConsts {
/**
* 导航开始
*/
public static final int MSG_NAVI_START = 1000;
/**
* 取消导航
*/
public static final int MSG_NAVI_STOP = 1001;
}

View File

@@ -0,0 +1,18 @@
package com.mogo.map.impl.amap.message;
import com.amap.api.navi.model.NaviInfo;
/**
* @author congtaowang
* @since 2019-12-28
* <p>
* 消息回调
*/
public interface AMapMessageListener {
void onNaviStarted();
void onNaviStopped();
void onNaviInfoUpdat( NaviInfo naviInfo );
}

View File

@@ -0,0 +1,118 @@
package com.mogo.map.impl.amap.message;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import androidx.annotation.NonNull;
import com.amap.api.navi.model.NaviInfo;
import java.util.ArrayList;
import java.util.List;
/**
* @author congtaowang
* @since 2019-12-28
* <p>
* 描述
*/
public class AMapMessageManager {
private static volatile AMapMessageManager sInstance;
private List< AMapMessageListener > mListeners = new ArrayList<>();
private AMapMessageManager() {
}
public static AMapMessageManager getInstance() {
if ( sInstance == null ) {
synchronized ( AMapMessageManager.class ) {
if ( sInstance == null ) {
sInstance = new AMapMessageManager();
}
}
}
return sInstance;
}
public synchronized void release() {
sInstance = null;
}
public synchronized void registerAMapMessageListener( AMapMessageListener listener ) {
if ( !mListeners.contains( listener ) ) {
mListeners.add( listener );
}
}
public synchronized void unregisterAMapMessageListener( AMapMessageListener listener ) {
mListeners.remove( listener );
}
private Handler mHandler = new Handler( Looper.getMainLooper() ) {
@Override
public void handleMessage( @NonNull Message msg ) {
super.handleMessage( msg );
AMapMessageManager.this.handleMessage( msg );
}
};
public void sendMessage( Message msg ) {
if ( msg != null ) {
mHandler.sendMessage( msg );
}
}
public void sendMessage( int what ) {
sendMessage( what, null );
}
public void sendMessage( int what, Object obj ) {
Message msg = Message.obtain();
msg.what = what;
msg.obj = obj;
sendMessage( msg );
}
public void postNaviStarted() {
sendMessage( AMapMessageConsts.MSG_NAVI_START );
}
public void postNaviStopped() {
sendMessage( AMapMessageConsts.MSG_NAVI_STOP );
}
private synchronized void handleMessage( Message msg ) {
if ( msg == null ) {
return;
}
switch ( msg.what ) {
case AMapMessageConsts.MSG_NAVI_START:
handleNaviStartedMsg();
break;
case AMapMessageConsts.MSG_NAVI_STOP:
handleNaviStoppedMsg();
break;
}
}
private void handleNaviStartedMsg() {
if ( mListeners == null ) {
return;
}
for ( AMapMessageListener listener : mListeners ) {
listener.onNaviStarted();
}
}
private void handleNaviStoppedMsg() {
if ( mListeners == null ) {
return;
}
for ( AMapMessageListener listener : mListeners ) {
listener.onNaviStopped();
}
}
}

View File

@@ -6,8 +6,11 @@ import com.amap.api.maps.model.Polyline;
import com.amap.api.navi.AMapNavi;
import com.amap.api.navi.enums.NaviType;
import com.amap.api.navi.model.AMapCalcRouteResult;
import com.amap.api.navi.model.AMapNaviInfo;
import com.amap.api.navi.model.AMapNaviLocation;
import com.amap.api.navi.model.NaviInfo;
import com.mogo.map.impl.amap.AMapWrapper;
import com.mogo.map.impl.amap.message.AMapMessageManager;
import com.mogo.map.impl.amap.utils.ObjectUtils;
import com.mogo.map.navi.MogoNaviListenerHandler;
import com.mogo.utils.logger.Logger;
@@ -85,6 +88,7 @@ public class NaviListenerAdapter extends AMapNaviListenerAdapter {
mAMapNavi.startSpeak();
}
MogoNaviListenerHandler.getInstance().onStartNavi();
AMapMessageManager.getInstance().postNaviStarted();
}
@Override
@@ -92,6 +96,7 @@ public class NaviListenerAdapter extends AMapNaviListenerAdapter {
setNaviing( false );
setStopped( true );
MogoNaviListenerHandler.getInstance().onStopNavi();
AMapMessageManager.getInstance().postNaviStopped();
}
@Override
@@ -99,11 +104,13 @@ public class NaviListenerAdapter extends AMapNaviListenerAdapter {
setNaviing( false );
setStopped( true );
MogoNaviListenerHandler.getInstance().onStopNavi();
AMapMessageManager.getInstance().postNaviStopped();
}
@Override
public void onNaviInfoUpdate( NaviInfo naviInfo ) {
MogoNaviListenerHandler.getInstance().onNaviInfoUpdate( ObjectUtils.fromAMap( naviInfo ) );
mNaviOverlayHelper.handleNaviInfoUpdate( naviInfo );
}
@Override
@@ -121,17 +128,24 @@ public class NaviListenerAdapter extends AMapNaviListenerAdapter {
mNaviOverlayHelper.showCalculatedPaths();
}
@Override
public void onLocationChange( AMapNaviLocation aMapNaviLocation ) {
super.onLocationChange( aMapNaviLocation );
mNaviOverlayHelper.handlePassedLocation( aMapNaviLocation );
}
public void stopNavi() {
setStopped( true );
setNaviing( false );
mAMapNavi.stopNavi();
MogoNaviListenerHandler.getInstance().onStopNavi();
AMapMessageManager.getInstance().postNaviStopped();
mNaviOverlayHelper.clearCalculatedOverlay();
}
public void handleClickedPolyline( Polyline polyline ) {
if ( mNaviOverlayHelper != null ) {
mNaviOverlayHelper.handleClickedPolyline( polyline );
mNaviOverlayHelper.handleClickedPolyline( polyline, isNaviing() );
if ( isNaviing() ) {
mAMapNavi.stopNavi();
mAMapNavi.selectRouteId( mNaviOverlayHelper.getSelectedPathId() );

View File

@@ -9,7 +9,9 @@ import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.model.LatLngBounds;
import com.amap.api.maps.model.Polyline;
import com.amap.api.navi.AMapNavi;
import com.amap.api.navi.model.AMapNaviLocation;
import com.amap.api.navi.model.AMapNaviPath;
import com.amap.api.navi.model.NaviInfo;
import com.mogo.map.impl.amap.R;
import com.mogo.map.impl.amap.overlay.RouteOverLayWrapper;
import com.mogo.utils.WindowUtils;
@@ -50,6 +52,7 @@ public class NaviOverlayHelper {
private List< CalculatePathItem > mCalculatePathItems;
private int mSelectedPathId;
private CalculatePathItem mSelectedCalculatePathItem;
public NaviOverlayHelper( AMapNavi mAMapNavi, AMap mAMap, Context mContext ) {
this.mAMapNavi = mAMapNavi;
@@ -138,7 +141,9 @@ public class NaviOverlayHelper {
wrapper.setTrafficLightsVisible( false );
// 默认选中第一个
if ( i == 0 ) {
wrapper.setStartBitmap( R.drawable.ic_amap_navi_cursor ).setEndBitmap( R.drawable.ic_search_choice_point );
mSelectedPathId = item.getId();
mSelectedCalculatePathItem = item;
wrapper.setStartBitmap( R.drawable.ic_search_poi_location ).setEndBitmap( R.drawable.ic_search_choice_point );
mAMapNavi.selectRouteId( item.getId() );
}
wrapper.addToMap();
@@ -167,16 +172,17 @@ public class NaviOverlayHelper {
* @param polyline 选中的线
* @return
*/
public boolean handleClickedPolyline( Polyline polyline ) {
public boolean handleClickedPolyline( Polyline polyline, boolean isNaviing ) {
if ( polyline == null ) {
return false;
}
Logger.i( TAG, "polyline id = " + polyline.getId() );
CalculatePathItem calculatePathItem = isCalculatePolyline( polyline );
if ( calculatePathItem == null ) {
mSelectedCalculatePathItem = isCalculatePolyline( polyline );
if ( mSelectedCalculatePathItem == null ) {
return false;
}
mSelectedPathId = calculatePathItem.getId();
mSelectedPathId = mSelectedCalculatePathItem.getId();
if ( mCalculatePathItems != null ) {
for ( CalculatePathItem item : mCalculatePathItems ) {
final RouteOverLayWrapper wrapper = item.getOverLazWrapper( false );
@@ -184,7 +190,7 @@ public class NaviOverlayHelper {
continue;
}
wrapper.setTransparency(
item == calculatePathItem
item == mSelectedCalculatePathItem
? AMAP_ROUTE_OVERLAY_TRANSPARENCY_SELECTED
: AMAP_ROUTE_OVERLAY_TRANSPARENCY_UNSELECTED
);
@@ -220,4 +226,27 @@ public class NaviOverlayHelper {
public int getSelectedPathId() {
return mSelectedPathId;
}
/**
* 车辆拐弯时绘制转向箭头
*
* @param naviInfo
*/
public void handleNaviInfoUpdate( NaviInfo naviInfo ) {
if ( mSelectedCalculatePathItem != null ) {
RouteOverLayWrapper wrapper = mSelectedCalculatePathItem.getOverLazWrapper( false );
if ( wrapper != null ) {
wrapper.drawArrow( naviInfo );
}
}
}
public void handlePassedLocation( AMapNaviLocation location ) {
if ( mSelectedCalculatePathItem != null ) {
RouteOverLayWrapper wrapper = mSelectedCalculatePathItem.getOverLazWrapper( false );
if ( wrapper != null ) {
wrapper.updatePolyline( location );
}
}
}
}

View File

@@ -1,5 +1,6 @@
package com.mogo.map.impl.amap.uicontroller;
import com.mogo.map.MogoLatLng;
import com.mogo.map.MogoMap;
import com.mogo.map.uicontroller.EnumMapUI;
import com.mogo.map.uicontroller.IMogoMapUIController;
@@ -56,6 +57,13 @@ public class AMapUIController implements IMogoMapUIController {
}
}
@Override
public void changeZoom( float zoom ) {
if ( mClient != null ) {
mClient.changeZoom( zoom );
}
}
@Override
public void changeMapMode( EnumMapUI mode ) {
if ( mClient != null ) {
@@ -64,9 +72,9 @@ public class AMapUIController implements IMogoMapUIController {
}
@Override
public void moveToCurrentLocation() {
public void moveToCenter( MogoLatLng latLng ) {
if ( mClient != null ) {
mClient.moveToCurrentLocation();
mClient.moveToCenter(latLng);
}
}
@@ -90,4 +98,12 @@ public class AMapUIController implements IMogoMapUIController {
mClient.displayOverview();
}
}
@Override
public float getScalePerPixel() {
if ( mClient != null ) {
return mClient.getScalePerPixel();
}
return 0;
}
}

View File

@@ -1,6 +1,7 @@
package com.mogo.map.impl.amap.utils;
import android.graphics.Bitmap;
import android.view.View;
import com.amap.api.location.AMapLocation;
import com.amap.api.maps.model.BitmapDescriptor;
@@ -33,6 +34,7 @@ import com.amap.api.services.poisearch.SubPoiItem;
import com.amap.api.services.road.Crossroad;
import com.mogo.map.MogoLatLng;
import com.mogo.map.location.MogoLocation;
import com.mogo.map.marker.IMogoMarkerIconViewCreator;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.map.model.MogoPoi;
import com.mogo.map.navi.MogoNaviInfo;
@@ -81,15 +83,19 @@ public class ObjectUtils {
if ( icon == null || icon.isRecycled() ) {
continue;
}
descriptors.add( BitmapDescriptorFactory.fromBitmap( icon ) );
}
}
BitmapDescriptor descriptor = getBitmapDescriptorFromMogo( opt );
return new MarkerOptions()
.position( new LatLng( opt.getLatitude(), opt.getLongitude() ) )
.title( opt.getTitle() )
.snippet( opt.getSnippet() )
.icon( BitmapDescriptorFactory.fromBitmap( opt.getIcon() ) )
.icon( descriptor )
.anchor( opt.getU(), opt.getV() )
.icons( descriptors )
.period( opt.getPeriod() )
.rotateAngle( opt.getRotate() )
@@ -104,6 +110,21 @@ public class ObjectUtils {
.zIndex( opt.getzIndex() );
}
private static BitmapDescriptor getBitmapDescriptorFromMogo( MogoMarkerOptions options ) {
if ( options == null ) {
return null;
}
Bitmap icon = options.getIcon();
if ( icon != null ) {
return BitmapDescriptorFactory.fromBitmap( icon );
}
View view = options.getIconView();
if ( view != null ) {
return BitmapDescriptorFactory.fromView( view );
}
return null;
}
public static MogoLocation fromAMap( AMapLocation aLocation ) {
if ( aLocation == null ) {