dev
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion "29.0.2"
|
||||
|
||||
|
||||
compileSdkVersion rootProject.ext.android.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.android.buildToolsVersion
|
||||
defaultConfig {
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
minSdkVersion rootProject.ext.android.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.android.targetSdkVersion
|
||||
versionCode Integer.valueOf(VERSION_CODE)
|
||||
versionName getValueFromRootProperties("${project.name.replace("-", "_").toUpperCase()}_VERSION")
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
@@ -32,6 +30,13 @@ dependencies {
|
||||
implementation rootProject.ext.dependencies.amapsearch
|
||||
implementation rootProject.ext.dependencies.amaplocation
|
||||
|
||||
implementation project(':foudations:mogo-utils')
|
||||
implementation project(':libraries:mogo-map-api')
|
||||
if (Boolean.valueOf(RELEASE)) {
|
||||
implementation rootProject.ext.dependencies.mogoutils
|
||||
implementation rootProject.ext.dependencies.mogomapapi
|
||||
} else {
|
||||
implementation project(':foudations:mogo-utils')
|
||||
implementation project(':libraries:mogo-map-api')
|
||||
}
|
||||
}
|
||||
|
||||
apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()
|
||||
|
||||
3
libraries/map-amap/gradle.properties
Normal file
3
libraries/map-amap/gradle.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
GROUP=com.mogo.map
|
||||
POM_ARTIFACT_ID=map-amap
|
||||
VERSION_CODE=1
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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实例为空,请检查" );
|
||||
|
||||
@@ -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." );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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 );
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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() );
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 ) {
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion "29.0.2"
|
||||
|
||||
|
||||
compileSdkVersion rootProject.ext.android.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.android.buildToolsVersion
|
||||
defaultConfig {
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
minSdkVersion rootProject.ext.android.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.android.targetSdkVersion
|
||||
versionCode Integer.valueOf(VERSION_CODE)
|
||||
versionName getValueFromRootProperties("${project.name.replace("-", "_").toUpperCase()}_VERSION")
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
@@ -56,3 +54,5 @@ dependencies {
|
||||
transitive = true
|
||||
}
|
||||
}
|
||||
|
||||
apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()
|
||||
|
||||
3
libraries/map-baidu/gradle.properties
Normal file
3
libraries/map-baidu/gradle.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
GROUP=com.mogo.map
|
||||
POM_ARTIFACT_ID=map-baidu
|
||||
VERSION_CODE=1
|
||||
15
libraries/mogo-map-api/apipackage.txt
Normal file
15
libraries/mogo-map-api/apipackage.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
com.mogo.map.uicontroller
|
||||
com.mogo.map.search.poisearch
|
||||
com.mogo.map.search.poisearch.query
|
||||
com.mogo.map.search.inputtips
|
||||
com.mogo.map.search.inputtips.query
|
||||
com.mogo.map.search.geo.query
|
||||
com.mogo.map.search.geo
|
||||
com.mogo.map.search
|
||||
com.mogo.map.navi
|
||||
com.mogo.map.marker
|
||||
com.mogo.map.model
|
||||
com.mogo.map.location
|
||||
com.mogo.map.listener
|
||||
com.mogo.map.exception
|
||||
com.mogo.map
|
||||
@@ -1,15 +1,13 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion "29.0.2"
|
||||
|
||||
|
||||
compileSdkVersion rootProject.ext.android.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.android.buildToolsVersion
|
||||
defaultConfig {
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
minSdkVersion rootProject.ext.android.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.android.targetSdkVersion
|
||||
versionCode Integer.valueOf(VERSION_CODE)
|
||||
versionName getValueFromRootProperties("${project.name.replace("-", "_").toUpperCase()}_VERSION")
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
@@ -28,5 +26,11 @@ dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation rootProject.ext.dependencies.androidxappcompat
|
||||
implementation project(':foudations:mogo-utils')
|
||||
if (Boolean.valueOf(RELEASE)) {
|
||||
implementation rootProject.ext.dependencies.mogoutils
|
||||
} else {
|
||||
implementation project(':foudations:mogo-utils')
|
||||
}
|
||||
}
|
||||
|
||||
apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()
|
||||
|
||||
3
libraries/mogo-map-api/gradle.properties
Normal file
3
libraries/mogo-map-api/gradle.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
GROUP=com.mogo.map
|
||||
POM_ARTIFACT_ID=mogo-map-api
|
||||
VERSION_CODE=1
|
||||
@@ -106,4 +106,13 @@ public interface IMogoMap {
|
||||
* 停止当前执行的改变地图状态的动画。
|
||||
*/
|
||||
void stopAnimation();
|
||||
|
||||
/**
|
||||
* 获取比例尺
|
||||
*
|
||||
* @return 当前缩放级别下,地图上1像素点对应的长度,单位米
|
||||
*/
|
||||
float getScalePerPixel();
|
||||
|
||||
void changeZoom(float zoom);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.mogo.map.listener;
|
||||
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListenerRegister;
|
||||
import com.mogo.map.navi.IMogoNaviListenerRegister;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-29
|
||||
* <p>
|
||||
* 主模块需要注册监听的事件
|
||||
*/
|
||||
public interface IMogoHosListenerRegister extends IMogoNaviListenerRegister,
|
||||
IMogoMapListenerRegister,
|
||||
IMogoMarkerClickListenerRegister {
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.mogo.map.listener;
|
||||
|
||||
import com.mogo.map.exception.MogoMapException;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-23
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.mogo.map.listener;
|
||||
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.marker.MogoMarkersHandler;
|
||||
import com.mogo.map.navi.IMogoNaviListener;
|
||||
import com.mogo.map.navi.MogoNaviListenerHandler;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-29
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class MogoHosListenerRegister implements IMogoHosListenerRegister {
|
||||
|
||||
private static volatile MogoHosListenerRegister sInstance;
|
||||
|
||||
private MogoHosListenerRegister() {
|
||||
}
|
||||
|
||||
public static MogoHosListenerRegister getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( MogoHosListenerRegister.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new MogoHosListenerRegister();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registerHostMapListener( IMogoMapListener listener ) {
|
||||
MogoMapListenerHandler.getInstance().registerHostMapListener( listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterHostMapListener() {
|
||||
MogoMapListenerHandler.getInstance().unregisterHostMapListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerHostNaviListener( IMogoNaviListener listener ) {
|
||||
MogoNaviListenerHandler.getInstance().registerHostNaviListener( listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterHostNaviListener() {
|
||||
MogoNaviListenerHandler.getInstance().unregisterHostNaviListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerMarkerClickListener( IMogoMarkerClickListener listener ) {
|
||||
MogoMarkersHandler.getInstance().registerMarkerClickListener( listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterMarkerClickListener() {
|
||||
MogoMarkersHandler.getInstance().unregisterMarkerClickListener();
|
||||
}
|
||||
}
|
||||
@@ -40,4 +40,6 @@ public interface IMogoLocationClient {
|
||||
void removeLocationListener( IMogoLocationListener listener );
|
||||
|
||||
MogoLocation getLastKnowLocation();
|
||||
|
||||
void destroy();
|
||||
}
|
||||
|
||||
@@ -10,5 +10,11 @@ import android.view.View;
|
||||
*/
|
||||
public interface IMogoInfoWindowAdapter {
|
||||
|
||||
/**
|
||||
* 获取infowindow的布局
|
||||
*
|
||||
* @param marker
|
||||
* @return
|
||||
*/
|
||||
View getInfoWindow( IMogoMarker marker );
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.mogo.map.marker;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.location.IMogoLocationClient;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -168,7 +167,38 @@ public interface IMogoMarker {
|
||||
*/
|
||||
void setInfoWindowAdapter( IMogoInfoWindowAdapter adapter );
|
||||
|
||||
/**
|
||||
* 自定义 infowindow 样式接口
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
IMogoInfoWindowAdapter getInfoWindowAdapter();
|
||||
|
||||
/**
|
||||
* 自定义marker样式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
void setMarkerIconView( IMogoMarkerIconViewCreator creator );
|
||||
|
||||
/**
|
||||
* 是否被销毁
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean isDestroyed();
|
||||
|
||||
/**
|
||||
* 设置marker的归属模块
|
||||
*
|
||||
* @param mOwner
|
||||
*/
|
||||
void setOwner( String mOwner );
|
||||
|
||||
/**
|
||||
* 获取marker的归属模块
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getOwner();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.mogo.map.marker;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-23
|
||||
* <p>
|
||||
* 地图操作回调
|
||||
*/
|
||||
public interface IMogoMarkerClickListenerRegister {
|
||||
|
||||
/**
|
||||
* 注册marker回调,各业务模块不用关注
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
void registerMarkerClickListener( IMogoMarkerClickListener listener );
|
||||
|
||||
|
||||
/**
|
||||
* 注销marker回调,各业务模块不需要关注
|
||||
*/
|
||||
void unregisterMarkerClickListener();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.mogo.map.marker;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-29
|
||||
* <p>
|
||||
* 动态变换 marker 样式接口
|
||||
*/
|
||||
public interface IMogoMarkerIconViewCreator {
|
||||
|
||||
/**
|
||||
* 返回自定义marker样式
|
||||
*
|
||||
* @param marker marker 的数据
|
||||
* @return
|
||||
*/
|
||||
View createView( IMogoMarker marker );
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.mogo.map.marker;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Observable;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -10,7 +12,7 @@ import java.util.ArrayList;
|
||||
* <p>
|
||||
* 地图marker
|
||||
*/
|
||||
public class MogoMarkerOptions {
|
||||
public class MogoMarkerOptions extends Observable {
|
||||
|
||||
private double latitude;
|
||||
private double longitude;
|
||||
@@ -41,7 +43,7 @@ public class MogoMarkerOptions {
|
||||
// Marker覆盖物锚点在水平范围的比例。
|
||||
private float u = 0.5f;
|
||||
// Marker覆盖物锚点垂直范围的比例。
|
||||
private float v = 0.5f;
|
||||
private float v = 1f;
|
||||
|
||||
// 设置Marker覆盖物是否可拖拽。
|
||||
private boolean draggable = false;
|
||||
@@ -53,6 +55,10 @@ public class MogoMarkerOptions {
|
||||
|
||||
// 设置Marker覆盖物 zIndex。
|
||||
private int zIndex = 0;
|
||||
// 自定义样式
|
||||
private View mIconView;
|
||||
// marker 归属模块
|
||||
private String mOwner;
|
||||
|
||||
public MogoMarkerOptions latitude( double latitude ) {
|
||||
this.latitude = latitude;
|
||||
@@ -74,6 +80,12 @@ public class MogoMarkerOptions {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 优先使用icon作为marker资源
|
||||
*
|
||||
* @param icon
|
||||
* @return
|
||||
*/
|
||||
public MogoMarkerOptions icon( Bitmap icon ) {
|
||||
this.icon = icon;
|
||||
return this;
|
||||
@@ -144,6 +156,22 @@ public class MogoMarkerOptions {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义marker图层样式,优先使用 icon {@link #icon(Bitmap)}作为marker资源
|
||||
*
|
||||
* @param iconView
|
||||
* @return
|
||||
*/
|
||||
public MogoMarkerOptions icon( View iconView ) {
|
||||
this.mIconView = iconView;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MogoMarkerOptions owner( String owner ) {
|
||||
this.mOwner = owner;
|
||||
return this;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
@@ -219,4 +247,12 @@ public class MogoMarkerOptions {
|
||||
public int getzIndex() {
|
||||
return zIndex;
|
||||
}
|
||||
|
||||
public View getIconView() {
|
||||
return mIconView;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return mOwner;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.mogo.map.marker;
|
||||
|
||||
import com.mogo.map.listener.IMogoMapListener;
|
||||
import com.mogo.map.listener.IMogoMapListenerRegister;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -12,9 +15,10 @@ import java.util.Map;
|
||||
* <p>
|
||||
* 管理地图上的所有marker
|
||||
*/
|
||||
public class MogoMarkersHandler {
|
||||
public class MogoMarkersHandler implements IMogoMarkerClickListener, IMogoMarkerClickListenerRegister {
|
||||
|
||||
private static volatile MogoMarkersHandler sInstance;
|
||||
private IMogoMarkerClickListener mDelegate;
|
||||
|
||||
public static MogoMarkersHandler getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
@@ -86,4 +90,22 @@ public class MogoMarkersHandler {
|
||||
}
|
||||
mServicesMarkers.get( tag ).addAll( markers );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerMarkerClickListener( IMogoMarkerClickListener listener ) {
|
||||
mDelegate = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterMarkerClickListener() {
|
||||
mDelegate = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMarkerClicked( IMogoMarker marker ) {
|
||||
if ( mDelegate != null ) {
|
||||
return mDelegate.onMarkerClicked( marker );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.mogo.map.uicontroller;
|
||||
|
||||
import com.mogo.map.MogoLatLng;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-26
|
||||
@@ -22,6 +24,13 @@ public interface IMogoMapUIController {
|
||||
*/
|
||||
void changeZoom( boolean zoomIn );
|
||||
|
||||
/**
|
||||
* 修改缩放级别
|
||||
*
|
||||
* @param zoom
|
||||
*/
|
||||
void changeZoom( float zoom );
|
||||
|
||||
/**
|
||||
* 切换2D/3D模式
|
||||
*
|
||||
@@ -32,7 +41,7 @@ public interface IMogoMapUIController {
|
||||
/**
|
||||
* 将地图移动至当前位置
|
||||
*/
|
||||
void moveToCurrentLocation();
|
||||
void moveToCenter( MogoLatLng latLng );
|
||||
|
||||
/**
|
||||
* 显示我的位置
|
||||
@@ -50,4 +59,11 @@ public interface IMogoMapUIController {
|
||||
* 预览全程
|
||||
*/
|
||||
void displayOverview();
|
||||
|
||||
/**
|
||||
* 获取比例尺数据
|
||||
*
|
||||
* @return 当前缩放级别下,地图上1像素点对应的长度,单位米
|
||||
*/
|
||||
float getScalePerPixel();
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion "29.0.2"
|
||||
|
||||
|
||||
compileSdkVersion rootProject.ext.android.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.android.buildToolsVersion
|
||||
defaultConfig {
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
minSdkVersion rootProject.ext.android.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.android.targetSdkVersion
|
||||
versionCode Integer.valueOf(VERSION_CODE)
|
||||
versionName getValueFromRootProperties("${project.name.replace("-", "_").toUpperCase()}_VERSION")
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
@@ -27,7 +25,15 @@ dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation rootProject.ext.dependencies.androidxappcompat
|
||||
|
||||
implementation project(':foudations:mogo-utils')
|
||||
implementation project(':libraries:mogo-map-api')
|
||||
api project(':libraries:map-amap')
|
||||
if (Boolean.valueOf(RELEASE)) {
|
||||
implementation rootProject.ext.dependencies.mogoutils
|
||||
implementation rootProject.ext.dependencies.mogomapapi
|
||||
api rootProject.ext.dependencies.mapamap
|
||||
} else {
|
||||
implementation project(':foudations:mogo-utils')
|
||||
implementation project(':libraries:mogo-map-api')
|
||||
api project(':libraries:map-amap')
|
||||
}
|
||||
}
|
||||
|
||||
apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()
|
||||
|
||||
3
libraries/mogo-map/gradle.properties
Normal file
3
libraries/mogo-map/gradle.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
GROUP=com.mogo.map
|
||||
POM_ARTIFACT_ID=mogo-map
|
||||
VERSION_CODE=1
|
||||
@@ -3,8 +3,8 @@ package com.mogo.map;
|
||||
import android.content.Context;
|
||||
|
||||
import com.mogo.map.impl.amap.location.ALocationClient;
|
||||
import com.mogo.map.location.IMogoLocationListener;
|
||||
import com.mogo.map.location.IMogoLocationClient;
|
||||
import com.mogo.map.location.IMogoLocationListener;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
|
||||
/**
|
||||
@@ -16,8 +16,8 @@ public class MogoLocationClient implements IMogoLocationClient {
|
||||
|
||||
private static volatile MogoLocationClient sInstance;
|
||||
|
||||
private MogoLocationClient( Context context ) {
|
||||
mDelegate = ALocationClient.getInstance( context );
|
||||
public MogoLocationClient( Context context ) {
|
||||
mDelegate = new ALocationClient( context );
|
||||
}
|
||||
|
||||
public static MogoLocationClient getInstance( Context context ) {
|
||||
@@ -75,4 +75,11 @@ public class MogoLocationClient implements IMogoLocationClient {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
if ( mDelegate != null ) {
|
||||
mDelegate.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,13 @@ public class MogoMapUIController implements IMogoMapUIController {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeZoom( float zoom ) {
|
||||
if ( mDelegate != null ) {
|
||||
mDelegate.changeZoom( zoom );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeMapMode( EnumMapUI mode ) {
|
||||
if ( mDelegate != null ) {
|
||||
@@ -57,9 +64,9 @@ public class MogoMapUIController implements IMogoMapUIController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveToCurrentLocation() {
|
||||
public void moveToCenter( MogoLatLng latLng ) {
|
||||
if ( mDelegate != null ) {
|
||||
mDelegate.moveToCurrentLocation();
|
||||
mDelegate.moveToCenter( latLng );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,4 +90,12 @@ public class MogoMapUIController implements IMogoMapUIController {
|
||||
mDelegate.displayOverview();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScalePerPixel() {
|
||||
if ( mDelegate != null ) {
|
||||
return mDelegate.getScalePerPixel();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user