1
libraries/map-amap/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/build
|
||||
@@ -1,62 +0,0 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.android.compileSdkVersion
|
||||
// buildToolsVersion rootProject.ext.android.buildToolsVersion
|
||||
defaultConfig {
|
||||
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'
|
||||
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
arguments = [AROUTER_MODULE_NAME: project.getName()]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility 1.8
|
||||
targetCompatibility 1.8
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation rootProject.ext.dependencies.androidxappcompat
|
||||
api rootProject.ext.dependencies.amapnavi3dmap
|
||||
api rootProject.ext.dependencies.amapsearch
|
||||
api rootProject.ext.dependencies.amaplocation
|
||||
|
||||
implementation rootProject.ext.dependencies.arouter
|
||||
annotationProcessor rootProject.ext.dependencies.aroutercompiler
|
||||
|
||||
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
|
||||
implementation rootProject.ext.dependencies.mogoutils
|
||||
implementation rootProject.ext.dependencies.mogomapapi
|
||||
implementation rootProject.ext.dependencies.mogocommons
|
||||
} else {
|
||||
implementation project(':foudations:mogo-utils')
|
||||
implementation project(':libraries:mogo-map-api')
|
||||
implementation project(':foudations:mogo-commons')
|
||||
}
|
||||
}
|
||||
|
||||
apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()
|
||||
@@ -1,10 +0,0 @@
|
||||
#-----library-MapAMap-----
|
||||
-keep class com.mogo.map.impl.amap.hook.BnHooker{*;}
|
||||
-keep class com.mogo.map.impl.amap.marker.CombineMovingPointOverlay.Status{*;}
|
||||
-keep class com.mogo.map.impl.amap.navi.PathPlanningErrorCodeConstants{*;}
|
||||
-keep class com.mogo.map.impl.amap.overlay.RouteOverLayWrapper{
|
||||
private hookRouteArrow();
|
||||
}
|
||||
-keep class com.mogo.map.impl.amap.utils.MapStyleUtils.ColorEnum{*;}
|
||||
-keep class com.mogo.map.impl.amap.AMapUiSettingsWrapper{*;}
|
||||
-keep class com.mogo.map.impl.amap.AMapViewWrapper{*;}
|
||||
@@ -1,3 +0,0 @@
|
||||
GROUP=com.mogo.map
|
||||
POM_ARTIFACT_ID=map-amap
|
||||
VERSION_CODE=1
|
||||
27
libraries/map-amap/proguard-rules.pro
vendored
@@ -1,27 +0,0 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
||||
#-----library-MapAMap-----
|
||||
-keep class com.mogo.map.impl.amap.hook.BnHooker.*{*;}
|
||||
-keep class com.mogo.map.impl.amap.marker.CombineMovingPointOverlay.Status
|
||||
-keep class com.mogo.map.impl.amap.navi.PathPlanningErrorCodeConstants
|
||||
-keep class com.mogo.map.impl.amap.utils.MapStyleUtils.ColorEnum
|
||||
@@ -1,8 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mogo.map.impl.amap">
|
||||
|
||||
<application>
|
||||
<!--定位服务-->
|
||||
<service android:name="com.amap.api.location.APSService" />
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -1,128 +0,0 @@
|
||||
package com.mogo.map.impl.amap;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.map.CoordinatesTransformer;
|
||||
import com.mogo.map.IMogoMapApiBuilder;
|
||||
import com.mogo.map.IMogoMapView;
|
||||
import com.mogo.map.MapApiPath;
|
||||
import com.mogo.map.impl.amap.location.ALocationClient;
|
||||
import com.mogo.map.impl.amap.navi.AimlessClient;
|
||||
import com.mogo.map.impl.amap.navi.NaviClient;
|
||||
import com.mogo.map.impl.amap.search.GeocodeSearchClient;
|
||||
import com.mogo.map.impl.amap.search.InputtipsSearch;
|
||||
import com.mogo.map.impl.amap.search.PoiSearchClient;
|
||||
import com.mogo.map.impl.amap.search.RoadSearchClient;
|
||||
import com.mogo.map.impl.amap.search.TrafficSearchClient;
|
||||
import com.mogo.map.impl.amap.uicontroller.AMapUIController;
|
||||
import com.mogo.map.impl.amap.utils.IconTypeUtils;
|
||||
import com.mogo.map.location.IMogoLocationClient;
|
||||
import com.mogo.map.navi.IMogoAimless;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.map.search.drive.IMogoRoadSearch;
|
||||
import com.mogo.map.search.geo.IMogoGeoSearch;
|
||||
import com.mogo.map.search.inputtips.IMogoInputtipsSearch;
|
||||
import com.mogo.map.search.inputtips.query.MogoInputtipsQuery;
|
||||
import com.mogo.map.search.poisearch.IMogoPoiSearch;
|
||||
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
|
||||
import com.mogo.map.search.traffic.IMogoTrafficSearch;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/12/9
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
@Route( path = MapApiPath.PATH )
|
||||
class AMapApiBuilder implements IMogoMapApiBuilder {
|
||||
|
||||
private static final String TAG = "AMapApiBuilder";
|
||||
|
||||
@Override
|
||||
public IMogoGeoSearch getGeoSearch( Context context ) {
|
||||
return new GeocodeSearchClient( context );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoInputtipsSearch getInputtipsSearch( Context context, MogoInputtipsQuery query ) {
|
||||
return new InputtipsSearch( context, query );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoLocationClient getLocationClient( Context context ) {
|
||||
return new ALocationClient( context );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoMapUIController getMapUIController() {
|
||||
return AMapUIController.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoNavi getNavi( Context context ) {
|
||||
return NaviClient.getInstance( context );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoPoiSearch getPoiSearchClient( Context context, MogoPoiSearchQuery query ) {
|
||||
return new PoiSearchClient( context, query );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoRoadSearch getRoadSearch() {
|
||||
return new RoadSearchClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoAimless getAimless( Context context ) {
|
||||
return AimlessClient.getInstance( context );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMapView( Context context ) {
|
||||
AMapViewHandler.createMapView( context );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
AMapViewHandler.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoMapView getMapView( Context context ) {
|
||||
// Logger.e("lianglihui","AMapApiBuilder getMapView");
|
||||
IMogoMapView mapView = AMapViewHandler.getMapView();
|
||||
if ( mapView != null
|
||||
&& mapView.getMapView() != null
|
||||
&& mapView.getMapView().getParent() != null ) {
|
||||
ViewGroup group = ( ViewGroup ) mapView.getMapView().getParent();
|
||||
group.removeView( mapView.getMapView() );
|
||||
}
|
||||
return mapView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoTrafficSearch getTrafficSearch() {
|
||||
return new TrafficSearchClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getResIdByIconType( Context context, int iconType ) {
|
||||
return IconTypeUtils.getResIdByIconType( context, iconType );
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoordinatesTransformer getCoordinatesTransformer() {
|
||||
return AMapCoordinatesTransformer.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
Logger.d( TAG, "init." );
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.mogo.map.impl.amap;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.mogo.map.IMogoMapView;
|
||||
import com.mogo.map.IMogoMapViewCreator;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-25
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class AMapBaseMapView implements IMogoMapViewCreator {
|
||||
|
||||
private static final String TAG = "AMapBaseMapView";
|
||||
|
||||
@Override
|
||||
public IMogoMapView create( Context context ) {
|
||||
IMogoMapView mapView = AMapViewHandler.getMapView();
|
||||
if ( mapView != null
|
||||
&& mapView.getMapView() != null
|
||||
&& mapView.getMapView().getParent() != null ) {
|
||||
ViewGroup group = ( ViewGroup ) mapView.getMapView().getParent();
|
||||
group.removeView( mapView.getMapView() );
|
||||
}
|
||||
return mapView;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.mogo.map.impl.amap;
|
||||
|
||||
import com.mogo.map.CoordinatesTransformer;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/12/17
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
class AMapCoordinatesTransformer implements CoordinatesTransformer {
|
||||
|
||||
private AMapCoordinatesTransformer() {
|
||||
// private constructor
|
||||
}
|
||||
|
||||
private static final class InstanceHolder {
|
||||
private static final AMapCoordinatesTransformer INSTANCE = new AMapCoordinatesTransformer();
|
||||
}
|
||||
|
||||
public static AMapCoordinatesTransformer getInstance() {
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private Object readResolve() {
|
||||
// 阻止反序列化,必须实现 Serializable 接口
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] transform( double lat, double lon ) {
|
||||
double[] coor = new double[2];
|
||||
coor[0] = lat;
|
||||
coor[1] = lon;
|
||||
return coor;
|
||||
// return new double[]{lat, lon};
|
||||
// return CoordinateUtils.transformGcj02toWgs84( lat, lon );
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-24
|
||||
* <p>
|
||||
* marker 点击事件处理
|
||||
*/
|
||||
public class AMapMarkerClickHandler {
|
||||
|
||||
public boolean handleMarkerClicked( Marker marker ) {
|
||||
if ( marker == null ) {
|
||||
return false;
|
||||
}
|
||||
if ( marker.getObject() instanceof IMogoMarker ) {
|
||||
IMogoMarker mogoMarker = ( ( IMogoMarker ) marker.getObject() );
|
||||
final IMogoMarkerClickListener listener = mogoMarker.getOnMarkerClickListener();
|
||||
Logger.d( "AMapMarkerWrapper", "marker 点击回调:%s -> %s", mogoMarker, marker );
|
||||
if ( listener != null ) {
|
||||
boolean result = listener.onMarkerClicked( mogoMarker );
|
||||
if ( result ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return MogoMarkersHandler.getInstance().onMarkerClicked( mogoMarker );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
package com.mogo.map.impl.amap;
|
||||
|
||||
import com.amap.api.maps.UiSettings;
|
||||
import com.mogo.map.IMogoUiSettings;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-18
|
||||
* <p>
|
||||
* 代理高德地图UiSettings
|
||||
*/
|
||||
public class AMapUiSettingsWrapper implements IMogoUiSettings {
|
||||
|
||||
private UiSettings mUiSettings;
|
||||
|
||||
public AMapUiSettingsWrapper( UiSettings mUiSettings ) {
|
||||
this.mUiSettings = mUiSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScaleControlsEnabled( boolean enabled ) {
|
||||
if ( mUiSettings != null ) {
|
||||
mUiSettings.setScaleControlsEnabled( enabled );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setZoomControlsEnabled( boolean enabled ) {
|
||||
if ( mUiSettings != null ) {
|
||||
mUiSettings.setZoomControlsEnabled( enabled );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompassEnabled( boolean enabled ) {
|
||||
if ( mUiSettings != null ) {
|
||||
mUiSettings.setCompassEnabled( enabled );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMyLocationButtonEnabled( boolean enabled ) {
|
||||
if ( mUiSettings != null ) {
|
||||
mUiSettings.setMyLocationButtonEnabled( enabled );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScrollGesturesEnabled( boolean enabled ) {
|
||||
if ( mUiSettings != null ) {
|
||||
mUiSettings.setScrollGesturesEnabled( enabled );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setZoomGesturesEnabled( boolean enabled ) {
|
||||
if ( mUiSettings != null ) {
|
||||
mUiSettings.setZoomGesturesEnabled( enabled );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTiltGesturesEnabled( boolean enabled ) {
|
||||
if ( mUiSettings != null ) {
|
||||
mUiSettings.setTiltGesturesEnabled( enabled );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotateGesturesEnabled( boolean enabled ) {
|
||||
if ( mUiSettings != null ) {
|
||||
mUiSettings.setRotateGesturesEnabled( enabled );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAllGesturesEnabled( boolean enabled ) {
|
||||
if ( mUiSettings != null ) {
|
||||
mUiSettings.setAllGesturesEnabled( enabled );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIndoorSwitchEnabled( boolean enabled ) {
|
||||
if ( mUiSettings != null ) {
|
||||
mUiSettings.setIndoorSwitchEnabled( enabled );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogoEnable( boolean enabled ) {
|
||||
if ( mUiSettings != null ) {
|
||||
try {
|
||||
Method method = mUiSettings.getClass().getMethod( "setLogoEnable", boolean.class );
|
||||
method.setAccessible( true );
|
||||
method.invoke( mUiSettings, enabled );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.mogo.map.impl.amap;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.amap.api.maps.MapView;
|
||||
import com.amap.api.navi.AMapNaviView;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.map.IMogoMapView;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/9/10
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
class AMapViewHandler {
|
||||
|
||||
private static final String TAG = "AMapViewHandler";
|
||||
|
||||
private static IMogoMapView sMapView;
|
||||
|
||||
public static void createMapView( Context context ) {
|
||||
sMapView = new AMapNaviViewWrapper( new AMapNaviView( context ) );
|
||||
Logger.d( TAG, "created." );
|
||||
}
|
||||
|
||||
public static IMogoMapView getMapView() {
|
||||
return sMapView;
|
||||
}
|
||||
|
||||
public static void destroy() {
|
||||
sMapView = null;
|
||||
}
|
||||
}
|
||||
@@ -1,832 +0,0 @@
|
||||
package com.mogo.map.impl.amap;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.os.Trace;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.AMapUtils;
|
||||
import com.amap.api.maps.CameraUpdateFactory;
|
||||
import com.amap.api.maps.MapView;
|
||||
import com.amap.api.maps.model.BitmapDescriptorFactory;
|
||||
import com.amap.api.maps.model.CameraPosition;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.LatLngBounds;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.amap.api.maps.model.MyLocationStyle;
|
||||
import com.amap.api.maps.model.Poi;
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.maps.model.animation.Animation;
|
||||
import com.amap.api.maps.model.animation.TranslateAnimation;
|
||||
import com.amap.api.navi.model.NaviInfo;
|
||||
import com.mogo.map.IMogoMap;
|
||||
import com.mogo.map.IMogoMapView;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.map.impl.amap.hook.BnHooker;
|
||||
import com.mogo.map.impl.amap.marker.AMapMarkerWrapper;
|
||||
import com.mogo.map.impl.amap.message.AMapMessageListener;
|
||||
import com.mogo.map.impl.amap.message.AMapMessageManager;
|
||||
import com.mogo.map.impl.amap.navi.NaviClient;
|
||||
import com.mogo.map.impl.amap.uicontroller.AMapUIController;
|
||||
import com.mogo.map.impl.amap.utils.MogoMapUtils;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.listener.MogoMapListenerHandler;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.uicontroller.CarCursorOption;
|
||||
import com.mogo.map.uicontroller.EnumMapUI;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.map.uicontroller.MapCameraPosition;
|
||||
import com.mogo.map.uicontroller.MapControlResult;
|
||||
import com.mogo.map.uicontroller.VisualAngleMode;
|
||||
import com.mogo.utils.NetworkUtils;
|
||||
import com.mogo.utils.WindowUtils;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-18
|
||||
* <p>
|
||||
* 代理高德导航地图
|
||||
*/
|
||||
public class AMapViewWrapper implements IMogoMapView,
|
||||
IMogoMapUIController,
|
||||
AMap.OnMarkerClickListener,
|
||||
AMap.OnMapLoadedListener,
|
||||
AMap.OnMapTouchListener,
|
||||
AMap.OnPOIClickListener,
|
||||
AMap.OnMapClickListener,
|
||||
AMap.OnPolylineClickListener,
|
||||
AMapMessageListener,
|
||||
AMap.OnCameraChangeListener,
|
||||
AMap.OnMyLocationChangeListener {
|
||||
|
||||
private static final String TAG = "AMapViewWrapper";
|
||||
|
||||
private final MapView mMapView;
|
||||
private IMogoMap mIMap;
|
||||
|
||||
private AMapMarkerClickHandler mMarkerClickHandler;
|
||||
private EnumMapUI mCurrentUIMode;
|
||||
|
||||
private boolean mIsCarLocked = false;
|
||||
|
||||
private float mDefaultZoomLevel = 16.0f;
|
||||
private final CarCursorOption DEFAULT_OPTION = new CarCursorOption.Builder()
|
||||
.carCursorRes( R.drawable.map_api_ic_current_location2 )
|
||||
.naviCursorRes( R.drawable.ic_amap_navi_cursor )
|
||||
.build();
|
||||
private CarCursorOption mCarCursorOption = DEFAULT_OPTION;
|
||||
|
||||
public AMapViewWrapper( MapView mapView ) {
|
||||
this.mMapView = mapView;
|
||||
this.mIMap = new AMapWrapper( mMapView.getMap(), mMapView.getContext(), this );
|
||||
try {
|
||||
new BnHooker( mMapView.getMap() );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void initMapView() {
|
||||
if ( mMapView == null ) {
|
||||
return;
|
||||
}
|
||||
// AMapNaviViewOptions options = mMapView.getViewOptions();
|
||||
// if ( options != null ) {
|
||||
// // 设置是否开启自动黑夜模式切换,默认为false,不自动切换
|
||||
// options.setAutoNaviViewNightMode( false );
|
||||
// // 设置6秒后是否自动锁车
|
||||
// options.setAutoLockCar( false );
|
||||
// // 设置路线上的摄像头气泡是否显示
|
||||
// options.setCameraBubbleShow( true );
|
||||
// // 设置路线相关的配置属性,如:路线的路况颜色,路线上是否显示摄像头气泡等。
|
||||
// // options.setRouteOverlayOptions( MapStyleUtils.getRouteOverlayOptions() );
|
||||
// // 设置自车的图片对象
|
||||
// options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(), DEFAULT_OPTION.getNaviCursorRes() ) );
|
||||
// // 设置指南针图标否在导航界面显示,默认显示。true,显示;false,隐藏。
|
||||
// options.setCompassEnabled( false );
|
||||
// // 黑夜模式
|
||||
// options.setNaviNight( true );
|
||||
// //设置路况光柱条是否显示(只适用于驾车导航,需要联网)。
|
||||
// options.setTrafficBarEnabled( false );
|
||||
// // 设置[实时交通图层开关按钮]是否显示(只适用于驾车导航,需要联网)。
|
||||
// options.setTrafficLayerEnabled( false );
|
||||
// // 设置导航界面是否显示路线全览按钮。
|
||||
// options.setRouteListButtonShow( false );
|
||||
// // 设置屏幕是否常亮,默认开启
|
||||
// options.setScreenAlwaysBright( false );
|
||||
// // 设置交通播报是否打开(只适用于驾车导航,需要联网)。
|
||||
// options.setTrafficInfoUpdateEnabled( true );
|
||||
// // 设置摄像头播报是否打开(只适用于驾车导航)。
|
||||
// options.setCameraInfoUpdateEnabled( true );
|
||||
// // 设置菜单按钮是否在导航界面显示。
|
||||
// options.setSettingMenuEnabled( false );
|
||||
// // 设置是否绘制显示交通路况的线路(彩虹线),拥堵-红色,畅通-绿色,缓慢-黄色,未知-蓝色。默认不绘制彩虹线。
|
||||
// options.setTrafficLine( true );
|
||||
// // 设置是否绘制牵引线(当前位置到目的地的指引线)。默认不绘制牵引线。
|
||||
// options.setLeaderLineEnabled( -1 );
|
||||
// // 设置导航界面UI是否显示。
|
||||
// options.setLayoutVisible( false );
|
||||
// // 设置是否自动画路
|
||||
// options.setAutoDrawRoute( false );
|
||||
// // 设置是否显示路口放大图(实景图)
|
||||
// options.setRealCrossDisplayShow( false );
|
||||
// // 设置是否显示路口放大图(路口模型图)
|
||||
// options.setModeCrossDisplayShow( false );
|
||||
// // 设置是否显示道路信息view
|
||||
// options.setLaneInfoShow( false );
|
||||
// // 设置是否自动改变缩放等级
|
||||
// options.setAutoChangeZoom( false );
|
||||
// // 设置是否自动全览模式,即在算路成功后自动进入全览模式
|
||||
// options.setAutoDisplayOverview( false );
|
||||
// // 设置路线转向箭头隐藏和显示
|
||||
// options.setNaviArrowVisible( false );
|
||||
// // 通过路线是否自动置灰,仅支持驾车导航
|
||||
// options.setAfterRouteAutoGray( true );
|
||||
// options.setZoom( ( ( int ) mDefaultZoomLevel ) );
|
||||
// options.setPointToCenter( 0.7D, 0.5D );
|
||||
// // 2D模式
|
||||
// options.setTilt( 0 );
|
||||
// mMapView.setViewOptions( options );
|
||||
// }
|
||||
// mMapView.setRouteOverlayVisible( false );
|
||||
// mMapView.setCarOverlayVisible( false );
|
||||
changeMapMode( EnumMapUI.CarUp_2D );
|
||||
if ( NetworkUtils.isConnected( mMapView.getContext() ) ) {
|
||||
setTrafficEnabled( true );
|
||||
}
|
||||
mMapView.getMap().moveCamera( CameraUpdateFactory.zoomTo( mDefaultZoomLevel ) );
|
||||
}
|
||||
|
||||
private void initListeners() {
|
||||
|
||||
mMarkerClickHandler = new AMapMarkerClickHandler();
|
||||
final AMap aMap = mMapView.getMap();
|
||||
if ( aMap != null ) {
|
||||
aMap.setOnMarkerClickListener( this );
|
||||
aMap.setOnMapLoadedListener( this );
|
||||
aMap.setOnMapTouchListener( this );
|
||||
aMap.setOnPolylineClickListener( this );
|
||||
aMap.setOnCameraChangeListener( this );
|
||||
aMap.setOnPOIClickListener( this );
|
||||
aMap.setOnMapClickListener( this );
|
||||
aMap.setOnCameraChangeListener( this );
|
||||
aMap.setOnMyLocationChangeListener( this );
|
||||
}
|
||||
AMapMessageManager.getInstance().clear();
|
||||
AMapMessageManager.getInstance().registerAMapMessageListener( this );
|
||||
}
|
||||
|
||||
private Context getContext() {
|
||||
return mMapView.getContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getMapView() {
|
||||
return mMapView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoMap getMap() {
|
||||
return mIMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate( Bundle bundle ) {
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onCreate( bundle );
|
||||
Logger.d( TAG, "map onCreate" );
|
||||
initMapView();
|
||||
initListeners();
|
||||
initMyLocation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onResume();
|
||||
Logger.d( TAG, "map onResume" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onPause();
|
||||
Logger.d( TAG, "map onPause" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onDestroy();
|
||||
AMapUIController.getInstance().release();
|
||||
AMapWrapper.release();
|
||||
Logger.d( TAG, "map onDestroy" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState( Bundle outState ) {
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onSaveInstanceState( outState );
|
||||
Logger.d( TAG, "map onSaveInstanceState" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onLowMemory();
|
||||
}
|
||||
Logger.d( TAG, "map onLowMemory" );
|
||||
}
|
||||
|
||||
/**
|
||||
* 地图marker点击
|
||||
*/
|
||||
@Override
|
||||
public boolean onMarkerClick( Marker marker ) {
|
||||
return mMarkerClickHandler.handleMarkerClicked( marker );
|
||||
}
|
||||
|
||||
/**
|
||||
* 地图加载完毕
|
||||
*/
|
||||
@Override
|
||||
public void onMapLoaded() {
|
||||
MogoMapListenerHandler.getInstance().onMapLoaded();
|
||||
}
|
||||
|
||||
/**
|
||||
* 地图点击回调
|
||||
*/
|
||||
@Override
|
||||
public void onTouch( MotionEvent motionEvent ) {
|
||||
MogoMapListenerHandler.getInstance().onTouch( motionEvent );
|
||||
if ( mIsCarLocked ) {
|
||||
loseLockMode();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POI 点击
|
||||
*/
|
||||
@Override
|
||||
public void onPOIClick( Poi poi ) {
|
||||
if ( InterceptorHandler.getInstance().ignorePoiClicked( getContext() ) ) {
|
||||
return;
|
||||
}
|
||||
MogoMapListenerHandler.getInstance().onPOIClick( ObjectUtils.fromAMap( poi ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapClick( LatLng latLng ) {
|
||||
if ( InterceptorHandler.getInstance().ignoreMapClicked( getContext() ) ) {
|
||||
return;
|
||||
}
|
||||
MogoMapListenerHandler.getInstance().onMapClick( ObjectUtils.fromAMap( latLng ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPolylineClick( Polyline polyline ) {
|
||||
if ( !NaviClient.getInstance( getContext() ).isNaviing() ) {
|
||||
NaviClient.getInstance( getContext() ).handleClickedPolyline( polyline );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTrafficEnabled( boolean visible ) {
|
||||
if ( checkMapView() ) {
|
||||
Logger.d( TAG, "setTrafficEnabled" );
|
||||
mMapView.getMap().setTrafficEnabled( true );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapControlResult changeZoom( boolean zoom ) {
|
||||
if ( checkMapView() ) {
|
||||
mDefaultZoomLevel = ( int ) ( getMap().getZoomLevel() + 0.5f );
|
||||
|
||||
if ( zoom ) {
|
||||
if ( mDefaultZoomLevel >= 20 ) {
|
||||
return MapControlResult.TARGET;
|
||||
}
|
||||
} else {
|
||||
if ( mDefaultZoomLevel <= 3 ) {
|
||||
return MapControlResult.TARGET;
|
||||
}
|
||||
}
|
||||
|
||||
if ( zoom ) {
|
||||
mDefaultZoomLevel += 2f;
|
||||
if ( mDefaultZoomLevel > 20 ) {
|
||||
mDefaultZoomLevel = 20;
|
||||
}
|
||||
} else {
|
||||
mDefaultZoomLevel -= 2f;
|
||||
if ( mDefaultZoomLevel < 1 ) {
|
||||
mDefaultZoomLevel = 1;
|
||||
}
|
||||
}
|
||||
changeZoom( ( int ) mDefaultZoomLevel );
|
||||
}
|
||||
return MapControlResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapControlResult changeZoom( float zoom ) {
|
||||
Logger.d( TAG, "changeZoom %s", zoom );
|
||||
getMap().changeZoom( zoom );
|
||||
return MapControlResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeMapMode( EnumMapUI ui ) {
|
||||
if ( ui == null ) {
|
||||
return;
|
||||
}
|
||||
if ( checkMapView() ) {
|
||||
switch ( ui ) {
|
||||
|
||||
case CarUp_3D:
|
||||
mMapView.getMap().moveCamera( CameraUpdateFactory.changeTilt( 60 ) );
|
||||
break;
|
||||
case NorthUP_2D:
|
||||
mMapView.getMap().moveCamera( CameraUpdateFactory.changeTilt( 0 ) );
|
||||
break;
|
||||
case CarUp_2D:
|
||||
mMapView.getMap().moveCamera( CameraUpdateFactory.changeTilt( 0 ) );
|
||||
break;
|
||||
case Type_Light:
|
||||
mMapView.getMap().setMapType( AMap.MAP_TYPE_NORMAL );
|
||||
break;
|
||||
case Type_Night:
|
||||
mMapView.getMap().setMapType( AMap.MAP_TYPE_NIGHT );
|
||||
break;
|
||||
case Type_AUTO_LIGHT_Night:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeMapVisualAngle(VisualAngleMode angelMode, MogoLatLng mogoLatLng) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisualAngleMode getCurrentMapVisualAngle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean checkMapView() {
|
||||
if ( mMapView == null || mMapView.getMap() == null ) {
|
||||
Logger.e( TAG, "高德mapView实例为空,请检查" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveToCenter( MogoLatLng latLng, boolean animate ) {
|
||||
Logger.d( TAG, "move to center %s", latLng );
|
||||
if ( latLng == null || latLng.lat == 0.0d || latLng.lng == 0.0d ) {
|
||||
Logger.e( TAG, "latlng = null or is illegal" );
|
||||
return;
|
||||
}
|
||||
loseLockMode();
|
||||
if ( animate ) {
|
||||
mMapView.getMap().animateCamera( CameraUpdateFactory.newLatLng( new LatLng( latLng.lat, latLng.lng ) ) );
|
||||
} else {
|
||||
mMapView.getMap().moveCamera( CameraUpdateFactory.newLatLng( new LatLng( latLng.lat, latLng.lng ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMyLocation( boolean visible ) {
|
||||
Logger.d( TAG, "showMyLocation1 %s", visible );
|
||||
if ( visible && NaviClient.getInstance( getContext() ).isNaviing() ) {
|
||||
return;
|
||||
}
|
||||
if ( checkMapView() ) {
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
if ( style == null ) {
|
||||
style = new MyLocationStyle();
|
||||
}
|
||||
style.showMyLocation( visible );
|
||||
if ( visible ) {
|
||||
// 强制刷新一遍车标
|
||||
style.myLocationIcon( BitmapDescriptorFactory.fromResource( mCarCursorOption.getCarCursorRes() ) );
|
||||
}
|
||||
mMapView.getMap().setMyLocationStyle( style );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emphasizeMyLocation() {
|
||||
// 空实现
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMyLocation( View view ) {
|
||||
if ( NaviClient.getInstance( getContext() ).isNaviing() ) {
|
||||
return;
|
||||
}
|
||||
if ( checkMapView() ) {
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
if ( style == null ) {
|
||||
style = new MyLocationStyle();
|
||||
}
|
||||
style.showMyLocation( true );
|
||||
style.myLocationIcon( BitmapDescriptorFactory.fromView( view ) );
|
||||
mMapView.getMap().setMyLocationStyle( style );
|
||||
}
|
||||
}
|
||||
|
||||
public void initMyLocation() {
|
||||
if ( checkMapView() ) {
|
||||
mMapView.getMap().setMyLocationEnabled( true );
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER );
|
||||
style.interval( 1000 );
|
||||
style.anchor( 0.5F, 0.5F );
|
||||
style.strokeColor( Color.TRANSPARENT );
|
||||
style.strokeWidth( 0 );
|
||||
style.radiusFillColor( Color.TRANSPARENT );
|
||||
mMapView.getMap().setMyLocationStyle( style );
|
||||
}
|
||||
}
|
||||
|
||||
private MyLocationStyle getMyLocationStyle() {
|
||||
MyLocationStyle style = null;
|
||||
try {
|
||||
style = mMapView.getMap().getMyLocationStyle();
|
||||
} catch ( Exception e ) {
|
||||
style = new MyLocationStyle();
|
||||
} finally {
|
||||
if ( style == null ) {
|
||||
style = new MyLocationStyle();
|
||||
}
|
||||
return style;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recoverLockMode() {
|
||||
if ( checkMapView() ) {
|
||||
Logger.d( TAG, "锁车" );
|
||||
Location target = NaviClient.getInstance( getContext() ).getCarLocation2();
|
||||
if ( target != null ) {
|
||||
mMapView.getMap().animateCamera( CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition( new LatLng( target.getLatitude(), target.getLongitude() ),
|
||||
mDefaultZoomLevel,
|
||||
0,
|
||||
0
|
||||
)
|
||||
), new AMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onFinish() {
|
||||
changeMyLocationStyle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
changeMyLocationStyle();
|
||||
}
|
||||
} );
|
||||
} else {
|
||||
changeMyLocationStyle();
|
||||
}
|
||||
mIsCarLocked = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void changeMyLocationStyle() {
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
if ( style == null ) {
|
||||
style = new MyLocationStyle();
|
||||
}
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_FOLLOW );
|
||||
mMapView.getMap().setMyLocationStyle( style );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loseLockMode() {
|
||||
Logger.d( TAG, "解锁锁车" );
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER );
|
||||
mMapView.getMap().setMyLocationStyle( style );
|
||||
mIsCarLocked = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟点击事件,达到锁车->普通事件
|
||||
*/
|
||||
private void mockTouchEvent() {
|
||||
long downTime = SystemClock.uptimeMillis();
|
||||
long eventTime = downTime + 1;
|
||||
int metaState = 0;
|
||||
MotionEvent motionEvent = MotionEvent.obtain( downTime, eventTime, MotionEvent.ACTION_DOWN, 0, 0, metaState );
|
||||
mMapView.dispatchTouchEvent( motionEvent );
|
||||
MotionEvent upEvent = MotionEvent.obtain( downTime + 1, eventTime + 2, MotionEvent.ACTION_UP, 0, 0, metaState );
|
||||
mMapView.dispatchTouchEvent( upEvent );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLockZoom( int var1 ) {
|
||||
if ( checkMapView() ) {
|
||||
Logger.d( TAG, "Zoom锁定锁车比例尺 %s", var1 );
|
||||
// mMapView.setLockZoom( var1 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayOverview( Rect bounds ) {
|
||||
if ( checkMapView() ) {
|
||||
if ( NaviClient.getInstance( getContext() ).isNaviing() ) {
|
||||
loseLockMode();
|
||||
NaviClient.getInstance( getContext() ).displayOverview( bounds );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScalePerPixel() {
|
||||
return getMap().getScalePerPixel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getZoomLevel() {
|
||||
return getMap().getZoomLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRoadWidth(double lon, double lat, float angle, boolean isGpsLocation, boolean isRTK) {
|
||||
return getMap().getRoadWidth(lon, lat, angle, isGpsLocation, isRTK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviStarted() {
|
||||
if ( checkMapView() ) {
|
||||
showMyLocation( false );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviStopped() {
|
||||
if ( checkMapView() ) {
|
||||
showMyLocation( true );
|
||||
NaviClient.getInstance( getContext() ).startAimlessMode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviInfoUpdat( NaviInfo naviInfo ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculateSuccess() {
|
||||
loseLockMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraChange( CameraPosition cameraPosition ) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraChangeFinish( CameraPosition cameraPosition ) {
|
||||
if ( cameraPosition != null ) {
|
||||
Trace.beginSection( "timer.onCameraChangeFinish" );
|
||||
MogoMapListenerHandler.getInstance().onMapChanged( ObjectUtils.fromAMap( cameraPosition.target ),
|
||||
cameraPosition.zoom,
|
||||
cameraPosition.tilt,
|
||||
cameraPosition.bearing );
|
||||
Trace.endSection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getCameraNorthEastPosition() {
|
||||
try {
|
||||
return ObjectUtils.fromAMap( mMapView.getMap().getProjection().getVisibleRegion().latLngBounds.northeast );
|
||||
} catch ( Exception e ) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getCameraSouthWestPosition() {
|
||||
try {
|
||||
return ObjectUtils.fromAMap( mMapView.getMap().getProjection().getVisibleRegion().latLngBounds.southwest );
|
||||
} catch ( Exception e ) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getWindowCenterLocation() {
|
||||
try {
|
||||
return ObjectUtils.fromAMap( mMapView.getMap().getCameraPosition().target );
|
||||
} catch ( Exception e ) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPointToCenter( double mapCenterX, double mapCenterY ) {
|
||||
if ( checkMapView() ) {
|
||||
Logger.d( TAG, "setPointToCenter(%s, %s)", mapCenterX, mapCenterY );
|
||||
mMapView.getMap().setPointToCenter( ( ( int ) ( mapCenterX * WindowUtils.getScreenWidth( getContext() ) ) ),
|
||||
( ( int ) ( mapCenterY * WindowUtils.getScreenHeight( getContext() ) ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getLocationPointInScreen( MogoLatLng latLng ) {
|
||||
if ( checkMapView() ) {
|
||||
try {
|
||||
return mMapView.getMap()
|
||||
.getProjection()
|
||||
.toScreenLocation( ObjectUtils.fromMogo2( latLng ) );
|
||||
} catch ( Exception e ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getLocationMogoLatLngInScreen( Point point ) {
|
||||
if ( checkMapView() ) {
|
||||
try {
|
||||
return ObjectUtils.fromAMap(
|
||||
mMapView.getMap().getProjection().fromScreenLocation( point ) );
|
||||
} catch ( Exception e ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startJumpAnimation( IMogoMarker marker, float high, Interpolator interpolator,
|
||||
long duration ) {
|
||||
if ( marker == null || high <= 0.0f || interpolator == null || duration < 0 ) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final LatLng latLng = ObjectUtils.fromMogo2( marker.getPosition() );
|
||||
Point point = mMapView.getMap().getProjection().toScreenLocation( latLng );
|
||||
point.y -= WindowUtils.dip2px( getContext(), high );
|
||||
LatLng target = mMapView.getMap().getProjection().fromScreenLocation( point );
|
||||
//使用TranslateAnimation,填写一个需要移动的目标点
|
||||
Animation animation = new TranslateAnimation( target );
|
||||
animation.setInterpolator( interpolator );
|
||||
//整个移动所需要的时间
|
||||
animation.setDuration( duration );
|
||||
//设置动画
|
||||
if ( marker instanceof AMapMarkerWrapper ) {
|
||||
( ( AMapMarkerWrapper ) marker ).getMarker().setAnimation( animation );
|
||||
( ( AMapMarkerWrapper ) marker ).getMarker().startAnimation();
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRenderFps( int fps ) {
|
||||
if ( checkMapView() ) {
|
||||
if ( mMapView.getMap() != null ) {
|
||||
mMapView.getMap().setRenderFps( fps );
|
||||
Logger.d( TAG, "设置刷新帧率 fps = %s", fps );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showBounds( String tag, MogoLatLng carPosition, List< MogoLatLng > lonLats, Rect bound, boolean lockCarPosition ) {
|
||||
if ( !checkMapView() ) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
LatLngBounds latLngBounds = MogoMapUtils.getLatLngBounds( carPosition, lonLats, lockCarPosition );
|
||||
if ( !lockCarPosition ) {
|
||||
loseLockMode();
|
||||
}
|
||||
mMapView.getMap().moveCamera( CameraUpdateFactory.newLatLngBoundsRect( latLngBounds, bound.left, bound.right, bound.top, bound.bottom ) );
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "%s error.", tag );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceRender() {
|
||||
if ( checkMapView() ) {
|
||||
mMapView.getMap().runOnDrawFrame();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float calculateLineDistance( MogoLatLng p1, MogoLatLng p2 ) throws Exception {
|
||||
if ( p1 == null || p2 == null ) {
|
||||
throw new Exception( "计算距离的点不能为 null" );
|
||||
}
|
||||
return AMapUtils.calculateLineDistance( ObjectUtils.fromMogo2( p1 ), ObjectUtils.fromMogo2( p2 ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMyLocationChange( Location location ) {
|
||||
NaviClient.getInstance( getContext() ).syncCarLocation( location );
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumMapUI getCurrentUiMode() {
|
||||
return mCurrentUIMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeMyLocation( Location location ) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isCarLocked() {
|
||||
return mIsCarLocked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCarCursorOption( CarCursorOption option ) {
|
||||
if ( mCarCursorOption != null && mCarCursorOption != DEFAULT_OPTION ) {
|
||||
mCarCursorOption.destroy();
|
||||
}
|
||||
if ( option != null ) {
|
||||
try {
|
||||
mCarCursorOption = option.clone();
|
||||
} catch ( Exception e ) {
|
||||
mCarCursorOption = DEFAULT_OPTION;
|
||||
}
|
||||
} else {
|
||||
mCarCursorOption = DEFAULT_OPTION;
|
||||
}
|
||||
if ( !checkMapView() ) {
|
||||
return;
|
||||
}
|
||||
if ( mMapView.getMap() == null ) {
|
||||
return;
|
||||
}
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
if ( mCarCursorOption.getCarCursorBmp() != null && !mCarCursorOption.getCarCursorBmp().isRecycled() ) {
|
||||
style.myLocationIcon( BitmapDescriptorFactory.fromBitmap( mCarCursorOption.getCarCursorBmp() ) );
|
||||
} else {
|
||||
if ( mCarCursorOption.getCarCursorRes() != 0 ) {
|
||||
style.myLocationIcon( BitmapDescriptorFactory.fromResource( mCarCursorOption.getCarCursorRes() ) );
|
||||
} else {
|
||||
style.myLocationIcon( BitmapDescriptorFactory.fromResource( DEFAULT_OPTION.getCarCursorRes() ) );
|
||||
}
|
||||
}
|
||||
mMapView.getMap().setMyLocationStyle( style );
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapCameraPosition getMapCameraPosition() {
|
||||
if ( checkMapView() ) {
|
||||
CameraPosition cameraPosition = mMapView.getMap().getCameraPosition();
|
||||
return ObjectUtils.fromAMap( cameraPosition );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeBearing( float bearing ) {
|
||||
if ( checkMapView() ) {
|
||||
mMapView.getMap().moveCamera( CameraUpdateFactory.changeBearing( bearing ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTileId(double lon, double lat) {
|
||||
return getMap().getUIController().getTileId(lon,lat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAdasRecognizedResult(int drawlevel) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,269 +0,0 @@
|
||||
package com.mogo.map.impl.amap;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.CameraUpdateFactory;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.amap.api.maps.model.MarkerOptions;
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.maps.model.PolylineOptions;
|
||||
import com.amap.api.navi.AMapNaviView;
|
||||
import com.mogo.map.IMogoMap;
|
||||
import com.mogo.map.IMogoUiSettings;
|
||||
import com.mogo.map.impl.amap.marker.AMapInfoWindowAdapter;
|
||||
import com.mogo.map.impl.amap.marker.AMapMarkerWrapper;
|
||||
import com.mogo.map.impl.amap.overlay.AMapPolylineWrapper;
|
||||
import com.mogo.map.impl.amap.uicontroller.AMapUIController;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.map.marker.MogoMarkersHandler;
|
||||
import com.mogo.map.overlay.IMogoPolyline;
|
||||
import com.mogo.map.overlay.MogoPolylineOptions;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-18
|
||||
* <p>
|
||||
* 代理高德AMap
|
||||
*/
|
||||
public class AMapWrapper implements IMogoMap {
|
||||
|
||||
private static final String TAG = "AMapWrapper";
|
||||
|
||||
private static AMap sAMap;
|
||||
private final Context mContext;
|
||||
private IMogoMapUIController mUIcontroller;
|
||||
private AMap mAMap;
|
||||
private IMogoUiSettings mUiSettings;
|
||||
|
||||
public AMapWrapper( AMap map, Context context, IMogoMapUIController controller ) {
|
||||
this.mAMap = map;
|
||||
sAMap = map;
|
||||
mContext = context.getApplicationContext();
|
||||
mUIcontroller = controller;
|
||||
// 设置实现自定义 info window
|
||||
if(mAMap!=null) {
|
||||
mAMap.setInfoWindowAdapter(new AMapInfoWindowAdapter());
|
||||
}
|
||||
AMapUIController.getInstance().initClient( mUIcontroller );
|
||||
}
|
||||
|
||||
public static AMap getAMap() {
|
||||
return sAMap;
|
||||
}
|
||||
|
||||
public static void release(){
|
||||
sAMap = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoUiSettings getUiSettings() {
|
||||
if ( !checkAMap() ) {
|
||||
return null;
|
||||
}
|
||||
if ( mUiSettings == null ) {
|
||||
mUiSettings = new AMapUiSettingsWrapper( mAMap.getUiSettings() );
|
||||
}
|
||||
return mUiSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoMapUIController getUIController() {
|
||||
return mUIcontroller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoMarker addMarker( String tag, MogoMarkerOptions options ) {
|
||||
if ( !checkAMap() ) {
|
||||
return null;
|
||||
}
|
||||
MarkerOptions markerOptions = ObjectUtils.fromMogo( options );
|
||||
if ( markerOptions == null ) {
|
||||
Logger.e( TAG, "marker参数为空" );
|
||||
return null;
|
||||
}
|
||||
final IMogoMarker mogoMarker = new AMapMarkerWrapper( mAMap.addMarker( markerOptions ), options );
|
||||
if ( options.isAutoManager() ) {
|
||||
MogoMarkersHandler.getInstance().add( tag, mogoMarker );
|
||||
}
|
||||
return mogoMarker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList< IMogoMarker > addMarkers( String tag, ArrayList< MogoMarkerOptions > options, boolean moveToCenter ) {
|
||||
if ( !checkAMap() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( options == null || options.isEmpty() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 地图导航时,忽略参数
|
||||
if ( InterceptorHandler.getInstance().ignoreAddMarkersMoveToCenterParameters( getContext() ) ) {
|
||||
moveToCenter = false;
|
||||
}
|
||||
|
||||
ArrayList< Marker > markers = null;
|
||||
ArrayList< MarkerOptions > markerOptions = new ArrayList<>();
|
||||
ArrayList< IMogoMarker > mogoMarkers = new ArrayList<>();
|
||||
|
||||
for ( MogoMarkerOptions option : options ) {
|
||||
if ( option == null ) {
|
||||
continue;
|
||||
}
|
||||
MarkerOptions mo = ObjectUtils.fromMogo( option );
|
||||
if ( mo == null ) {
|
||||
continue;
|
||||
}
|
||||
markerOptions.add( mo );
|
||||
}
|
||||
if ( markerOptions.isEmpty() ) {
|
||||
return null;
|
||||
}
|
||||
markers = mAMap.addMarkers( markerOptions, moveToCenter );
|
||||
if ( markers == null || markers.isEmpty() ) {
|
||||
return null;
|
||||
}
|
||||
for ( int i = 0; i < markers.size(); i++ ) {
|
||||
Marker marker = markers.get( i );
|
||||
if ( marker == null ) {
|
||||
continue;
|
||||
}
|
||||
mogoMarkers.add( new AMapMarkerWrapper( marker, options.get( i ) ) );
|
||||
}
|
||||
MogoMarkersHandler.getInstance().add( tag, mogoMarkers );
|
||||
return mogoMarkers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if ( checkAMap() ) {
|
||||
mAMap.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear( boolean isKeepMyLocationOverlay ) {
|
||||
if ( checkAMap() ) {
|
||||
mAMap.clear( isKeepMyLocationOverlay );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPointToCenter( int x, int y ) {
|
||||
if ( checkAMap() ) {
|
||||
mAMap.setPointToCenter( x, y );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTouchPoiEnable( boolean touchPoiEnable ) {
|
||||
if ( checkAMap() ) {
|
||||
mAMap.setTouchPoiEnable( touchPoiEnable );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTrafficEnable( boolean enable ) {
|
||||
if ( checkAMap() ) {
|
||||
mAMap.setTrafficEnabled( enable );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showBuildings( boolean enabled ) {
|
||||
if ( checkAMap() ) {
|
||||
mAMap.showBuildings( enabled );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showIndoorMap( boolean enable ) {
|
||||
if ( checkAMap() ) {
|
||||
mAMap.showIndoorMap( enable );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMapText( boolean enable ) {
|
||||
if ( checkAMap() ) {
|
||||
mAMap.showMapText( enable );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopAnimation() {
|
||||
if ( checkAMap() ) {
|
||||
mAMap.stopAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScalePerPixel() {
|
||||
if ( checkAMap() ) {
|
||||
return mAMap.getScalePerPixel();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeZoom( float zoom ) {
|
||||
if ( checkAMap() ) {
|
||||
mAMap.moveCamera( CameraUpdateFactory.zoomTo( zoom ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getZoomLevel() {
|
||||
if ( checkAMap() ) {
|
||||
try {
|
||||
return mAMap.getCameraPosition().zoom;
|
||||
} catch ( Exception e ) {
|
||||
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoPolyline addPolyline( MogoPolylineOptions options ) {
|
||||
if ( checkAMap() ) {
|
||||
PolylineOptions polylineOptions = ObjectUtils.fromMogo( options );
|
||||
if ( polylineOptions == null ) {
|
||||
return null;
|
||||
}
|
||||
Polyline polyline = mAMap.addPolyline( polylineOptions );
|
||||
return new AMapPolylineWrapper( polyline, options );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMapVersion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean checkAMap() {
|
||||
if ( mAMap == null ) {
|
||||
Logger.e( TAG, "高德map实例为空,请检查" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRoadWidth(double lon, double lat, float angle, boolean isGpsLocation, boolean isRTK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private Context getContext() {
|
||||
return mContext;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.mogo.map.impl.amap;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-27
|
||||
* <p>
|
||||
* 操作拦截器
|
||||
*/
|
||||
public interface IInterceptor {
|
||||
|
||||
/**
|
||||
* 是否忽略添加多个marker时聚拢参数
|
||||
* <p>
|
||||
* 导航时:不需要聚拢
|
||||
*
|
||||
* @return true - 忽略 false - 不忽略
|
||||
*/
|
||||
boolean ignoreAddMarkersMoveToCenterParameters( Context context );
|
||||
|
||||
/**
|
||||
* 导航时,是否响应 poi 点击
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
boolean ignorePoiClicked( Context context );
|
||||
|
||||
/**
|
||||
* 导航时,是否响应地图点击
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
boolean ignoreMapClicked( Context context );
|
||||
|
||||
/**
|
||||
* 请求绘制路线
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
boolean ignoreDrawRouteOverlay( Context context );
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.mogo.map.impl.amap;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.mogo.map.impl.amap.navi.NaviClient;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-27
|
||||
* <p>
|
||||
* 操作拦截器
|
||||
*/
|
||||
public class InterceptorHandler implements IInterceptor {
|
||||
|
||||
private static volatile InterceptorHandler sInstance;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private InterceptorHandler() {
|
||||
}
|
||||
|
||||
public static InterceptorHandler getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( InterceptorHandler.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new InterceptorHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
public void init( Context context ) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignoreAddMarkersMoveToCenterParameters( Context context ) {
|
||||
return NaviClient.getInstance( context ).isNaviing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignorePoiClicked( Context context ) {
|
||||
return NaviClient.getInstance( context ).isNaviing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignoreMapClicked( Context context ) {
|
||||
return NaviClient.getInstance( context ).isNaviing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignoreDrawRouteOverlay( Context context ) {
|
||||
return NaviClient.getInstance( context ).isNaviing();
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package com.mogo.map.impl.amap.hook;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.autonavi.amap.mapcore.interfaces.IAMap;
|
||||
import com.autonavi.base.ae.gmap.GLMapEngine;
|
||||
import com.autonavi.base.amap.api.mapcore.IAMapDelegate;
|
||||
import com.autonavi.base.amap.mapcore.interfaces.IAMapListener;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-03-12
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class BnHooker implements InvocationHandler {
|
||||
|
||||
private static final String TAG = "BnHooker";
|
||||
|
||||
private Object host;
|
||||
private Method getGLMapEngineMethod;
|
||||
private GLMapEngine glMapEngineObject;
|
||||
|
||||
public BnHooker( AMap map ) throws Exception {
|
||||
|
||||
if ( map == null ) {
|
||||
return;
|
||||
}
|
||||
Field field = AMap.class.getDeclaredField( "a" );
|
||||
field.setAccessible( true );
|
||||
host = field.get( map );
|
||||
Object object = Proxy.newProxyInstance(
|
||||
BnHooker.class.getClassLoader(),
|
||||
new Class[]{
|
||||
com.amap.api.col.n3.ft.a.class,
|
||||
IAMapDelegate.class,
|
||||
IAMapListener.class,
|
||||
IAMap.class
|
||||
},
|
||||
this
|
||||
);
|
||||
field.set( map, object );
|
||||
|
||||
}
|
||||
|
||||
public void clearAllMessages() throws Exception {
|
||||
if ( glMapEngineObject == null ) {
|
||||
if ( getGLMapEngineMethod == null ) {
|
||||
getGLMapEngineMethod = host.getClass().getDeclaredMethod( "getGLMapEngine" );
|
||||
getGLMapEngineMethod.setAccessible( true );
|
||||
}
|
||||
glMapEngineObject = ( GLMapEngine ) getGLMapEngineMethod.invoke( host );
|
||||
}
|
||||
if ( glMapEngineObject != null ) {
|
||||
clearMessageList( "mStateMessageList", glMapEngineObject );
|
||||
clearMessageList( "mAnimateStateMessageList", glMapEngineObject );
|
||||
}
|
||||
}
|
||||
|
||||
private void clearMessageList( String filedName, Object obj ) throws Exception {
|
||||
Field stateMessageListField = obj.getClass().getDeclaredField( filedName );
|
||||
stateMessageListField.setAccessible( true );
|
||||
List valList = ( List ) stateMessageListField.get( obj );
|
||||
valList.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable {
|
||||
if ( method.getName().equals( "setRenderFps" ) ) {
|
||||
return method.invoke( host, 10 );
|
||||
}
|
||||
return method.invoke( host, args );
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
package com.mogo.map.impl.amap.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Trace;
|
||||
|
||||
import com.amap.api.location.AMapLocation;
|
||||
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.IMogoLocationClient;
|
||||
import com.mogo.map.location.IMogoLocationListener;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
import com.mogo.map.location.MogoLocationListenerRegister;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-19
|
||||
* <p>
|
||||
* 高德定位
|
||||
*/
|
||||
public class ALocationClient implements IMogoLocationClient {
|
||||
|
||||
private static final String TAG = "LocationClient";
|
||||
private final Context mContext;
|
||||
|
||||
private MogoLocation mLastLocation;
|
||||
private AMapLocationListener mListener = new InternalLocationListener();
|
||||
|
||||
private boolean mIsDestroyed = false;
|
||||
|
||||
public ALocationClient( Context context ) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
private AMapLocationClient mClient;
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
start( 2_000L );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start( long interval ) {
|
||||
if ( mClient == null ) {
|
||||
mClient = new AMapLocationClient( mContext );
|
||||
mClient.setLocationListener( mListener );
|
||||
mLastLocation = ObjectUtils.fromAMap( mClient.getLastKnownLocation() );
|
||||
}
|
||||
if ( !mClient.isStarted() ) {
|
||||
AMapLocationClientOption option = new AMapLocationClientOption();
|
||||
option.setLocationMode( AMapLocationClientOption.AMapLocationMode.Hight_Accuracy );
|
||||
option.setNeedAddress( true );
|
||||
option.setGpsFirst( true );
|
||||
option.setInterval( interval );
|
||||
mClient.setLocationOption( option );
|
||||
mClient.startLocation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if ( mIsDestroyed ) {
|
||||
destroyWarming();
|
||||
return;
|
||||
}
|
||||
if ( mClient != null && mClient.isStarted() ) {
|
||||
mClient.stopLocation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLocationListener( IMogoLocationListener listener ) {
|
||||
// do not impl.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLocationListener( IMogoLocationListener listener ) {
|
||||
// do not impl.
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLocation getLastKnowLocation() {
|
||||
if ( mIsDestroyed ) {
|
||||
destroyWarming();
|
||||
return null;
|
||||
}
|
||||
if ( mLastLocation == null ) {
|
||||
mLastLocation = new MogoLocation();
|
||||
}
|
||||
return mLastLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void destroy() {
|
||||
mIsDestroyed = true;
|
||||
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;
|
||||
}
|
||||
Trace.beginSection( "timer.onLocationChanged" );
|
||||
mLastLocation = ObjectUtils.fromAMap( aMapLocation );
|
||||
Set<IMogoLocationListener> listeners = MogoLocationListenerRegister.getInstance().getListeners();
|
||||
synchronized ( listeners ) {
|
||||
Iterator< IMogoLocationListener > listenerIterator = listeners.iterator();
|
||||
while ( listenerIterator.hasNext() ) {
|
||||
listenerIterator.next().onLocationChanged( mLastLocation );
|
||||
}
|
||||
}
|
||||
Trace.endSection();
|
||||
}
|
||||
}
|
||||
|
||||
private void destroyWarming() {
|
||||
Logger.w( TAG, "location client has destroyed." );
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.mogo.map.impl.amap.marker;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.mogo.map.marker.IMogoInfoWindowAdapter;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-24
|
||||
* <p>
|
||||
* 自定义infowindow
|
||||
*/
|
||||
public final class AMapInfoWindowAdapter implements AMap.InfoWindowAdapter {
|
||||
|
||||
@Override
|
||||
public View getInfoWindow( Marker marker ) {
|
||||
if ( marker.getObject() instanceof IMogoMarker ) {
|
||||
IMogoMarker mogoMarker = ( ( IMogoMarker ) marker.getObject() );
|
||||
IMogoInfoWindowAdapter delegate = mogoMarker.getInfoWindowAdapter();
|
||||
if ( delegate != null ) {
|
||||
return delegate.getInfoWindow( mogoMarker );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getInfoContents( Marker marker ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,552 +0,0 @@
|
||||
package com.mogo.map.impl.amap.marker;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Point;
|
||||
import android.view.View;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import com.amap.api.maps.model.BitmapDescriptor;
|
||||
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.animation.AlphaAnimation;
|
||||
import com.amap.api.maps.model.animation.Animation;
|
||||
import com.amap.api.maps.model.animation.AnimationSet;
|
||||
import com.amap.api.maps.model.animation.ScaleAnimation;
|
||||
import com.amap.api.maps.model.animation.TranslateAnimation;
|
||||
import com.amap.api.maps.utils.overlay.MovingPointOverlay;
|
||||
import com.autonavi.amap.mapcore.IPoint;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.map.impl.amap.AMapWrapper;
|
||||
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 com.mogo.map.marker.anim.OnMarkerAnimationListener;
|
||||
import com.mogo.utils.WindowUtils;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-18
|
||||
* <p>
|
||||
* 高德marker
|
||||
*/
|
||||
public class AMapMarkerWrapper implements IMogoMarker, Observer {
|
||||
|
||||
private final String TAG = AMapMarkerWrapper.class.getName();
|
||||
|
||||
private Marker mMarker;
|
||||
private Object mObject;
|
||||
private IMogoMarkerClickListener mMogoMarkerClickListener;
|
||||
private IMogoInfoWindowAdapter mMogoInfoWindowAdapter;
|
||||
|
||||
private boolean mIsDestroy = false;
|
||||
|
||||
private MogoMarkerOptions mMogoMarkerOptions;
|
||||
private String mOwner;
|
||||
|
||||
private MovingPointOverlay mMovingPointOverlay;
|
||||
|
||||
public AMapMarkerWrapper( Marker marker, MogoMarkerOptions mogoMarkerOptions ) {
|
||||
this.mMarker = marker;
|
||||
if ( marker != null ) {
|
||||
// 设置高德 marker 的object对象为 IMogoMarker 实例。!!!!
|
||||
marker.setObject( this );
|
||||
}
|
||||
setObject( mogoMarkerOptions.getObject() );
|
||||
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.setObject( null );
|
||||
mMarker.remove();
|
||||
mMarker = null;
|
||||
}
|
||||
if ( mMovingPointOverlay != null ) {
|
||||
try {
|
||||
mMovingPointOverlay.stopMove();
|
||||
mMovingPointOverlay.destroy();
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mMovingPointOverlay = null;
|
||||
}
|
||||
mMogoInfoWindowAdapter = null;
|
||||
mMogoMarkerClickListener = null;
|
||||
mObject = null;
|
||||
mIsDestroy = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideInfoWindow() {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.hideInfoWindow();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha( float alpha ) {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setAlpha( alpha );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnchor( float anchorU, float anchorV ) {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setAnchor( anchorU, anchorV );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDraggable( boolean paramBoolean ) {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setDraggable( paramBoolean );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIcon( Bitmap icon ) {
|
||||
if ( icon == null || icon.isRecycled() ) {
|
||||
return;
|
||||
}
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setIcon( BitmapDescriptorFactory.fromBitmap( icon ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIcons( ArrayList< Bitmap > icons ) {
|
||||
if ( icons == null || icons.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
ArrayList< BitmapDescriptor > descriptors = new ArrayList<>();
|
||||
for ( Bitmap icon : icons ) {
|
||||
if ( icon == null || icon.isRecycled() ) {
|
||||
continue;
|
||||
}
|
||||
descriptors.add( BitmapDescriptorFactory.fromBitmap( icon ) );
|
||||
}
|
||||
if ( descriptors.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setIcons( descriptors );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInfoWindowEnable( boolean enabled ) {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setInfoWindowEnable( enabled );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMarkerOptions( MogoMarkerOptions opt ) {
|
||||
|
||||
final MarkerOptions options = ObjectUtils.fromMogo( opt );
|
||||
if ( options == null ) {
|
||||
return;
|
||||
}
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setMarkerOptions( options );
|
||||
setObject( opt.getObject() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setObject( Object object ) {
|
||||
mObject = object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObject() {
|
||||
return mObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPeriod( int period ) {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setPeriod( period );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition( double lat, double lng ) {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setPosition( new LatLng( lat, lng ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getPosition() {
|
||||
if ( mMarker != null ) {
|
||||
final LatLng latLng = mMarker.getPosition();
|
||||
return ObjectUtils.fromAMap( latLng );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotateAngle( float rotate ) {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setRotateAngle( rotate );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSnippet( String snippet ) {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setSnippet( snippet );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle( String title ) {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setTitle( title );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setToTop() {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setToTop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible( boolean visible ) {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setVisible( visible );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setZIndex( int zIndex ) {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setZIndex( zIndex );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showInfoWindow() {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.showInfoWindow();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMarkerAssInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnMarkerClickListener( IMogoMarkerClickListener listener ) {
|
||||
mMogoMarkerClickListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoMarkerClickListener getOnMarkerClickListener() {
|
||||
return mMogoMarkerClickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInfoWindowAdapter( IMogoInfoWindowAdapter adapter ) {
|
||||
mMogoInfoWindowAdapter = adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoInfoWindowAdapter getInfoWindowAdapter() {
|
||||
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() {
|
||||
if ( mOwner != null ) {
|
||||
return mOwner;
|
||||
}
|
||||
if ( mMogoMarkerOptions != null ) {
|
||||
return mMogoMarkerOptions.getOwner();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPositionByPixels( Point position ) {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setPositionByPixels( position.x, position.y );
|
||||
}
|
||||
}
|
||||
|
||||
public Marker getMarker() {
|
||||
return mMarker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoMarkerOptions getMogoMarkerOptions() {
|
||||
return mMogoMarkerOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startScaleAnimation( float fromX, float toX, float fromY, float toY, int duration, Interpolator interpolator ) {
|
||||
if ( isDestroyed() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
ScaleAnimation animationScale = new ScaleAnimation( fromX, toX, fromY, toY );
|
||||
animationScale.setDuration( duration );
|
||||
animationScale.setFillMode( Animation.FILL_MODE_FORWARDS );
|
||||
if ( interpolator != null ) {
|
||||
animationScale.setInterpolator( interpolator );
|
||||
}
|
||||
|
||||
mMarker.setAnimation( animationScale );
|
||||
try {
|
||||
mMarker.startAnimation();
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startScaleAnimation( float fromX, float toX, float fromY, float toY, int duration, Interpolator interpolator, OnMarkerAnimationListener listener ) {
|
||||
if ( isDestroyed() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
ScaleAnimation animationScale = new ScaleAnimation( fromX, toX, fromY, toY );
|
||||
animationScale.setDuration( duration );
|
||||
animationScale.setFillMode( Animation.FILL_MODE_FORWARDS );
|
||||
if ( interpolator != null ) {
|
||||
animationScale.setInterpolator( interpolator );
|
||||
}
|
||||
animationScale.setAnimationListener( new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart() {
|
||||
if ( isDestroyed() ) {
|
||||
return;
|
||||
}
|
||||
if ( listener != null ) {
|
||||
listener.onAnimStart();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd() {
|
||||
if ( isDestroyed() ) {
|
||||
return;
|
||||
}
|
||||
if ( listener != null ) {
|
||||
listener.onAnimEnd();
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
mMarker.setAnimation( animationScale );
|
||||
mMarker.startAnimation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startScaleAnimationWithAlpha( float fromX, float toX, float fromY, float toY, float fromAlpha, float toAlpha, int duration, Interpolator interpolator, OnMarkerAnimationListener listener ) {
|
||||
if ( isDestroyed() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
ScaleAnimation animationScale = new ScaleAnimation( fromX, toX, fromY, toY );
|
||||
animationScale.setFillMode( Animation.FILL_MODE_FORWARDS );
|
||||
|
||||
AlphaAnimation alphaAnimation = new AlphaAnimation( fromAlpha, toAlpha );
|
||||
alphaAnimation.setFillMode( Animation.FILL_MODE_FORWARDS );
|
||||
|
||||
AnimationSet animationSet = new AnimationSet( true );
|
||||
animationSet.setDuration( duration );
|
||||
if ( interpolator != null ) {
|
||||
animationSet.setInterpolator( interpolator );
|
||||
}
|
||||
animationSet.setAnimationListener( new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart() {
|
||||
if ( isDestroyed() ) {
|
||||
return;
|
||||
}
|
||||
if ( listener != null ) {
|
||||
listener.onAnimStart();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd() {
|
||||
if ( isDestroyed() ) {
|
||||
return;
|
||||
}
|
||||
if ( listener != null ) {
|
||||
listener.onAnimEnd();
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
mMarker.setAnimation( animationSet );
|
||||
try {
|
||||
mMarker.startAnimation();
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startJumpAnimation( float high, long duration, Interpolator interpolator, OnMarkerAnimationListener listener ) {
|
||||
if ( isDestroyed() || high <= 0.0f || interpolator == null || duration < 0 ) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final LatLng latLng = ObjectUtils.fromMogo2( getPosition() );
|
||||
Point point = AMapWrapper.getAMap().getProjection().toScreenLocation( latLng );
|
||||
point.y -= WindowUtils.dip2px( AbsMogoApplication.getApp(), high );
|
||||
LatLng target = AMapWrapper.getAMap().getProjection().fromScreenLocation( point );
|
||||
//使用TranslateAnimation,填写一个需要移动的目标点
|
||||
Animation animation = new TranslateAnimation( target );
|
||||
animation.setInterpolator( interpolator );
|
||||
animation.setAnimationListener( new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart() {
|
||||
if ( isDestroyed() ) {
|
||||
return;
|
||||
}
|
||||
if ( listener != null ) {
|
||||
listener.onAnimStart();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd() {
|
||||
if ( isDestroyed() ) {
|
||||
return;
|
||||
}
|
||||
if ( listener != null ) {
|
||||
listener.onAnimEnd();
|
||||
}
|
||||
}
|
||||
} );
|
||||
//整个移动所需要的时间
|
||||
animation.setDuration( duration );
|
||||
//设置动画
|
||||
mMarker.setAnimation( animation );
|
||||
mMarker.startAnimation();
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClickable( boolean clickable ) {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setClickable( clickable );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startSmooth( List< MogoLatLng > points, int duration ) {
|
||||
|
||||
if ( isDestroyed() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( mMarker == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( points == null || points.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
List< LatLng > newPoints = new ArrayList<>();
|
||||
for ( int i = 0; i < points.size(); i++ ) {
|
||||
LatLng point = ObjectUtils.fromMogo2( points.get( i ) );
|
||||
if ( point == null ) {
|
||||
continue;
|
||||
}
|
||||
newPoints.add( point );
|
||||
}
|
||||
if ( newPoints.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
if ( mMovingPointOverlay == null ) {
|
||||
mMovingPointOverlay = new MovingPointOverlay( AMapWrapper.getAMap(), mMarker );
|
||||
}
|
||||
mMovingPointOverlay.setPoints( newPoints );
|
||||
mMovingPointOverlay.setTotalDuration( duration );
|
||||
mMovingPointOverlay.startSmoothMove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startSmoothInMs( List< MogoLatLng > points, long duration ) {
|
||||
startSmooth( points, ( ( int ) ( duration / 1000 ) ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoWindowShowing() {
|
||||
if ( mMarker == null ) {
|
||||
return false;
|
||||
}
|
||||
return mMarker.isInfoWindowShown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGps( boolean isGps ) {
|
||||
MarkerOptions options = mMarker.getOptions();
|
||||
options.setGps( isGps );
|
||||
mMarker.setMarkerOptions( options );
|
||||
}
|
||||
}
|
||||
@@ -1,330 +0,0 @@
|
||||
package com.mogo.map.impl.amap.marker;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.AMapUtils;
|
||||
import com.amap.api.maps.model.BasePointOverlay;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.autonavi.amap.mapcore.IPoint;
|
||||
import com.autonavi.amap.mapcore.MapProjection;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/6/15
|
||||
* <p>
|
||||
*/
|
||||
class CombineMovingPointOverlay {
|
||||
|
||||
private static final String TAG = "CombineMovingPointOverlay";
|
||||
|
||||
private AMap mAMap;
|
||||
private long mDuration = 1_000L;
|
||||
private long mStepDuration = 20L;
|
||||
private LinkedList< LatLng > mPoints = new LinkedList<>();
|
||||
private LinkedList< Double > mEachDistance = new LinkedList<>();
|
||||
|
||||
private double mTotalDistance = 0.0D;
|
||||
private double mRemainDistance = 0.0D;
|
||||
private ExecutorService mThreadPools;
|
||||
private Object mLock = new Object();
|
||||
private BasePointOverlay mBaseOverlay = null;
|
||||
private int mIndex = 0;
|
||||
private boolean mUseDefaultDescriptor = false;
|
||||
AtomicBoolean mExitFlag = new AtomicBoolean( false );
|
||||
private MoveListener mMoveListener;
|
||||
private Status mStatus;
|
||||
private long mPauseMillis;
|
||||
private long mAnimationBeginTime;
|
||||
|
||||
public CombineMovingPointOverlay( AMap amap, BasePointOverlay baseOverlay ) {
|
||||
mStatus = Status.Status1;
|
||||
mAnimationBeginTime = System.currentTimeMillis();
|
||||
if ( amap != null && baseOverlay != null ) {
|
||||
this.mAMap = amap;
|
||||
this.mBaseOverlay = baseOverlay;
|
||||
mThreadPools = new ThreadPoolExecutor( 1, 2, 5L, TimeUnit.SECONDS, new SynchronousQueue(), new ThreadFactoryImpl() );
|
||||
}
|
||||
}
|
||||
|
||||
public void setMoveListener( MoveListener moveListener ) {
|
||||
this.mMoveListener = moveListener;
|
||||
}
|
||||
|
||||
public void setPoints( List< LatLng > list ) {
|
||||
synchronized ( mLock ) {
|
||||
if ( list != null && list.size() >= 2 ) {
|
||||
stopMove();
|
||||
if ( mPoints != null ) {
|
||||
mPoints.clear();
|
||||
}
|
||||
Iterator< LatLng > iterator = list.listIterator();
|
||||
while ( iterator.hasNext() ) {
|
||||
LatLng latLng = iterator.next();
|
||||
if ( latLng != null ) {
|
||||
mPoints.add( latLng );
|
||||
}
|
||||
}
|
||||
|
||||
mEachDistance.clear();
|
||||
mTotalDistance = 0.0D;
|
||||
|
||||
for ( int i = 0; i < mPoints.size(); i++ ) {
|
||||
double distance = AMapUtils.calculateLineDistance( mPoints.get( i ), mPoints.get( i + 1 ) );
|
||||
mEachDistance.add( distance );
|
||||
mTotalDistance += distance;
|
||||
}
|
||||
|
||||
mRemainDistance = mTotalDistance;
|
||||
mBaseOverlay.setPosition( mPoints.get( 0 ) );
|
||||
reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getIndex() {
|
||||
return mIndex;
|
||||
}
|
||||
|
||||
public BasePointOverlay getBaseOverlay() {
|
||||
return mBaseOverlay;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
try {
|
||||
removeMarker();
|
||||
mThreadPools.shutdown();
|
||||
synchronized ( mLock ) {
|
||||
mPoints.clear();
|
||||
mEachDistance.clear();
|
||||
;
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void removeMarker() {
|
||||
try {
|
||||
reset();
|
||||
if ( mBaseOverlay != null ) {
|
||||
mBaseOverlay.remove();
|
||||
mBaseOverlay = null;
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
|
||||
public void stopMove() {
|
||||
if ( mStatus == Status.Status3 ) {
|
||||
mStatus = Status.Status4;
|
||||
mPauseMillis = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
if ( mStatus == Status.Status3 || mStatus == Status.Status4 ) {
|
||||
mExitFlag.set( true );
|
||||
try {
|
||||
mThreadPools.awaitTermination( mStepDuration + 20L, TimeUnit.MICROSECONDS );
|
||||
mBaseOverlay.setAnimation( null );
|
||||
mStatus = Status.Status1;
|
||||
} catch ( InterruptedException e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetIndex() {
|
||||
mIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
public void setTotalDuration( int seconds ) {
|
||||
mDuration = seconds * 1_000L;
|
||||
}
|
||||
|
||||
public void startSmoothMove() {
|
||||
if ( mStatus == Status.Status4 ) {
|
||||
mStatus = Status.Status3;
|
||||
long interval = System.currentTimeMillis() - mPauseMillis;
|
||||
mAnimationBeginTime += interval;
|
||||
} else {
|
||||
if ( mStatus == Status.Status1 || mStatus == Status.Status5 ) {
|
||||
if ( mPoints.size() <= 0 ) {
|
||||
return;
|
||||
}
|
||||
mIndex = 0;
|
||||
mThreadPools.execute( new MarkerMovingRunnable() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setVisible( boolean visible ) {
|
||||
if ( mBaseOverlay != null ) {
|
||||
try {
|
||||
mBaseOverlay.setVisible( visible );
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class MarkerMovingRunnable implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mAnimationBeginTime = System.currentTimeMillis();
|
||||
mStatus = Status.Status2;
|
||||
mExitFlag.set( false );
|
||||
|
||||
try {
|
||||
for ( ; !mExitFlag.get() && mIndex <= mPoints.size() - 1; Thread.sleep( mStepDuration ) ) {
|
||||
synchronized ( mLock ) {
|
||||
if ( mExitFlag.get() ) {
|
||||
return;
|
||||
}
|
||||
if ( mStatus == Status.Status4 ) {
|
||||
long interval = System.currentTimeMillis() - mAnimationBeginTime;
|
||||
IPoint point = getCurPosition( interval );
|
||||
mBaseOverlay.setGeoPoint( point );
|
||||
mStatus = Status.Status3;
|
||||
}
|
||||
}
|
||||
}
|
||||
mStatus = Status.Status5;
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IPoint getCurPosition( long interval ) {
|
||||
if ( interval > mDuration ) {
|
||||
mExitFlag.set( true );
|
||||
IPoint point = new IPoint();
|
||||
mIndex = mPoints.size() - 1;
|
||||
LatLng latLng = mPoints.get( mIndex );
|
||||
--mIndex;
|
||||
mIndex = Math.max( mIndex, 0 );
|
||||
mRemainDistance = 0.0D;
|
||||
MapProjection.lonlat2Geo( latLng.longitude, latLng.latitude, point );
|
||||
if ( mMoveListener != null ) {
|
||||
mMoveListener.move( mRemainDistance );
|
||||
}
|
||||
return point;
|
||||
} else {
|
||||
double step = interval * mTotalDistance / mDuration;
|
||||
mRemainDistance = mTotalDistance - step;
|
||||
int targetIndex = 0;
|
||||
double val = 1.0D;
|
||||
|
||||
for ( int i = 0; i < mEachDistance.size(); i++ ) {
|
||||
double distance = mEachDistance.get( i );
|
||||
if ( step <= distance ) {
|
||||
if ( distance > 0.0D ) {
|
||||
val = step / distance;
|
||||
}
|
||||
targetIndex = i;
|
||||
break;
|
||||
}
|
||||
step -= distance;
|
||||
}
|
||||
|
||||
if ( targetIndex != mIndex && mMoveListener != null ) {
|
||||
mMoveListener.move( mRemainDistance );
|
||||
}
|
||||
|
||||
mIndex = targetIndex;
|
||||
LatLng latLng = mPoints.get( mIndex );
|
||||
LatLng latLng1 = mPoints.get( mIndex + 1 );
|
||||
IPoint point = new IPoint();
|
||||
MapProjection.lonlat2Geo( latLng.longitude, latLng.latitude, point );
|
||||
IPoint point1 = new IPoint();
|
||||
MapProjection.lonlat2Geo( latLng1.longitude, latLng1.latitude, point1 );
|
||||
|
||||
int xDelta = point1.x - point.x;
|
||||
int yDelta = point1.y - point.y;
|
||||
|
||||
if ( AMapUtils.calculateLineDistance( latLng, latLng1 ) > 1.0F ) {
|
||||
float rotate = getRotate( point, point1 );
|
||||
setRotate( rotate );
|
||||
}
|
||||
return new IPoint( ( ( int ) ( point.x + ( ( double ) xDelta ) * val ) ), ( ( int ) ( point.y + ( ( double ) yDelta ) * val ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
private float getRotate( IPoint point, IPoint point1 ) {
|
||||
if ( point != null && point1 != null ) {
|
||||
double py1 = ( double ) point1.y;
|
||||
double py = ( double ) point.y;
|
||||
double px = ( double ) point.x;
|
||||
return ( float ) ( Math.atan2( ( double ) point1.x - px, py - py1 ) / 3.141592653589793D * 180.0D );
|
||||
} else {
|
||||
return 0.0F;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPoint( LatLng latLng ) {
|
||||
if ( mBaseOverlay != null ) {
|
||||
try {
|
||||
mBaseOverlay.setPosition( latLng );
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setRotate( float rotate ) {
|
||||
if ( mBaseOverlay == null ) {
|
||||
return;
|
||||
}
|
||||
if ( mAMap == null ) {
|
||||
return;
|
||||
}
|
||||
if ( mAMap.getCameraPosition() == null ) {
|
||||
return;
|
||||
}
|
||||
mBaseOverlay.setRotateAngle( 360.0F - rotate + mAMap.getCameraPosition().bearing );
|
||||
}
|
||||
|
||||
public LatLng getPosition() {
|
||||
if ( mBaseOverlay != null ) {
|
||||
return mBaseOverlay.getPosition();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private enum Status {
|
||||
Status1,
|
||||
Status2,
|
||||
Status3,
|
||||
Status4,
|
||||
Status5
|
||||
}
|
||||
|
||||
public interface MoveListener {
|
||||
void move( double val );
|
||||
}
|
||||
|
||||
private static class ThreadFactoryImpl implements ThreadFactory {
|
||||
|
||||
private static int mCounter = 1;
|
||||
|
||||
@Override
|
||||
public Thread newThread( Runnable r ) {
|
||||
return new Thread( r, "MoveSmoothThread - " + mCounter++ );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
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;
|
||||
/**
|
||||
* 规划路线成功
|
||||
*/
|
||||
public static final int MSG_CALCULATE_SUCCESS = 1002;
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
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 );
|
||||
|
||||
void onCalculateSuccess();
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
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 clear(){
|
||||
if ( mListeners != null ) {
|
||||
mListeners.clear();
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
public void postCalculateSuccess() {
|
||||
sendMessage( AMapMessageConsts.MSG_CALCULATE_SUCCESS );
|
||||
}
|
||||
|
||||
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;
|
||||
case AMapMessageConsts.MSG_CALCULATE_SUCCESS:
|
||||
handleCalculateSuccessMsg();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleCalculateSuccessMsg() {
|
||||
if ( mListeners == null ) {
|
||||
return;
|
||||
}
|
||||
for ( AMapMessageListener listener : mListeners ) {
|
||||
listener.onCalculateSuccess();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,241 +0,0 @@
|
||||
package com.mogo.map.impl.amap.navi;
|
||||
|
||||
import com.amap.api.navi.AMapNaviListener;
|
||||
import com.amap.api.navi.model.AMapCalcRouteResult;
|
||||
import com.amap.api.navi.model.AMapLaneInfo;
|
||||
import com.amap.api.navi.model.AMapModelCross;
|
||||
import com.amap.api.navi.model.AMapNaviCameraInfo;
|
||||
import com.amap.api.navi.model.AMapNaviCross;
|
||||
import com.amap.api.navi.model.AMapNaviInfo;
|
||||
import com.amap.api.navi.model.AMapNaviLocation;
|
||||
import com.amap.api.navi.model.AMapNaviRouteNotifyData;
|
||||
import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
|
||||
import com.amap.api.navi.model.AMapServiceAreaInfo;
|
||||
import com.amap.api.navi.model.AimLessModeCongestionInfo;
|
||||
import com.amap.api.navi.model.AimLessModeStat;
|
||||
import com.amap.api.navi.model.NaviInfo;
|
||||
import com.autonavi.tbt.TrafficFacilityInfo;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.voice.AIAssist;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-25
|
||||
* <p>
|
||||
* 高德导航事件:导航事件
|
||||
*/
|
||||
public abstract class AMapNaviListenerAdapter implements AMapNaviListener {
|
||||
|
||||
private static final String TAG = "AMapNaviListenerAdapter";
|
||||
protected String mLastSpeakWord;
|
||||
|
||||
@Override
|
||||
public void onInitNaviFailure() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitNaviSuccess() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartNavi( int i ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrafficStatusUpdate() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChange( AMapNaviLocation aMapNaviLocation ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetNavigationText( int i, String s ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetNavigationText( String s ) {
|
||||
mLastSpeakWord = s;
|
||||
Logger.d( TAG, s );
|
||||
// TTSSpeaker.getInstance().speakTTS( s );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEndEmulatorNavi() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onArriveDestination() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculateRouteFailure( int i ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReCalculateRouteForYaw() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReCalculateRouteForTrafficJam() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onArrivedWayPoint( int i ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGpsOpenStatus( boolean b ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviInfoUpdate( NaviInfo naviInfo ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviInfoUpdated( AMapNaviInfo aMapNaviInfo ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCameraInfo( AMapNaviCameraInfo[] aMapNaviCameraInfos ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateIntervalCameraInfo( AMapNaviCameraInfo aMapNaviCameraInfo, AMapNaviCameraInfo aMapNaviCameraInfo1, int i ) {
|
||||
if ( aMapNaviCameraInfo != null ) {
|
||||
Logger.i( TAG, "current camera speed: %d, status = %d", aMapNaviCameraInfo.getCameraSpeed(), i );
|
||||
}
|
||||
if ( aMapNaviCameraInfo1 != null ) {
|
||||
Logger.i( TAG, "current camera speed: %d, status = %d", aMapNaviCameraInfo1.getCameraSpeed(), i );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onServiceAreaUpdate( AMapServiceAreaInfo[] aMapServiceAreaInfos ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showCross( AMapNaviCross aMapNaviCross ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideCross() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showModeCross( AMapModelCross aMapModelCross ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideModeCross() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showLaneInfo( AMapLaneInfo[] aMapLaneInfos, byte[] bytes, byte[] bytes1 ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showLaneInfo( AMapLaneInfo aMapLaneInfo ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideLaneInfo() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculateRouteSuccess( int[] ints ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyParallelRoad( int i ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void OnUpdateTrafficFacility( AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void OnUpdateTrafficFacility( AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void OnUpdateTrafficFacility( TrafficFacilityInfo trafficFacilityInfo ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 巡航回调
|
||||
* 连续5个点速度大于15km/h后触发 updateAimlessModeStatistics 回调,通过 AimLessModeStat 对象可获取巡航的连续行驶距离和连续启用时间
|
||||
*
|
||||
* @param aimLessModeStat
|
||||
*/
|
||||
@Override
|
||||
public void updateAimlessModeStatistics( AimLessModeStat aimLessModeStat ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 巡航回调
|
||||
* 出现拥堵长度大于500米且拥堵时间大于5分钟时,会进到 updateAimlessModeCongestionInfo 回调中,通过 AimLessModeCongestionInfo 对象,可获取到道路拥堵信息(如:导致拥堵的事件类型、拥堵的状态等)
|
||||
*
|
||||
* @param aimLessModeCongestionInfo
|
||||
*/
|
||||
@Override
|
||||
public void updateAimlessModeCongestionInfo( AimLessModeCongestionInfo aimLessModeCongestionInfo ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayRing( int i ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculateRouteSuccess( AMapCalcRouteResult aMapCalcRouteResult ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculateRouteFailure( AMapCalcRouteResult aMapCalcRouteResult ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviRouteNotify( AMapNaviRouteNotifyData aMapNaviRouteNotifyData ) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
package com.mogo.map.impl.amap.navi;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.amap.api.navi.AMapNavi;
|
||||
import com.amap.api.navi.enums.AimLessMode;
|
||||
import com.mogo.map.navi.IMogoAimless;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.storage.SharedPrefsMgr;
|
||||
|
||||
/**
|
||||
* @author donghongyu
|
||||
* @since 2020-11-05
|
||||
* <p>
|
||||
* 高德巡航
|
||||
*/
|
||||
public class AimlessClient implements IMogoAimless {
|
||||
|
||||
/**
|
||||
* 巡航状态控制
|
||||
*/
|
||||
public static final String KEY_AIMLESS_STATUS = "KEY_AIMLESS_STATUS";
|
||||
|
||||
private static final String TAG = "AimlessClient";
|
||||
private final Context mContext;
|
||||
|
||||
private AMapNavi mAMapNavi;
|
||||
|
||||
private AimlessModeListenerAdapter mAimlessModeListener;
|
||||
|
||||
private static volatile AimlessClient sInstance;
|
||||
|
||||
/**
|
||||
* 巡航模式配置状态
|
||||
*/
|
||||
private boolean mAimlessModeStatus;
|
||||
|
||||
/**
|
||||
* 巡航状态
|
||||
*/
|
||||
private boolean mAimlessStatus;
|
||||
|
||||
private AimlessClient(Context context) {
|
||||
mContext = context.getApplicationContext();
|
||||
// 按需初始化高德导航组件
|
||||
initAMapNavi();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化导航组件
|
||||
*/
|
||||
private void initAMapNavi() {
|
||||
Logger.d(TAG, "initAMapNavi");
|
||||
if (mAMapNavi != null) {
|
||||
return;
|
||||
}
|
||||
mAMapNavi = AMapNavi.getInstance(mContext);
|
||||
mAMapNavi.setEmulatorNaviSpeed(120);
|
||||
mAMapNavi.setUseInnerVoice(true, true);
|
||||
mAMapNavi.stopSpeak();
|
||||
mAimlessModeListener = new AimlessModeListenerAdapter() {
|
||||
};
|
||||
mAMapNavi.addAimlessModeListener(mAimlessModeListener);
|
||||
mAimlessModeStatus = SharedPrefsMgr.getInstance(mContext).getBoolean(KEY_AIMLESS_STATUS, false);
|
||||
}
|
||||
|
||||
public static AimlessClient getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
synchronized (AimlessClient.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new AimlessClient(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
private boolean checkAMapNavi() {
|
||||
if (mAMapNavi == null) {
|
||||
Logger.e(TAG, "高德导航实例为空!!!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startAimlessMode() {
|
||||
if (!checkAMapNavi()) {
|
||||
return;
|
||||
}
|
||||
if (mAimlessModeStatus) {
|
||||
mAMapNavi.startAimlessMode(AimLessMode.CAMERA_AND_SPECIALROAD_DETECTED);
|
||||
mAimlessStatus = true;
|
||||
Logger.d(TAG, "开启巡航成功");
|
||||
} else {
|
||||
mAimlessStatus = false;
|
||||
Logger.d(TAG, "开启巡航失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopAimlessMode() {
|
||||
if (!checkAMapNavi()) {
|
||||
return;
|
||||
}
|
||||
mAMapNavi.stopAimlessMode();
|
||||
mAimlessStatus = false;
|
||||
Logger.d(TAG, "关闭巡航成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAimlessModeStatus(boolean open) {
|
||||
this.mAimlessModeStatus = open;
|
||||
SharedPrefsMgr.getInstance(mContext).putBoolean(KEY_AIMLESS_STATUS, open);
|
||||
if (open) {
|
||||
if (!mAimlessStatus) {
|
||||
startAimlessMode();
|
||||
}
|
||||
} else {
|
||||
if (mAimlessStatus) {
|
||||
stopAimlessMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.mogo.map.impl.amap.navi;
|
||||
|
||||
import com.amap.api.navi.AimlessModeListener;
|
||||
import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
|
||||
import com.amap.api.navi.model.AimLessModeCongestionInfo;
|
||||
import com.amap.api.navi.model.AimLessModeStat;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.navi.MogoCongestionInfo;
|
||||
import com.mogo.map.navi.MogoNaviListenerHandler;
|
||||
import com.mogo.map.navi.MogoTraffic;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-01-16
|
||||
* <p>
|
||||
* 巡航监听
|
||||
*/
|
||||
public class AimlessModeListenerAdapter implements AimlessModeListener {
|
||||
public String TAG="AimlessModeListenerAdapter";
|
||||
|
||||
@Override
|
||||
public void onUpdateTrafficFacility( AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos ) {
|
||||
MogoTraffic traffic = ObjectUtils.fromAMap( aMapNaviTrafficFacilityInfos );
|
||||
if ( traffic != null ) {
|
||||
MogoNaviListenerHandler.getInstance().onUpdateTraffic2( traffic );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateAimlessModeElecCameraInfo( AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos ) {
|
||||
MogoTraffic traffic = ObjectUtils.fromAMap( aMapNaviTrafficFacilityInfos );
|
||||
if ( traffic != null ) {
|
||||
MogoNaviListenerHandler.getInstance().onUpdateTraffic2( traffic );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAimlessModeStatistics( AimLessModeStat aimLessModeStat ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAimlessModeCongestionInfo( AimLessModeCongestionInfo aimLessModeCongestionInfo ) {
|
||||
Logger.d( TAG, "updateAimlessModeCongestionInfo " + GsonUtil.jsonFromObject(aimLessModeCongestionInfo));
|
||||
MogoCongestionInfo congestionInfo = ObjectUtils.fromAMap( aimLessModeCongestionInfo );
|
||||
if ( congestionInfo != null ) {
|
||||
MogoNaviListenerHandler.getInstance().onUpdateCongestion( congestionInfo );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,181 +0,0 @@
|
||||
package com.mogo.map.impl.amap.navi;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.navi.model.AMapNaviPath;
|
||||
import com.amap.api.navi.model.AMapNaviStep;
|
||||
import com.amap.api.navi.model.NaviLatLng;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.map.impl.amap.overlay.RouteOverLayWrapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-04
|
||||
* <p>
|
||||
* 导航路径代理类
|
||||
*/
|
||||
public class CalculatePathItem {
|
||||
|
||||
private Context mContext;
|
||||
private AMap mAMap;
|
||||
private int mId;
|
||||
private AMapNaviPath mPath;
|
||||
|
||||
private RouteOverLayWrapper mOverLazWrapper;
|
||||
private ArrayList< MogoLatLng > mPoints;
|
||||
|
||||
public int getId() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
public AMapNaviPath getPath() {
|
||||
return mPath;
|
||||
}
|
||||
|
||||
public RouteOverLayWrapper getOverLazWrapper( boolean createIfNull ) {
|
||||
if ( mOverLazWrapper == null && createIfNull ) {
|
||||
mOverLazWrapper = new RouteOverLayWrapper( mContext, mAMap, mPath );
|
||||
}
|
||||
return mOverLazWrapper;
|
||||
}
|
||||
|
||||
public CalculatePathItem( Context context, AMap amap, int id, AMapNaviPath path ) {
|
||||
mContext = context;
|
||||
mAMap = amap;
|
||||
this.mId = id;
|
||||
this.mPath = path;
|
||||
}
|
||||
|
||||
public String getStrategyName() {
|
||||
return mPath.getLabels();
|
||||
}
|
||||
|
||||
public String getFormattedTime() {
|
||||
if ( mTimeBuilder == null ) {
|
||||
final int time = mPath.getAllTime();
|
||||
mTimeBuilder = new StringBuilder();
|
||||
fillFormatTime( time, mTimeBuilder );
|
||||
}
|
||||
return mTimeBuilder.toString();
|
||||
}
|
||||
|
||||
public int getTime(){
|
||||
return mPath.getAllTime();
|
||||
}
|
||||
|
||||
public int getDistance(){
|
||||
return mPath.getAllLength();
|
||||
}
|
||||
|
||||
private StringBuilder mTimeBuilder;
|
||||
|
||||
private void fillFormatTime( int seconds, StringBuilder builder ) {
|
||||
// int days = seconds / ( 24 * 60 * 60 );
|
||||
// if ( days > 0 ) {
|
||||
// builder.append( days ).append( "天" );
|
||||
// }
|
||||
// seconds -= days * 24 * 60 * 60;
|
||||
int hours = seconds / ( 60 * 60 );
|
||||
if ( hours > 0 ) {
|
||||
builder.append( hours ).append( "小时" );
|
||||
}
|
||||
seconds -= hours * 60 * 60;
|
||||
int min = seconds / 60;
|
||||
builder.append( min > 1 ? min : 1 ).append( "分钟" );
|
||||
}
|
||||
|
||||
private String mDistanceCacheStr = "";
|
||||
|
||||
public String getFormattedDistance() {
|
||||
if ( TextUtils.isEmpty( mDistanceCacheStr ) ) {
|
||||
int distance = mPath.getAllLength();
|
||||
if ( distance == -1 ) {
|
||||
mDistanceCacheStr = "路程总程未获取";
|
||||
}
|
||||
if ( distance >= 1000 ) {
|
||||
mDistanceCacheStr = String.format( "%.1f公里", ( float ) distance / 1000 );
|
||||
} else {
|
||||
mDistanceCacheStr = distance + "米";
|
||||
}
|
||||
}
|
||||
return mDistanceCacheStr;
|
||||
}
|
||||
|
||||
private StringBuilder mDescBuilder = null;
|
||||
|
||||
public String getDesc() {
|
||||
if ( mDescBuilder == null ) {
|
||||
mDescBuilder = new StringBuilder();
|
||||
int lightsSize = getTrafficNumber();
|
||||
if ( lightsSize > 0 ) {
|
||||
mDescBuilder.append( "红绿灯" ).append( lightsSize ).append( "个" );
|
||||
}
|
||||
mDescBuilder.append( " " );
|
||||
mDescBuilder.append( "收费" ).append( mPath.getTollCost() ).append( "元" );
|
||||
}
|
||||
|
||||
return mDescBuilder.toString();
|
||||
}
|
||||
|
||||
public int getTrafficNumber() {
|
||||
int trafficLightNumber = 0;
|
||||
if ( mPath == null ) {
|
||||
return trafficLightNumber;
|
||||
}
|
||||
List< AMapNaviStep > steps = mPath.getSteps();
|
||||
for ( AMapNaviStep step : steps ) {
|
||||
trafficLightNumber += step.getTrafficLightNumber();
|
||||
}
|
||||
return trafficLightNumber;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
mContext = null;
|
||||
mAMap = null;
|
||||
mPath = null;
|
||||
if ( mOverLazWrapper != null ) {
|
||||
mOverLazWrapper.destroy();
|
||||
}
|
||||
mOverLazWrapper = null;
|
||||
if ( mPoints != null ) {
|
||||
mPoints.clear();
|
||||
}
|
||||
mPoints = null;
|
||||
}
|
||||
|
||||
public List< MogoLatLng > getCoordList() {
|
||||
if ( mPoints == null ) {
|
||||
mPoints = new ArrayList<>();
|
||||
for ( NaviLatLng latlng : mPath.getCoordList() ) {
|
||||
MogoLatLng mogoLatLng = new MogoLatLng( latlng.getLatitude(), latlng.getLongitude() );
|
||||
mPoints.add( mogoLatLng );
|
||||
}
|
||||
}
|
||||
return mPoints;
|
||||
}
|
||||
|
||||
public MogoLatLng getDriveStartPoint() {
|
||||
if ( mPath != null && mPath.getCoordList() != null && mPath.getCoordList().size() > 0 ) {
|
||||
NaviLatLng startPoint = mPath.getCoordList().get( 0 );
|
||||
if ( startPoint != null ) {
|
||||
return new MogoLatLng( startPoint.getLatitude(), startPoint.getLongitude() );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public MogoLatLng getDriveEndPoint() {
|
||||
if ( mPath != null && mPath.getCoordList() != null && mPath.getCoordList().size() > 0 ) {
|
||||
NaviLatLng endPoint = mPath.getCoordList().get( mPath.getCoordList().size() - 1 );
|
||||
if ( endPoint != null ) {
|
||||
return new MogoLatLng( endPoint.getLatitude(), endPoint.getLongitude() );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,451 +0,0 @@
|
||||
package com.mogo.map.impl.amap.navi;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.location.Location;
|
||||
|
||||
import com.amap.api.maps.LocationSource;
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.navi.AMapNavi;
|
||||
import com.amap.api.navi.enums.AimLessMode;
|
||||
import com.amap.api.navi.enums.NaviType;
|
||||
import com.amap.api.navi.model.AMapNaviPath;
|
||||
import com.amap.api.navi.model.NaviLatLng;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
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.IMogoCarLocationChangedListener2;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.map.navi.MogoCalculatePath;
|
||||
import com.mogo.map.navi.MogoCarLocationChangedListenerRegister;
|
||||
import com.mogo.map.navi.MogoNaviConfig;
|
||||
import com.mogo.map.navi.MogoNaviListenerHandler;
|
||||
import com.mogo.map.navi.OnCalculatePathItemClickInteraction;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.storage.SharedPrefsMgr;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-25
|
||||
* <p>
|
||||
* 高德导航
|
||||
*/
|
||||
public class NaviClient implements IMogoNavi {
|
||||
|
||||
/**
|
||||
* 巡航状态控制
|
||||
*/
|
||||
public static final String KEY_AIMLESS_STATUS = "KEY_AIMLESS_STATUS";
|
||||
|
||||
private static final String TAG = "NaviClient";
|
||||
private final Context mContext;
|
||||
|
||||
private AMapNavi mAMapNavi;
|
||||
private NaviListenerAdapter mAMapNaviListener;
|
||||
|
||||
private AimlessModeListenerAdapter mAimlessModeListener;
|
||||
|
||||
/**
|
||||
* 导航策略配置
|
||||
*/
|
||||
|
||||
private MogoNaviConfig mMogoNaviConfig = new MogoNaviConfig();
|
||||
|
||||
private static volatile NaviClient sInstance;
|
||||
private boolean mIsRealNavi;
|
||||
|
||||
private Location mCarLocation;
|
||||
private LocationSource.OnLocationChangedListener mOnLocationChangedListener;
|
||||
/**
|
||||
* 巡航模式配置状态
|
||||
*/
|
||||
private boolean mAimlessModeStatus;
|
||||
|
||||
/**
|
||||
* 巡航状态
|
||||
*/
|
||||
private boolean mAimlessStatus;
|
||||
|
||||
private NaviClient( Context context ) {
|
||||
mContext = context.getApplicationContext();
|
||||
if ( DebugConfig.isUseCustomNavi() ) {
|
||||
// 按需初始化导航组件
|
||||
initAMapNavi();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化导航组件
|
||||
*/
|
||||
private void initAMapNavi() {
|
||||
if ( mAMapNavi != null ) {
|
||||
return;
|
||||
}
|
||||
mAMapNavi = AMapNavi.getInstance( mContext );
|
||||
mAMapNavi.setEmulatorNaviSpeed( 120 );
|
||||
mAMapNavi.setUseInnerVoice( true, true );
|
||||
mAMapNavi.stopSpeak();
|
||||
mAMapNaviListener = new NaviListenerAdapter( mContext, this );
|
||||
mAimlessModeListener = new AimlessModeListenerAdapter() {
|
||||
};
|
||||
mAMapNavi.addAMapNaviListener( mAMapNaviListener );
|
||||
mAMapNavi.addAimlessModeListener( mAimlessModeListener );
|
||||
mAimlessModeStatus = SharedPrefsMgr.getInstance( mContext ).getBoolean( KEY_AIMLESS_STATUS, false );
|
||||
}
|
||||
|
||||
public static NaviClient getInstance( Context context ) {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( NaviClient.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new NaviClient( context );
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void naviTo( MogoLatLng endPoint ) {
|
||||
naviTo( endPoint, mMogoNaviConfig );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void naviTo( MogoLatLng endPoint, MogoNaviConfig config ) {
|
||||
naviTo( endPoint, null, config );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void naviTo( MogoLatLng endPoint, List< MogoLatLng > wayPoints ) {
|
||||
naviTo( endPoint, wayPoints, mMogoNaviConfig );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void naviTo( MogoLatLng endPoint, List< MogoLatLng > wayPoints, MogoNaviConfig config ) {
|
||||
if ( !checkAMapNavi() ) {
|
||||
return;
|
||||
}
|
||||
Logger.i( TAG, "开始规划路径" );
|
||||
mMogoNaviConfig = config;
|
||||
if ( mMogoNaviConfig == null ) {
|
||||
mMogoNaviConfig = new MogoNaviConfig();
|
||||
}
|
||||
int strategy = mAMapNavi.strategyConvert( mMogoNaviConfig.isCongestion(), mMogoNaviConfig.isAvoidSpeed(), mMogoNaviConfig.isCost(), mMogoNaviConfig.isHighSpeed(), config.isMultipleRoute() );
|
||||
List< NaviLatLng > naviWayPoints = null;
|
||||
if ( wayPoints != null && !wayPoints.isEmpty() ) {
|
||||
naviWayPoints = new ArrayList<>( wayPoints.size() );
|
||||
for ( MogoLatLng wayPoint : wayPoints ) {
|
||||
naviWayPoints.add( ObjectUtils.fromMogoAsNavi( wayPoint ) );
|
||||
}
|
||||
} else {
|
||||
naviWayPoints = new ArrayList<>();
|
||||
}
|
||||
mAMapNavi.calculateDriveRoute(
|
||||
new ArrayList( Arrays.asList( ObjectUtils.fromMogoAsNavi( endPoint ) ) ),
|
||||
naviWayPoints,
|
||||
strategy
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reCalculateRoute( MogoNaviConfig config ) {
|
||||
if ( !checkAMapNavi() ) {
|
||||
return;
|
||||
}
|
||||
mMogoNaviConfig = config;
|
||||
if ( mMogoNaviConfig == null ) {
|
||||
mMogoNaviConfig = new MogoNaviConfig();
|
||||
}
|
||||
int strategy = mAMapNavi.strategyConvert( mMogoNaviConfig.isCongestion(), mMogoNaviConfig.isAvoidSpeed(), mMogoNaviConfig.isCost(), mMogoNaviConfig.isHighSpeed(), config.isMultipleRoute() );
|
||||
mAMapNavi.reCalculateRoute( strategy );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopNavi() {
|
||||
if ( mAMapNaviListener != null ) {
|
||||
mAMapNaviListener.stopNavi();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopAMapNavi() {
|
||||
if ( mAMapNavi != null ) {
|
||||
mAMapNavi.stopNavi();
|
||||
}
|
||||
}
|
||||
|
||||
public void selectAMapRouteId( int routeId ) {
|
||||
if ( mAMapNavi != null ) {
|
||||
mAMapNavi.selectRouteId( routeId );
|
||||
}
|
||||
}
|
||||
|
||||
public Map< Integer, AMapNaviPath > getAMapNaviPaths() {
|
||||
if ( mAMapNavi != null ) {
|
||||
return mAMapNavi.getNaviPaths();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startNavi( boolean isRealNavi ) {
|
||||
if ( mAMapNaviListener != null && mAMapNaviListener.isStopped() ) {
|
||||
return;
|
||||
}
|
||||
mIsRealNavi = isRealNavi;
|
||||
stopAimlessMode();
|
||||
boolean isNaving = isNaviing();
|
||||
boolean result = mAMapNavi.startNavi( isRealNavi ? NaviType.GPS : NaviType.EMULATOR );
|
||||
if ( isNaving && !result ) {
|
||||
// 如果正在导航,又重新规划路线,startNavi 不会成功,不会重新回调 #onStartNavi
|
||||
MogoNaviListenerHandler.getInstance().onStartNavi();
|
||||
AMapMessageManager.getInstance().postNaviStarted();
|
||||
}
|
||||
Logger.d( TAG, "start navi status: %s", result );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNaviing() {
|
||||
if ( mAMapNaviListener != null ) {
|
||||
return mAMapNaviListener.isNaviing();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List< MogoCalculatePath > getCalculatedStrategies() {
|
||||
if ( mAMapNaviListener != null ) {
|
||||
return mAMapNaviListener.getCalculateStrategies();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List< MogoLatLng > getCalculatedPathPos() {
|
||||
if ( mAMapNaviListener != null ) {
|
||||
return mAMapNaviListener.getCalculatedPathPos();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OnCalculatePathItemClickInteraction getItemClickInteraction() {
|
||||
if ( mAMapNaviListener != null ) {
|
||||
return mAMapNaviListener.getItemClickInteraction();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLineClickInteraction( OnCalculatePathItemClickInteraction lineClickInteraction ) {
|
||||
// do not impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCalculatePaths() {
|
||||
if ( mAMapNaviListener != null ) {
|
||||
mAMapNaviListener.clearCalculatePaths();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCalculatePathDisplayBounds( Rect bounds ) {
|
||||
if ( mAMapNaviListener != null ) {
|
||||
mAMapNaviListener.setCalculatePathDisplayBounds( bounds );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoNaviConfig getNaviConfig() {
|
||||
return mMogoNaviConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBroadcastMode( int mode ) {
|
||||
if ( !checkAMapNavi() ) {
|
||||
return false;
|
||||
}
|
||||
return mAMapNavi.setBroadcastMode( mode );
|
||||
}
|
||||
|
||||
@Override
|
||||
public List< MogoLatLng > getNaviPathCoordinates() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getCarLocation() {
|
||||
if ( mCarLocation != null ) {
|
||||
synchronized ( mCarLocation ) {
|
||||
return new MogoLatLng( mCarLocation.getLatitude(), mCarLocation.getLongitude() );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getCarLocation2() {
|
||||
return mCarLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCarLocationChangedListener( IMogoCarLocationChangedListener2 listener ) {
|
||||
// do not impl.
|
||||
}
|
||||
|
||||
// -- end
|
||||
|
||||
public void syncCarLocation( Location location ) {
|
||||
mCarLocation = location;
|
||||
mCarLocation = location;
|
||||
if ( MogoCarLocationChangedListenerRegister.getInstance().getListener() != null ) {
|
||||
MogoCarLocationChangedListenerRegister.getInstance().getListener().onCarLocationChanged2( location );
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkAMapNavi() {
|
||||
if ( mAMapNavi == null ) {
|
||||
Logger.e( TAG, "高德导航实例为空!!!" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isRealNavi() {
|
||||
return mIsRealNavi;
|
||||
}
|
||||
|
||||
public void handleClickedPolyline( Polyline polyline ) {
|
||||
if ( mAMapNaviListener != null ) {
|
||||
mAMapNaviListener.handleClickedPolyline( polyline );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startAimlessMode() {
|
||||
if ( !checkAMapNavi() ) {
|
||||
return;
|
||||
}
|
||||
if ( mAimlessModeStatus && !isNaviing() ) {
|
||||
mAMapNavi.startSpeak();
|
||||
mAMapNavi.startAimlessMode( AimLessMode.CAMERA_AND_SPECIALROAD_DETECTED );
|
||||
mAimlessStatus = true;
|
||||
Logger.d( TAG, "开启巡航成功" );
|
||||
} else {
|
||||
mAimlessStatus = false;
|
||||
mAMapNavi.stopSpeak();
|
||||
Logger.d( TAG, "开启巡航失败" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopAimlessMode() {
|
||||
if ( !checkAMapNavi() ) {
|
||||
return;
|
||||
}
|
||||
mAMapNavi.stopAimlessMode();
|
||||
mAMapNavi.stopSpeak();
|
||||
mAimlessStatus = false;
|
||||
Logger.d( TAG, "关闭巡航成功" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAimlessModeStatus( boolean open ) {
|
||||
this.mAimlessModeStatus = open;
|
||||
SharedPrefsMgr.getInstance( mContext ).putBoolean( KEY_AIMLESS_STATUS, open );
|
||||
if ( open ) {
|
||||
if ( !mAimlessStatus ) {
|
||||
startAimlessMode();
|
||||
}
|
||||
} else {
|
||||
if ( mAimlessStatus ) {
|
||||
stopAimlessMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayOverview( Rect bounds ) {
|
||||
if ( mAMapNaviListener != null ) {
|
||||
mAMapNaviListener.displayOverview( bounds );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseExtraGPSData( boolean use ) {
|
||||
// 如果使用平台模拟位置变化,需要用到导航组件
|
||||
if ( use ) {
|
||||
initAMapNavi();
|
||||
} else {
|
||||
destroyAMapNavi();
|
||||
}
|
||||
if ( checkAMapNavi() ) {
|
||||
return;
|
||||
}
|
||||
Logger.d( TAG, "设置外部gps源状态 %s", use );
|
||||
mAMapNavi.setIsUseExtraGPSData( use );
|
||||
if ( AMapWrapper.getAMap() == null ) {
|
||||
return;
|
||||
}
|
||||
if ( use ) {
|
||||
AMapWrapper.getAMap().setLocationSource( new LocationSource() {
|
||||
@Override
|
||||
public void activate( OnLocationChangedListener onLocationChangedListener ) {
|
||||
NaviClient.this.mOnLocationChangedListener = onLocationChangedListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivate() {
|
||||
}
|
||||
} );
|
||||
} else {
|
||||
AMapWrapper.getAMap().setLocationSource( new com.amap.api.col.n3.dd( AbsMogoApplication.getApp() ) );
|
||||
mOnLocationChangedListener = null;
|
||||
}
|
||||
AMapWrapper.getAMap().setMyLocationEnabled( true );
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁导航组件
|
||||
*/
|
||||
private void destroyAMapNavi() {
|
||||
if ( mAMapNavi != null ) {
|
||||
mAMapNavi.removeAMapNaviListener( mAMapNaviListener );
|
||||
mAMapNavi.removeAimlessModeListener( mAimlessModeListener );
|
||||
mAMapNavi.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExtraGPSData( double lon, double lat, float speed, float accuracy, float bearing, long timestamp ) {
|
||||
if ( !checkAMapNavi() ) {
|
||||
return;
|
||||
}
|
||||
if ( !mAMapNavi.getIsUseExtraGPSData() ) {
|
||||
Logger.d( TAG, "拒绝外部GPS数据" );
|
||||
return;
|
||||
}
|
||||
Location location = new Location( "外部GPS源" );
|
||||
location.setLongitude( lon );
|
||||
location.setLatitude( lat );
|
||||
location.setSpeed( speed );
|
||||
location.setAccuracy( accuracy );
|
||||
location.setBearing( bearing );
|
||||
location.setTime( timestamp );
|
||||
//type字段传1时代表WGS84坐标
|
||||
mAMapNavi.setExtraGPSData( 2, location );
|
||||
if ( mOnLocationChangedListener != null ) {
|
||||
mOnLocationChangedListener.onLocationChanged( location );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,287 +0,0 @@
|
||||
package com.mogo.map.impl.amap.navi;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Trace;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.navi.enums.CameraType;
|
||||
import com.amap.api.navi.enums.NaviType;
|
||||
import com.amap.api.navi.model.AMapCalcRouteResult;
|
||||
import com.amap.api.navi.model.AMapNaviCameraInfo;
|
||||
import com.amap.api.navi.model.AMapNaviLocation;
|
||||
import com.amap.api.navi.model.NaviInfo;
|
||||
import com.mogo.commons.voice.AIAssist;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
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.MogoCalculatePath;
|
||||
import com.mogo.map.navi.MogoNaviListenerHandler;
|
||||
import com.mogo.map.navi.MogoTraffic;
|
||||
import com.mogo.map.navi.OnCalculatePathItemClickInteraction;
|
||||
import com.mogo.utils.UiThreadHandler;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-25
|
||||
* <p>
|
||||
* 高德导航回调
|
||||
*/
|
||||
public class NaviListenerAdapter extends AMapNaviListenerAdapter {
|
||||
|
||||
private static final String TAG = "NaviListenerAdapter";
|
||||
|
||||
private Context mContext;
|
||||
private NaviClient mClient;
|
||||
/**
|
||||
* 导航状态:true - 导航 onStartNavi(int) 被调用, false - 到达目的地、手动挺固执
|
||||
*/
|
||||
private boolean mIsNaviing = false;
|
||||
|
||||
/**
|
||||
* 导航是否被停止:true - 手动停止或到达目的地、false - 规划路径成功、开启导航
|
||||
*/
|
||||
private boolean mIsStopped = true;
|
||||
|
||||
/**
|
||||
* 路线规划
|
||||
*/
|
||||
private NaviOverlayHelper mNaviOverlayHelper;
|
||||
|
||||
public NaviListenerAdapter( Context mContext, NaviClient client ) {
|
||||
this.mContext = mContext;
|
||||
this.mClient = client;
|
||||
mNaviOverlayHelper = new NaviOverlayHelper( AMapWrapper.getAMap(), mContext );
|
||||
}
|
||||
|
||||
public void setNaviing( boolean mIsNaviing ) {
|
||||
this.mIsNaviing = mIsNaviing;
|
||||
}
|
||||
|
||||
public boolean isNaviing() {
|
||||
return mIsNaviing;
|
||||
}
|
||||
|
||||
public void setStopped( boolean isStopped ) {
|
||||
this.mIsStopped = isStopped;
|
||||
}
|
||||
|
||||
public boolean isStopped() {
|
||||
return mIsStopped;
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return mContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitNaviFailure() {
|
||||
MogoNaviListenerHandler.getInstance().onInitNaviFailure();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitNaviSuccess() {
|
||||
MogoNaviListenerHandler.getInstance().onInitNaviSuccess();
|
||||
NaviClient.getInstance( mContext ).startAimlessMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCameraInfo( AMapNaviCameraInfo[] aMapNaviCameraInfos ) {
|
||||
super.updateCameraInfo( aMapNaviCameraInfos );
|
||||
if ( aMapNaviCameraInfos == null || aMapNaviCameraInfos.length == 0 ) {
|
||||
return;
|
||||
}
|
||||
int limitSpeed = 0;
|
||||
for ( AMapNaviCameraInfo aMapNaviCameraInfo : aMapNaviCameraInfos ) {
|
||||
if ( aMapNaviCameraInfo == null ) {
|
||||
continue;
|
||||
}
|
||||
limitSpeed = aMapNaviCameraInfo.getCameraSpeed();
|
||||
if ( limitSpeed > 0 && aMapNaviCameraInfo.getCameraType() == CameraType.SPEED ) {
|
||||
MogoTraffic traffic = new MogoTraffic( MogoTraffic.TYPE_NAVI );
|
||||
traffic.setDistance( aMapNaviCameraInfo.getCameraDistance() );
|
||||
traffic.setSpeedLimit( aMapNaviCameraInfo.getCameraSpeed() );
|
||||
MogoNaviListenerHandler.getInstance().onUpdateTraffic2( traffic );
|
||||
}
|
||||
|
||||
// switch ( aMapNaviCameraInfo.getCameraType() ) {
|
||||
// case CameraType.SPEED:
|
||||
//
|
||||
// break;
|
||||
// case CameraType.SURVEILLANCE:
|
||||
// traffic.setDesc( "监控摄像" );
|
||||
// break;
|
||||
// case CameraType.TRAFFICLIGHT:
|
||||
// traffic.setDesc( "闯红灯拍照" );
|
||||
// break;
|
||||
// case CameraType.BREAKRULE:
|
||||
// traffic.setDesc( "违章拍照" );
|
||||
// break;
|
||||
// case CameraType.BUSWAY:
|
||||
// traffic.setDesc( "公交专用道摄像头" );
|
||||
// break;
|
||||
// case CameraType.EMERGENCY:
|
||||
// traffic.setDesc( "应急车道拍照" );
|
||||
// break;
|
||||
// case CameraType.BICYCLE:
|
||||
// traffic.setDesc( "非机动车道" );
|
||||
// break;
|
||||
// case CameraType.INTERVALVELOCITYSTART:
|
||||
// traffic.setDesc( "区间测速起始" );
|
||||
// break;
|
||||
// case CameraType.INTERVALVELOCITYEND:
|
||||
// traffic.setDesc( "区间测速解除" );
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
if ( limitSpeed <= 0 ) {
|
||||
MogoTraffic traffic = new MogoTraffic( MogoTraffic.TYPE_NAVI );
|
||||
traffic.setDistance( 0 );
|
||||
traffic.setSpeedLimit( 0 );
|
||||
MogoNaviListenerHandler.getInstance().onUpdateTraffic2( traffic );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartNavi( int type ) {
|
||||
|
||||
Logger.d( TAG, "onStartNavi type = %s", type );
|
||||
// 巡航
|
||||
if ( type != NaviType.CRUISE ) {
|
||||
setStopped( false );
|
||||
setNaviing( true );
|
||||
MogoNaviListenerHandler.getInstance().onStartNavi();
|
||||
AMapMessageManager.getInstance().postNaviStarted();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEndEmulatorNavi() {
|
||||
stopNaviDelay( () -> {
|
||||
MogoNaviListenerHandler.getInstance().onEndEmulatorNavi();
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onArriveDestination() {
|
||||
stopNaviDelay( () -> {
|
||||
MogoNaviListenerHandler.getInstance().onArriveDestination();
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* 避免导航结束语音播报被立刻打断的情况
|
||||
*
|
||||
* @param after 停止后的行为
|
||||
*/
|
||||
private void stopNaviDelay( Runnable after ) {
|
||||
UiThreadHandler.postDelayed( () -> {
|
||||
if ( TextUtils.isEmpty( mLastSpeakWord ) || !mLastSpeakWord.contains( "结束" ) ) {
|
||||
AIAssist.getInstance( mContext ).speakTTSVoice( "到达目的地附近,本次导航结束" );
|
||||
}
|
||||
mLastSpeakWord = "";
|
||||
stopNavi();
|
||||
if ( after != null ) {
|
||||
after.run();
|
||||
}
|
||||
}, 5_000L );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviInfoUpdate( NaviInfo naviInfo ) {
|
||||
Trace.beginSection( "NaviListenerAdapter.onNaviInfoUpdate" );
|
||||
MogoNaviListenerHandler.getInstance().onNaviInfoUpdate( ObjectUtils.fromAMap( mContext, naviInfo ) );
|
||||
mNaviOverlayHelper.handleNaviInfoUpdate( naviInfo );
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculateRouteFailure( AMapCalcRouteResult aMapCalcRouteResult ) {
|
||||
if ( aMapCalcRouteResult != null ) {
|
||||
Logger.i( TAG, PathPlanningErrorCodeConstants.getErrorMsg( aMapCalcRouteResult.getErrorCode() ) );
|
||||
}
|
||||
MogoNaviListenerHandler.getInstance().onoCalculateFailed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculateRouteSuccess( AMapCalcRouteResult aMapCalcRouteResult ) {
|
||||
super.onCalculateRouteSuccess( aMapCalcRouteResult );
|
||||
Logger.i( TAG, "导航规划成功" );
|
||||
setStopped( false );
|
||||
mNaviOverlayHelper.showCalculatedPaths( () -> {
|
||||
AMapMessageManager.getInstance().postCalculateSuccess();
|
||||
MogoNaviListenerHandler.getInstance().onCalculateSuccess();
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChange( AMapNaviLocation aMapNaviLocation ) {
|
||||
Trace.beginSection( "NaviListenerAdapter.onLocationChange" );
|
||||
super.onLocationChange( aMapNaviLocation );
|
||||
mNaviOverlayHelper.handlePassedLocation( aMapNaviLocation );
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
public void stopNavi() {
|
||||
TTSSpeaker.getInstance().shutUp();
|
||||
mNaviOverlayHelper.clearCalculatedOverlay();
|
||||
setStopped( true );
|
||||
setNaviing( false );
|
||||
mClient.stopAMapNavi();
|
||||
MogoNaviListenerHandler.getInstance().onStopNavi();
|
||||
AMapMessageManager.getInstance().postNaviStopped();
|
||||
}
|
||||
|
||||
public void handleClickedPolyline( Polyline polyline ) {
|
||||
if ( mNaviOverlayHelper != null ) {
|
||||
mNaviOverlayHelper.handleClickedPolyline( polyline, isNaviing() );
|
||||
mClient.selectAMapRouteId( mNaviOverlayHelper.getSelectedPathId() );
|
||||
mNaviOverlayHelper.showBoundsWithSettingBounds();
|
||||
}
|
||||
}
|
||||
|
||||
public List< MogoCalculatePath > getCalculateStrategies() {
|
||||
if ( mNaviOverlayHelper != null ) {
|
||||
return mNaviOverlayHelper.getCalculateStrategies();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List< MogoLatLng > getCalculatedPathPos() {
|
||||
if ( mNaviOverlayHelper != null ) {
|
||||
return mNaviOverlayHelper.getCalculatedPathPos();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public OnCalculatePathItemClickInteraction getItemClickInteraction() {
|
||||
if ( mNaviOverlayHelper != null ) {
|
||||
return mNaviOverlayHelper.getItemClickInteraction();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void clearCalculatePaths() {
|
||||
if ( mNaviOverlayHelper != null ) {
|
||||
mNaviOverlayHelper.clearCalculatedOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
public void setCalculatePathDisplayBounds( Rect bounds ) {
|
||||
if ( mNaviOverlayHelper != null ) {
|
||||
mNaviOverlayHelper.setCalculatePathDisplayBounds( bounds );
|
||||
}
|
||||
}
|
||||
|
||||
public void displayOverview( Rect bounds ) {
|
||||
if ( mNaviOverlayHelper != null ) {
|
||||
mNaviOverlayHelper.displayOverview( bounds );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,455 +0,0 @@
|
||||
package com.mogo.map.impl.amap.navi;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Rect;
|
||||
import android.text.TextUtils;
|
||||
|
||||
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.LatLngBounds;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.amap.api.maps.model.MarkerOptions;
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.navi.model.AMapNaviLocation;
|
||||
import com.amap.api.navi.model.AMapNaviPath;
|
||||
import com.amap.api.navi.model.NaviInfo;
|
||||
import com.amap.api.navi.model.NaviLatLng;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.map.impl.amap.AMapWrapper;
|
||||
import com.mogo.map.impl.amap.R;
|
||||
import com.mogo.map.impl.amap.overlay.RouteOverLayWrapper;
|
||||
import com.mogo.map.marker.MogoMarkersHandler;
|
||||
import com.mogo.map.navi.MogoCalculatePath;
|
||||
import com.mogo.map.navi.MogoOperationListenerRegister;
|
||||
import com.mogo.map.navi.OnCalculatePathItemClickInteraction;
|
||||
import com.mogo.utils.WindowUtils;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-27
|
||||
* <p>
|
||||
* 导航路径管理
|
||||
*/
|
||||
public class NaviOverlayHelper implements OnCalculatePathItemClickInteraction {
|
||||
|
||||
private static final String TAG = "NaviOverlayHelper";
|
||||
|
||||
/**
|
||||
* 选中的路径透明度
|
||||
*/
|
||||
public static final float AMAP_ROUTE_OVERLAY_TRANSPARENCY_SELECTED = 1f;
|
||||
|
||||
/**
|
||||
* 未选中的路径透明度
|
||||
*/
|
||||
public static final float AMAP_ROUTE_OVERLAY_TRANSPARENCY_UNSELECTED = 0.3f;
|
||||
|
||||
private AMap mAMap;
|
||||
private Context mContext;
|
||||
// 规划的路线显示边距
|
||||
private Rect mBoundRect = null;
|
||||
|
||||
private List< CalculatePathItem > mCalculatePathItems;
|
||||
private List< MogoCalculatePath > mPaths = new ArrayList<>();
|
||||
|
||||
private int mSelectedPathId;
|
||||
private CalculatePathItem mSelectedCalculatePathItem;
|
||||
|
||||
/**
|
||||
* 起点终点marker
|
||||
*/
|
||||
private List< Marker > mMarkers = new ArrayList<>();
|
||||
|
||||
public NaviOverlayHelper( AMap mAMap, Context mContext ) {
|
||||
this.mAMap = mAMap;
|
||||
this.mContext = mContext;
|
||||
calculateBoundArea();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示规划的路径
|
||||
*/
|
||||
public void showCalculatedPaths( Runnable after ) {
|
||||
clearCalculatedOverlay();
|
||||
mCalculatePathItems = getSortedPaths();
|
||||
if ( mCalculatePathItems == null || mCalculatePathItems.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
showPathsBound( getBounds(), () -> {
|
||||
addEndPoints();
|
||||
renderPathOverlay( mCalculatePathItems );
|
||||
if ( after != null ) {
|
||||
after.run();
|
||||
}
|
||||
}, mBoundRect );
|
||||
}
|
||||
|
||||
private LatLngBounds getBounds() {
|
||||
if ( mCalculatePathItems == null ) {
|
||||
return null;
|
||||
}
|
||||
LatLngBounds.Builder builder = new LatLngBounds.Builder();
|
||||
for ( CalculatePathItem calculatePathItem : mCalculatePathItems ) {
|
||||
if ( calculatePathItem == null ) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
LatLngBounds bounds = calculatePathItem.getPath().getBoundsForPath();
|
||||
builder.include( bounds.northeast );
|
||||
builder.include( bounds.southwest );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按pathId升序排序
|
||||
*
|
||||
* @return 排序好的路径规划列表
|
||||
*/
|
||||
private List< CalculatePathItem > getSortedPaths() {
|
||||
checkAMapInstance();
|
||||
final Map< Integer, AMapNaviPath > pathMap = NaviClient.getInstance( mContext ).getAMapNaviPaths();
|
||||
if ( pathMap == null || pathMap.isEmpty() ) {
|
||||
return null;
|
||||
}
|
||||
TreeMap< Integer, AMapNaviPath > sortedMap =
|
||||
new TreeMap< Integer, AMapNaviPath >( new Comparator< Integer >() {
|
||||
@Override
|
||||
public int compare( Integer obj1, Integer obj2 ) {
|
||||
if ( obj1 != null ) {
|
||||
return obj1.compareTo( obj2 );
|
||||
}
|
||||
if ( obj2 != null ) {
|
||||
return obj2.compareTo( obj1 );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} );
|
||||
sortedMap.putAll( pathMap );
|
||||
|
||||
final List< CalculatePathItem > items = new ArrayList<>();
|
||||
for ( Map.Entry< Integer, AMapNaviPath > entry : sortedMap.entrySet() ) {
|
||||
if ( entry == null || entry.getKey() == null || entry.getValue() == null ) {
|
||||
continue;
|
||||
}
|
||||
items.add( new CalculatePathItem( mContext, mAMap, entry.getKey(), entry.getValue() ) );
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private void calculateBoundArea() {
|
||||
if ( mBoundRect == null ) {
|
||||
mBoundRect = new Rect();
|
||||
final int padding = WindowUtils.dip2px( mContext, 80 );
|
||||
mBoundRect.left = padding;
|
||||
mBoundRect.right = padding;
|
||||
mBoundRect.top = padding;
|
||||
mBoundRect.bottom = padding;
|
||||
}
|
||||
}
|
||||
|
||||
public void showBoundsWithSettingBounds() {
|
||||
showBounds( mBoundRect );
|
||||
}
|
||||
|
||||
public void showBounds( Rect bounds ) {
|
||||
Logger.d( TAG, "showBounds" );
|
||||
showPathsBound( getBounds(), null, bounds );
|
||||
}
|
||||
|
||||
/**
|
||||
* 将规划好的路径显示在视野内
|
||||
*/
|
||||
private void showPathsBound( LatLngBounds bounds, Runnable after, Rect rect ) {
|
||||
if ( bounds == null ) {
|
||||
return;
|
||||
}
|
||||
if ( rect == null ) {
|
||||
rect = new Rect();
|
||||
}
|
||||
checkAMapInstance();
|
||||
mAMap.moveCamera( CameraUpdateFactory.newLatLngBoundsRect(
|
||||
bounds,
|
||||
rect.left,
|
||||
rect.right,
|
||||
rect.top,
|
||||
rect.bottom ) );
|
||||
if ( after != null ) {
|
||||
after.run();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAMapInstance() {
|
||||
if ( mAMap == null ) {
|
||||
mAMap = AMapWrapper.getAMap();
|
||||
}
|
||||
}
|
||||
|
||||
public void renderPathOverlay( List< CalculatePathItem > paths ) {
|
||||
if ( paths == null || paths.size() == 0 ) {
|
||||
return;
|
||||
}
|
||||
for ( int i = 0; i < paths.size(); i++ ) {
|
||||
final CalculatePathItem item = paths.get( i );
|
||||
if ( item == null || item.getPath() == null ) {
|
||||
continue;
|
||||
}
|
||||
RouteOverLayWrapper wrapper = item.getOverLazWrapper( true );
|
||||
wrapper.setTrafficLightsVisible( false );
|
||||
// 默认选中第一个
|
||||
if ( i == 0 ) {
|
||||
mSelectedPathId = item.getId();
|
||||
mSelectedCalculatePathItem = item;
|
||||
//wrapper.setStartBitmap( R.drawable.ic_navi_start )
|
||||
// .setEndBitmap( R.drawable.ic_navi_target );
|
||||
NaviClient.getInstance( mContext ).selectAMapRouteId( item.getId() );
|
||||
Logger.d( TAG, "renderPathOverlay set default path" );
|
||||
}
|
||||
wrapper.addToMap();
|
||||
wrapper.setTransparency( i == 0 ? AMAP_ROUTE_OVERLAY_TRANSPARENCY_SELECTED : AMAP_ROUTE_OVERLAY_TRANSPARENCY_UNSELECTED );
|
||||
}
|
||||
}
|
||||
|
||||
public void addEndPoints() {
|
||||
if ( mCalculatePathItems == null || mCalculatePathItems.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bitmap = BitmapFactory.decodeResource( mContext.getResources(), R.drawable.ic_endpoint );
|
||||
Bitmap startBitmap = BitmapFactory.decodeResource( mContext.getResources(), R.drawable.ic_navi_start );
|
||||
Bitmap endBitmap = BitmapFactory.decodeResource( mContext.getResources(), R.drawable.ic_navi_target );
|
||||
MarkerOptions options = new MarkerOptions().icon( BitmapDescriptorFactory.fromBitmap( bitmap ) ).zIndex( 0 ).anchor( 0.5f, 0.5f );
|
||||
MarkerOptions startOptions = new MarkerOptions().icon( BitmapDescriptorFactory.fromBitmap( startBitmap ) ).zIndex( 0 ).anchor( 0.5f, 1 );
|
||||
MarkerOptions endOptions = new MarkerOptions().icon( BitmapDescriptorFactory.fromBitmap( endBitmap ) ).zIndex( 0 ).anchor( 0.5f, 1 );
|
||||
for ( CalculatePathItem path : mCalculatePathItems ) {
|
||||
List< MogoLatLng > points = path.getCoordList();
|
||||
if ( points == null || points.isEmpty() ) {
|
||||
continue;
|
||||
}
|
||||
MogoLatLng startPoint = path.getDriveStartPoint();
|
||||
MogoLatLng endPoint = path.getDriveEndPoint();
|
||||
if ( startPoint == null || endPoint == null ) {
|
||||
continue;
|
||||
}
|
||||
mMarkers.add( mAMap.addMarker( options.position( new LatLng( startPoint.lat, startPoint.lng ) ) ) );
|
||||
mMarkers.add( mAMap.addMarker( options.position( new LatLng( endPoint.lat, endPoint.lng ) ) ) );
|
||||
mMarkers.add( mAMap.addMarker( startOptions.position( new LatLng( startPoint.lat, startPoint.lng ) ) ) );
|
||||
mMarkers.add( mAMap.addMarker( endOptions.position( new LatLng( endPoint.lat, endPoint.lng ) ) ) );
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void clearCalculatedOverlay() {
|
||||
if ( mCalculatePathItems != null && !mCalculatePathItems.isEmpty() ) {
|
||||
for ( CalculatePathItem calculatePathItem : mCalculatePathItems ) {
|
||||
if ( calculatePathItem == null ) {
|
||||
continue;
|
||||
}
|
||||
RouteOverLayWrapper wrapper = calculatePathItem.getOverLazWrapper( false );
|
||||
if ( wrapper != null ) {
|
||||
wrapper.destroy();
|
||||
}
|
||||
calculatePathItem.release();
|
||||
}
|
||||
mCalculatePathItems.clear();
|
||||
}
|
||||
if ( mPaths != null ) {
|
||||
mPaths.clear();
|
||||
}
|
||||
if ( !mMarkers.isEmpty() ) {
|
||||
for ( Marker mMarker : mMarkers ) {
|
||||
if ( mMarker == null ) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
mMarker.remove();
|
||||
mMarker.destroy();
|
||||
} catch ( Exception e ) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
MogoMarkersHandler.getInstance().remove( TAG );
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否切换成功
|
||||
*
|
||||
* @param polyline 选中的线
|
||||
*/
|
||||
public boolean handleClickedPolyline( Polyline polyline, boolean isNaviing ) {
|
||||
if ( polyline == null ) {
|
||||
return false;
|
||||
}
|
||||
if ( mPaths != null && !mPaths.isEmpty() ) {
|
||||
for ( MogoCalculatePath path : mPaths ) {
|
||||
if ( TextUtils.equals( path.getTagId(), polyline.getId() ) ) {
|
||||
if ( MogoOperationListenerRegister.getInstance().getItemClickInteraction() != null ) {
|
||||
MogoOperationListenerRegister.getInstance().getItemClickInteraction().onItemClicked( path.getTagId() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return handleClickedPolyline( polyline.getId() );
|
||||
}
|
||||
|
||||
private boolean handleClickedPolyline( String id ) {
|
||||
if ( id == null ) {
|
||||
return false;
|
||||
}
|
||||
Logger.i( TAG, "polyline id = " + id );
|
||||
mSelectedCalculatePathItem = isCalculatePolyline( id );
|
||||
if ( mSelectedCalculatePathItem == null ) {
|
||||
return false;
|
||||
}
|
||||
mSelectedPathId = mSelectedCalculatePathItem.getId();
|
||||
if ( mCalculatePathItems != null ) {
|
||||
for ( CalculatePathItem item : mCalculatePathItems ) {
|
||||
final RouteOverLayWrapper wrapper = item.getOverLazWrapper( false );
|
||||
if ( wrapper == null ) {
|
||||
continue;
|
||||
}
|
||||
wrapper.setTransparency(
|
||||
item == mSelectedCalculatePathItem
|
||||
? AMAP_ROUTE_OVERLAY_TRANSPARENCY_SELECTED
|
||||
: AMAP_ROUTE_OVERLAY_TRANSPARENCY_UNSELECTED
|
||||
);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private CalculatePathItem isCalculatePolyline( String id ) {
|
||||
CalculatePathItem result = null;
|
||||
if ( mCalculatePathItems == null || mCalculatePathItems.isEmpty() ) {
|
||||
return result;
|
||||
}
|
||||
for ( CalculatePathItem calculatePathItem : mCalculatePathItems ) {
|
||||
if ( calculatePathItem == null ) {
|
||||
continue;
|
||||
}
|
||||
final RouteOverLayWrapper wrapper = calculatePathItem.getOverLazWrapper( false );
|
||||
if ( wrapper == null ) {
|
||||
continue;
|
||||
}
|
||||
if ( wrapper.getTrafficColorfulPolyline() == null ) {
|
||||
continue;
|
||||
}
|
||||
if ( TextUtils.equals( wrapper.getTrafficColorfulPolyline().getId(), id ) ) {
|
||||
result = calculatePathItem;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getSelectedPathId() {
|
||||
return mSelectedPathId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 车辆拐弯时绘制转向箭头
|
||||
*/
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List< MogoCalculatePath > getCalculateStrategies() {
|
||||
if ( mCalculatePathItems != null && !mCalculatePathItems.isEmpty() ) {
|
||||
for ( CalculatePathItem calculatePathItem : mCalculatePathItems ) {
|
||||
MogoCalculatePath path = new MogoCalculatePath();
|
||||
path.setFormattedDistance( calculatePathItem.getFormattedDistance() );
|
||||
path.setPathId( calculatePathItem.getId() );
|
||||
path.setStrategyName( calculatePathItem.getStrategyName() );
|
||||
path.setFormattedTime( calculatePathItem.getFormattedTime() );
|
||||
path.setTime( calculatePathItem.getTime() );
|
||||
path.setDistance( calculatePathItem.getDistance() );
|
||||
List< NaviLatLng > coordList = calculatePathItem.getPath().getCoordList();
|
||||
ArrayList< MogoLatLng > mogoLatLngs = new ArrayList<>();
|
||||
for ( NaviLatLng latlng : coordList
|
||||
) {
|
||||
MogoLatLng mogoLatLng =
|
||||
new MogoLatLng( latlng.getLatitude(), latlng.getLongitude() );
|
||||
mogoLatLngs.add( mogoLatLng );
|
||||
}
|
||||
path.setCoordList( mogoLatLngs );
|
||||
path.setTrafficLights( calculatePathItem.getTrafficNumber() );
|
||||
mPaths.add( path );
|
||||
final RouteOverLayWrapper wrapper = calculatePathItem.getOverLazWrapper( true );
|
||||
if ( wrapper == null ) {
|
||||
continue;
|
||||
}
|
||||
if ( wrapper.getTrafficColorfulPolyline() == null ) {
|
||||
continue;
|
||||
}
|
||||
path.setTagId( wrapper.getTrafficColorfulPolyline().getId() );
|
||||
}
|
||||
}
|
||||
|
||||
return mPaths;
|
||||
}
|
||||
|
||||
public List< MogoLatLng > getCalculatedPathPos() {
|
||||
|
||||
if ( mSelectedCalculatePathItem != null ) {
|
||||
return mSelectedCalculatePathItem.getCoordList();
|
||||
}
|
||||
//if (mPaths != null && !mPaths.isEmpty()) {
|
||||
// return mPaths.get(0).getCoordList();
|
||||
//}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClicked( String tagId ) {
|
||||
handleClickedPolyline( tagId );
|
||||
NaviClient.getInstance( mContext ).selectAMapRouteId( getSelectedPathId() );
|
||||
showBounds( mBoundRect );
|
||||
}
|
||||
|
||||
public OnCalculatePathItemClickInteraction getItemClickInteraction() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setCalculatePathDisplayBounds( Rect bounds ) {
|
||||
if ( bounds != null ) {
|
||||
mBoundRect = bounds;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示全程
|
||||
*/
|
||||
public void displayOverview( Rect bounds ) {
|
||||
showBounds( bounds );
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package com.mogo.map.impl.amap.navi;
|
||||
|
||||
import com.amap.api.navi.enums.PathPlanningErrCode;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-10-18
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public enum PathPlanningErrorCodeConstants {
|
||||
|
||||
NONE( -1, "路线规划错误,请重试" ),
|
||||
|
||||
ACCESS_TOO_FREQUENT( PathPlanningErrCode.ACCESS_TOO_FREQUENT, "访问过于频繁,请稍后再试" ),
|
||||
|
||||
DISABLE_RESTRICT( PathPlanningErrCode.DISABLE_RESTRICT, "无法躲避限行区域,请重新规划" ),
|
||||
|
||||
ERROR_BUF( PathPlanningErrCode.ERROR_BUF, "Buf数据格式错误" ),
|
||||
|
||||
ERROR_CONNECTION( PathPlanningErrCode.ERROR_CONNECTION, "网络超时或网络失败。" ),
|
||||
|
||||
ERROR_DISTANCE( PathPlanningErrCode.ERROR_DISTANCE, "起点/终点/途经点的距离太长(步行距离>100km,骑行距离>1200km)" ),
|
||||
|
||||
ERROR_ENCODER( PathPlanningErrCode.ERROR_ENCODER, "算路服务端编码失败" ),
|
||||
|
||||
ERROR_ENDPOINT( PathPlanningErrCode.ERROR_ENDPOINT, "终点错误" ),
|
||||
|
||||
ERROR_NAVI_PARAMS( PathPlanningErrCode.ERROR_NAVI_PARAMS, "调用直接导航 没有算路 参数错误,缺失有效的导航路径,无法开始导航" ),
|
||||
|
||||
ERROR_NOROADFORENDPOINT( PathPlanningErrCode.ERROR_NOROADFORENDPOINT, "终点没有找到道路" ),
|
||||
|
||||
ERROR_NOROADFORSTARTPOINT( PathPlanningErrCode.ERROR_NOROADFORSTARTPOINT, "起点没有找到道路。" ),
|
||||
|
||||
ERROR_NOROADFORWAYPOINT( PathPlanningErrCode.ERROR_NOROADFORWAYPOINT, "途径点没有找到道路" ),
|
||||
|
||||
ERROR_PREVIEW( PathPlanningErrCode.ERROR_PREVIEW, "路径数据缺乏预览数据" ),
|
||||
|
||||
ERROR_PROTOCOL( PathPlanningErrCode.ERROR_PROTOCOL, "请求协议非法。" ),
|
||||
|
||||
ERROR_STARTPOINT( PathPlanningErrCode.ERROR_STARTPOINT, "起点错误" ),
|
||||
|
||||
ERROR_WAYPOINT( PathPlanningErrCode.ERROR_WAYPOINT, "途经点错误" ),
|
||||
|
||||
INSUFFICIENT_PRIVILEGES( PathPlanningErrCode.INSUFFICIENT_PRIVILEGES, "无权限访问此服务。" ),
|
||||
|
||||
INVALID_PARAMS( PathPlanningErrCode.INVALID_PARAMS, "请求参数非法。" ),
|
||||
|
||||
INVALID_USER_KEY( PathPlanningErrCode.INVALID_USER_KEY, "用户key非法或过期(请检查key是否正确)" ),
|
||||
|
||||
INVALID_USER_SCODE( PathPlanningErrCode.INVALID_USER_SCODE, "MD5安全码未通过验证,需要开发者判定key绑定的SHA1,package是否与sdk包里的一致." ),
|
||||
|
||||
OUT_OF_SERVICE( PathPlanningErrCode.OUT_OF_SERVICE, "使用路径规划服务接口时可能出现该问题,规划点(包括起点、终点、途经点)不在中国陆地范围内" ),
|
||||
|
||||
OVER_DIRECTION_RANGE( PathPlanningErrCode.OVER_DIRECTION_RANGE, "使用路径规划服务接口时可能出现该问题,路线计算失败,通常是由于道路起点和终点距离过长导致" ),
|
||||
|
||||
OVER_QUOTA( PathPlanningErrCode.OVER_QUOTA, "请求超出配额。" ),
|
||||
|
||||
SERVICE_NOT_EXIST( PathPlanningErrCode.SERVICE_NOT_EXIST, "请求服务不存在。" ),
|
||||
|
||||
SERVICE_RESPONSE_ERROR( PathPlanningErrCode.SERVICE_RESPONSE_ERROR, "请求服务响应错误。" ),
|
||||
|
||||
UNKNOWN_ERROR( PathPlanningErrCode.UNKNOWN_ERROR, "未知错误(可能是由于连接的网络无法访问外网)" ),
|
||||
|
||||
USERKEY_PLAT_NOMATCH( PathPlanningErrCode.USERKEY_PLAT_NOMATCH, "请求中使用的key与绑定平台不符,例如:开发者申请的是js api的key,却用来调web服务接口" );
|
||||
|
||||
private int code;
|
||||
private String errorMsg;
|
||||
|
||||
PathPlanningErrorCodeConstants( int code, String errorMsg ) {
|
||||
this.code = code;
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getErrorMsg() {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
public static String getErrorMsg( int code ) {
|
||||
for ( PathPlanningErrorCodeConstants value : PathPlanningErrorCodeConstants.values() ) {
|
||||
if ( value.getCode() == code ) {
|
||||
return value.getErrorMsg();
|
||||
}
|
||||
}
|
||||
return NONE.getErrorMsg();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package com.mogo.map.impl.amap.navi;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.voice.AIAssist;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-04-21
|
||||
* <p>
|
||||
* 播报导航TTS
|
||||
* <p>
|
||||
* 策略:队列缓存预播报的 tts,然后上一句播完后
|
||||
*/
|
||||
public class TTSSpeaker {
|
||||
|
||||
private static volatile TTSSpeaker sInstance;
|
||||
|
||||
private TTSSpeaker() {
|
||||
}
|
||||
|
||||
public static TTSSpeaker getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( TTSSpeaker.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new TTSSpeaker();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
private LinkedList< String > mWaiting = new LinkedList<>();
|
||||
|
||||
private String mLastTts = null;
|
||||
private String mLastTtsId = null;
|
||||
|
||||
public synchronized void speakTTS( String tts ) {
|
||||
if ( TextUtils.isEmpty( tts ) ) {
|
||||
return;
|
||||
}
|
||||
mWaiting.add( tts );
|
||||
}
|
||||
|
||||
public synchronized void shutUp() {
|
||||
if ( mLastTtsId != null ) {
|
||||
AIAssist.getInstance( AbsMogoApplication.getApp() ).shutUp( mLastTtsId, mLastTts );
|
||||
mWaiting.clear();
|
||||
mLastTtsId = null;
|
||||
mLastTts = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
package com.mogo.map.impl.amap.overlay;
|
||||
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.maps.model.PolylineOptions;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.overlay.IMogoPolyline;
|
||||
import com.mogo.map.overlay.MogoPolylineOptions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-03-10
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class AMapPolylineWrapper implements IMogoPolyline {
|
||||
|
||||
private Polyline mPolyline;
|
||||
private MogoPolylineOptions mOptions;
|
||||
private boolean mIsDestroyed = false;
|
||||
|
||||
public AMapPolylineWrapper( Polyline mPolyline,
|
||||
MogoPolylineOptions mOptions ) {
|
||||
this.mPolyline = mPolyline;
|
||||
this.mOptions = mOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.remove();
|
||||
}
|
||||
mIsDestroyed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
if ( mPolyline != null ) {
|
||||
return mPolyline.getId();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPoints( List< MogoLatLng > lonLats ) {
|
||||
if ( lonLats == null || lonLats.isEmpty() ) {
|
||||
mPolyline.setPoints( new ArrayList< LatLng >() );
|
||||
return;
|
||||
}
|
||||
ArrayList< LatLng > points = new ArrayList<>();
|
||||
for ( MogoLatLng lonLat : lonLats ) {
|
||||
LatLng latLng = ObjectUtils.fromMogo2( lonLat );
|
||||
if ( latLng == null ) {
|
||||
continue;
|
||||
}
|
||||
points.add( latLng );
|
||||
}
|
||||
mPolyline.setPoints( points );
|
||||
}
|
||||
|
||||
@Override
|
||||
public List< MogoLatLng > getPoints() {
|
||||
if ( mPolyline == null ) {
|
||||
return null;
|
||||
}
|
||||
ArrayList< MogoLatLng > lonLats = new ArrayList<>();
|
||||
List< LatLng > points = mPolyline.getPoints();
|
||||
if ( points != null ) {
|
||||
for ( LatLng latLng : points ) {
|
||||
MogoLatLng lonLat = ObjectUtils.fromAMap( latLng );
|
||||
if ( lonLat == null ) {
|
||||
continue;
|
||||
}
|
||||
lonLats.add( lonLat );
|
||||
}
|
||||
}
|
||||
return lonLats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGeodesic( boolean draw ) {
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.setGeodesic( draw );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGeodesic() {
|
||||
return mPolyline == null ? false : mPolyline.isGeodesic();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDottedLine( boolean dottedLine ) {
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.setDottedLine( dottedLine );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDottedLine() {
|
||||
return mPolyline == null ? false : mPolyline.isDottedLine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidth( float width ) {
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.setWidth( width );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWidth() {
|
||||
if ( mPolyline != null ) {
|
||||
return mPolyline.getWidth();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor( int color ) {
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.setColor( color );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
if ( mPolyline != null ) {
|
||||
return mPolyline.getColor();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setZIndex( float zIndex ) {
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.setZIndex( zIndex );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getZIndex() {
|
||||
if ( mPolyline != null ) {
|
||||
return mPolyline.getZIndex();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible( boolean visible ) {
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.setVisible( visible );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
if ( mPolyline != null ) {
|
||||
return mPolyline.isVisible();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransparency( float transparency ) {
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.setTransparency( transparency );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOption( MogoPolylineOptions option ) {
|
||||
PolylineOptions target = ObjectUtils.fromMogo( option );
|
||||
if ( target == null ) {
|
||||
return;
|
||||
}
|
||||
mOptions = option;
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.setOptions( target );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDestroyed() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,268 +0,0 @@
|
||||
package com.mogo.map.impl.amap.overlay;
|
||||
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.services.core.LatLonPoint;
|
||||
import com.amap.api.services.route.BusPath;
|
||||
import com.amap.api.services.route.BusStep;
|
||||
import com.amap.api.services.route.RouteBusLineItem;
|
||||
import com.amap.api.services.route.RouteRailwayItem;
|
||||
import com.mogo.map.impl.amap.R;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class AMapUtil {
|
||||
/**
|
||||
* 判断edittext是否null
|
||||
*/
|
||||
public static String checkEditText(EditText editText) {
|
||||
if (editText != null && editText.getText() != null
|
||||
&& !(editText.getText().toString().trim().equals(""))) {
|
||||
return editText.getText().toString().trim();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static Spanned stringToSpan(String src) {
|
||||
return src == null ? null : Html.fromHtml(src.replace("\n", "<br />"));
|
||||
}
|
||||
|
||||
public static String colorFont(String src, String color) {
|
||||
StringBuffer strBuf = new StringBuffer();
|
||||
|
||||
strBuf.append("<font color=").append(color).append(">").append(src)
|
||||
.append("</font>");
|
||||
return strBuf.toString();
|
||||
}
|
||||
|
||||
public static String makeHtmlNewLine() {
|
||||
return "<br />";
|
||||
}
|
||||
|
||||
public static String makeHtmlSpace(int number) {
|
||||
final String space = " ";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < number; i++) {
|
||||
result.append(space);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String getFriendlyLength(int lenMeter) {
|
||||
if (lenMeter > 10000) // 10 km
|
||||
{
|
||||
int dis = lenMeter / 1000;
|
||||
return dis + ChString.Kilometer;
|
||||
}
|
||||
|
||||
if (lenMeter > 1000) {
|
||||
float dis = (float) lenMeter / 1000;
|
||||
DecimalFormat fnum = new DecimalFormat("##0.0");
|
||||
String dstr = fnum.format(dis);
|
||||
return dstr + ChString.Kilometer;
|
||||
}
|
||||
|
||||
if (lenMeter > 100) {
|
||||
int dis = lenMeter / 50 * 50;
|
||||
return dis + ChString.Meter;
|
||||
}
|
||||
|
||||
int dis = lenMeter / 10 * 10;
|
||||
if (dis == 0) {
|
||||
dis = 10;
|
||||
}
|
||||
|
||||
return dis + ChString.Meter;
|
||||
}
|
||||
|
||||
public static boolean IsEmptyOrNullString(String s) {
|
||||
return (s == null) || (s.trim().length() == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把LatLng对象转化为LatLonPoint对象
|
||||
*/
|
||||
public static LatLonPoint convertToLatLonPoint(LatLng latlon) {
|
||||
return new LatLonPoint(latlon.latitude, latlon.longitude);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把LatLonPoint对象转化为LatLon对象
|
||||
*/
|
||||
public static LatLng convertToLatLng(LatLonPoint latLonPoint) {
|
||||
return new LatLng(latLonPoint.getLatitude(), latLonPoint.getLongitude());
|
||||
}
|
||||
|
||||
/**
|
||||
* 把集合体的LatLonPoint转化为集合体的LatLng
|
||||
*/
|
||||
public static ArrayList<LatLng> convertArrList(List<LatLonPoint> shapes) {
|
||||
ArrayList<LatLng> lineShapes = new ArrayList<LatLng>();
|
||||
for (LatLonPoint point : shapes) {
|
||||
LatLng latLngTemp = AMapUtil.convertToLatLng(point);
|
||||
lineShapes.add(latLngTemp);
|
||||
}
|
||||
return lineShapes;
|
||||
}
|
||||
|
||||
/**
|
||||
* long类型时间格式化
|
||||
*/
|
||||
public static String convertToTime(long time) {
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = new Date(time);
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
public static final String HtmlBlack = "#000000";
|
||||
public static final String HtmlGray = "#808080";
|
||||
|
||||
public static String getFriendlyTime(int second) {
|
||||
if (second > 3600) {
|
||||
int hour = second / 3600;
|
||||
int miniate = (second % 3600) / 60;
|
||||
return hour + "小时" + miniate + "分钟";
|
||||
}
|
||||
if (second >= 60) {
|
||||
int miniate = second / 60;
|
||||
return miniate + "分钟";
|
||||
}
|
||||
return second + "秒";
|
||||
}
|
||||
|
||||
//路径规划方向指示和图片对应
|
||||
public static int getDriveActionID(String actionName) {
|
||||
if (actionName == null || actionName.equals("")) {
|
||||
return R.drawable.dir3;
|
||||
}
|
||||
if ("左转".equals(actionName)) {
|
||||
return R.drawable.dir2;
|
||||
}
|
||||
if ("右转".equals(actionName)) {
|
||||
return R.drawable.dir1;
|
||||
}
|
||||
if ("向左前方行驶".equals(actionName) || "靠左".equals(actionName)) {
|
||||
return R.drawable.dir6;
|
||||
}
|
||||
if ("向右前方行驶".equals(actionName) || "靠右".equals(actionName)) {
|
||||
return R.drawable.dir5;
|
||||
}
|
||||
if ("向左后方行驶".equals(actionName) || "左转调头".equals(actionName)) {
|
||||
return R.drawable.dir7;
|
||||
}
|
||||
if ("向右后方行驶".equals(actionName)) {
|
||||
return R.drawable.dir8;
|
||||
}
|
||||
if ("直行".equals(actionName)) {
|
||||
return R.drawable.dir3;
|
||||
}
|
||||
if ("减速行驶".equals(actionName)) {
|
||||
return R.drawable.dir4;
|
||||
}
|
||||
return R.drawable.dir3;
|
||||
}
|
||||
|
||||
public static int getWalkActionID(String actionName) {
|
||||
if (actionName == null || actionName.equals("")) {
|
||||
return R.drawable.dir13;
|
||||
}
|
||||
if ("左转".equals(actionName)) {
|
||||
return R.drawable.dir2;
|
||||
}
|
||||
if ("右转".equals(actionName)) {
|
||||
return R.drawable.dir1;
|
||||
}
|
||||
if ("向左前方".equals(actionName) || "靠左".equals(actionName) || actionName.contains("向左前方")) {
|
||||
return R.drawable.dir6;
|
||||
}
|
||||
if ("向右前方".equals(actionName) || "靠右".equals(actionName) || actionName.contains("向右前方")) {
|
||||
return R.drawable.dir5;
|
||||
}
|
||||
if ("向左后方".equals(actionName) || actionName.contains("向左后方")) {
|
||||
return R.drawable.dir7;
|
||||
}
|
||||
if ("向右后方".equals(actionName) || actionName.contains("向右后方")) {
|
||||
return R.drawable.dir8;
|
||||
}
|
||||
if ("直行".equals(actionName)) {
|
||||
return R.drawable.dir3;
|
||||
}
|
||||
if ("通过人行横道".equals(actionName)) {
|
||||
return R.drawable.dir9;
|
||||
}
|
||||
if ("通过过街天桥".equals(actionName)) {
|
||||
return R.drawable.dir11;
|
||||
}
|
||||
if ("通过地下通道".equals(actionName)) {
|
||||
return R.drawable.dir10;
|
||||
}
|
||||
|
||||
return R.drawable.dir13;
|
||||
}
|
||||
|
||||
public static String getBusPathTitle(BusPath busPath) {
|
||||
if (busPath == null) {
|
||||
return String.valueOf("");
|
||||
}
|
||||
List<BusStep> busSetps = busPath.getSteps();
|
||||
if (busSetps == null) {
|
||||
return String.valueOf("");
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (BusStep busStep : busSetps) {
|
||||
StringBuffer title = new StringBuffer();
|
||||
if (busStep.getBusLines().size() > 0) {
|
||||
for (RouteBusLineItem busline : busStep.getBusLines()) {
|
||||
if (busline == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String buslineName = getSimpleBusLineName(busline.getBusLineName());
|
||||
title.append(buslineName);
|
||||
title.append(" / ");
|
||||
}
|
||||
// RouteBusLineItem busline = busStep.getBusLines().get(0);
|
||||
|
||||
sb.append(title.substring(0, title.length() - 3));
|
||||
sb.append(" > ");
|
||||
}
|
||||
if (busStep.getRailway() != null) {
|
||||
RouteRailwayItem railway = busStep.getRailway();
|
||||
sb.append(railway.getTrip() + "(" + railway.getDeparturestop().getName()
|
||||
+ " - " + railway.getArrivalstop().getName() + ")");
|
||||
sb.append(" > ");
|
||||
}
|
||||
}
|
||||
return sb.substring(0, sb.length() - 3);
|
||||
}
|
||||
|
||||
public static String getBusPathDes(BusPath busPath) {
|
||||
if (busPath == null) {
|
||||
return String.valueOf("");
|
||||
}
|
||||
long second = busPath.getDuration();
|
||||
String time = getFriendlyTime((int) second);
|
||||
float subDistance = busPath.getDistance();
|
||||
String subDis = getFriendlyLength((int) subDistance);
|
||||
float walkDistance = busPath.getWalkDistance();
|
||||
String walkDis = getFriendlyLength((int) walkDistance);
|
||||
return String.valueOf(time + " | " + subDis + " | 步行" + walkDis);
|
||||
}
|
||||
|
||||
public static String getSimpleBusLineName(String busLineName) {
|
||||
if (busLineName == null) {
|
||||
return String.valueOf("");
|
||||
}
|
||||
return busLineName.replaceAll("\\(.*?\\)", "");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.mogo.map.impl.amap.overlay;
|
||||
|
||||
public class ChString {
|
||||
public static final String Kilometer = "\u516c\u91cc";// "公里";
|
||||
public static final String Meter = "\u7c73";// "米";
|
||||
public static final String ByFoot = "\u6b65\u884c";// "步行";
|
||||
public static final String To = "\u53bb\u5f80";// "去往";
|
||||
public static final String Station = "\u8f66\u7ad9";// "车站";
|
||||
public static final String TargetPlace = "\u76ee\u7684\u5730";// "目的地";
|
||||
public static final String StartPlace = "\u51fa\u53d1\u5730";// "出发地";
|
||||
public static final String About = "\u5927\u7ea6";// "大约";
|
||||
public static final String Direction = "\u65b9\u5411";// "方向";
|
||||
|
||||
public static final String GetOn = "\u4e0a\u8f66";// "上车";
|
||||
public static final String GetOff = "\u4e0b\u8f66";// "下车";
|
||||
public static final String Zhan = "\u7ad9";// "站";
|
||||
|
||||
public static final String cross = "\u4ea4\u53c9\u8def\u53e3"; // 交叉路口
|
||||
public static final String type = "\u7c7b\u522b"; // 类别
|
||||
public static final String address = "\u5730\u5740"; // 地址
|
||||
public static final String PrevStep = "\u4e0a\u4e00\u6b65";
|
||||
public static final String NextStep = "\u4e0b\u4e00\u6b65";
|
||||
public static final String Gong = "\u516c\u4ea4";
|
||||
public static final String ByBus = "\u4e58\u8f66";
|
||||
public static final String Arrive = "\u5230\u8FBE";// 到达
|
||||
}
|
||||
@@ -1,388 +0,0 @@
|
||||
package com.mogo.map.impl.amap.overlay;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.model.BitmapDescriptor;
|
||||
import com.amap.api.maps.model.BitmapDescriptorFactory;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.LatLngBounds;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.amap.api.maps.model.MarkerOptions;
|
||||
import com.amap.api.maps.model.PolylineOptions;
|
||||
import com.amap.api.services.core.LatLonPoint;
|
||||
import com.amap.api.services.route.DrivePath;
|
||||
import com.amap.api.services.route.DriveStep;
|
||||
import com.amap.api.services.route.TMC;
|
||||
import com.mogo.map.impl.amap.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 导航路线图层类
|
||||
*/
|
||||
public class DrivingRouteOverlay extends RouteOverlay {
|
||||
private DrivePath drivePath;
|
||||
private List<LatLonPoint> throughPointList;
|
||||
private List<Marker> throughPointMarkerList = new ArrayList<Marker>();
|
||||
private boolean throughPointMarkerVisible = true;
|
||||
private List<TMC> tmcs;
|
||||
private PolylineOptions mPolylineOptions;
|
||||
private PolylineOptions mPolylineOptionscolor;
|
||||
private Context mContext;
|
||||
private boolean isColorfulline = true;
|
||||
private float mWidth = 4;
|
||||
private List<LatLng> mLatLngsOfPath;
|
||||
|
||||
public void setIsColorfulline(boolean iscolorfulline) {
|
||||
this.isColorfulline = iscolorfulline;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据给定的参数,构造一个导航路线图层类对象。
|
||||
*
|
||||
* @param amap 地图对象。
|
||||
* @param path 导航路线规划方案。
|
||||
* @param context 当前的activity对象。
|
||||
*/
|
||||
public DrivingRouteOverlay(Context context,
|
||||
AMap amap,
|
||||
DrivePath path,
|
||||
LatLonPoint start,
|
||||
LatLonPoint end,
|
||||
List<LatLonPoint> throughPointList) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
mAMap = amap;
|
||||
this.drivePath = path;
|
||||
startPoint = AMapUtil.convertToLatLng(start);
|
||||
endPoint = AMapUtil.convertToLatLng(end);
|
||||
this.throughPointList = throughPointList;
|
||||
|
||||
initBitmapDescriptor();
|
||||
}
|
||||
|
||||
public float getRouteWidth() {
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置路线宽度
|
||||
*
|
||||
* @param mWidth 路线宽度,取值范围:大于0
|
||||
*/
|
||||
public void setRouteWidth(float mWidth) {
|
||||
this.mWidth = mWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加驾车路线添加到地图上显示。
|
||||
*/
|
||||
public void addToMap() {
|
||||
initPolylineOptions();
|
||||
try {
|
||||
if (mAMap == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mWidth == 0 || drivePath == null) {
|
||||
return;
|
||||
}
|
||||
mLatLngsOfPath = new ArrayList<LatLng>();
|
||||
tmcs = new ArrayList<TMC>();
|
||||
List<DriveStep> drivePaths = drivePath.getSteps();
|
||||
mPolylineOptions.add(startPoint);
|
||||
for (int i = 0; i < drivePaths.size(); i++) {
|
||||
DriveStep step = drivePaths.get(i);
|
||||
List<LatLonPoint> latlonPoints = step.getPolyline();
|
||||
List<TMC> tmclist = step.getTMCs();
|
||||
tmcs.addAll(tmclist);
|
||||
addDrivingStationMarkers(step, convertToLatLng(latlonPoints.get(0)));
|
||||
for (LatLonPoint latlonpoint : latlonPoints) {
|
||||
mPolylineOptions.add(convertToLatLng(latlonpoint));
|
||||
mLatLngsOfPath.add(convertToLatLng(latlonpoint));
|
||||
}
|
||||
}
|
||||
mPolylineOptions.add(endPoint);
|
||||
if (startMarker != null) {
|
||||
startMarker.remove();
|
||||
startMarker = null;
|
||||
}
|
||||
|
||||
if (endMarker != null) {
|
||||
endMarker.remove();
|
||||
endMarker = null;
|
||||
}
|
||||
// addStartAndEndMarker();
|
||||
// addThroughPointMarker();
|
||||
if (isColorfulline && tmcs.size() > 0) {
|
||||
colorWayUpdate(tmcs);
|
||||
showcolorPolyline();
|
||||
} else {
|
||||
showPolyline();
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化线段属性
|
||||
*/
|
||||
private void initPolylineOptions() {
|
||||
mPolylineOptions = null;
|
||||
mPolylineOptions = new PolylineOptions();
|
||||
mPolylineOptions.color(getDriveColor()).width(getRouteWidth());
|
||||
}
|
||||
|
||||
private void showPolyline() {
|
||||
addPolyLine(mPolylineOptions);
|
||||
}
|
||||
|
||||
private void showcolorPolyline() {
|
||||
addPolyLine(mPolylineOptionscolor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据不同的路段拥堵情况展示不同的颜色
|
||||
*
|
||||
* @param tmcSection
|
||||
*/
|
||||
private void colorWayUpdate(List<TMC> tmcSection) {
|
||||
if (mAMap == null) {
|
||||
return;
|
||||
}
|
||||
if (tmcSection == null || tmcSection.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
TMC segmentTrafficStatus;
|
||||
mPolylineOptionscolor = null;
|
||||
mPolylineOptionscolor = new PolylineOptions();
|
||||
mPolylineOptionscolor.width(getRouteWidth());
|
||||
List<Integer> colorList = new ArrayList<Integer>();
|
||||
List<BitmapDescriptor> bitmapDescriptors = new ArrayList<BitmapDescriptor>();
|
||||
List<LatLng> points = new ArrayList<>();
|
||||
List<Integer> texIndexList = new ArrayList<Integer>();
|
||||
// mPolylineOptionscolor.add(startPoint);
|
||||
// mPolylineOptionscolor.add(AMapUtil.convertToLatLng(tmcSection.get(0).getPolyline().get(0)));
|
||||
|
||||
points.add(startPoint);
|
||||
points.add(AMapUtil.convertToLatLng(tmcSection.get(0).getPolyline().get(0)));
|
||||
colorList.add(getDriveColor());
|
||||
bitmapDescriptors.add(defaultRoute);
|
||||
|
||||
BitmapDescriptor bitmapDescriptor = null;
|
||||
int textIndex = 0;
|
||||
texIndexList.add(textIndex);
|
||||
texIndexList.add(++textIndex);
|
||||
for (int i = 0; i < tmcSection.size(); i++) {
|
||||
segmentTrafficStatus = tmcSection.get(i);
|
||||
int color = getcolor(segmentTrafficStatus.getStatus());
|
||||
bitmapDescriptor = getTrafficBitmapDescriptor(segmentTrafficStatus.getStatus());
|
||||
List<LatLonPoint> mployline = segmentTrafficStatus.getPolyline();
|
||||
for (int j = 0; j < mployline.size(); j++) {
|
||||
// mPolylineOptionscolor.add(AMapUtil.convertToLatLng(mployline.get(j)));
|
||||
points.add(AMapUtil.convertToLatLng(mployline.get(j)));
|
||||
colorList.add(color);
|
||||
|
||||
texIndexList.add(++textIndex);
|
||||
bitmapDescriptors.add(bitmapDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
points.add(endPoint);
|
||||
colorList.add(getDriveColor());
|
||||
bitmapDescriptors.add(defaultRoute);
|
||||
texIndexList.add(++textIndex);
|
||||
mPolylineOptionscolor.addAll(points);
|
||||
mPolylineOptionscolor.colorValues(colorList);
|
||||
|
||||
// mPolylineOptionscolor.setCustomTextureIndex(texIndexList);
|
||||
// mPolylineOptionscolor.setCustomTextureList(bitmapDescriptors);
|
||||
}
|
||||
|
||||
private BitmapDescriptor defaultRoute = null;
|
||||
private BitmapDescriptor unknownTraffic = null;
|
||||
private BitmapDescriptor smoothTraffic = null;
|
||||
private BitmapDescriptor slowTraffic = null;
|
||||
private BitmapDescriptor jamTraffic = null;
|
||||
private BitmapDescriptor veryJamTraffic = null;
|
||||
|
||||
private void initBitmapDescriptor() {
|
||||
defaultRoute = BitmapDescriptorFactory.fromResource( R.drawable.amap_route_color_texture_6_arrow);
|
||||
smoothTraffic = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_4_arrow);
|
||||
unknownTraffic = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_0_arrow);
|
||||
slowTraffic = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_3_arrow);
|
||||
jamTraffic = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_2_arrow);
|
||||
veryJamTraffic = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_9_arrow);
|
||||
}
|
||||
|
||||
private BitmapDescriptor getTrafficBitmapDescriptor(String status) {
|
||||
if (status.equals("畅通")) {
|
||||
return smoothTraffic;
|
||||
} else if (status.equals("缓行")) {
|
||||
return slowTraffic;
|
||||
} else if (status.equals("拥堵")) {
|
||||
return jamTraffic;
|
||||
} else if (status.equals("严重拥堵")) {
|
||||
return veryJamTraffic;
|
||||
} else {
|
||||
return defaultRoute;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int getcolor(String status) {
|
||||
if (status.equals("畅通")) {
|
||||
return Color.GREEN;
|
||||
} else if (status.equals("缓行")) {
|
||||
return Color.YELLOW;
|
||||
} else if (status.equals("拥堵")) {
|
||||
return Color.RED;
|
||||
} else if (status.equals("严重拥堵")) {
|
||||
return Color.parseColor("#990033");
|
||||
} else {
|
||||
return Color.GREEN;
|
||||
}
|
||||
}
|
||||
|
||||
public LatLng convertToLatLng(LatLonPoint point) {
|
||||
return new LatLng(point.getLatitude(), point.getLongitude());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param driveStep
|
||||
* @param latLng
|
||||
*/
|
||||
private void addDrivingStationMarkers(DriveStep driveStep, LatLng latLng) {
|
||||
addStationMarker(new MarkerOptions()
|
||||
.position(latLng)
|
||||
.title("\u65B9\u5411:" + driveStep.getAction()
|
||||
+ "\n\u9053\u8DEF:" + driveStep.getRoad())
|
||||
.snippet(driveStep.getInstruction()).visible(nodeIconVisible)
|
||||
.anchor(0.5f, 0.5f).icon(getDriveBitmapDescriptor()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LatLngBounds getLatLngBounds() {
|
||||
LatLngBounds.Builder b = LatLngBounds.builder();
|
||||
b.include(new LatLng(startPoint.latitude, startPoint.longitude));
|
||||
b.include(new LatLng(endPoint.latitude, endPoint.longitude));
|
||||
if (this.throughPointList != null && this.throughPointList.size() > 0) {
|
||||
for (int i = 0; i < this.throughPointList.size(); i++) {
|
||||
b.include(new LatLng(
|
||||
this.throughPointList.get(i).getLatitude(),
|
||||
this.throughPointList.get(i).getLongitude()));
|
||||
}
|
||||
}
|
||||
return b.build();
|
||||
}
|
||||
|
||||
public void setThroughPointIconVisibility(boolean visible) {
|
||||
try {
|
||||
throughPointMarkerVisible = visible;
|
||||
if (this.throughPointMarkerList != null
|
||||
&& this.throughPointMarkerList.size() > 0) {
|
||||
for (int i = 0; i < this.throughPointMarkerList.size(); i++) {
|
||||
this.throughPointMarkerList.get(i).setVisible(visible);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void addThroughPointMarker() {
|
||||
if (this.throughPointList != null && this.throughPointList.size() > 0) {
|
||||
LatLonPoint latLonPoint = null;
|
||||
for (int i = 0; i < this.throughPointList.size(); i++) {
|
||||
latLonPoint = this.throughPointList.get(i);
|
||||
if (latLonPoint != null) {
|
||||
throughPointMarkerList.add(mAMap
|
||||
.addMarker((new MarkerOptions())
|
||||
.position(
|
||||
new LatLng(latLonPoint
|
||||
.getLatitude(), latLonPoint
|
||||
.getLongitude()))
|
||||
.visible(throughPointMarkerVisible)
|
||||
.icon(getThroughPointBitDes())
|
||||
.title("\u9014\u7ECF\u70B9")));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BitmapDescriptor getThroughPointBitDes() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_through);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取两点间距离
|
||||
*
|
||||
* @param start
|
||||
* @param end
|
||||
* @return
|
||||
*/
|
||||
public static int calculateDistance(LatLng start, LatLng end) {
|
||||
double x1 = start.longitude;
|
||||
double y1 = start.latitude;
|
||||
double x2 = end.longitude;
|
||||
double y2 = end.latitude;
|
||||
return calculateDistance(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
public static int calculateDistance(double x1, double y1, double x2, double y2) {
|
||||
final double NF_pi = 0.01745329251994329; // 弧度 PI/180
|
||||
x1 *= NF_pi;
|
||||
y1 *= NF_pi;
|
||||
x2 *= NF_pi;
|
||||
y2 *= NF_pi;
|
||||
double sinx1 = Math.sin(x1);
|
||||
double siny1 = Math.sin(y1);
|
||||
double cosx1 = Math.cos(x1);
|
||||
double cosy1 = Math.cos(y1);
|
||||
double sinx2 = Math.sin(x2);
|
||||
double siny2 = Math.sin(y2);
|
||||
double cosx2 = Math.cos(x2);
|
||||
double cosy2 = Math.cos(y2);
|
||||
double[] v1 = new double[3];
|
||||
v1[0] = cosy1 * cosx1 - cosy2 * cosx2;
|
||||
v1[1] = cosy1 * sinx1 - cosy2 * sinx2;
|
||||
v1[2] = siny1 - siny2;
|
||||
double dist = Math.sqrt(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]);
|
||||
|
||||
return (int) (Math.asin(dist / 2) * 12742001.5798544);
|
||||
}
|
||||
|
||||
|
||||
//获取指定两点之间固定距离点
|
||||
public static LatLng getPointForDis(LatLng sPt, LatLng ePt, double dis) {
|
||||
double lSegLength = calculateDistance(sPt, ePt);
|
||||
double preResult = dis / lSegLength;
|
||||
return new LatLng((ePt.latitude - sPt.latitude) * preResult + sPt.latitude, (ePt.longitude - sPt.longitude) * preResult + sPt.longitude);
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉DriveLineOverlay上的线段和标记。
|
||||
*/
|
||||
@Override
|
||||
public void removeFromMap() {
|
||||
try {
|
||||
super.removeFromMap();
|
||||
if (this.throughPointMarkerList != null
|
||||
&& this.throughPointMarkerList.size() > 0) {
|
||||
for (int i = 0; i < this.throughPointMarkerList.size(); i++) {
|
||||
this.throughPointMarkerList.get(i).remove();
|
||||
}
|
||||
this.throughPointMarkerList.clear();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.mogo.map.impl.amap.overlay;
|
||||
|
||||
import com.amap.api.services.route.BusRouteResult;
|
||||
import com.amap.api.services.route.DriveRouteResult;
|
||||
import com.amap.api.services.route.RideRouteResult;
|
||||
import com.amap.api.services.route.RouteSearch;
|
||||
import com.amap.api.services.route.WalkRouteResult;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-01-08
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public abstract class OnRouteSearchListenerAdapter implements RouteSearch.OnRouteSearchListener {
|
||||
|
||||
@Override
|
||||
public void onBusRouteSearched( BusRouteResult busRouteResult, int i ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDriveRouteSearched( DriveRouteResult driveRouteResult, int i ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalkRouteSearched( WalkRouteResult walkRouteResult, int i ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRideRouteSearched( RideRouteResult rideRouteResult, int i ) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,211 +0,0 @@
|
||||
package com.mogo.map.impl.amap.overlay;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.util.Log;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.model.NavigateArrowOptions;
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.navi.model.AMapNaviLocation;
|
||||
import com.amap.api.navi.model.AMapNaviPath;
|
||||
import com.amap.api.navi.model.NaviInfo;
|
||||
import com.amap.api.navi.model.RouteOverlayOptions;
|
||||
import com.amap.api.navi.view.RouteOverLay;
|
||||
import com.mogo.map.impl.amap.utils.MapStyleUtils;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-10-04
|
||||
* <p>
|
||||
* 路径覆盖物
|
||||
*/
|
||||
public class RouteOverLayWrapper {
|
||||
|
||||
private static final String TAG = "RouteOverLayWrapper";
|
||||
|
||||
private final WeakReference< Context > mContextRef;
|
||||
private final AMap mAMap;
|
||||
private final AMapNaviPath mPath;
|
||||
|
||||
private RouteOverLay mRouteOverLay;
|
||||
private boolean mIsRemoved = true;
|
||||
|
||||
private boolean mIsTrafficLightsVisible = true;
|
||||
private int mStartBitmapResId = 0;
|
||||
private int mEndBitmapResId = 0;
|
||||
private int mZIndex = 1;
|
||||
|
||||
private static RouteOverlayOptions sOptions;
|
||||
|
||||
public RouteOverLayWrapper( Context context,
|
||||
AMap mAMap,
|
||||
AMapNaviPath mPath ) {
|
||||
this.mContextRef = new WeakReference<>( context );
|
||||
this.mAMap = mAMap;
|
||||
this.mPath = mPath;
|
||||
}
|
||||
|
||||
public void addToMap() {
|
||||
if ( mContextRef == null || mContextRef.get() == null ) {
|
||||
return;
|
||||
}
|
||||
mRouteOverLay = new RouteOverLay( mAMap, mPath, mContextRef.get() );
|
||||
if ( sOptions == null ) {
|
||||
sOptions = MapStyleUtils.getRouteOverlayOptions();
|
||||
}
|
||||
mRouteOverLay.setRouteOverlayOptions( sOptions );
|
||||
mRouteOverLay.setTrafficLine( true );
|
||||
mRouteOverLay.setRouteOverlayVisible( true );
|
||||
mRouteOverLay.setTrafficLightsVisible( true );
|
||||
mRouteOverLay.setArrowOnRoute( true );
|
||||
mRouteOverLay.setZindex( mZIndex );
|
||||
mRouteOverLay.setNaviArrowVisible( true );
|
||||
mRouteOverLay.setLightsVisible( true );
|
||||
mRouteOverLay.setTrafficLightsVisible( mIsTrafficLightsVisible );
|
||||
hookRouteArrow();
|
||||
|
||||
if ( mStartBitmapResId != 0 ) {
|
||||
try {
|
||||
mRouteOverLay.setStartPointBitmap( BitmapFactory.decodeResource( mContextRef.get().getResources(), mStartBitmapResId ) );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
mRouteOverLay.setStartPointBitmap( null );
|
||||
}
|
||||
|
||||
if ( mEndBitmapResId != 0 ) {
|
||||
try {
|
||||
mRouteOverLay.setEndPointBitmap( BitmapFactory.decodeResource( mContextRef.get().getResources(), mEndBitmapResId ) );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
mRouteOverLay.setEndPointBitmap( null );
|
||||
}
|
||||
|
||||
mRouteOverLay.addToMap();
|
||||
mIsRemoved = false;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
Log.d( TAG, "remove" );
|
||||
if ( mRouteOverLay != null ) {
|
||||
try {
|
||||
mRouteOverLay.removeFromMap();
|
||||
mIsRemoved = true;
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置透明度
|
||||
*
|
||||
* @param alpha
|
||||
*/
|
||||
public void setTransparency( float alpha ) {
|
||||
if ( mRouteOverLay != null ) {
|
||||
mRouteOverLay.setTransparency( alpha );
|
||||
}
|
||||
}
|
||||
|
||||
public RouteOverLayWrapper setTrafficLightsVisible( boolean visible ) {
|
||||
mIsTrafficLightsVisible = visible;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RouteOverLayWrapper setStartBitmap( int startBitmapResId ) {
|
||||
mStartBitmapResId = startBitmapResId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RouteOverLayWrapper setEndBitmap( int endBitmapResId ) {
|
||||
mEndBitmapResId = endBitmapResId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RouteOverLayWrapper setZIndex( int zIndex ) {
|
||||
mZIndex = zIndex;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getZIndex() {
|
||||
return mZIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
super.finalize();
|
||||
mIsRemoved = true;
|
||||
}
|
||||
|
||||
public synchronized boolean isRemoved() {
|
||||
return mIsRemoved;
|
||||
}
|
||||
|
||||
public void updatePolyline( AMapNaviLocation aMapNaviLocation ) {
|
||||
if ( mIsRemoved ) {
|
||||
return;
|
||||
}
|
||||
if ( mRouteOverLay != null ) {
|
||||
mRouteOverLay.updatePolyline( aMapNaviLocation );
|
||||
}
|
||||
}
|
||||
|
||||
public void drawArrow( NaviInfo naviInfo ) {
|
||||
Log.d( TAG, "drawArrow" );
|
||||
if ( mIsRemoved ) {
|
||||
return;
|
||||
}
|
||||
if ( naviInfo == null ) {
|
||||
return;
|
||||
}
|
||||
if ( mRouteOverLay != null ) {
|
||||
try {
|
||||
mRouteOverLay.drawArrow( mRouteOverLay.getArrowPoints( naviInfo.getCurStep() ) );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void hookRouteArrow() {
|
||||
if ( mRouteOverLay != null && sOptions != null ) {
|
||||
try {
|
||||
Field field = mRouteOverLay.getClass().getDeclaredField( "naviArrow" );
|
||||
field.setAccessible( true );
|
||||
field.set( mRouteOverLay, mAMap.addNavigateArrow( new NavigateArrowOptions().topColor( sOptions.getArrowColor() ).width( sOptions.getLineWidth() ).sideColor( sOptions.getArrowSideColor() ) ) );
|
||||
Logger.d( TAG, "hook 成功。" );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Polyline getTrafficColorfulPolyline() {
|
||||
if ( mRouteOverLay != null ) {
|
||||
return mRouteOverLay.mTrafficColorfulPolyline;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
Log.d( TAG, "destroy" );
|
||||
if ( mRouteOverLay != null ) {
|
||||
try {
|
||||
mRouteOverLay.destroy();
|
||||
mIsRemoved = true;
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,236 +0,0 @@
|
||||
package com.mogo.map.impl.amap.overlay;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.CameraUpdateFactory;
|
||||
import com.amap.api.maps.model.BitmapDescriptor;
|
||||
import com.amap.api.maps.model.BitmapDescriptorFactory;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.LatLngBounds;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.amap.api.maps.model.MarkerOptions;
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.maps.model.PolylineOptions;
|
||||
import com.mogo.map.impl.amap.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class RouteOverlay {
|
||||
protected List<Marker> stationMarkers = new ArrayList<Marker>();
|
||||
protected List<Polyline> allPolyLines = new ArrayList<Polyline>();
|
||||
protected Marker startMarker;
|
||||
protected Marker endMarker;
|
||||
protected LatLng startPoint;
|
||||
protected LatLng endPoint;
|
||||
protected AMap mAMap;
|
||||
private Context mContext;
|
||||
private Bitmap startBit, endBit, busBit, walkBit, driveBit;
|
||||
protected boolean nodeIconVisible = true;
|
||||
|
||||
public RouteOverlay(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉BusRouteOverlay上所有的Marker。
|
||||
*
|
||||
* @since V2.1.0
|
||||
*/
|
||||
public void removeFromMap() {
|
||||
if (startMarker != null) {
|
||||
startMarker.remove();
|
||||
|
||||
}
|
||||
if (endMarker != null) {
|
||||
endMarker.remove();
|
||||
}
|
||||
for (Marker marker : stationMarkers) {
|
||||
marker.remove();
|
||||
}
|
||||
for (Polyline line : allPolyLines) {
|
||||
line.remove();
|
||||
}
|
||||
destroyBit();
|
||||
}
|
||||
|
||||
private void destroyBit() {
|
||||
if (startBit != null) {
|
||||
startBit.recycle();
|
||||
startBit = null;
|
||||
}
|
||||
if (endBit != null) {
|
||||
endBit.recycle();
|
||||
endBit = null;
|
||||
}
|
||||
if (busBit != null) {
|
||||
busBit.recycle();
|
||||
busBit = null;
|
||||
}
|
||||
if (walkBit != null) {
|
||||
walkBit.recycle();
|
||||
walkBit = null;
|
||||
}
|
||||
if (driveBit != null) {
|
||||
driveBit.recycle();
|
||||
driveBit = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 给起点Marker设置图标,并返回更换图标的图片。如不用默认图片,需要重写此方法。
|
||||
*
|
||||
* @return 更换的Marker图片。
|
||||
* @since V2.1.0
|
||||
*/
|
||||
protected BitmapDescriptor getStartBitmapDescriptor() {
|
||||
return BitmapDescriptorFactory.fromResource( R.drawable.amap_start);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给终点Marker设置图标,并返回更换图标的图片。如不用默认图片,需要重写此方法。
|
||||
*
|
||||
* @return 更换的Marker图片。
|
||||
* @since V2.1.0
|
||||
*/
|
||||
protected BitmapDescriptor getEndBitmapDescriptor() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给公交Marker设置图标,并返回更换图标的图片。如不用默认图片,需要重写此方法。
|
||||
*
|
||||
* @return 更换的Marker图片。
|
||||
* @since V2.1.0
|
||||
*/
|
||||
protected BitmapDescriptor getBusBitmapDescriptor() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_bus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给步行Marker设置图标,并返回更换图标的图片。如不用默认图片,需要重写此方法。
|
||||
*
|
||||
* @return 更换的Marker图片。
|
||||
* @since V2.1.0
|
||||
*/
|
||||
protected BitmapDescriptor getWalkBitmapDescriptor() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_man);
|
||||
}
|
||||
|
||||
protected BitmapDescriptor getDriveBitmapDescriptor() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_car);
|
||||
}
|
||||
|
||||
protected void addStartAndEndMarker() {
|
||||
startMarker = mAMap.addMarker((new MarkerOptions())
|
||||
.position(startPoint).icon(getStartBitmapDescriptor())
|
||||
.title("\u8D77\u70B9"));
|
||||
// startMarker.showInfoWindow();
|
||||
|
||||
endMarker = mAMap.addMarker((new MarkerOptions()).position(endPoint)
|
||||
.icon(getEndBitmapDescriptor()).title("\u7EC8\u70B9"));
|
||||
// mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(startPoint,
|
||||
// getShowRouteZoom()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动镜头到当前的视角。
|
||||
*
|
||||
* @since V2.1.0
|
||||
*/
|
||||
public void zoomToSpan() {
|
||||
if (startPoint != null) {
|
||||
if (mAMap == null)
|
||||
return;
|
||||
try {
|
||||
LatLngBounds bounds = getLatLngBounds();
|
||||
mAMap.animateCamera(CameraUpdateFactory
|
||||
.newLatLngBounds(bounds, 50));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected LatLngBounds getLatLngBounds() {
|
||||
LatLngBounds.Builder b = LatLngBounds.builder();
|
||||
b.include(new LatLng(startPoint.latitude, startPoint.longitude));
|
||||
b.include(new LatLng(endPoint.latitude, endPoint.longitude));
|
||||
for (Polyline polyline : allPolyLines) {
|
||||
for (LatLng point : polyline.getPoints()) {
|
||||
b.include(point);
|
||||
}
|
||||
}
|
||||
return b.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 路段节点图标控制显示接口。
|
||||
*
|
||||
* @param visible true为显示节点图标,false为不显示。
|
||||
* @since V2.3.1
|
||||
*/
|
||||
public void setNodeIconVisibility(boolean visible) {
|
||||
try {
|
||||
nodeIconVisible = visible;
|
||||
if (this.stationMarkers != null && this.stationMarkers.size() > 0) {
|
||||
for (int i = 0; i < this.stationMarkers.size(); i++) {
|
||||
this.stationMarkers.get(i).setVisible(visible);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected void addStationMarker(MarkerOptions options) {
|
||||
if (options == null) {
|
||||
return;
|
||||
}
|
||||
Marker marker = mAMap.addMarker(options);
|
||||
if (marker != null) {
|
||||
stationMarkers.add(marker);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void addPolyLine(PolylineOptions options) {
|
||||
if (options == null) {
|
||||
return;
|
||||
}
|
||||
Polyline polyline = mAMap.addPolyline(options);
|
||||
if (polyline != null) {
|
||||
allPolyLines.add(polyline);
|
||||
}
|
||||
}
|
||||
|
||||
protected float getRouteWidth() {
|
||||
return 18f;
|
||||
}
|
||||
|
||||
protected int getWalkColor() {
|
||||
return Color.parseColor("#6db74d");
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义路线颜色。
|
||||
* return 自定义路线颜色。
|
||||
*
|
||||
* @since V2.2.1
|
||||
*/
|
||||
protected int getBusColor() {
|
||||
return Color.parseColor("#537edc");
|
||||
}
|
||||
|
||||
protected int getDriveColor() {
|
||||
return Color.parseColor("#537edc");
|
||||
}
|
||||
|
||||
// protected int getShowRouteZoom() {
|
||||
// return 15;
|
||||
// }
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
package com.mogo.map.impl.amap.overlay;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.amap.api.services.core.LatLonPoint;
|
||||
import com.amap.api.services.route.DriveRouteResult;
|
||||
import com.amap.api.services.route.RouteSearch;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.map.impl.amap.AMapWrapper;
|
||||
import com.mogo.map.impl.amap.InterceptorHandler;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-01-08
|
||||
* <p>
|
||||
* 给定起点、途经点,规划路径
|
||||
*/
|
||||
public class RouteOverlayHelper {
|
||||
|
||||
private static final String TAG = "RouteOverlayHelper";
|
||||
|
||||
private static volatile RouteOverlayHelper sInstance;
|
||||
|
||||
private DrivingRouteOverlay mDrivingRouteOverlay;
|
||||
|
||||
private RouteOverlayHelper() {
|
||||
}
|
||||
|
||||
public static RouteOverlayHelper getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( RouteOverlayHelper.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new RouteOverlayHelper();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
public void addRouteWay( final Context context, MogoLatLng start, MogoLatLng end, List< MogoLatLng > wayPoints ) {
|
||||
if ( wayPoints == null || wayPoints.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
if ( InterceptorHandler.getInstance().ignoreDrawRouteOverlay( context ) ) {
|
||||
Logger.w( TAG, "naviing." );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( mDrivingRouteOverlay != null ) {
|
||||
mDrivingRouteOverlay.removeFromMap();
|
||||
}
|
||||
|
||||
RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo( new LatLonPoint( start.lat, start.lng ),
|
||||
new LatLonPoint( end.lat, end.lng ) );
|
||||
final List< LatLonPoint > ways = new ArrayList<>();
|
||||
for ( MogoLatLng wayPoint : wayPoints ) {
|
||||
ways.add( new LatLonPoint( wayPoint.lat, wayPoint.lng ) );
|
||||
}
|
||||
RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery( fromAndTo, 0, ways, null, "" );
|
||||
RouteSearch routeSearch = new RouteSearch( context );
|
||||
routeSearch.calculateDriveRouteAsyn( query );
|
||||
routeSearch.setRouteSearchListener( new OnRouteSearchListenerAdapter() {
|
||||
@Override
|
||||
public void onDriveRouteSearched( DriveRouteResult driveRouteResult, int i ) {
|
||||
super.onDriveRouteSearched( driveRouteResult, i );
|
||||
if ( i != 1000 ) {
|
||||
Logger.e( TAG, "算路失败. code = %d", i );
|
||||
return;
|
||||
}
|
||||
mDrivingRouteOverlay = new DrivingRouteOverlay( context, AMapWrapper.getAMap(),
|
||||
driveRouteResult.getPaths().get( 0 ),
|
||||
driveRouteResult.getStartPos(),
|
||||
driveRouteResult.getTargetPos(),
|
||||
null );
|
||||
mDrivingRouteOverlay.setNodeIconVisibility( false );
|
||||
mDrivingRouteOverlay.setIsColorfulline( false );
|
||||
mDrivingRouteOverlay.addToMap();
|
||||
mDrivingRouteOverlay.zoomToSpan();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
public void removeAll() {
|
||||
if ( mDrivingRouteOverlay != null ) {
|
||||
mDrivingRouteOverlay.removeFromMap();
|
||||
}
|
||||
mDrivingRouteOverlay = null;
|
||||
}
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
package com.mogo.map.impl.amap.search;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.amap.api.services.core.AMapException;
|
||||
import com.amap.api.services.geocoder.GeocodeAddress;
|
||||
import com.amap.api.services.geocoder.GeocodeQuery;
|
||||
import com.amap.api.services.geocoder.GeocodeResult;
|
||||
import com.amap.api.services.geocoder.GeocodeSearch;
|
||||
import com.amap.api.services.geocoder.RegeocodeAddress;
|
||||
import com.amap.api.services.geocoder.RegeocodeQuery;
|
||||
import com.amap.api.services.geocoder.RegeocodeResult;
|
||||
import com.mogo.map.exception.MogoMapException;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.search.geo.IMogoGeoSearch;
|
||||
import com.mogo.map.search.geo.IMogoGeoSearchListener;
|
||||
import com.mogo.map.search.geo.MogoGeocodeAddress;
|
||||
import com.mogo.map.search.geo.MogoRegeocodeAddress;
|
||||
import com.mogo.map.search.geo.query.MogoGeocodeQuery;
|
||||
import com.mogo.map.search.geo.query.MogoRegeocodeQuery;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-19
|
||||
* <p>
|
||||
* 地理编码/逆地理编码高德实现
|
||||
*/
|
||||
public class GeocodeSearchClient implements IMogoGeoSearch, GeocodeSearch.OnGeocodeSearchListener {
|
||||
|
||||
private static final String TAG = "GeocodeSearchClient";
|
||||
|
||||
private GeocodeSearch mClient;
|
||||
private IMogoGeoSearchListener mListener;
|
||||
|
||||
public GeocodeSearchClient( Context context ) {
|
||||
mClient = new GeocodeSearch( context );
|
||||
mClient.setOnGeocodeSearchListener( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGeoSearchListener( IMogoGeoSearchListener listener ) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoRegeocodeAddress getFromLocation( MogoRegeocodeQuery query ) throws MogoMapException {
|
||||
try {
|
||||
RegeocodeAddress regeocodeAddress = mClient.getFromLocation( ObjectUtils.fromMogo( query ) );
|
||||
return ObjectUtils.fromAMap( regeocodeAddress );
|
||||
} catch ( AMapException e ) {
|
||||
throw new MogoMapException( e );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List< MogoGeocodeAddress > getFromLocationName( MogoGeocodeQuery query ) throws MogoMapException {
|
||||
try {
|
||||
List< GeocodeAddress > geocodeAddress = mClient.getFromLocationName( ObjectUtils.fromMogo( query ) );
|
||||
if ( geocodeAddress != null ) {
|
||||
List< MogoGeocodeAddress > mogoGeocodeAddresses = new ArrayList<>();
|
||||
for ( GeocodeAddress address : geocodeAddress ) {
|
||||
MogoGeocodeAddress mogoGeocodeAddress = ObjectUtils.fromAMap( address );
|
||||
if ( mogoGeocodeAddress != null ) {
|
||||
mogoGeocodeAddresses.add( mogoGeocodeAddress );
|
||||
}
|
||||
}
|
||||
return mogoGeocodeAddresses;
|
||||
}
|
||||
return new ArrayList<>();
|
||||
} catch ( AMapException e ) {
|
||||
throw new MogoMapException( e );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getFromLocationAsyn( MogoRegeocodeQuery query ) {
|
||||
if ( mClient != null ) {
|
||||
if ( query == null ) {
|
||||
Logger.e( TAG, "query parameter is null." );
|
||||
return;
|
||||
}
|
||||
RegeocodeQuery origin = ObjectUtils.fromMogo( query );
|
||||
if ( origin == null || !query.check() ) {
|
||||
Logger.e( TAG, "query parameter is null or no point parameter." );
|
||||
return;
|
||||
}
|
||||
mClient.getFromLocationAsyn( origin );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getFromLocationNameAsyn( MogoGeocodeQuery query ) {
|
||||
if ( mClient != null ) {
|
||||
if ( query == null ) {
|
||||
Logger.e( TAG, "query parameter is null." );
|
||||
return;
|
||||
}
|
||||
GeocodeQuery origin = ObjectUtils.fromMogo( query );
|
||||
if ( origin == null || !query.check() ) {
|
||||
Logger.e( TAG, "query parameter is null or locationName is empty." );
|
||||
return;
|
||||
}
|
||||
mClient.getFromLocationNameAsyn( origin );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegeocodeSearched( RegeocodeResult regeocodeResult, int i ) {
|
||||
if ( mListener != null ) {
|
||||
mListener.onRegeocodeSearched( ObjectUtils.fromAMap( regeocodeResult ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGeocodeSearched( GeocodeResult geocodeResult, int i ) {
|
||||
if ( mListener != null ) {
|
||||
mListener.onGeocodeSearched( ObjectUtils.fromAMap( geocodeResult ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
mClient = null;
|
||||
mListener = null;
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
package com.mogo.map.impl.amap.search;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.amap.api.services.core.AMapException;
|
||||
import com.amap.api.services.help.Inputtips;
|
||||
import com.amap.api.services.help.InputtipsQuery;
|
||||
import com.amap.api.services.help.Tip;
|
||||
import com.mogo.map.exception.MogoMapException;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.search.inputtips.IMogoInputtipsListener;
|
||||
import com.mogo.map.search.inputtips.IMogoInputtipsSearch;
|
||||
import com.mogo.map.search.inputtips.MogoTip;
|
||||
import com.mogo.map.search.inputtips.query.MogoInputtipsQuery;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-20
|
||||
* <p>
|
||||
* 高德地图 inputtips搜索实现
|
||||
*/
|
||||
public class InputtipsSearch implements IMogoInputtipsSearch, Inputtips.InputtipsListener {
|
||||
|
||||
private static final String TAG = "InputtipsSearch";
|
||||
|
||||
private Inputtips mClient;
|
||||
private InputtipsQuery mQuery;
|
||||
private IMogoInputtipsListener mListener;
|
||||
|
||||
public InputtipsSearch(Context context, MogoInputtipsQuery query) {
|
||||
mQuery = ObjectUtils.fromMogo(query);
|
||||
mClient = new Inputtips(context, mQuery);
|
||||
mClient.setInputtipsListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQuery(MogoInputtipsQuery query) {
|
||||
this.mQuery = ObjectUtils.fromMogo(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInputtipsListener(IMogoInputtipsListener listener) {
|
||||
this.mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestInputtipsAsyn() {
|
||||
if (mClient != null) {
|
||||
mClient.requestInputtipsAsyn();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetInputtips(List<Tip> list, int i) {
|
||||
if (i == 1000) {
|
||||
if (mListener != null) {
|
||||
mListener.onGetInputtips(getResult(list));
|
||||
}
|
||||
} else {
|
||||
Logger.e(TAG, "errorcode = " + i);
|
||||
}
|
||||
}
|
||||
|
||||
private List<MogoTip> getResult(List<Tip> tips) {
|
||||
List<MogoTip> mogoTips = new ArrayList<>();
|
||||
if (tips != null) {
|
||||
//只添加有坐标的结果
|
||||
for (Tip tip : tips) {
|
||||
MogoTip mogoTip = ObjectUtils.fromAMap(tip);
|
||||
if (mogoTip != null && mogoTip.getPoint() != null) {
|
||||
mogoTips.add(mogoTip);
|
||||
}
|
||||
}
|
||||
}
|
||||
return mogoTips;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
mClient = null;
|
||||
mListener = null;
|
||||
mQuery = null;
|
||||
}
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
package com.mogo.map.impl.amap.search;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.amap.api.services.core.AMapException;
|
||||
import com.amap.api.services.core.PoiItem;
|
||||
import com.amap.api.services.poisearch.PoiResult;
|
||||
import com.amap.api.services.poisearch.PoiSearch;
|
||||
import com.mogo.map.exception.MogoMapException;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.search.geo.MogoPoiItem;
|
||||
import com.mogo.map.search.poisearch.IMogoPoiSearch;
|
||||
import com.mogo.map.search.poisearch.IMogoPoiSearchListener;
|
||||
import com.mogo.map.search.poisearch.MogoPoiResult;
|
||||
import com.mogo.map.search.poisearch.MogoSearchBound;
|
||||
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-24
|
||||
* <p>
|
||||
* poi搜索高德实现
|
||||
* <p>
|
||||
* 错误码对照表:https://lbs.amap.com/api/android-sdk/guide/map-tools/error-code
|
||||
*/
|
||||
public class PoiSearchClient implements IMogoPoiSearch, PoiSearch.OnPoiSearchListener {
|
||||
|
||||
private static final String TAG = "PoiSearchClient";
|
||||
|
||||
private MogoPoiSearchQuery mQuery;
|
||||
private PoiSearch mClient;
|
||||
private IMogoPoiSearchListener mListener;
|
||||
private MogoSearchBound mBound;
|
||||
|
||||
public PoiSearchClient( Context context, MogoPoiSearchQuery query ) {
|
||||
mQuery = query;
|
||||
mClient = new PoiSearch( context, ObjectUtils.fromMogo( mQuery ) );
|
||||
mClient.setOnPoiSearchListener( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPoiSearchListener( IMogoPoiSearchListener listener ) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void searchPOIAsyn() {
|
||||
if ( mClient != null ) {
|
||||
mClient.searchPOIAsyn();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoPoiResult searchPOI() throws MogoMapException {
|
||||
if ( mClient != null ) {
|
||||
try {
|
||||
PoiResult search = mClient.searchPOI();
|
||||
return ObjectUtils.fromAMap( search );
|
||||
} catch ( AMapException e ) {
|
||||
throw new MogoMapException( e );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQuery( MogoPoiSearchQuery query ) {
|
||||
mQuery = query;
|
||||
if ( mClient != null ) {
|
||||
mClient.setQuery( ObjectUtils.fromMogo( mQuery ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoPoiItem searchPOIId( String poiId ) throws MogoMapException {
|
||||
if ( mClient != null ) {
|
||||
try {
|
||||
PoiItem poiItem = mClient.searchPOIId( poiId );
|
||||
return ObjectUtils.fromAMap( poiItem );
|
||||
} catch ( AMapException e ) {
|
||||
throw new MogoMapException( e );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void searchPOIIdAsyn( String poiId ) {
|
||||
if ( mClient != null ) {
|
||||
mClient.searchPOIIdAsyn( poiId );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBound( MogoSearchBound bound ) {
|
||||
mBound = bound;
|
||||
if ( mClient != null ) {
|
||||
mClient.setBound( ObjectUtils.fromMogo( mBound ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPoiSearched( PoiResult poiResult, int errorCode ) {
|
||||
if ( errorCode != 1000 ) {
|
||||
Logger.e( TAG, "errorcode is %d", errorCode );
|
||||
}
|
||||
if ( mListener != null ) {
|
||||
mListener.onPoiSearched( ObjectUtils.fromAMap( poiResult ), errorCode );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPoiItemSearched( PoiItem poiItem, int errorCode ) {
|
||||
if ( errorCode != 1000 ) {
|
||||
Logger.e( TAG, "errorcode is %d", errorCode );
|
||||
}
|
||||
if ( mListener != null ) {
|
||||
mListener.onPoiItemSearched( ObjectUtils.fromAMap( poiItem ), errorCode );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
mQuery = null;
|
||||
mClient = null;
|
||||
mListener = null;
|
||||
mBound = null;
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
package com.mogo.map.impl.amap.search;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.amap.api.services.core.LatLonPoint;
|
||||
import com.amap.api.services.route.BusRouteResult;
|
||||
import com.amap.api.services.route.DrivePath;
|
||||
import com.amap.api.services.route.DriveRouteResult;
|
||||
import com.amap.api.services.route.DriveStep;
|
||||
import com.amap.api.services.route.RideRouteResult;
|
||||
import com.amap.api.services.route.RouteSearch;
|
||||
import com.amap.api.services.route.WalkRouteResult;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.search.drive.IMogoRoadSearch;
|
||||
import com.mogo.map.search.drive.IMogoRoadSearchListener;
|
||||
import com.mogo.map.search.drive.MogoRoadSearchQuery;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/6/1
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class RoadSearchClient implements IMogoRoadSearch, RouteSearch.OnRouteSearchListener {
|
||||
|
||||
private static final String TAG = "DriveSearchClient";
|
||||
|
||||
private RouteSearch mRouteSearch;
|
||||
private IMogoRoadSearchListener mListener;
|
||||
|
||||
@Override
|
||||
public void searchRoadPath( Context context,
|
||||
MogoRoadSearchQuery query ) {
|
||||
|
||||
if ( query == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !checkPoint( query.mStart, "起点坐标" ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !checkPoint( query.mTarget, "终点坐标" ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo( ObjectUtils.fromMogo( query.mStart ), ObjectUtils.fromMogo( query.mTarget ) );
|
||||
final List< LatLonPoint > latLonPointWays = new ArrayList<>();
|
||||
if ( query.mWays != null ) {
|
||||
for ( MogoLatLng wayPoint : query.mWays ) {
|
||||
if ( checkPoint( wayPoint, "途经点" ) ) {
|
||||
latLonPointWays.add( ObjectUtils.fromMogo( wayPoint ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RouteSearch.DriveRouteQuery searchQuery = new RouteSearch.DriveRouteQuery( fromAndTo, RouteSearch.DRIVING_MULTI_CHOICE_AVOID_CONGESTION, latLonPointWays, null, "" );
|
||||
if ( mRouteSearch == null ) {
|
||||
mRouteSearch = new RouteSearch( context );
|
||||
mRouteSearch.setRouteSearchListener(this);
|
||||
}
|
||||
mRouteSearch.calculateDriveRouteAsyn( searchQuery );
|
||||
}
|
||||
|
||||
private boolean checkPoint( MogoLatLng latLng, String msg ) {
|
||||
if ( latLng == null ) {
|
||||
Logger.e( TAG, msg + " is null" );
|
||||
return false;
|
||||
}
|
||||
if ( latLng.lat <= 0d || latLng.lon <= 0d ) {
|
||||
Logger.e( TAG, msg + " is not a valid " );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRoadPathSearchListener( IMogoRoadSearchListener listener ) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBusRouteSearched( BusRouteResult busRouteResult, int i ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDriveRouteSearched( DriveRouteResult driveRouteResult, int i ) {
|
||||
if ( mListener == null ) {
|
||||
return;
|
||||
}
|
||||
List< MogoLatLng > points = new ArrayList<>();
|
||||
Logger.d(TAG,"onDriveRouteSearched i : " + i);
|
||||
if ( driveRouteResult == null
|
||||
|| driveRouteResult.getPaths() == null
|
||||
|| driveRouteResult.getPaths().isEmpty() ) {
|
||||
Logger.d(TAG,"onDriveRouteSearched result is null");
|
||||
mListener.onDrivePathSearched( null );
|
||||
return;
|
||||
}
|
||||
DrivePath drivePath = driveRouteResult.getPaths().get( 0 );
|
||||
int size = driveRouteResult.getPaths().size();
|
||||
Logger.d(TAG,"onDriveRouteSearched driveRouteResult size : " + size);
|
||||
|
||||
List< DriveStep > steps = drivePath.getSteps();
|
||||
if ( steps == null || steps.isEmpty() ) {
|
||||
mListener.onDrivePathSearched( null );
|
||||
return;
|
||||
}
|
||||
for ( DriveStep step : steps ) {
|
||||
List< LatLonPoint > polylineList = step.getPolyline();
|
||||
if ( polylineList == null || polylineList.isEmpty() ) {
|
||||
continue;
|
||||
}
|
||||
for ( LatLonPoint latLonPoint : polylineList ) {
|
||||
MogoLatLng latLng = ObjectUtils.fromAMap( latLonPoint );
|
||||
if ( latLng == null ) {
|
||||
continue;
|
||||
}
|
||||
points.add( latLng );
|
||||
}
|
||||
}
|
||||
mListener.onDrivePathSearched( points );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalkRouteSearched( WalkRouteResult walkRouteResult, int i ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRideRouteSearched( RideRouteResult rideRouteResult, int i ) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
package com.mogo.map.impl.amap.search;
|
||||
|
||||
import com.amap.api.services.core.LatLonPoint;
|
||||
import com.amap.api.services.traffic.CircleTrafficQuery;
|
||||
import com.amap.api.services.traffic.RoadTrafficQuery;
|
||||
import com.amap.api.services.traffic.TrafficSearch;
|
||||
import com.amap.api.services.traffic.TrafficStatusEvaluation;
|
||||
import com.amap.api.services.traffic.TrafficStatusInfo;
|
||||
import com.amap.api.services.traffic.TrafficStatusResult;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.map.search.traffic.IMogoTrafficSearch;
|
||||
import com.mogo.map.search.traffic.IMogoTrafficSearchListener;
|
||||
import com.mogo.map.search.traffic.MogoTrafficResult;
|
||||
import com.mogo.map.search.traffic.MogoTrafficStatusEvaluation;
|
||||
import com.mogo.map.search.traffic.MogoTrafficStatusInfo;
|
||||
import com.mogo.utils.Dispatch;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TrafficSearchClient implements IMogoTrafficSearch, TrafficSearch.OnTrafficSearchListener {
|
||||
|
||||
private static final String TAG = "TrafficSearchClient";
|
||||
private static final int DEFAULT_SEARCH_RADIUS = 500;
|
||||
|
||||
private IMogoTrafficSearchListener mListener;
|
||||
private TrafficSearch trafficSearch;
|
||||
|
||||
public TrafficSearchClient() {
|
||||
if (trafficSearch == null) {
|
||||
trafficSearch = new TrafficSearch(AbsMogoApplication.getApp().getApplicationContext());
|
||||
trafficSearch.setTrafficSearchListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void searchTrafficByRoad(String adCode, String roadName) {
|
||||
if (adCode == null || roadName == null) {
|
||||
if (mListener != null) {
|
||||
mListener.onTrafficSearchError("adCode or roadName can not be null");
|
||||
}
|
||||
return;
|
||||
}
|
||||
String formatRoadName = roadName.replace("/", "").replace(",", "");
|
||||
Logger.d(TAG, "searchTrafficByRoad formatRoad : " + formatRoadName);
|
||||
RoadTrafficQuery roadTrafficQuery = new RoadTrafficQuery(formatRoadName, adCode, TrafficSearch.ROAD_LEVEL_NONAME_WAY);
|
||||
try {
|
||||
trafficSearch.loadTrafficByRoadAsyn(roadTrafficQuery);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (mListener != null) {
|
||||
mListener.onTrafficSearchError(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void searchTrafficByCircleArea(MogoLatLng mogoLatLng, int radius) {
|
||||
if (mogoLatLng == null) {
|
||||
if (mListener != null) {
|
||||
mListener.onTrafficSearchError("adCode or roadName can not be null");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (radius <= 0) {
|
||||
radius = DEFAULT_SEARCH_RADIUS;
|
||||
}
|
||||
CircleTrafficQuery circleTrafficQuery = new CircleTrafficQuery(new LatLonPoint(mogoLatLng.getLat(), mogoLatLng.lon), radius, TrafficSearch.ROAD_LEVEL_NONAME_WAY);
|
||||
Logger.d(TAG, "loadTrafficByCircle circleTrafficQuery : " + circleTrafficQuery.toString());
|
||||
try {
|
||||
trafficSearch.loadTrafficByCircleAsyn(circleTrafficQuery);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (mListener != null) {
|
||||
mListener.onTrafficSearchError(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerTrafficSearchListener(IMogoTrafficSearchListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoadTrafficSearched(TrafficStatusResult trafficStatusResult, int i) {
|
||||
if (mListener == null) {
|
||||
return;
|
||||
}
|
||||
if (trafficStatusResult != null && i == 1000) {
|
||||
Logger.d(TAG, "onRoadTrafficSearched result : " + GsonUtil.jsonFromObject(trafficStatusResult));
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
List<MogoTrafficStatusInfo> trafficStatusInfoList = new ArrayList<>();
|
||||
List<TrafficStatusInfo> statusInfo = trafficStatusResult.getRoads();
|
||||
Dispatch.stream(statusInfo).forEach(info -> {
|
||||
MogoTrafficStatusInfo mogoTrafficStatusInfo = new MogoTrafficStatusInfo();
|
||||
mogoTrafficStatusInfo.setAngle(info.getAngle());
|
||||
mogoTrafficStatusInfo.setDirection(info.getDirection());
|
||||
mogoTrafficStatusInfo.setName(info.getName());
|
||||
mogoTrafficStatusInfo.setStatus(info.getStatus());
|
||||
List<MogoLatLng> mogoLatLngs = new ArrayList<>();
|
||||
Dispatch.stream(info.getCoordinates()).forEach(latLonPoint -> mogoLatLngs.add(new MogoLatLng(latLonPoint.getLatitude(), latLonPoint.getLongitude())));
|
||||
mogoTrafficStatusInfo.setMogoLatLngs(mogoLatLngs);
|
||||
trafficStatusInfoList.add(mogoTrafficStatusInfo);
|
||||
});
|
||||
MogoTrafficResult mogoTrafficResult = new MogoTrafficResult();
|
||||
mogoTrafficResult.setDescription(trafficStatusResult.getDescription());
|
||||
mogoTrafficResult.setTrafficStatusInfos(trafficStatusInfoList);
|
||||
long endTime = System.currentTimeMillis();
|
||||
Logger.d(TAG, "onRoadTrafficSearched MogoTrafficResult : " + GsonUtil.jsonFromObject(mogoTrafficResult));
|
||||
Logger.d(TAG, "onRoadTrafficSearched countTime : " + (endTime - startTime));
|
||||
mListener.onTrafficSearchInfo(mogoTrafficResult);
|
||||
} else {
|
||||
mListener.onTrafficSearchError("交通态势查询返回 errorCode : " + i + " trafficStatusResult : " + trafficStatusResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,324 +0,0 @@
|
||||
package com.mogo.map.impl.amap.uicontroller;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.location.Location;
|
||||
import android.view.View;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.uicontroller.CarCursorOption;
|
||||
import com.mogo.map.uicontroller.EnumMapUI;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.map.uicontroller.MapCameraPosition;
|
||||
import com.mogo.map.uicontroller.MapControlResult;
|
||||
import com.mogo.map.uicontroller.VisualAngleMode;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-26
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class AMapUIController implements IMogoMapUIController {
|
||||
|
||||
private static final String TAG = "AMapUIController";
|
||||
|
||||
private static volatile AMapUIController sInstance;
|
||||
|
||||
private IMogoMapUIController mClient;
|
||||
|
||||
private AMapUIController() {
|
||||
}
|
||||
|
||||
public static AMapUIController getInstance() {
|
||||
if (sInstance == null) {
|
||||
synchronized (AMapUIController.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new AMapUIController();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public void initClient(IMogoMapUIController client) {
|
||||
Logger.d("whatthefuck-AMapUIController", "init %s", this);
|
||||
this.mClient = client;
|
||||
}
|
||||
|
||||
public synchronized void destroy() {
|
||||
mClient = null;
|
||||
}
|
||||
|
||||
public static synchronized void release() {
|
||||
sInstance.destroy();
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTrafficEnabled(boolean visible) {
|
||||
if (mClient != null) {
|
||||
mClient.setTrafficEnabled(visible);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapControlResult changeZoom(boolean zoom) {
|
||||
if (mClient != null) {
|
||||
return mClient.changeZoom(zoom);
|
||||
}
|
||||
return MapControlResult.ERROR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapControlResult changeZoom(float zoom) {
|
||||
if (mClient != null) {
|
||||
return mClient.changeZoom(zoom);
|
||||
}
|
||||
return MapControlResult.ERROR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeMapMode(EnumMapUI mode) {
|
||||
Logger.d("whatthefuck-AMapUIController", "%s", this);
|
||||
if (mClient != null) {
|
||||
mClient.changeMapMode(mode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeMapVisualAngle(VisualAngleMode angelMode, MogoLatLng mogoLatLng) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisualAngleMode getCurrentMapVisualAngle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveToCenter(MogoLatLng latLng, boolean animate) {
|
||||
if (mClient != null) {
|
||||
mClient.moveToCenter(latLng, animate);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMyLocation(boolean visible) {
|
||||
if (mClient != null) {
|
||||
mClient.showMyLocation(visible);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emphasizeMyLocation() {
|
||||
if (mClient != null) {
|
||||
mClient.emphasizeMyLocation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMyLocation(View view) {
|
||||
if (mClient != null) {
|
||||
mClient.showMyLocation(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recoverLockMode() {
|
||||
if (mClient != null) {
|
||||
mClient.recoverLockMode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loseLockMode() {
|
||||
if (mClient != null) {
|
||||
mClient.loseLockMode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLockZoom(int var1) {
|
||||
if (mClient != null) {
|
||||
mClient.setLockZoom(var1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayOverview(Rect bounds) {
|
||||
if (mClient != null) {
|
||||
mClient.displayOverview(bounds);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScalePerPixel() {
|
||||
if (mClient != null) {
|
||||
return mClient.getScalePerPixel();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getZoomLevel() {
|
||||
if (mClient != null) {
|
||||
return mClient.getZoomLevel();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRoadWidth(double lon, double lat, float angle, boolean isGpsLocation, boolean isRTK) {
|
||||
if (mClient != null) {
|
||||
return mClient.getRoadWidth(lon, lat, angle, isGpsLocation, isRTK);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getCameraNorthEastPosition() {
|
||||
if (mClient != null) {
|
||||
return mClient.getCameraNorthEastPosition();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getCameraSouthWestPosition() {
|
||||
if (mClient != null) {
|
||||
return mClient.getCameraSouthWestPosition();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getWindowCenterLocation() {
|
||||
if (mClient != null) {
|
||||
return mClient.getWindowCenterLocation();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPointToCenter(double mapCenterX, double mapCenterY) {
|
||||
if (mClient != null) {
|
||||
mClient.setPointToCenter(mapCenterX, mapCenterY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getLocationPointInScreen(MogoLatLng latLng) {
|
||||
if (mClient != null) {
|
||||
return mClient.getLocationPointInScreen(latLng);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getLocationMogoLatLngInScreen(Point point) {
|
||||
if (mClient != null) {
|
||||
return mClient.getLocationMogoLatLngInScreen(point);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startJumpAnimation(IMogoMarker marker, float high, Interpolator interpolator,
|
||||
long duration) {
|
||||
if (mClient != null) {
|
||||
mClient.startJumpAnimation(marker, high, interpolator, duration);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRenderFps(int fps) {
|
||||
if (mClient != null) {
|
||||
mClient.setRenderFps(fps);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showBounds(String tag, MogoLatLng carPosition, List<MogoLatLng> lonLats, Rect bound, boolean lockCarPosition) {
|
||||
if (mClient != null) {
|
||||
mClient.showBounds(tag, carPosition, lonLats, bound, lockCarPosition);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceRender() {
|
||||
if (mClient != null) {
|
||||
mClient.forceRender();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float calculateLineDistance(MogoLatLng p1, MogoLatLng p2) throws Exception {
|
||||
if (mClient != null) {
|
||||
return mClient.calculateLineDistance(p1, p2);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumMapUI getCurrentUiMode() {
|
||||
if (mClient != null) {
|
||||
return mClient.getCurrentUiMode();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeMyLocation(Location location) {
|
||||
if (mClient != null) {
|
||||
mClient.changeMyLocation(location);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarLocked() {
|
||||
if (mClient != null) {
|
||||
return mClient.isCarLocked();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCarCursorOption(CarCursorOption option) {
|
||||
if (mClient != null) {
|
||||
mClient.setCarCursorOption(option);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapCameraPosition getMapCameraPosition() {
|
||||
if (mClient != null) {
|
||||
return mClient.getMapCameraPosition();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeBearing(float bearing) {
|
||||
if (mClient != null) {
|
||||
mClient.changeBearing(bearing);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAdasRecognizedResult(int drawLevel) {
|
||||
if ( mClient != null ) {
|
||||
mClient.setAdasRecognizedResult(drawLevel);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTileId(double lon, double lat) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.mogo.map.impl.amap.utils;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.amap.api.maps.CoordinateConverter;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CoordinateConvertUtils {
|
||||
|
||||
public static MogoLatLng CoordinateConverterFrom84(Context mContext, MogoLatLng mogoLatLng){
|
||||
CoordinateConverter mCoordinateConverter = new CoordinateConverter(mContext);
|
||||
mCoordinateConverter.from(CoordinateConverter.CoordType.GPS);
|
||||
mCoordinateConverter.coord(new LatLng(mogoLatLng.lat,mogoLatLng.lon));
|
||||
LatLng latLng = mCoordinateConverter.convert();
|
||||
return new MogoLatLng(latLng.latitude,latLng.longitude);
|
||||
}
|
||||
|
||||
public static List<MogoLatLng> CoordinateConverterFrom84ForList(Context mContext, List<MogoLatLng> mogoLatLngList){
|
||||
|
||||
List<MogoLatLng> list = new ArrayList<>();
|
||||
for (MogoLatLng m:mogoLatLngList) {
|
||||
MogoLatLng mogoLatLng = CoordinateConverterFrom84(mContext,m);
|
||||
list.add(mogoLatLng);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
package com.mogo.map.impl.amap.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.amap.api.navi.enums.IconType;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-09-29
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class IconTypeUtils {
|
||||
|
||||
private static SparseArray< String > sIconName = new SparseArray<>();
|
||||
|
||||
static {
|
||||
sIconName.put( IconType.ARRIVED_DESTINATION, "到达目的地" );
|
||||
sIconName.put( IconType.ARRIVED_SERVICE_AREA, "到达服务区" );
|
||||
sIconName.put( IconType.ARRIVED_TOLLGATE, "到达收费站" );
|
||||
sIconName.put( IconType.ARRIVED_TUNNEL, "到达隧道" );
|
||||
sIconName.put( IconType.ARRIVED_WAYPOINT, "到达途经点" );
|
||||
sIconName.put( IconType.BRIDGE, "通过桥" );
|
||||
sIconName.put( IconType.BY_ELEVATOR, "电梯换层" );
|
||||
sIconName.put( IconType.BY_ESCALATOR, "扶梯换层" );
|
||||
sIconName.put( IconType.BY_STAIR, "楼梯换层" );
|
||||
sIconName.put( IconType.CABLEWAY, "通过索道" );
|
||||
sIconName.put( IconType.CHANNEL, "通过通道" );
|
||||
sIconName.put( IconType.CROSSWALK, "通过人行横道" );
|
||||
sIconName.put( IconType.CRUISE_ROUTE, "通过游船路线" );
|
||||
sIconName.put( IconType.DEFAULT, "自车" );
|
||||
sIconName.put( IconType.ENTER_BUILDING, "进入建筑物" );
|
||||
sIconName.put( IconType.ENTER_ROUNDABOUT, "进入环岛" );
|
||||
sIconName.put( IconType.ENTRY_LEFT_RING, "进入环岛" );
|
||||
sIconName.put( IconType.ENTRY_LEFT_RING_CONTINUE, "绕环岛直行" );
|
||||
sIconName.put( IconType.ENTRY_LEFT_RING_LEFT, "绕环岛左转" );
|
||||
sIconName.put( IconType.ENTRY_LEFT_RING_RIGHT, "绕环岛右转" );
|
||||
sIconName.put( IconType.ENTRY_LEFTRINGU_TURN, "绕环岛调头" );
|
||||
sIconName.put( IconType.ENTRY_RING_CONTINUE, "绕环岛直行" );
|
||||
sIconName.put( IconType.ENTRY_RING_LEFT, "绕环岛左转" );
|
||||
sIconName.put( IconType.ENTRY_RING_RIGHT, "绕环岛右转" );
|
||||
sIconName.put( IconType.ENTRY_RING_UTURN, "绕环岛调头" );
|
||||
sIconName.put( IconType.FERRY, "通过轮渡" );
|
||||
sIconName.put( IconType.LADDER, "通过阶梯" );
|
||||
sIconName.put( IconType.LEAVE_BUILDING, "离开建筑物" );
|
||||
sIconName.put( IconType.LEAVE_LEFT_RING, "驶出环岛" );
|
||||
sIconName.put( IconType.LEFT, "左转" );
|
||||
sIconName.put( IconType.LEFT_BACK, "左后" );
|
||||
sIconName.put( IconType.LEFT_FRONT, "左前方" );
|
||||
sIconName.put( IconType.LEFT_TURN_AROUND, "左转掉头" );
|
||||
sIconName.put( IconType.LIFT, "通过直梯" );
|
||||
sIconName.put( IconType.LOW_CROSS, "通过普通路口" );
|
||||
sIconName.put( IconType.LOW_TRAFFIC_CROSS, "红绿灯路口" );
|
||||
sIconName.put( IconType.NONE, "无定义" );
|
||||
sIconName.put( IconType.OUT_ROUNDABOUT, "驶出环岛" );
|
||||
sIconName.put( IconType.OVERPASS, "通过过街天桥" );
|
||||
sIconName.put( IconType.PARK, "通过公园" );
|
||||
sIconName.put( IconType.RIGHT, "右转" );
|
||||
sIconName.put( IconType.RIGHT_BACK, "右后方" );
|
||||
sIconName.put( IconType.RIGHT_FRONT, "右前方" );
|
||||
sIconName.put( IconType.SIGHTSEEING_BUSLINE, "通过观光车路线" );
|
||||
sIconName.put( IconType.SKY_CHANNEL, "通过空中通道" );
|
||||
sIconName.put( IconType.SLIDEWAY, "通过滑道" );
|
||||
sIconName.put( IconType.SLOPE, "通过斜坡" );
|
||||
sIconName.put( IconType.SPECIAL_CONTINUE, "顺行" );
|
||||
sIconName.put( IconType.SQUARE, "通过广场" );
|
||||
sIconName.put( IconType.STAIRCASE, "通过扶梯" );
|
||||
sIconName.put( IconType.STRAIGHT, "直行" );
|
||||
sIconName.put( IconType.SUBWAY, "通过地铁通道" );
|
||||
sIconName.put( IconType.U_TURN_RIGHT, "右转掉头" );
|
||||
sIconName.put( IconType.UNDERPASS, "通过地下通道" );
|
||||
sIconName.put( IconType.WALK_ROAD, "通过行人道路" );
|
||||
}
|
||||
|
||||
private static int lastIconType = 0;
|
||||
private static int lastIconResId = 0;
|
||||
|
||||
public static String getNameByIconType( int iconType ) {
|
||||
return sIconName.get( iconType );
|
||||
}
|
||||
|
||||
public static int getResIdByIconType( Context context, int iconType ) {
|
||||
try {
|
||||
if ( iconType == lastIconType ) {
|
||||
return lastIconResId;
|
||||
}
|
||||
int target = context.getResources().getIdentifier( "ic_" + iconType, "drawable", context.getPackageName() );
|
||||
lastIconType = iconType;
|
||||
lastIconResId = target;
|
||||
return target;
|
||||
} catch ( Exception e ) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package com.mogo.map.impl.amap.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.amap.api.navi.model.RouteOverlayOptions;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.map.impl.amap.R;
|
||||
import com.mogo.eagle.core.utilcode.mogo.toast.ResourcesHelper;
|
||||
import com.mogo.utils.WindowUtils;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-10-04
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class MapStyleUtils {
|
||||
|
||||
enum ColorEnum {
|
||||
route_overlay_line_normal( Color.parseColor( "#00C96D" ) ),
|
||||
route_overlay_line_unknown( Color.parseColor( "#3CD26E" ) ),
|
||||
route_overlay_line_slow( Color.parseColor( "#ECC71F" ) ),
|
||||
route_overlay_line_very_traffic( Color.parseColor( "#E16262" ) ),
|
||||
route_overlay_line_traffic( Color.parseColor( "#E88181" ) ),
|
||||
transparent( Color.parseColor( "#00000000" ) ),
|
||||
light_gray( Color.parseColor( "#334BD089" ) );
|
||||
|
||||
private int color;
|
||||
|
||||
ColorEnum( int color ) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
public static RouteOverlayOptions getRouteOverlayOptions() {
|
||||
RouteOverlayOptions options = new RouteOverlayOptions();
|
||||
// 设置导航线路的宽度
|
||||
options.setLineWidth( AbsMogoApplication.getApp().getResources().getDimension(R.dimen.path_width) );
|
||||
// // 设置交通状况情况良好下的纹理位图
|
||||
// options.setSmoothTraffic( colorToBitmap( ColorEnum.route_overlay_line_normal.getColor() ) );
|
||||
// // 设置路线的图标
|
||||
// options.setNormalRoute( colorToBitmap( ColorEnum.route_overlay_line_normal.getColor() ) );
|
||||
// // 设置交通状况未知下的纹理位图
|
||||
// options.setUnknownTraffic( colorToBitmap( ColorEnum.route_overlay_line_unknown.getColor() ) );
|
||||
// // 设置交通状况迟缓下的纹理位图
|
||||
// options.setSlowTraffic( colorToBitmap( ColorEnum.route_overlay_line_slow.getColor() ) );
|
||||
// // 设置交通状况非常拥堵下的纹理位图
|
||||
// options.setVeryJamTraffic( colorToBitmap( ColorEnum.route_overlay_line_very_traffic.getColor() ) );
|
||||
// // 设置交通状况拥堵下的纹理位图
|
||||
// options.setJamTraffic( colorToBitmap( ColorEnum.route_overlay_line_traffic.getColor() ) );
|
||||
// // 设置浮于道路上的『小箭头』图标的纹理位图
|
||||
// options.setArrowOnTrafficRoute( colorToBitmap( ColorEnum.transparent.getColor() ) );
|
||||
// 自定义走过路线纹理,默认走过路线置灰功能为关,需要在AMapNaviViewOptions.setAfterRouteAutoGray(boolean)打开,该方法才生效
|
||||
options.setPassRoute( colorToBitmap( ColorEnum.light_gray.getColor() ) );
|
||||
// // 设置路线虚线纹理
|
||||
// options.setFairWayRes( colorToBitmap( ColorEnum.route_overlay_line_normal.getColor() ) );
|
||||
options.setArrowColor( Color.parseColor( "#92C9FF" ) ); // 高德地图内部配置颜色
|
||||
options.setArrowSideColor( Color.parseColor( "#4F9BF2" ) ); // 高德地图内部配置颜色
|
||||
return options;
|
||||
}
|
||||
|
||||
public static Bitmap colorToBitmap( int color ) {
|
||||
Bitmap.Config config = Bitmap.Config.ARGB_8888;
|
||||
Bitmap bitmap = Bitmap.createBitmap( 1, 1, config );
|
||||
bitmap.eraseColor( color );
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
package com.mogo.map.impl.amap.utils;
|
||||
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.LatLngBounds;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.map.exception.MogoMapException;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-03-04
|
||||
* <p>
|
||||
* 地图工具类
|
||||
*/
|
||||
public class MogoMapUtils {
|
||||
|
||||
private static final String TAG = "MogoMapUtils";
|
||||
|
||||
public static LatLngBounds getLatLngBounds( MogoLatLng carPosition, List< MogoLatLng > lonLats, boolean lockCarPosition ) throws Exception {
|
||||
|
||||
if ( lonLats == null || lonLats.isEmpty() ) {
|
||||
throw new MogoMapException( "经纬度不能为null或空集合" );
|
||||
}
|
||||
LatLngBounds.Builder builder = new LatLngBounds.Builder();
|
||||
for ( MogoLatLng lonLat : lonLats ) {
|
||||
builder.include( ObjectUtils.fromMogo2( lonLat ) );
|
||||
}
|
||||
if ( carPosition != null && !lockCarPosition ) {
|
||||
builder.include( ObjectUtils.fromMogo2( carPosition ) );
|
||||
}
|
||||
LatLngBounds latLngBounds = builder.build();
|
||||
if ( !lockCarPosition ) {
|
||||
return latLngBounds;
|
||||
}
|
||||
|
||||
if ( carPosition == null ) {
|
||||
throw new MogoMapException( "自车位置经纬度信息不能为空" );
|
||||
}
|
||||
|
||||
if ( latLngBounds.northeast == null && latLngBounds.southwest == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
double south = 0.0;
|
||||
double west = 0.0;
|
||||
|
||||
double east = 0.0;
|
||||
double north = 0.0;
|
||||
|
||||
double dLat = 0.0;
|
||||
double dLon = 0.0;
|
||||
|
||||
if ( latLngBounds.northeast == null ) {
|
||||
dLat = Math.abs( carPosition.lat - latLngBounds.southwest.latitude );
|
||||
dLon = Math.abs( carPosition.lng - latLngBounds.southwest.longitude );
|
||||
} else if ( latLngBounds.southwest == null ) {
|
||||
dLat = Math.abs( carPosition.lat - latLngBounds.northeast.latitude );
|
||||
dLon = Math.abs( carPosition.lng - latLngBounds.northeast.longitude );
|
||||
} else {
|
||||
final double dLat1 = Math.abs( carPosition.lat - latLngBounds.southwest.latitude );
|
||||
final double dLon1 = Math.abs( carPosition.lng - latLngBounds.southwest.longitude );
|
||||
final double dLat2 = Math.abs( carPosition.lat - latLngBounds.northeast.latitude );
|
||||
final double dLon2 = Math.abs( carPosition.lng - latLngBounds.northeast.longitude );
|
||||
dLat = dLat1 > dLat2 ? dLat1 : dLat2;
|
||||
dLon = dLon1 > dLon2 ? dLon1 : dLon2;
|
||||
}
|
||||
|
||||
west = carPosition.lat - dLat;
|
||||
south = carPosition.lng + dLon;
|
||||
|
||||
east = carPosition.lat + dLat;
|
||||
north = carPosition.lng - dLon;
|
||||
|
||||
if ( south == 0.0 || west == 0.0 || east == 0.0 || north == 0.0 ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( east < west ) {
|
||||
double tmp = east;
|
||||
east = west;
|
||||
west = tmp;
|
||||
}
|
||||
|
||||
if( north < south ){
|
||||
double tmp = north;
|
||||
north = south;
|
||||
south = tmp;
|
||||
}
|
||||
|
||||
Logger.d( TAG, "west = %s, east = %s, north = %s, south = %s", west, east, north, south );
|
||||
|
||||
return new LatLngBounds.Builder().include( new LatLng( east, north ) ).include( new LatLng( west, south ) ).build();
|
||||
}
|
||||
}
|
||||
@@ -1,756 +0,0 @@
|
||||
package com.mogo.map.impl.amap.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.view.View;
|
||||
|
||||
import com.amap.api.location.AMapLocation;
|
||||
import com.amap.api.maps.model.BitmapDescriptor;
|
||||
import com.amap.api.maps.model.BitmapDescriptorFactory;
|
||||
import com.amap.api.maps.model.CameraPosition;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.MarkerOptions;
|
||||
import com.amap.api.maps.model.Poi;
|
||||
import com.amap.api.maps.model.PolylineOptions;
|
||||
import com.amap.api.navi.model.AMapCongestionLink;
|
||||
import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
|
||||
import com.amap.api.navi.model.AimLessModeCongestionInfo;
|
||||
import com.amap.api.navi.model.NaviInfo;
|
||||
import com.amap.api.navi.model.NaviLatLng;
|
||||
import com.amap.api.services.core.LatLonPoint;
|
||||
import com.amap.api.services.core.PoiItem;
|
||||
import com.amap.api.services.geocoder.AoiItem;
|
||||
import com.amap.api.services.geocoder.BusinessArea;
|
||||
import com.amap.api.services.geocoder.GeocodeAddress;
|
||||
import com.amap.api.services.geocoder.GeocodeQuery;
|
||||
import com.amap.api.services.geocoder.GeocodeResult;
|
||||
import com.amap.api.services.geocoder.RegeocodeAddress;
|
||||
import com.amap.api.services.geocoder.RegeocodeQuery;
|
||||
import com.amap.api.services.geocoder.RegeocodeResult;
|
||||
import com.amap.api.services.geocoder.RegeocodeRoad;
|
||||
import com.amap.api.services.geocoder.StreetNumber;
|
||||
import com.amap.api.services.help.InputtipsQuery;
|
||||
import com.amap.api.services.help.Tip;
|
||||
import com.amap.api.services.poisearch.IndoorData;
|
||||
import com.amap.api.services.poisearch.Photo;
|
||||
import com.amap.api.services.poisearch.PoiItemExtension;
|
||||
import com.amap.api.services.poisearch.PoiResult;
|
||||
import com.amap.api.services.poisearch.PoiSearch;
|
||||
import com.amap.api.services.poisearch.SubPoiItem;
|
||||
import com.amap.api.services.road.Crossroad;
|
||||
import com.mogo.eagle.core.data.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.MogoCongestionInfo;
|
||||
import com.mogo.map.navi.MogoCongestionLink;
|
||||
import com.mogo.map.navi.MogoNaviInfo;
|
||||
import com.mogo.map.navi.MogoNaviListenerHandler;
|
||||
import com.mogo.map.navi.MogoTraffic;
|
||||
import com.mogo.map.overlay.MogoPolylineOptions;
|
||||
import com.mogo.map.search.geo.MogoAoiItem;
|
||||
import com.mogo.map.search.geo.MogoBusinessArea;
|
||||
import com.mogo.map.search.geo.MogoCrossroad;
|
||||
import com.mogo.map.search.geo.MogoGeocodeAddress;
|
||||
import com.mogo.map.search.geo.MogoGeocodeResult;
|
||||
import com.mogo.map.search.geo.MogoIndoorData;
|
||||
import com.mogo.map.search.geo.MogoPhoto;
|
||||
import com.mogo.map.search.geo.MogoPoiItem;
|
||||
import com.mogo.map.search.geo.MogoPoiItemExtension;
|
||||
import com.mogo.map.search.geo.MogoRegeocodeAddress;
|
||||
import com.mogo.map.search.geo.MogoRegeocodeResult;
|
||||
import com.mogo.map.search.geo.MogoRegeocodeRoad;
|
||||
import com.mogo.map.search.geo.MogoStreetNumber;
|
||||
import com.mogo.map.search.geo.MogoSubPoiItem;
|
||||
import com.mogo.map.search.geo.query.MogoGeocodeQuery;
|
||||
import com.mogo.map.search.geo.query.MogoRegeocodeQuery;
|
||||
import com.mogo.map.search.inputtips.MogoTip;
|
||||
import com.mogo.map.search.inputtips.query.MogoInputtipsQuery;
|
||||
import com.mogo.map.search.poisearch.MogoPoiResult;
|
||||
import com.mogo.map.search.poisearch.MogoSearchBound;
|
||||
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
|
||||
import com.mogo.map.uicontroller.MapCameraPosition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-18
|
||||
* <p>
|
||||
* 业务对象和实际对象转换
|
||||
*/
|
||||
public class ObjectUtils {
|
||||
|
||||
public static MarkerOptions fromMogo( MogoMarkerOptions opt ) {
|
||||
|
||||
if ( opt == null ) {
|
||||
return null;
|
||||
}
|
||||
ArrayList< BitmapDescriptor > descriptors = new ArrayList<>();
|
||||
final ArrayList< Bitmap > icons = opt.getIcons();
|
||||
if ( icons != null && !icons.isEmpty() ) {
|
||||
for ( Bitmap icon : icons ) {
|
||||
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( descriptor )
|
||||
.anchor( opt.getU(), opt.getV() )
|
||||
.icons( descriptors )
|
||||
.period( opt.getPeriod() )
|
||||
.rotateAngle( opt.getRotate() )
|
||||
.setFlat( opt.isFlat() )
|
||||
.visible( opt.isVisible() )
|
||||
.infoWindowEnable( opt.isInifoWindowEnable() )
|
||||
.alpha( opt.getAlpha() )
|
||||
.setGps( opt.isGps() )
|
||||
.anchor( opt.getU(), opt.getV() )
|
||||
.draggable( opt.isDraggable() )
|
||||
.setInfoWindowOffset( opt.getOffsetX(), opt.getOffsetY() )
|
||||
.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 ) {
|
||||
return null;
|
||||
}
|
||||
MogoLocation location = new MogoLocation();
|
||||
location.setLocType( aLocation.getLocationType() );
|
||||
location.setSpeed( aLocation.getSpeed() );
|
||||
location.setLatitude( aLocation.getLatitude() );
|
||||
location.setLongitude( aLocation.getLongitude() );
|
||||
location.setAltitude( aLocation.getAltitude() );
|
||||
location.setTime( aLocation.getTime() );
|
||||
location.setBearing( aLocation.getBearing() );
|
||||
location.setAccuracy( aLocation.getAccuracy() );
|
||||
location.setCityCode( aLocation.getCityCode() );
|
||||
location.setCityName( aLocation.getCity() );
|
||||
location.setProvider( aLocation.getProvider() );
|
||||
location.setAddress( aLocation.getAddress() );
|
||||
location.setDistrict( aLocation.getDistrict() );
|
||||
location.setProvince( aLocation.getProvince() );
|
||||
location.setAdCode( aLocation.getAdCode() );
|
||||
location.setLocationDetail( aLocation.getLocationDetail() );
|
||||
location.setPoiName( aLocation.getPoiName() );
|
||||
location.setAoiName( aLocation.getAoiName() );
|
||||
location.setErrCode( aLocation.getErrorCode() );
|
||||
location.setErrInfo( aLocation.getErrorInfo() );
|
||||
location.setStreet( aLocation.getStreet() );
|
||||
location.setStreetNum( aLocation.getStreetNum() );
|
||||
location.setDescription( aLocation.getDescription() );
|
||||
location.setBuildingId( aLocation.getBuildingId() );
|
||||
location.setFloor( aLocation.getFloor() );
|
||||
location.setGpsAccuracyStatus( aLocation.getGpsAccuracyStatus() );
|
||||
location.setSatellite( aLocation.getSatellites() );
|
||||
return location;
|
||||
}
|
||||
|
||||
public static LatLonPoint fromMogo( MogoLatLng latLng ) {
|
||||
if ( latLng == null ) {
|
||||
return null;
|
||||
}
|
||||
return new LatLonPoint( latLng.lat, latLng.lng );
|
||||
}
|
||||
|
||||
public static NaviLatLng fromMogoAsNavi( MogoLatLng latLng ) {
|
||||
if ( latLng == null ) {
|
||||
return null;
|
||||
}
|
||||
return new NaviLatLng( latLng.lat, latLng.lng );
|
||||
}
|
||||
|
||||
public static LatLng fromMogo2( MogoLatLng latLng ) {
|
||||
if ( latLng == null ) {
|
||||
return null;
|
||||
}
|
||||
return new LatLng( latLng.lat, latLng.lon );
|
||||
}
|
||||
|
||||
public static MogoLatLng fromAMap( LatLonPoint point ) {
|
||||
if ( point == null ) {
|
||||
return null;
|
||||
}
|
||||
return new MogoLatLng( point.getLatitude(), point.getLongitude() );
|
||||
}
|
||||
|
||||
public static MogoLatLng CameraPositionfromAMap( LatLng point ) {
|
||||
if ( point == null ) {
|
||||
return null;
|
||||
}
|
||||
return new MogoLatLng( point.latitude, point.longitude );
|
||||
}
|
||||
|
||||
public static GeocodeQuery fromMogo( MogoGeocodeQuery query ) {
|
||||
if ( query == null ) {
|
||||
return null;
|
||||
}
|
||||
GeocodeQuery q = new GeocodeQuery( query.getLocationName(), query.getCity() );
|
||||
return q;
|
||||
}
|
||||
|
||||
public static RegeocodeQuery fromMogo( MogoRegeocodeQuery query ) {
|
||||
if ( query == null ) {
|
||||
return null;
|
||||
}
|
||||
RegeocodeQuery q = new RegeocodeQuery( fromMogo( query.getPoint() ), query.getRadius(), query.getLatlngType() );
|
||||
return q;
|
||||
}
|
||||
|
||||
public static MogoAoiItem fromAMap( AoiItem amapItem ) {
|
||||
if ( amapItem == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoAoiItem mogoAoiItem = new MogoAoiItem();
|
||||
mogoAoiItem.setAdCode( amapItem.getAdCode() );
|
||||
mogoAoiItem.setAoiArea( amapItem.getAoiArea() );
|
||||
mogoAoiItem.setAoiCenterPoint( fromAMap( amapItem.getAoiCenterPoint() ) );
|
||||
mogoAoiItem.setAoiId( amapItem.getAoiId() );
|
||||
mogoAoiItem.setAoiName( amapItem.getAoiName() );
|
||||
return mogoAoiItem;
|
||||
}
|
||||
|
||||
public static MogoBusinessArea fromAMap( BusinessArea amapItem ) {
|
||||
if ( amapItem == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoBusinessArea mogoBusinessArea = new MogoBusinessArea();
|
||||
mogoBusinessArea.setCenterPoint( fromAMap( amapItem.getCenterPoint() ) );
|
||||
mogoBusinessArea.setName( amapItem.getName() );
|
||||
return mogoBusinessArea;
|
||||
}
|
||||
|
||||
|
||||
public static MogoCrossroad fromAMap( Crossroad amapItem ) {
|
||||
if ( amapItem == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoCrossroad mogoCrossroad = new MogoCrossroad();
|
||||
mogoCrossroad.setDirection( amapItem.getDirection() );
|
||||
mogoCrossroad.setDistance( amapItem.getDistance() );
|
||||
mogoCrossroad.setFirstRoadId( amapItem.getFirstRoadId() );
|
||||
mogoCrossroad.setFirstRoadName( amapItem.getFirstRoadName() );
|
||||
mogoCrossroad.setSecondRoadId( amapItem.getSecondRoadId() );
|
||||
mogoCrossroad.setSecondRoadName( amapItem.getSecondRoadName() );
|
||||
return mogoCrossroad;
|
||||
}
|
||||
|
||||
public static MogoGeocodeAddress fromAMap( GeocodeAddress address ) {
|
||||
if ( address == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoGeocodeAddress mogoGeocodeAddress = new MogoGeocodeAddress();
|
||||
mogoGeocodeAddress.setAdcode( address.getAdcode() );
|
||||
mogoGeocodeAddress.setBuilding( address.getBuilding() );
|
||||
mogoGeocodeAddress.setCity( address.getCity() );
|
||||
mogoGeocodeAddress.setDistrict( address.getDistrict() );
|
||||
mogoGeocodeAddress.setFormatAddress( address.getFormatAddress() );
|
||||
mogoGeocodeAddress.setLatlng( fromAMap( address.getLatLonPoint() ) );
|
||||
mogoGeocodeAddress.setLevel( address.getLevel() );
|
||||
mogoGeocodeAddress.setNeighborhood( address.getNeighborhood() );
|
||||
mogoGeocodeAddress.setProvince( address.getProvince() );
|
||||
mogoGeocodeAddress.setTownship( address.getTownship() );
|
||||
return mogoGeocodeAddress;
|
||||
}
|
||||
|
||||
public static MogoGeocodeResult fromAMap( GeocodeResult result ) {
|
||||
if ( result == null || result.getGeocodeAddressList() == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoGeocodeResult mogoGeocodeResult = new MogoGeocodeResult();
|
||||
final List< MogoGeocodeAddress > addresses = new ArrayList<>();
|
||||
for ( GeocodeAddress geocodeAddress : result.getGeocodeAddressList() ) {
|
||||
final MogoGeocodeAddress mogoGeocodeAddress = fromAMap( geocodeAddress );
|
||||
if ( mogoGeocodeAddress != null ) {
|
||||
addresses.add( mogoGeocodeAddress );
|
||||
}
|
||||
}
|
||||
|
||||
mogoGeocodeResult.setAddresses( addresses );
|
||||
return mogoGeocodeResult;
|
||||
}
|
||||
|
||||
public static MogoIndoorData fromAMap( IndoorData data ) {
|
||||
if ( data == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoIndoorData mogoIndoorData = new MogoIndoorData();
|
||||
mogoIndoorData.setFloor( data.getFloor() );
|
||||
mogoIndoorData.setFloorName( data.getFloorName() );
|
||||
mogoIndoorData.setPoiId( data.getPoiId() );
|
||||
return mogoIndoorData;
|
||||
}
|
||||
|
||||
public static MogoPhoto fromAMap( Photo photo ) {
|
||||
if ( photo == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoPhoto mogoPhoto = new MogoPhoto();
|
||||
mogoPhoto.setTitle( photo.getTitle() );
|
||||
mogoPhoto.setUrl( photo.getUrl() );
|
||||
return mogoPhoto;
|
||||
}
|
||||
|
||||
public static MogoPoiItemExtension fromAMap( PoiItemExtension poiItemExtension ) {
|
||||
if ( poiItemExtension == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoPoiItemExtension mogoPoiItemExtension = new MogoPoiItemExtension();
|
||||
mogoPoiItemExtension.setOpentime( poiItemExtension.getOpentime() );
|
||||
mogoPoiItemExtension.setRating( poiItemExtension.getmRating() );
|
||||
return mogoPoiItemExtension;
|
||||
}
|
||||
|
||||
public static MogoRegeocodeRoad fromAMap( RegeocodeRoad regeocodeRoad ) {
|
||||
if ( regeocodeRoad == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoRegeocodeRoad mogoRegeocodeRoad = new MogoRegeocodeRoad();
|
||||
mogoRegeocodeRoad.setDirection( regeocodeRoad.getDirection() );
|
||||
mogoRegeocodeRoad.setDistance( regeocodeRoad.getDistance() );
|
||||
mogoRegeocodeRoad.setId( regeocodeRoad.getId() );
|
||||
mogoRegeocodeRoad.setName( regeocodeRoad.getName() );
|
||||
mogoRegeocodeRoad.setPoint( fromAMap( regeocodeRoad.getLatLngPoint() ) );
|
||||
return mogoRegeocodeRoad;
|
||||
}
|
||||
|
||||
public static MogoStreetNumber fromAMap( StreetNumber streetNumber ) {
|
||||
if ( streetNumber == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoStreetNumber mogoStreetNumber = new MogoStreetNumber();
|
||||
mogoStreetNumber.setDirection( streetNumber.getDirection() );
|
||||
mogoStreetNumber.setDistance( streetNumber.getDistance() );
|
||||
mogoStreetNumber.setLatLonPoint( fromAMap( streetNumber.getLatLonPoint() ) );
|
||||
mogoStreetNumber.setNumber( streetNumber.getNumber() );
|
||||
mogoStreetNumber.setStreet( streetNumber.getStreet() );
|
||||
return mogoStreetNumber;
|
||||
}
|
||||
|
||||
public static MogoSubPoiItem fromAMap( SubPoiItem subPoiItem ) {
|
||||
if ( subPoiItem == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoSubPoiItem mogoSubPoiItem = new MogoSubPoiItem();
|
||||
mogoSubPoiItem.setDistance( subPoiItem.getDistance() );
|
||||
mogoSubPoiItem.setPoiId( subPoiItem.getPoiId() );
|
||||
mogoSubPoiItem.setPoint( fromAMap( subPoiItem.getLatLonPoint() ) );
|
||||
mogoSubPoiItem.setSnippet( subPoiItem.getSnippet() );
|
||||
mogoSubPoiItem.setSubName( mogoSubPoiItem.getSubName() );
|
||||
mogoSubPoiItem.setSubTypeDes( mogoSubPoiItem.getSubTypeDes() );
|
||||
mogoSubPoiItem.setTitle( mogoSubPoiItem.getTitle() );
|
||||
return mogoSubPoiItem;
|
||||
}
|
||||
|
||||
public static MogoPoiItem fromAMap( PoiItem poiItem ) {
|
||||
if ( poiItem == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoPoiItem mogoPoiItem = new MogoPoiItem();
|
||||
mogoPoiItem.setAdCode( poiItem.getAdCode() );
|
||||
mogoPoiItem.setAdName( poiItem.getAdName() );
|
||||
mogoPoiItem.setBusinessArea( poiItem.getBusinessArea() );
|
||||
mogoPoiItem.setCityCode( poiItem.getCityCode() );
|
||||
mogoPoiItem.setCityName( poiItem.getCityName() );
|
||||
mogoPoiItem.setDirection( poiItem.getDirection() );
|
||||
mogoPoiItem.setDistance( poiItem.getDistance() );
|
||||
mogoPoiItem.setEmail( poiItem.getEmail() );
|
||||
mogoPoiItem.setEnter( fromAMap( poiItem.getEnter() ) );
|
||||
mogoPoiItem.setExit( fromAMap( poiItem.getExit() ) );
|
||||
mogoPoiItem.setIndoorData( fromAMap( poiItem.getIndoorData() ) );
|
||||
mogoPoiItem.setParkingType( poiItem.getParkingType() );
|
||||
mogoPoiItem.setIndoorMap( poiItem.isIndoorMap() );
|
||||
if ( poiItem.getPhotos() != null ) {
|
||||
List< MogoPhoto > mogoPhotos = new ArrayList<>();
|
||||
for ( Photo photo : poiItem.getPhotos() ) {
|
||||
MogoPhoto mogoPhoto = fromAMap( photo );
|
||||
if ( mogoPhoto != null ) {
|
||||
mogoPhotos.add( mogoPhoto );
|
||||
}
|
||||
}
|
||||
mogoPoiItem.setPhotos( mogoPhotos );
|
||||
}
|
||||
mogoPoiItem.setPoiExtension( fromAMap( poiItem.getPoiExtension() ) );
|
||||
mogoPoiItem.setPoiId( poiItem.getPoiId() );
|
||||
mogoPoiItem.setPoint( fromAMap( poiItem.getLatLonPoint() ) );
|
||||
mogoPoiItem.setPostcode( poiItem.getPostcode() );
|
||||
mogoPoiItem.setProvinceCode( poiItem.getProvinceCode() );
|
||||
mogoPoiItem.setProvinceName( poiItem.getProvinceName() );
|
||||
mogoPoiItem.setShopID( poiItem.getShopID() );
|
||||
mogoPoiItem.setSnippet( poiItem.getSnippet() );
|
||||
if ( poiItem.getSubPois() != null ) {
|
||||
List< MogoSubPoiItem > mogoSubPoiItems = new ArrayList<>();
|
||||
for ( SubPoiItem subPois : poiItem.getSubPois() ) {
|
||||
MogoSubPoiItem mogoSubPoiItem = fromAMap( subPois );
|
||||
if ( mogoPoiItem != null ) {
|
||||
mogoSubPoiItems.add( mogoSubPoiItem );
|
||||
}
|
||||
}
|
||||
mogoPoiItem.setSubPois( mogoSubPoiItems );
|
||||
}
|
||||
mogoPoiItem.setTel( poiItem.getTel() );
|
||||
mogoPoiItem.setTypeCode( poiItem.getTypeCode() );
|
||||
mogoPoiItem.setTitle( poiItem.getTitle() );
|
||||
mogoPoiItem.setTypeDes( poiItem.getTypeDes() );
|
||||
mogoPoiItem.setWebsite( poiItem.getWebsite() );
|
||||
return mogoPoiItem;
|
||||
}
|
||||
|
||||
public static MogoRegeocodeAddress fromAMap( RegeocodeAddress regeocodeAddress ) {
|
||||
if ( regeocodeAddress == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoRegeocodeAddress mogoRegeocodeAddress = new MogoRegeocodeAddress();
|
||||
mogoRegeocodeAddress.setAdCode( regeocodeAddress.getAdCode() );
|
||||
if ( regeocodeAddress.getAois() != null ) {
|
||||
List< MogoAoiItem > items = new ArrayList<>();
|
||||
for ( AoiItem aois : regeocodeAddress.getAois() ) {
|
||||
final MogoAoiItem mogoAoiItem = fromAMap( aois );
|
||||
if ( mogoAoiItem != null ) {
|
||||
items.add( mogoAoiItem );
|
||||
}
|
||||
}
|
||||
mogoRegeocodeAddress.setAois( items );
|
||||
}
|
||||
|
||||
mogoRegeocodeAddress.setBuilding( regeocodeAddress.getBuilding() );
|
||||
if ( regeocodeAddress.getBusinessAreas() != null ) {
|
||||
List< MogoBusinessArea > mogoBusinessAreas = new ArrayList<>();
|
||||
for ( BusinessArea businessArea : regeocodeAddress.getBusinessAreas() ) {
|
||||
MogoBusinessArea mogoBusinessArea = fromAMap( businessArea );
|
||||
if ( mogoBusinessArea != null ) {
|
||||
mogoBusinessAreas.add( mogoBusinessArea );
|
||||
}
|
||||
}
|
||||
mogoRegeocodeAddress.setBusinessAreas( mogoBusinessAreas );
|
||||
}
|
||||
|
||||
mogoRegeocodeAddress.setCity( regeocodeAddress.getCity() );
|
||||
mogoRegeocodeAddress.setCityCode( regeocodeAddress.getCityCode() );
|
||||
mogoRegeocodeAddress.setCountry( regeocodeAddress.getCountry() );
|
||||
if ( regeocodeAddress.getCrossroads() != null ) {
|
||||
List< MogoCrossroad > mogoCrossroads = new ArrayList<>();
|
||||
for ( Crossroad crossroad : regeocodeAddress.getCrossroads() ) {
|
||||
|
||||
MogoCrossroad mogoCrossroad = fromAMap( crossroad );
|
||||
if ( mogoCrossroad != null ) {
|
||||
mogoCrossroads.add( mogoCrossroad );
|
||||
}
|
||||
}
|
||||
mogoRegeocodeAddress.setCrossroads( mogoCrossroads );
|
||||
}
|
||||
mogoRegeocodeAddress.setDistrict( regeocodeAddress.getDistrict() );
|
||||
mogoRegeocodeAddress.setFormatAddress( regeocodeAddress.getFormatAddress() );
|
||||
mogoRegeocodeAddress.setNeighborhood( regeocodeAddress.getNeighborhood() );
|
||||
if ( regeocodeAddress.getPois() != null ) {
|
||||
List< MogoPoiItem > mogoPoiItems = new ArrayList<>();
|
||||
for ( PoiItem pois : regeocodeAddress.getPois() ) {
|
||||
MogoPoiItem mogoPoiItem = fromAMap( pois );
|
||||
mogoPoiItems.add( mogoPoiItem );
|
||||
}
|
||||
mogoRegeocodeAddress.setPois( mogoPoiItems );
|
||||
}
|
||||
mogoRegeocodeAddress.setProvince( regeocodeAddress.getProvince() );
|
||||
if ( regeocodeAddress.getRoads() != null ) {
|
||||
List< MogoRegeocodeRoad > mogoRegeocodeRoads = new ArrayList<>();
|
||||
for ( RegeocodeRoad road : regeocodeAddress.getRoads() ) {
|
||||
MogoRegeocodeRoad mogoRegeocodeRoad = fromAMap( road );
|
||||
if ( mogoRegeocodeRoad != null ) {
|
||||
mogoRegeocodeRoads.add( mogoRegeocodeRoad );
|
||||
}
|
||||
}
|
||||
mogoRegeocodeAddress.setRoads( mogoRegeocodeRoads );
|
||||
}
|
||||
mogoRegeocodeAddress.setStreetNumber( fromAMap( regeocodeAddress.getStreetNumber() ) );
|
||||
mogoRegeocodeAddress.setTowncode( regeocodeAddress.getTowncode() );
|
||||
mogoRegeocodeAddress.setTownship( regeocodeAddress.getTownship() );
|
||||
return mogoRegeocodeAddress;
|
||||
}
|
||||
|
||||
public static MogoRegeocodeResult fromAMap( RegeocodeResult regeocodeResult ) {
|
||||
if ( regeocodeResult == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoRegeocodeResult mogoRegeocodeResult = new MogoRegeocodeResult();
|
||||
mogoRegeocodeResult.setRegeocodeAddress( fromAMap( regeocodeResult.getRegeocodeAddress() ) );
|
||||
return mogoRegeocodeResult;
|
||||
}
|
||||
|
||||
public static InputtipsQuery fromMogo( MogoInputtipsQuery query ) {
|
||||
if ( query == null ) {
|
||||
return null;
|
||||
}
|
||||
InputtipsQuery inputtipsQuery = new InputtipsQuery( query.getKeyword(), query.getCity() );
|
||||
inputtipsQuery.setCityLimit( query.isCityLimit() );
|
||||
inputtipsQuery.setLocation( fromMogo( query.getLocation() ) );
|
||||
inputtipsQuery.setType( query.getType() );
|
||||
return inputtipsQuery;
|
||||
}
|
||||
|
||||
public static MogoTip fromAMap( Tip tip ) {
|
||||
if ( tip == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoTip mogoTip = new MogoTip();
|
||||
mogoTip.setAdCode( tip.getAdcode() );
|
||||
mogoTip.setAddress( tip.getAddress() );
|
||||
mogoTip.setDistrict( tip.getDistrict() );
|
||||
mogoTip.setName( tip.getName() );
|
||||
mogoTip.setPoiID( tip.getPoiID() );
|
||||
mogoTip.setPoint( fromAMap( tip.getPoint() ) );
|
||||
mogoTip.setTypeCode( tip.getTypeCode() );
|
||||
return mogoTip;
|
||||
}
|
||||
|
||||
public static MogoPoi fromAMap( Poi poi ) {
|
||||
if ( poi == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoPoi mogoPoi = new MogoPoi();
|
||||
mogoPoi.setCoordinate( fromAMap( poi.getCoordinate() ) );
|
||||
mogoPoi.setName( poi.getName() );
|
||||
mogoPoi.setPoiId( poi.getPoiId() );
|
||||
return mogoPoi;
|
||||
}
|
||||
|
||||
public static MogoPoiSearchQuery fromAMap( PoiSearch.Query query ) {
|
||||
if ( query == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoPoiSearchQuery mogoPoiSearchQuery = new MogoPoiSearchQuery( query.getQueryString(), query.getCategory(), query.getCity() );
|
||||
mogoPoiSearchQuery.setBuilding( query.getBuilding() );
|
||||
mogoPoiSearchQuery.setCityLimit( query.getCityLimit() );
|
||||
mogoPoiSearchQuery.setDistanceSort( query.isDistanceSort() );
|
||||
mogoPoiSearchQuery.setLocation( fromAMap( query.getLocation() ) );
|
||||
mogoPoiSearchQuery.setPageNum( query.getPageNum() );
|
||||
mogoPoiSearchQuery.setPageSize( query.getPageSize() );
|
||||
return mogoPoiSearchQuery;
|
||||
}
|
||||
|
||||
public static PoiSearch.Query fromMogo( MogoPoiSearchQuery query ) {
|
||||
if ( query == null ) {
|
||||
return null;
|
||||
}
|
||||
PoiSearch.Query psq = new PoiSearch.Query( query.getQuery(), query.getCategory(), query.getCity() );
|
||||
psq.setBuilding( query.getBuilding() );
|
||||
psq.setCityLimit( query.isCityLimit() );
|
||||
psq.setDistanceSort( query.isDistanceSort() );
|
||||
psq.setLocation( fromMogo( query.getLocation() ) );
|
||||
psq.setPageNum( query.getPageNum() );
|
||||
psq.setPageSize( query.getPageSize() );
|
||||
return psq;
|
||||
}
|
||||
|
||||
public static MogoSearchBound fromAMap( PoiSearch.SearchBound bound ) {
|
||||
if ( bound == null ) {
|
||||
return null;
|
||||
}
|
||||
if ( bound.getShape() == PoiSearch.SearchBound.BOUND_SHAPE ) {
|
||||
return new MogoSearchBound( fromAMap( bound.getCenter() ), bound.getRange(), bound.isDistanceSort() );
|
||||
} else if ( bound.getShape() == PoiSearch.SearchBound.POLYGON_SHAPE ) {
|
||||
return new MogoSearchBound( fromAMap( bound.getPolyGonList() ) );
|
||||
} else if ( bound.getShape() == PoiSearch.SearchBound.RECTANGLE_SHAPE ) {
|
||||
return new MogoSearchBound( fromAMap( bound.getLowerLeft() ), fromAMap( bound.getUpperRight() ) );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List< MogoLatLng > fromAMap( List< LatLonPoint > latLngs ) {
|
||||
if ( latLngs == null ) {
|
||||
return null;
|
||||
}
|
||||
List< MogoLatLng > result = new ArrayList<>( latLngs.size() );
|
||||
for ( LatLonPoint latLng : latLngs ) {
|
||||
result.add( fromAMap( latLng ) );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List< LatLonPoint > fromMogo( List< MogoLatLng > latLngs ) {
|
||||
if ( latLngs == null ) {
|
||||
return null;
|
||||
}
|
||||
List< LatLonPoint > result = new ArrayList<>( latLngs.size() );
|
||||
for ( MogoLatLng latLng : latLngs ) {
|
||||
result.add( fromMogo( latLng ) );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static PoiSearch.SearchBound fromMogo( MogoSearchBound bound ) {
|
||||
if ( bound == null ) {
|
||||
return null;
|
||||
}
|
||||
if ( bound.getShape() == MogoSearchBound.SHAPE_BOUND ) {
|
||||
return new PoiSearch.SearchBound( fromMogo( bound.getCenterPoint() ), bound.getRadiusInMeters(), bound.isDistanceSort() );
|
||||
} else if ( bound.getShape() == MogoSearchBound.SHAPE_POLYGON ) {
|
||||
return new PoiSearch.SearchBound( fromMogo( bound.getPolyGonList() ) );
|
||||
} else if ( bound.getShape() == MogoSearchBound.SHAPE_RECTANGLE ) {
|
||||
return new PoiSearch.SearchBound( fromMogo( bound.getLowerLeft() ), fromMogo( bound.getUpperRight() ) );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static MogoPoiResult fromAMap( PoiResult result ) {
|
||||
if ( result == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoPoiResult mogoPoiResult = new MogoPoiResult();
|
||||
if ( result.getPois() != null ) {
|
||||
final List< PoiItem > poiItems = result.getPois();
|
||||
final ArrayList< MogoPoiItem > mogoPoiItems = new ArrayList<>( poiItems.size() );
|
||||
for ( PoiItem poiItem : poiItems ) {
|
||||
mogoPoiItems.add( fromAMap( poiItem ) );
|
||||
}
|
||||
mogoPoiResult.setPois( mogoPoiItems );
|
||||
}
|
||||
return mogoPoiResult;
|
||||
}
|
||||
|
||||
public static MogoNaviInfo fromAMap( Context context, NaviInfo naviInfo ) {
|
||||
if ( naviInfo == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoNaviInfo mogoNaviInfo = new MogoNaviInfo();
|
||||
mogoNaviInfo.setCurrentRoadName( naviInfo.getCurrentRoadName() );
|
||||
mogoNaviInfo.setCurrentSpeed( naviInfo.getCurrentSpeed() );
|
||||
mogoNaviInfo.setCurStepRetainDistance( naviInfo.getCurStepRetainDistance() );
|
||||
mogoNaviInfo.setCurStepRetainTime( naviInfo.getCurStepRetainTime() );
|
||||
mogoNaviInfo.setIconResId( IconTypeUtils.getResIdByIconType( context, naviInfo.getIconType() ) );
|
||||
mogoNaviInfo.setNextRoadName( naviInfo.getNextRoadName() );
|
||||
mogoNaviInfo.setPathRetainDistance( naviInfo.getPathRetainDistance() );
|
||||
mogoNaviInfo.setPathRetainTime( naviInfo.getPathRetainTime() );
|
||||
mogoNaviInfo.setCurrentSpeed( naviInfo.getLimitSpeed() );
|
||||
return mogoNaviInfo;
|
||||
}
|
||||
|
||||
public static MogoCongestionInfo fromAMap( AimLessModeCongestionInfo aimLessModeCongestionInfo ) {
|
||||
if ( aimLessModeCongestionInfo == null ) {
|
||||
return null;
|
||||
}
|
||||
MogoCongestionInfo congestionInfo = new MogoCongestionInfo();
|
||||
congestionInfo.setCongestionStatus( aimLessModeCongestionInfo.getCongestionStatus() );
|
||||
congestionInfo.setEventLat( aimLessModeCongestionInfo.getEventLat() );
|
||||
congestionInfo.setEventLon( aimLessModeCongestionInfo.getEventLon() );
|
||||
congestionInfo.setEventType( aimLessModeCongestionInfo.getEventType() );
|
||||
congestionInfo.setCongestionLinks( new ArrayList< MogoCongestionLink >() );
|
||||
congestionInfo.setLength( aimLessModeCongestionInfo.getLength() );
|
||||
congestionInfo.setRoadName( aimLessModeCongestionInfo.getRoadName() );
|
||||
congestionInfo.setTime( aimLessModeCongestionInfo.getTime() );
|
||||
if ( aimLessModeCongestionInfo.getAmapCongestionLinks() != null
|
||||
&& aimLessModeCongestionInfo.getAmapCongestionLinks().length != 0 ) {
|
||||
for ( AMapCongestionLink amapCongestionLink : aimLessModeCongestionInfo.getAmapCongestionLinks() ) {
|
||||
if ( amapCongestionLink == null ) {
|
||||
continue;
|
||||
}
|
||||
MogoCongestionLink link = new MogoCongestionLink();
|
||||
link.setCongestionStatus( amapCongestionLink.getCongestionStatus() );
|
||||
if ( amapCongestionLink.getCoords() != null ) {
|
||||
link.setCoords( new ArrayList< MogoLatLng >() );
|
||||
Iterator< NaviLatLng > iterator = amapCongestionLink.getCoords().iterator();
|
||||
while ( iterator.hasNext() ) {
|
||||
NaviLatLng naviLatLng = iterator.next();
|
||||
if ( naviLatLng == null ) {
|
||||
continue;
|
||||
}
|
||||
link.getCoords().add( new MogoLatLng( naviLatLng.getLatitude(), naviLatLng.getLongitude() ) );
|
||||
}
|
||||
}
|
||||
congestionInfo.getCongestionLinks().add( link );
|
||||
}
|
||||
}
|
||||
return congestionInfo;
|
||||
}
|
||||
|
||||
public static MogoTraffic fromAMap( AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos ) {
|
||||
if ( aMapNaviTrafficFacilityInfos == null || aMapNaviTrafficFacilityInfos.length == 0 ) {
|
||||
return null;
|
||||
}
|
||||
for ( AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo : aMapNaviTrafficFacilityInfos ) {
|
||||
if ( aMapNaviTrafficFacilityInfo == null ) {
|
||||
continue;
|
||||
}
|
||||
MogoTraffic traffic = new MogoTraffic( MogoTraffic.TYPE_AIM );
|
||||
traffic.setDistance( aMapNaviTrafficFacilityInfo.getDistance() );
|
||||
traffic.setSpeedLimit( aMapNaviTrafficFacilityInfo.getLimitSpeed() );
|
||||
traffic.setTrafficType( aMapNaviTrafficFacilityInfo.getBroadcastType() );
|
||||
traffic.setLat( aMapNaviTrafficFacilityInfo.latitude );
|
||||
traffic.setLon( aMapNaviTrafficFacilityInfo.longitude );
|
||||
return traffic;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PolylineOptions fromMogo( MogoPolylineOptions options ) {
|
||||
if ( options == null ) {
|
||||
return null;
|
||||
}
|
||||
PolylineOptions target = new PolylineOptions();
|
||||
if ( options.getPoints() != null ) {
|
||||
List< LatLng > points = new ArrayList<>();
|
||||
for ( MogoLatLng point : options.getPoints() ) {
|
||||
points.add( fromMogo2( point ) );
|
||||
}
|
||||
target.addAll( points );
|
||||
}
|
||||
target.width( options.getWidth() );
|
||||
target.color( options.getColor() );
|
||||
target.zIndex( options.getWidth() );
|
||||
target.visible( options.isVisible() );
|
||||
target.geodesic( options.isGeodesic() );
|
||||
target.setDottedLine( options.isDottedLine() );
|
||||
target.useGradient( options.isGradient() );
|
||||
if ( options.getColorValues() != null ) {
|
||||
target.colorValues( options.getColorValues() );
|
||||
}
|
||||
target.transparency( options.getTransparency() );
|
||||
target.aboveMaskLayer( options.isAboveMaskLayer() );
|
||||
target.lineCapType( PolylineOptions.LineCapType.LineCapRound );
|
||||
target.lineJoinType( PolylineOptions.LineJoinType.LineJoinRound );
|
||||
target.setDottedLineType( PolylineOptions.DOTTEDLINE_TYPE_CIRCLE );
|
||||
return target;
|
||||
}
|
||||
|
||||
public static MogoLatLng fromAMap( LatLng latLng ) {
|
||||
if ( latLng == null ) {
|
||||
return null;
|
||||
}
|
||||
return new MogoLatLng( latLng.latitude, latLng.longitude );
|
||||
}
|
||||
|
||||
public static MapCameraPosition fromAMap( CameraPosition position ) {
|
||||
if ( position == null ) {
|
||||
return null;
|
||||
}
|
||||
return new MapCameraPosition( fromAMap( position.target ), position.bearing, position.tilt, position.zoom );
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 347 B |
|
Before Width: | Height: | Size: 384 B |
|
Before Width: | Height: | Size: 375 B |
|
Before Width: | Height: | Size: 354 B |
|
Before Width: | Height: | Size: 380 B |
|
Before Width: | Height: | Size: 387 B |
|
Before Width: | Height: | Size: 382 B |
|
Before Width: | Height: | Size: 340 B |
|
Before Width: | Height: | Size: 341 B |
|
Before Width: | Height: | Size: 323 B |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 7.7 KiB |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 702 B |
|
Before Width: | Height: | Size: 910 B |
|
Before Width: | Height: | Size: 941 B |
|
Before Width: | Height: | Size: 865 B |
|
Before Width: | Height: | Size: 883 B |
|
Before Width: | Height: | Size: 949 B |
|
Before Width: | Height: | Size: 849 B |
|
Before Width: | Height: | Size: 742 B |
|
Before Width: | Height: | Size: 699 B |
|
Before Width: | Height: | Size: 712 B |
|
Before Width: | Height: | Size: 711 B |
|
Before Width: | Height: | Size: 838 B |
|
Before Width: | Height: | Size: 832 B |
|
Before Width: | Height: | Size: 791 B |
|
Before Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 942 B |
|
Before Width: | Height: | Size: 604 B |
|
Before Width: | Height: | Size: 601 B |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |