dev
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package com.mogo.map.impl.amap;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith( AndroidJUnit4.class )
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
|
||||
assertEquals( "com.mogo.map.impl.amap.test", appContext.getPackageName() );
|
||||
}
|
||||
}
|
||||
10
libraries/map-amap/src/main/AndroidManifest.xml
Normal file
10
libraries/map-amap/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mogo.map.impl.amap">
|
||||
|
||||
<application>
|
||||
<!-- 高德地图 -->
|
||||
<meta-data
|
||||
android:name="com.amap.api.v2.apikey"
|
||||
android:value="a36b9f7b086fa3951bb35338a5a06dd3" />
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.mogo.map.impl.amap;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.amap.api.navi.AMapNaviView;
|
||||
import com.mogo.map.IMogoMapView;
|
||||
import com.mogo.map.MogoBaseMapView;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-25
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class AMapBaseMapView extends MogoBaseMapView {
|
||||
|
||||
public AMapBaseMapView( Context context ) {
|
||||
super( context );
|
||||
}
|
||||
|
||||
public AMapBaseMapView( Context context, @Nullable AttributeSet attrs ) {
|
||||
super( context, attrs );
|
||||
}
|
||||
|
||||
public AMapBaseMapView( Context context, @Nullable AttributeSet attrs, int defStyleAttr ) {
|
||||
super( context, attrs, defStyleAttr );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IMogoMapView createMapView( Context context ) {
|
||||
return new AMapNaviViewWrapper( new AMapNaviView( context ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* @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 ) {
|
||||
final IMogoMarkerClickListener listener = ( ( IMogoMarker ) marker.getObject() ).getOnMarkerClickListener();
|
||||
if ( listener != null ) {
|
||||
return listener.onMarkerClicked( ( ( IMogoMarker ) marker.getObject() ) );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
package com.mogo.map.impl.amap;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Bundle;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.amap.api.maps.model.Poi;
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.navi.AMapNaviListener;
|
||||
import com.amap.api.navi.AMapNaviView;
|
||||
import com.amap.api.navi.AMapNaviViewListener;
|
||||
import com.amap.api.navi.AMapNaviViewOptions;
|
||||
import com.mogo.map.IMogoMap;
|
||||
import com.mogo.map.IMogoMapView;
|
||||
import com.mogo.map.impl.amap.navi.NaviClient;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.listener.MogoMapListenerHandler;
|
||||
import com.mogo.map.uicontroller.EnumMapUI;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-18
|
||||
* <p>
|
||||
* 代理高德导航地图
|
||||
*/
|
||||
public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
AMap.OnMarkerClickListener,
|
||||
AMap.OnMapLoadedListener,
|
||||
AMap.OnMapTouchListener,
|
||||
AMap.OnPOIClickListener,
|
||||
AMap.OnMapClickListener,
|
||||
AMap.OnPolylineClickListener,
|
||||
AMapNaviViewListener {
|
||||
|
||||
private static final String TAG = "AMapNaviViewWrapper";
|
||||
|
||||
private final AMapNaviView mMapView;
|
||||
private IMogoMap mIMap;
|
||||
|
||||
private AMapMarkerClickHandler mMarkerClickHandler;
|
||||
|
||||
public AMapNaviViewWrapper( AMapNaviView mapView ) {
|
||||
this.mMapView = mapView;
|
||||
this.mIMap = new AMapWrapper( mMapView.getMap(), mMapView );
|
||||
initMapView();
|
||||
initListeners();
|
||||
}
|
||||
|
||||
private void initMapView() {
|
||||
if ( mMapView != null ) {
|
||||
AMapNaviViewOptions options = mMapView.getViewOptions();
|
||||
if ( options != null ) {
|
||||
// 设置是否开启自动黑夜模式切换,默认为false,不自动切换
|
||||
options.setAutoNaviViewNightMode( false );
|
||||
// 设置6秒后是否自动锁车
|
||||
options.setAutoLockCar( true );
|
||||
// 设置路线上的摄像头气泡是否显示
|
||||
options.setCameraBubbleShow( true );
|
||||
// 设置路线相关的配置属性,如:路线的路况颜色,路线上是否显示摄像头气泡等。
|
||||
// options.setRouteOverlayOptions( MapStyleUtils.getRouteOverlayOptions() );
|
||||
// 设置自车的图片对象
|
||||
options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(), R.drawable.ic_search_poi_location ) );
|
||||
// 设置指南针图标否在导航界面显示,默认显示。true,显示;false,隐藏。
|
||||
options.setCompassEnabled( false );
|
||||
//设置路况光柱条是否显示(只适用于驾车导航,需要联网)。
|
||||
options.setTrafficBarEnabled( false );
|
||||
// 设置[实时交通图层开关按钮]是否显示(只适用于驾车导航,需要联网)。
|
||||
options.setTrafficLayerEnabled( false );
|
||||
// 设置导航界面是否显示路线全览按钮。
|
||||
options.setRouteListButtonShow( false );
|
||||
// 设置起点位图,须在画路前设置
|
||||
// options.setStartPointBitmap( BitmapFactory.decodeResource( getContext().getResources(), R.drawable.ic_current_location_cursor ) );
|
||||
// 设置终点位图,须在画路前设置
|
||||
// options.setEndPointBitmap( BitmapFactory.decodeResource( getContext().getResources(), R.drawable.ic_search_choice_point ) );
|
||||
// 设置导航状态下屏幕是否一直开启。
|
||||
options.setScreenAlwaysBright( true );
|
||||
// 设置交通播报是否打开(只适用于驾车导航,需要联网)。
|
||||
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.setPointToCenter( 0.5D, 0.5D );
|
||||
// 2D模式
|
||||
options.setTilt( 0 );
|
||||
mMapView.setViewOptions( options );
|
||||
}
|
||||
mMapView.setRouteOverlayVisible( false );
|
||||
mMapView.setNaviMode( AMapNaviView.NORTH_UP_MODE );
|
||||
}
|
||||
}
|
||||
|
||||
private void initListeners() {
|
||||
mMapView.setOnMarkerClickListener( this );
|
||||
mMarkerClickHandler = new AMapMarkerClickHandler();
|
||||
mMapView.setOnMapLoadedListener( this );
|
||||
mMapView.setOnMapTouchListener( this );
|
||||
mMapView.setOnPolylineClickListener( this );
|
||||
mMapView.setAMapNaviViewListener( this );
|
||||
if ( mMapView.getMap() != null ) {
|
||||
mMapView.getMap().setOnPOIClickListener( this );
|
||||
mMapView.getMap().setOnMapClickListener( 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 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onResume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onPause();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState( Bundle outState ) {
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onSaveInstanceState( outState );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 地图marker点击
|
||||
*
|
||||
* @param marker
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean onMarkerClick( Marker marker ) {
|
||||
return mMarkerClickHandler.handleMarkerClicked( marker );
|
||||
}
|
||||
|
||||
/**
|
||||
* 地图加载完毕
|
||||
*/
|
||||
@Override
|
||||
public void onMapLoaded() {
|
||||
MogoMapListenerHandler.getInstance().onMapLoaded();
|
||||
}
|
||||
|
||||
/**
|
||||
* 地图点击回调
|
||||
*
|
||||
* @param motionEvent
|
||||
*/
|
||||
@Override
|
||||
public void onTouch( MotionEvent motionEvent ) {
|
||||
MogoMapListenerHandler.getInstance().onTouch( motionEvent );
|
||||
}
|
||||
|
||||
/**
|
||||
* POI 点击
|
||||
*
|
||||
* @param poi
|
||||
*/
|
||||
@Override
|
||||
public void onPOIClick( Poi poi ) {
|
||||
if ( InterceptorHandler.getInstance().ignorePoiClickedWhenNaviing( getContext() ) ) {
|
||||
return;
|
||||
}
|
||||
MogoMapListenerHandler.getInstance().onPOIClick( ObjectUtils.fromAMap( poi ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapClick( LatLng latLng ) {
|
||||
if ( InterceptorHandler.getInstance().ignoreMapClickedWhenNaviing( getContext() ) ) {
|
||||
return;
|
||||
}
|
||||
MogoMapListenerHandler.getInstance().onMapClick( ObjectUtils.fromAMap( latLng ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPolylineClick( Polyline polyline ) {
|
||||
NaviClient.getInstance( getContext() ).handleClickedPolyline( polyline );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviSetting() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviCancel() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNaviBackClick() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviMapMode( int i ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviTurnClick() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNextRoadClick() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanViewButtonClick() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLockMap( boolean isLock ) {
|
||||
MogoMapListenerHandler.getInstance().onLockMap( isLock );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviViewLoaded() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapTypeChanged( int type ) {
|
||||
if ( type == AMap.MAP_TYPE_NAVI ) {
|
||||
MogoMapListenerHandler.getInstance().onMapModeChanged( EnumMapUI.Type_Navi );
|
||||
} else if ( type == AMap.MAP_TYPE_NORMAL ) {
|
||||
MogoMapListenerHandler.getInstance().onMapModeChanged( EnumMapUI.Type_Light );
|
||||
} else if ( type == AMap.MAP_TYPE_NIGHT ) {
|
||||
MogoMapListenerHandler.getInstance().onMapModeChanged( EnumMapUI.Type_Light );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviViewShowMode( int i ) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
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.BitmapDescriptorFactory;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.amap.api.maps.model.MarkerOptions;
|
||||
import com.amap.api.maps.model.MyLocationStyle;
|
||||
import com.amap.api.navi.AMapNaviView;
|
||||
import com.amap.api.navi.AMapNaviViewOptions;
|
||||
import com.mogo.map.IMogoMap;
|
||||
import com.mogo.map.IMogoUiSettings;
|
||||
import com.mogo.map.impl.amap.location.ALocationClient;
|
||||
import com.mogo.map.impl.amap.marker.AMapInfoWindowAdapter;
|
||||
import com.mogo.map.impl.amap.marker.AMapMarkerWrapper;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.map.marker.MogoMarkersHandler;
|
||||
import com.mogo.map.uicontroller.EnumMapUI;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-18
|
||||
* <p>
|
||||
* 代理高德AMap
|
||||
*/
|
||||
public class AMapWrapper implements IMogoMap, IMogoMapUIController {
|
||||
|
||||
private static final String TAG = "AMapWrapper";
|
||||
|
||||
private static AMap sAMap;
|
||||
private AMap mAMap;
|
||||
private AMapNaviView mMapView;
|
||||
private IMogoUiSettings mUiSettings;
|
||||
|
||||
public AMapWrapper( AMap map, AMapNaviView mapView ) {
|
||||
this.mAMap = map;
|
||||
sAMap = map;
|
||||
this.mMapView = mapView;
|
||||
// 设置实现自定义 info window
|
||||
mAMap.setInfoWindowAdapter( new AMapInfoWindowAdapter() );
|
||||
}
|
||||
|
||||
public static AMap getAMap() {
|
||||
return sAMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoUiSettings getUiSettings() {
|
||||
if ( !checkAMap() ) {
|
||||
return null;
|
||||
}
|
||||
if ( mUiSettings == null ) {
|
||||
mUiSettings = new AMapUiSettingsWrapper( mAMap.getUiSettings() );
|
||||
}
|
||||
return mUiSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoMapUIController getUIController() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@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 ) );
|
||||
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 ( Marker marker : markers ) {
|
||||
if ( marker == null ) {
|
||||
continue;
|
||||
}
|
||||
mogoMarkers.add( new AMapMarkerWrapper( marker ) );
|
||||
}
|
||||
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 void setTrafficEnabled( boolean visible ) {
|
||||
if ( checkAMap() ) {
|
||||
mAMap.setTrafficEnabled( visible );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeZoom( boolean zoom ) {
|
||||
if ( checkAMapView() ) {
|
||||
if ( zoom ) {
|
||||
mMapView.zoomIn();
|
||||
} else {
|
||||
mMapView.zoomOut();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeMapMode( EnumMapUI ui ) {
|
||||
if ( ui == null ) {
|
||||
return;
|
||||
}
|
||||
if ( checkAMapView() ) {
|
||||
AMapNaviViewOptions options = mMapView.getViewOptions();
|
||||
if ( options == null ) {
|
||||
options = new AMapNaviViewOptions();
|
||||
}
|
||||
switch ( ui ) {
|
||||
case CarUp_2D:
|
||||
options.setTilt( 0 );
|
||||
mMapView.setNaviMode( AMapNaviView.CAR_UP_MODE );
|
||||
break;
|
||||
case CarUp_3D:
|
||||
options.setTilt( 60 );
|
||||
mMapView.setNaviMode( AMapNaviView.CAR_UP_MODE );
|
||||
break;
|
||||
case NorthUP_2D:
|
||||
options.setTilt( 0 );
|
||||
mMapView.setNaviMode( AMapNaviView.NORTH_UP_MODE );
|
||||
break;
|
||||
case Type_Light:
|
||||
if ( checkAMap() ) {
|
||||
mAMap.setMapType( AMap.MAP_TYPE_NORMAL );
|
||||
}
|
||||
return;
|
||||
case Type_Night:
|
||||
if ( checkAMap() ) {
|
||||
mAMap.setMapType( AMap.MAP_TYPE_NIGHT );
|
||||
}
|
||||
return;
|
||||
case Type_Navi:
|
||||
if ( checkAMap() ) {
|
||||
mAMap.setMapType( AMap.MAP_TYPE_NAVI );
|
||||
}
|
||||
return;
|
||||
}
|
||||
mMapView.setViewOptions( options );
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkAMap() {
|
||||
if ( mAMap == null ) {
|
||||
Logger.e( TAG, "高德map实例为空,请检查" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean checkAMapView() {
|
||||
if ( mMapView == null ) {
|
||||
Logger.e( TAG, "高德mapView实例为空,请检查" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveToCurrentLocation() {
|
||||
MogoLocation location = ALocationClient.getInstance( getContext() ).getLastKnowLocation();
|
||||
if ( location != null ) {
|
||||
mAMap.animateCamera( CameraUpdateFactory.newLatLng( new LatLng( location.getLatitude(), location.getLongitude() ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
private Context getContext() {
|
||||
if ( checkAMapView() ) {
|
||||
return mMapView.getContext();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMyLocation( boolean visible ) {
|
||||
if ( checkAMapView() ) {
|
||||
mAMap.setMyLocationEnabled( true );
|
||||
MyLocationStyle style = mAMap.getMyLocationStyle();
|
||||
style.showMyLocation( visible );
|
||||
style.myLocationIcon( BitmapDescriptorFactory.fromResource( R.drawable.ic_search_poi_location ) );
|
||||
mAMap.setMyLocationStyle( style );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recoverLockMode() {
|
||||
if ( checkAMapView() ) {
|
||||
mMapView.recoverLockMode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayOverview() {
|
||||
if ( checkAMapView() ) {
|
||||
mMapView.displayOverview();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
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 ignorePoiClickedWhenNaviing( Context context );
|
||||
|
||||
/**
|
||||
* 导航时,是否响应地图点击
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
boolean ignoreMapClickedWhenNaviing( Context context );
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
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 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignoreAddMarkersMoveToCenterParameters( Context context ) {
|
||||
return NaviClient.getInstance( context ).isNaviing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignorePoiClickedWhenNaviing( Context context ) {
|
||||
return NaviClient.getInstance( context ).isNaviing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignoreMapClickedWhenNaviing( Context context ) {
|
||||
return NaviClient.getInstance( context ).isNaviing();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.mogo.map.impl.amap.location;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
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.IMogoLocationListener;
|
||||
import com.mogo.map.location.IMogoLocationClient;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
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 static volatile ALocationClient sInstance;
|
||||
private static Set< IMogoLocationListener > sListeners = new HashSet<>( 10 );
|
||||
private static MogoLocation sLastLocation = new MogoLocation();
|
||||
|
||||
private ALocationClient( Context context ) {
|
||||
mClient = new AMapLocationClient( context );
|
||||
mClient.setLocationListener( new InternalLocationListener() );
|
||||
sLastLocation = ObjectUtils.fromAMap( mClient.getLastKnownLocation() );
|
||||
}
|
||||
|
||||
public static ALocationClient getInstance( Context context ) {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( ALocationClient.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new ALocationClient( context );
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private AMapLocationClient mClient;
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
start( 2_000L );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start( long interval ) {
|
||||
stop();
|
||||
AMapLocationClientOption option = new AMapLocationClientOption();
|
||||
option.setLocationMode( AMapLocationClientOption.AMapLocationMode.Hight_Accuracy );
|
||||
option.setNeedAddress( true );
|
||||
option.setInterval( interval );
|
||||
if ( mClient != null ) {
|
||||
mClient.setLocationOption( option );
|
||||
}
|
||||
mClient.startLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if ( mClient != null ) {
|
||||
mClient.stopLocation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLocationListener( IMogoLocationListener listener ) {
|
||||
if ( listener != null ) {
|
||||
synchronized ( sListeners ) {
|
||||
sListeners.add( listener );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLocationListener( IMogoLocationListener listener ) {
|
||||
if ( listener != null ) {
|
||||
synchronized ( sListeners ) {
|
||||
sListeners.remove( listener );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLocation getLastKnowLocation() {
|
||||
return sLastLocation;
|
||||
}
|
||||
|
||||
private static class InternalLocationListener implements AMapLocationListener {
|
||||
@Override
|
||||
public void onLocationChanged( AMapLocation aMapLocation ) {
|
||||
if ( aMapLocation == null ||
|
||||
aMapLocation.getLatitude() == 0.0D ||
|
||||
aMapLocation.getLongitude() == 0.0D ) {
|
||||
return;
|
||||
}
|
||||
Logger.d( TAG, aMapLocation.toString() );
|
||||
sLastLocation = ObjectUtils.fromAMap( aMapLocation );
|
||||
synchronized ( sListeners ) {
|
||||
Iterator< IMogoLocationListener > listenerIterator = sListeners.iterator();
|
||||
while ( listenerIterator.hasNext() ) {
|
||||
listenerIterator.next().onLocationChanged( sLastLocation.clone() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
package com.mogo.map.impl.amap.marker;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
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.mogo.map.MogoLatLng;
|
||||
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.MogoMarkerOptions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-18
|
||||
* <p>
|
||||
* 高德marker
|
||||
*/
|
||||
public class AMapMarkerWrapper implements IMogoMarker {
|
||||
|
||||
private Marker mMarker;
|
||||
private Object mObject;
|
||||
private IMogoMarkerClickListener mMogoMarkerClickListener;
|
||||
private IMogoInfoWindowAdapter mMogoInfoWindowAdapter;
|
||||
|
||||
private boolean mIsDestroy = false;
|
||||
|
||||
public AMapMarkerWrapper( Marker marker ) {
|
||||
this.mMarker = marker;
|
||||
if ( marker != null ) {
|
||||
// 设置高德 marker 的object对象为 IMogoMarker 实例。!!!!
|
||||
marker.setObject( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.destroy();
|
||||
mMarker.setObject( null );
|
||||
mMarker = 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 );
|
||||
}
|
||||
}
|
||||
|
||||
@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 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 boolean isDestroyed() {
|
||||
return mIsDestroy;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-25
|
||||
* <p>
|
||||
* 高德导航事件:导航事件
|
||||
*/
|
||||
public abstract class AMapNaviListenerAdapter implements AMapNaviListener {
|
||||
|
||||
@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 ) {
|
||||
|
||||
}
|
||||
|
||||
@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 ) {
|
||||
|
||||
}
|
||||
|
||||
@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 ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAimlessModeStatistics( AimLessModeStat aimLessModeStat ) {
|
||||
|
||||
}
|
||||
|
||||
@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 ) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
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.mogo.map.impl.amap.overlay.RouteOverLayWrapper;
|
||||
|
||||
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;
|
||||
|
||||
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 getTime() {
|
||||
if ( mTimeBuilder == null ) {
|
||||
final int time = mPath.getAllTime();
|
||||
mTimeBuilder = new StringBuilder();
|
||||
fillFormatTime( time, mTimeBuilder );
|
||||
}
|
||||
return mTimeBuilder.toString();
|
||||
}
|
||||
|
||||
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 getDistance() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package com.mogo.map.impl.amap.navi;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.navi.AMapNavi;
|
||||
import com.amap.api.navi.enums.NaviType;
|
||||
import com.amap.api.navi.model.NaviLatLng;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.map.navi.MogoNaviConfig;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-25
|
||||
* <p>
|
||||
* 高德导航
|
||||
*/
|
||||
public class NaviClient implements IMogoNavi {
|
||||
|
||||
private static final String TAG = "NaviClient";
|
||||
|
||||
private AMapNavi mAMapNavi;
|
||||
private final NaviListenerAdapter mAMapNaviListener;
|
||||
|
||||
/**
|
||||
* 导航策略配置
|
||||
*/
|
||||
private MogoNaviConfig mMogoNaviConfig = new MogoNaviConfig();
|
||||
|
||||
private static volatile NaviClient sInstance;
|
||||
|
||||
private NaviClient( Context context ) {
|
||||
mAMapNavi = AMapNavi.getInstance( context );
|
||||
mAMapNaviListener = new NaviListenerAdapter( context, mAMapNavi, this );
|
||||
mAMapNavi.addAMapNaviListener( mAMapNaviListener );
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startNavi() {
|
||||
if ( mAMapNaviListener.isStopped() ) {
|
||||
return;
|
||||
}
|
||||
mAMapNavi.startNavi( isRealNavi() ? NaviType.GPS : NaviType.EMULATOR );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNaviing() {
|
||||
if ( mAMapNaviListener != null ) {
|
||||
return mAMapNaviListener.isNaviing();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// -- end
|
||||
|
||||
private boolean checkAMapNavi() {
|
||||
if ( mAMapNavi == null ) {
|
||||
Logger.e( TAG, "高德导航实例为空!!!" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isRealNavi() {
|
||||
if ( mMogoNaviConfig != null ) {
|
||||
return mMogoNaviConfig.isRealNavi();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void handleClickedPolyline( Polyline polyline ) {
|
||||
if ( mAMapNaviListener != null ) {
|
||||
mAMapNaviListener.handleClickedPolyline( polyline );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.mogo.map.impl.amap.navi;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.navi.AMapNavi;
|
||||
import com.amap.api.navi.enums.NaviType;
|
||||
import com.amap.api.navi.model.AMapCalcRouteResult;
|
||||
import com.amap.api.navi.model.NaviInfo;
|
||||
import com.mogo.map.impl.amap.AMapWrapper;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.navi.MogoNaviListenerHandler;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-25
|
||||
* <p>
|
||||
* 高德导航回调
|
||||
*/
|
||||
public class NaviListenerAdapter extends AMapNaviListenerAdapter {
|
||||
|
||||
private static final String TAG = "NaviListenerAdapter";
|
||||
|
||||
private Context mContext;
|
||||
private AMapNavi mAMapNavi;
|
||||
private NaviClient mClient;
|
||||
/**
|
||||
* 导航状态:true - 导航 onStartNavi(int) 被调用, false - 到达目的地、手动挺固执
|
||||
*/
|
||||
private boolean mIsNaviing = false;
|
||||
|
||||
/**
|
||||
* 导航是否被停止:true - 手动停止或到达目的地、false - 规划路径成功、开启导航
|
||||
*/
|
||||
private boolean mIsStopped = true;
|
||||
|
||||
/**
|
||||
* 路线规划
|
||||
*/
|
||||
private NaviOverlayHelper mNaviOverlayHelper;
|
||||
|
||||
public NaviListenerAdapter( Context mContext, AMapNavi mAMapNavi, NaviClient client ) {
|
||||
this.mContext = mContext;
|
||||
this.mAMapNavi = mAMapNavi;
|
||||
this.mClient = client;
|
||||
mNaviOverlayHelper = new NaviOverlayHelper( mAMapNavi, 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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartNavi( int i ) {
|
||||
setStopped( false );
|
||||
setNaviing( true );
|
||||
if ( mAMapNavi != null ) {
|
||||
mAMapNavi.startSpeak();
|
||||
}
|
||||
MogoNaviListenerHandler.getInstance().onStartNavi();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEndEmulatorNavi() {
|
||||
setNaviing( false );
|
||||
setStopped( true );
|
||||
MogoNaviListenerHandler.getInstance().onStopNavi();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onArriveDestination() {
|
||||
setNaviing( false );
|
||||
setStopped( true );
|
||||
MogoNaviListenerHandler.getInstance().onStopNavi();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviInfoUpdate( NaviInfo naviInfo ) {
|
||||
MogoNaviListenerHandler.getInstance().onNaviInfoUpdate( ObjectUtils.fromAMap( naviInfo ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculateRouteFailure( AMapCalcRouteResult aMapCalcRouteResult ) {
|
||||
if ( aMapCalcRouteResult != null ) {
|
||||
Logger.i( TAG, PathPlanningErrorCodeConstants.getErrorMsg( aMapCalcRouteResult.getErrorCode() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculateRouteSuccess( AMapCalcRouteResult aMapCalcRouteResult ) {
|
||||
super.onCalculateRouteSuccess( aMapCalcRouteResult );
|
||||
Logger.i( TAG, "导航规划成功" );
|
||||
setStopped( false );
|
||||
mNaviOverlayHelper.showCalculatedPaths();
|
||||
}
|
||||
|
||||
public void stopNavi() {
|
||||
setStopped( true );
|
||||
setNaviing( false );
|
||||
mAMapNavi.stopNavi();
|
||||
MogoNaviListenerHandler.getInstance().onStopNavi();
|
||||
mNaviOverlayHelper.clearCalculatedOverlay();
|
||||
}
|
||||
|
||||
public void handleClickedPolyline( Polyline polyline ) {
|
||||
if ( mNaviOverlayHelper != null ) {
|
||||
mNaviOverlayHelper.handleClickedPolyline( polyline );
|
||||
if ( isNaviing() ) {
|
||||
mAMapNavi.stopNavi();
|
||||
mAMapNavi.selectRouteId( mNaviOverlayHelper.getSelectedPathId() );
|
||||
mAMapNavi.startNavi( mClient.isRealNavi() ? NaviType.GPS : NaviType.EMULATOR );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
package com.mogo.map.impl.amap.navi;
|
||||
|
||||
import android.content.Context;
|
||||
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.LatLngBounds;
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.navi.AMapNavi;
|
||||
import com.amap.api.navi.model.AMapNaviPath;
|
||||
import com.mogo.map.impl.amap.R;
|
||||
import com.mogo.map.impl.amap.overlay.RouteOverLayWrapper;
|
||||
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 {
|
||||
|
||||
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 AMapNavi mAMapNavi;
|
||||
private AMap mAMap;
|
||||
private Context mContext;
|
||||
// 规划的路线显示边距
|
||||
private Rect mBoundRect = null;
|
||||
|
||||
private List< CalculatePathItem > mCalculatePathItems;
|
||||
|
||||
private int mSelectedPathId;
|
||||
|
||||
public NaviOverlayHelper( AMapNavi mAMapNavi, AMap mAMap, Context mContext ) {
|
||||
this.mAMapNavi = mAMapNavi;
|
||||
this.mAMap = mAMap;
|
||||
this.mContext = mContext;
|
||||
calculateBoundArea();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示规划的路径
|
||||
*/
|
||||
public void showCalculatedPaths() {
|
||||
clearCalculatedOverlay();
|
||||
mCalculatePathItems = getSortedPaths();
|
||||
if ( mCalculatePathItems == null || mCalculatePathItems.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
showPathsBound( mCalculatePathItems.get( 0 ).getPath().getBoundsForPath() );
|
||||
renderPathOverlay( mCalculatePathItems );
|
||||
}
|
||||
|
||||
/**
|
||||
* 按pathId升序排序
|
||||
*
|
||||
* @return 排序好的路径规划列表
|
||||
*/
|
||||
private List< CalculatePathItem > getSortedPaths() {
|
||||
final Map< Integer, AMapNaviPath > pathMap = mAMapNavi.getNaviPaths();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将规划好的路径显示在视野内
|
||||
*
|
||||
* @param bounds
|
||||
*/
|
||||
private void showPathsBound( LatLngBounds bounds ) {
|
||||
mAMap.animateCamera( CameraUpdateFactory.newLatLngBoundsRect( bounds, mBoundRect.left, mBoundRect.right, mBoundRect.top, mBoundRect.bottom ) );
|
||||
}
|
||||
|
||||
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 ) {
|
||||
wrapper.setStartBitmap( R.drawable.ic_amap_navi_cursor ).setEndBitmap( R.drawable.ic_search_choice_point );
|
||||
mAMapNavi.selectRouteId( item.getId() );
|
||||
}
|
||||
wrapper.addToMap();
|
||||
wrapper.setTransparency( i == 0 ? AMAP_ROUTE_OVERLAY_TRANSPARENCY_SELECTED : AMAP_ROUTE_OVERLAY_TRANSPARENCY_UNSELECTED );
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
mCalculatePathItems.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否切换成功
|
||||
*
|
||||
* @param polyline 选中的线
|
||||
* @return
|
||||
*/
|
||||
public boolean handleClickedPolyline( Polyline polyline ) {
|
||||
if ( polyline == null ) {
|
||||
return false;
|
||||
}
|
||||
Logger.i( TAG, "polyline id = " + polyline.getId() );
|
||||
CalculatePathItem calculatePathItem = isCalculatePolyline( polyline );
|
||||
if ( calculatePathItem == null ) {
|
||||
return false;
|
||||
}
|
||||
mSelectedPathId = calculatePathItem.getId();
|
||||
if ( mCalculatePathItems != null ) {
|
||||
for ( CalculatePathItem item : mCalculatePathItems ) {
|
||||
final RouteOverLayWrapper wrapper = item.getOverLazWrapper( false );
|
||||
if ( wrapper == null ) {
|
||||
continue;
|
||||
}
|
||||
wrapper.setTransparency(
|
||||
item == calculatePathItem
|
||||
? AMAP_ROUTE_OVERLAY_TRANSPARENCY_SELECTED
|
||||
: AMAP_ROUTE_OVERLAY_TRANSPARENCY_UNSELECTED
|
||||
);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private CalculatePathItem isCalculatePolyline( Polyline polyline ) {
|
||||
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(), polyline.getId() )
|
||||
|| wrapper.getTrafficColorfulPolyline() == polyline ) {
|
||||
result = calculatePathItem;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getSelectedPathId() {
|
||||
return mSelectedPathId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
package com.mogo.map.impl.amap.overlay;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.util.Log;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
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.view.RouteOverLay;
|
||||
import com.mogo.map.impl.amap.utils.MapStyleUtils;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* @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 = 0;
|
||||
|
||||
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() );
|
||||
mRouteOverLay.setRouteOverlayOptions( MapStyleUtils.getRouteOverlayOptions() );
|
||||
mRouteOverLay.setTrafficLine( true );
|
||||
mRouteOverLay.setRouteOverlayVisible( true );
|
||||
mRouteOverLay.setTrafficLightsVisible( true );
|
||||
mRouteOverLay.setArrowOnRoute( true );
|
||||
mRouteOverLay.setZindex( mZIndex );
|
||||
mRouteOverLay.setNaviArrowVisible( true );
|
||||
mRouteOverLay.setLightsVisible( true );
|
||||
mRouteOverLay.setTrafficLightsVisible( mIsTrafficLightsVisible );
|
||||
|
||||
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 ) {
|
||||
Log.d( TAG, "updatePolyline" );
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
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.GeocodeResult;
|
||||
import com.amap.api.services.geocoder.GeocodeSearch;
|
||||
import com.amap.api.services.geocoder.RegeocodeAddress;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-19
|
||||
* <p>
|
||||
* 地理编码/逆地理编码高德实现
|
||||
*/
|
||||
public class GeocodeSearchClient implements IMogoGeoSearch, GeocodeSearch.OnGeocodeSearchListener {
|
||||
|
||||
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 ) {
|
||||
mClient.getFromLocationAsyn( ObjectUtils.fromMogo( query ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getFromLocationNameAsyn( MogoGeocodeQuery query ) {
|
||||
if ( mClient != null ) {
|
||||
mClient.getFromLocationNameAsyn( ObjectUtils.fromMogo( query ) );
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
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 ) {
|
||||
mogoTips.add( mogoTip );
|
||||
}
|
||||
}
|
||||
}
|
||||
return mogoTips;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
mClient = null;
|
||||
mListener = null;
|
||||
mQuery = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.mogo.map.impl.amap.uicontroller;
|
||||
|
||||
import com.mogo.map.MogoMap;
|
||||
import com.mogo.map.uicontroller.EnumMapUI;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* @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() {
|
||||
try {
|
||||
mClient = MogoMap.getInstance().getMogoMap().getUIController();
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, "获取UI控制实例失败", e );
|
||||
}
|
||||
}
|
||||
|
||||
public static AMapUIController getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( AMapUIController.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new AMapUIController();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTrafficEnabled( boolean visible ) {
|
||||
if ( mClient != null ) {
|
||||
mClient.setTrafficEnabled( visible );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeZoom( boolean zoom ) {
|
||||
if ( mClient != null ) {
|
||||
mClient.changeZoom( zoom );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeMapMode( EnumMapUI mode ) {
|
||||
if ( mClient != null ) {
|
||||
mClient.changeMapMode( mode );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveToCurrentLocation() {
|
||||
if ( mClient != null ) {
|
||||
mClient.moveToCurrentLocation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMyLocation( boolean visible ) {
|
||||
if ( mClient != null ) {
|
||||
mClient.showMyLocation( visible );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recoverLockMode() {
|
||||
if ( mClient != null ) {
|
||||
mClient.recoverLockMode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayOverview() {
|
||||
if ( mClient != null ) {
|
||||
mClient.displayOverview();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.mogo.map.impl.amap.utils;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.amap.api.navi.model.RouteOverlayOptions;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-10-04
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class MapStyleUtils {
|
||||
|
||||
enum ColorEnum {
|
||||
route_overlay_line_normal( Color.parseColor( "#7AD9B4" ) ),
|
||||
route_overlay_line_unknown( Color.parseColor( "#3CD26E" ) ),
|
||||
route_overlay_line_slow( Color.parseColor( "#EFCC7A" ) ),
|
||||
route_overlay_line_very_traffic( Color.parseColor( "#E16262" ) ),
|
||||
route_overlay_line_traffic( Color.parseColor( "#E88181" ) ),
|
||||
transparent( Color.parseColor( "#00000000" ) ),
|
||||
light_gray( Color.parseColor( "#CDD8FF" ) );
|
||||
|
||||
private int color;
|
||||
|
||||
ColorEnum( int color ) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
public static RouteOverlayOptions getRouteOverlayOptions() {
|
||||
RouteOverlayOptions options = new RouteOverlayOptions();
|
||||
// 设置导航线路的宽度
|
||||
options.setLineWidth( 32 );
|
||||
// 设置交通状况情况良好下的纹理位图
|
||||
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() ) );
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,619 @@
|
||||
package com.mogo.map.impl.amap.utils;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
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.LatLng;
|
||||
import com.amap.api.maps.model.MarkerOptions;
|
||||
import com.amap.api.maps.model.Poi;
|
||||
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.map.MogoLatLng;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.map.model.MogoPoi;
|
||||
import com.mogo.map.navi.MogoNaviInfo;
|
||||
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 java.util.ArrayList;
|
||||
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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
return new MarkerOptions()
|
||||
.position( new LatLng( opt.getLatitude(), opt.getLongitude() ) )
|
||||
.title( opt.getTitle() )
|
||||
.snippet( opt.getSnippet() )
|
||||
.icon( BitmapDescriptorFactory.fromBitmap( opt.getIcon() ) )
|
||||
.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() );
|
||||
}
|
||||
|
||||
|
||||
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.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.lng );
|
||||
}
|
||||
|
||||
public static MogoLatLng fromAMap( LatLonPoint point ) {
|
||||
if ( point == null ) {
|
||||
return null;
|
||||
}
|
||||
return new MogoLatLng( point.getLatitude(), point.getLongitude() );
|
||||
}
|
||||
|
||||
public static MogoLatLng fromAMap( 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( 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.setIconType( naviInfo.getIconType() );
|
||||
mogoNaviInfo.setNextRoadName( naviInfo.getNextRoadName() );
|
||||
mogoNaviInfo.setPathRetainDistance( naviInfo.getPathRetainDistance() );
|
||||
mogoNaviInfo.setPathRetainTime( naviInfo.getPathRetainTime() );
|
||||
return mogoNaviInfo;
|
||||
}
|
||||
}
|
||||
3
libraries/map-amap/src/main/res/values/strings.xml
Normal file
3
libraries/map-amap/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">map-amap</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.mogo.map.impl.amap;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() {
|
||||
assertEquals( 4, 2 + 2 );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user