add api
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.mogo.launcher">
|
package="com.mogo.launcher">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".MogoApplication"
|
android:name=".MogoApplication"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import com.mogo.map.search.poisearch.IMogoPoiSearch;
|
|||||||
import com.mogo.map.search.poisearch.IMogoPoiSearchListener;
|
import com.mogo.map.search.poisearch.IMogoPoiSearchListener;
|
||||||
import com.mogo.map.search.poisearch.MogoPoiResult;
|
import com.mogo.map.search.poisearch.MogoPoiResult;
|
||||||
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
|
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
|
||||||
|
import com.mogo.module.common.MogoModulePaths;
|
||||||
import com.mogo.service.MogoServicePaths;
|
import com.mogo.service.MogoServicePaths;
|
||||||
import com.mogo.service.module.IMogoModuleLifecycle;
|
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||||
import com.mogo.service.map.IMogoMapService;
|
import com.mogo.service.map.IMogoMapService;
|
||||||
@@ -45,7 +46,7 @@ import java.util.Random;
|
|||||||
* @author congtaowang
|
* @author congtaowang
|
||||||
* @since 2019-12-24
|
* @since 2019-12-24
|
||||||
* <p>
|
* <p>
|
||||||
* 描述
|
* 描述:demo测试各种接口
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > >
|
public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > >
|
||||||
@@ -63,6 +64,7 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView >
|
|||||||
|
|
||||||
private Bitmap mMarkerIcon;
|
private Bitmap mMarkerIcon;
|
||||||
private Bitmap mClickedMarkerIcon;
|
private Bitmap mClickedMarkerIcon;
|
||||||
|
private TextView mLocInfo;
|
||||||
private TextView mLoc;
|
private TextView mLoc;
|
||||||
|
|
||||||
private IMogoMarker mLastClickedMarker;
|
private IMogoMarker mLastClickedMarker;
|
||||||
@@ -71,6 +73,8 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView >
|
|||||||
private IMogoPoiSearch mPoiSearch;
|
private IMogoPoiSearch mPoiSearch;
|
||||||
private IMogoLocationClient mLocationClient;
|
private IMogoLocationClient mLocationClient;
|
||||||
|
|
||||||
|
private DemoInfoWindowAdapter mDemoInfoWindowAdapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getLayoutId() {
|
protected int getLayoutId() {
|
||||||
return R.layout.demo_module_card_view;
|
return R.layout.demo_module_card_view;
|
||||||
@@ -84,9 +88,19 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView >
|
|||||||
mPoiSearch.setPoiSearchListener( this );
|
mPoiSearch.setPoiSearchListener( this );
|
||||||
mLocationClient = mMapService.getSingletonLocationClient( getContext() );
|
mLocationClient = mMapService.getSingletonLocationClient( getContext() );
|
||||||
mLocationClient.addLocationListener( this );
|
mLocationClient.addLocationListener( this );
|
||||||
mLocationClient.start( 1_000L );
|
|
||||||
|
|
||||||
|
mLocInfo = findViewById( R.id.demo_module_id_loc_info );
|
||||||
mLoc = findViewById( R.id.demo_module_id_loc );
|
mLoc = findViewById( R.id.demo_module_id_loc );
|
||||||
|
mLoc.setOnClickListener(
|
||||||
|
new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick( View v ) {
|
||||||
|
mLocationClient.start( 1_000L );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
mDemoInfoWindowAdapter = new DemoInfoWindowAdapter( getContext() );
|
||||||
|
|
||||||
mMarkerIcon = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher );
|
mMarkerIcon = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher );
|
||||||
mClickedMarkerIcon = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher_round );
|
mClickedMarkerIcon = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher_round );
|
||||||
@@ -94,12 +108,12 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView >
|
|||||||
mAddMarker.setOnClickListener( new View.OnClickListener() {
|
mAddMarker.setOnClickListener( new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick( View v ) {
|
public void onClick( View v ) {
|
||||||
IMogoMapService ims = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation();
|
|
||||||
MogoMarkerOptions options = new MogoMarkerOptions()
|
MogoMarkerOptions options = new MogoMarkerOptions()
|
||||||
.icon( mMarkerIcon )
|
.icon( mMarkerIcon )
|
||||||
.latitude( 39.974525d )
|
.latitude( 39.974525d )
|
||||||
.longitude( 116.41733d );
|
.longitude( 116.41733d );
|
||||||
IMogoMarker marker = ims.addMarker( options );
|
IMogoMarker marker = mMapService.addMarker( DemoConstants.TAG, options );
|
||||||
|
marker.setInfoWindowAdapter( mDemoInfoWindowAdapter );
|
||||||
marker.setOnMarkerClickListener( DemoCardViewFragment.this );
|
marker.setOnMarkerClickListener( DemoCardViewFragment.this );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
@@ -107,22 +121,29 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView >
|
|||||||
mAddMarkers.setOnClickListener( new View.OnClickListener() {
|
mAddMarkers.setOnClickListener( new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick( View v ) {
|
public void onClick( View v ) {
|
||||||
IMogoMapService ims = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation();
|
|
||||||
|
|
||||||
|
ArrayList< MogoMarkerOptions > optionsList = new ArrayList<>();
|
||||||
for ( int i = 0; i < 10; i++ ) {
|
for ( int i = 0; i < 10; i++ ) {
|
||||||
MogoMarkerOptions options = new MogoMarkerOptions()
|
MogoMarkerOptions options = new MogoMarkerOptions()
|
||||||
.icon( mMarkerIcon )
|
.icon( mMarkerIcon )
|
||||||
.latitude( 39.974525d + new Random().nextDouble() )
|
.latitude( 39.974525d + new Random().nextDouble() )
|
||||||
.longitude( 116.41733d + new Random().nextDouble() );
|
.longitude( 116.41733d + new Random().nextDouble() );
|
||||||
List< IMogoMarker > iMogoMarkers = ims.addMarkers( new ArrayList<>( Arrays.asList( options ) ), true );
|
optionsList.add( options );
|
||||||
for ( IMogoMarker iMogoMarker : iMogoMarkers ) {
|
}
|
||||||
iMogoMarker.setOnMarkerClickListener( DemoCardViewFragment.this );
|
List< IMogoMarker > iMogoMarkers = mMapService.addMarkers( DemoConstants.TAG, optionsList, true );
|
||||||
}
|
for ( IMogoMarker iMogoMarker : iMogoMarkers ) {
|
||||||
|
iMogoMarker.setInfoWindowAdapter( mDemoInfoWindowAdapter );
|
||||||
|
iMogoMarker.setOnMarkerClickListener( DemoCardViewFragment.this );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
findViewById( R.id.demo_module_id_clear ).setOnClickListener( new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick( View v ) {
|
||||||
|
mMapService.removeMarkers( DemoConstants.TAG );
|
||||||
|
}
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -138,6 +159,8 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView >
|
|||||||
}
|
}
|
||||||
marker.setIcon( mClickedMarkerIcon );
|
marker.setIcon( mClickedMarkerIcon );
|
||||||
mLastClickedMarker = marker;
|
mLastClickedMarker = marker;
|
||||||
|
|
||||||
|
marker.showInfoWindow();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +230,15 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView >
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged( MogoLocation location ) {
|
public void onLocationChanged( MogoLocation location ) {
|
||||||
|
mLocationClient.stop();
|
||||||
Logger.i( TAG, location.toString() );
|
Logger.i( TAG, location.toString() );
|
||||||
|
if ( mLocInfo != null ) {
|
||||||
|
if ( location.getErrCode() == 0 ) {
|
||||||
|
mLocInfo.setText( "当前位置:" + location.getAddress() );
|
||||||
|
} else {
|
||||||
|
mLocInfo.setText( location.getErrInfo() );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class DemoCardViewProvider implements IMogoModuleProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModuleName() {
|
public String getModuleName() {
|
||||||
return MogoModulePaths.PATH_MODULE_DEMO;
|
return DemoConstants.TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.mogo.demo.module.map;
|
||||||
|
|
||||||
|
import com.mogo.module.common.MogoModulePaths;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-24
|
||||||
|
* <p>
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
public class DemoConstants {
|
||||||
|
|
||||||
|
public static final String TAG = MogoModulePaths.PATH_MODULE_DEMO;
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.mogo.demo.module.map;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.mogo.map.marker.IMogoInfoWindowAdapter;
|
||||||
|
import com.mogo.map.marker.IMogoMarker;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-24
|
||||||
|
* <p>
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
public class DemoInfoWindowAdapter implements IMogoInfoWindowAdapter {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
public DemoInfoWindowAdapter( Context mContext ) {
|
||||||
|
this.mContext = mContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getInfoWindow( IMogoMarker marker ) {
|
||||||
|
View view = LayoutInflater.from( mContext ).inflate( R.layout.demo_module_demo_info_window, null );
|
||||||
|
renderView( view, marker );
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderView( View view, final IMogoMarker marker ) {
|
||||||
|
final TextView time = view.findViewById( R.id.demo_module_id_iw_time );
|
||||||
|
Button refresh = view.findViewById( R.id.demo_module_id_iw_refresh );
|
||||||
|
time.setText( new SimpleDateFormat( "yyyyMMdd HHMMSS" ).format( new Date() ) );
|
||||||
|
refresh.setOnClickListener( new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick( View v ) {
|
||||||
|
marker.showInfoWindow();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
android:background="#ff0000">
|
android:background="#ff0000">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/demo_module_id_loc"
|
android:id="@+id/demo_module_id_loc_info"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
android:layout_width="200dp"
|
android:layout_width="200dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="添加一个覆盖物"
|
android:text="添加一个覆盖物"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
@@ -28,9 +27,28 @@
|
|||||||
android:id="@+id/demo_module_id_add_markers"
|
android:id="@+id/demo_module_id_add_markers"
|
||||||
android:layout_width="200dp"
|
android:layout_width="200dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="75dp"
|
android:layout_marginTop="50dp"
|
||||||
android:text="添加多个覆盖物"
|
android:text="添加多个覆盖物"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/demo_module_id_loc"
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="100dp"
|
||||||
|
android:text="定位"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/demo_module_id_clear"
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="100dp"
|
||||||
|
android:text="清空覆盖物"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="#ff0000">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/demo_module_id_iw_time"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/demo_module_id_iw_refresh"
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:text="点击刷新当前时间"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -1,2 +1,15 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.mogo.map" />
|
package="com.mogo.map">
|
||||||
|
<!--允许程序打开网络套接字-->
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<!--允许程序设置内置sd卡的写权限-->
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
<!--允许程序获取网络状态-->
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<!--允许程序访问WiFi网络信息-->
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
|
<!--允许程序读写手机状态和身份-->
|
||||||
|
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||||
|
<!--允许程序访问CellID或WiFi热点来获取粗略的位置-->
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
|
</manifest>
|
||||||
|
|||||||
@@ -23,19 +23,21 @@ public interface IMogoMap {
|
|||||||
/**
|
/**
|
||||||
* 在地图上添一个图片标记(marker)对象。
|
* 在地图上添一个图片标记(marker)对象。
|
||||||
*
|
*
|
||||||
|
* @param tag 标识服务
|
||||||
* @param options
|
* @param options
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
IMogoMarker addMarker( MogoMarkerOptions options );
|
IMogoMarker addMarker( String tag, MogoMarkerOptions options );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在地图上添一组图片标记(marker)对象,并设置是否改变地图状态以至于所有的marker对象都在当前地图可视区域范围内显示。
|
* 在地图上添一组图片标记(marker)对象,并设置是否改变地图状态以至于所有的marker对象都在当前地图可视区域范围内显示。
|
||||||
*
|
*
|
||||||
|
* @param tag 标识服务
|
||||||
* @param options
|
* @param options
|
||||||
* @param moveToCenter
|
* @param moveToCenter
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ArrayList< IMogoMarker > addMarkers( ArrayList< MogoMarkerOptions > options, boolean moveToCenter );
|
ArrayList< IMogoMarker > addMarkers( String tag, ArrayList< MogoMarkerOptions > options, boolean moveToCenter );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从地图上删除所有的overlay(marker,circle,polyline 等对象)。
|
* 从地图上删除所有的overlay(marker,circle,polyline 等对象)。
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class AMapUiSettingsWrapper implements IUiSettings {
|
|||||||
public void setLogoEnable( boolean enabled ) {
|
public void setLogoEnable( boolean enabled ) {
|
||||||
if ( mUiSettings != null ) {
|
if ( mUiSettings != null ) {
|
||||||
try {
|
try {
|
||||||
Method method = mUiSettings.getClass().getMethod( "setLogoEnable", Boolean.class );
|
Method method = mUiSettings.getClass().getMethod( "setLogoEnable", boolean.class );
|
||||||
method.setAccessible( true );
|
method.setAccessible( true );
|
||||||
method.invoke( mUiSettings, enabled );
|
method.invoke( mUiSettings, enabled );
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ package com.mogo.map.amap;
|
|||||||
import com.amap.api.maps.AMap;
|
import com.amap.api.maps.AMap;
|
||||||
import com.amap.api.maps.model.Marker;
|
import com.amap.api.maps.model.Marker;
|
||||||
import com.amap.api.maps.model.MarkerOptions;
|
import com.amap.api.maps.model.MarkerOptions;
|
||||||
import com.amap.api.maps.model.Poi;
|
|
||||||
import com.mogo.map.IMogoMap;
|
import com.mogo.map.IMogoMap;
|
||||||
import com.mogo.map.IUiSettings;
|
import com.mogo.map.IUiSettings;
|
||||||
|
import com.mogo.map.amap.marker.AMapInfoWindowAdapter;
|
||||||
import com.mogo.map.amap.marker.AMapMarkerWrapper;
|
import com.mogo.map.amap.marker.AMapMarkerWrapper;
|
||||||
import com.mogo.map.amap.utils.ObjectUtils;
|
import com.mogo.map.amap.utils.ObjectUtils;
|
||||||
import com.mogo.map.marker.IMogoMarker;
|
import com.mogo.map.marker.IMogoMarker;
|
||||||
import com.mogo.map.marker.MogoMarkerOptions;
|
import com.mogo.map.marker.MogoMarkerOptions;
|
||||||
import com.mogo.utils.TipToast;
|
import com.mogo.map.marker.MogoMarkersHandler;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@@ -27,6 +27,8 @@ public class AMapWrapper implements IMogoMap {
|
|||||||
|
|
||||||
public AMapWrapper( AMap map ) {
|
public AMapWrapper( AMap map ) {
|
||||||
this.mAMap = map;
|
this.mAMap = map;
|
||||||
|
// 设置实现自定义 info window
|
||||||
|
mAMap.setInfoWindowAdapter( new AMapInfoWindowAdapter() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -38,7 +40,7 @@ public class AMapWrapper implements IMogoMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMogoMarker addMarker( MogoMarkerOptions options ) {
|
public IMogoMarker addMarker( String tag, MogoMarkerOptions options ) {
|
||||||
if ( mAMap == null ) {
|
if ( mAMap == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -46,12 +48,13 @@ public class AMapWrapper implements IMogoMap {
|
|||||||
if ( markerOptions == null ) {
|
if ( markerOptions == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new AMapMarkerWrapper( mAMap.addMarker( markerOptions ) );
|
final IMogoMarker mogoMarker = new AMapMarkerWrapper( mAMap.addMarker( markerOptions ) );
|
||||||
|
MogoMarkersHandler.getInstance().add( tag, mogoMarker );
|
||||||
|
return mogoMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList< IMogoMarker > addMarkers( ArrayList< MogoMarkerOptions > options, boolean moveToCenter ) {
|
public ArrayList< IMogoMarker > addMarkers( String tag, ArrayList< MogoMarkerOptions > options, boolean moveToCenter ) {
|
||||||
|
|
||||||
if ( mAMap == null ) {
|
if ( mAMap == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -87,6 +90,7 @@ public class AMapWrapper implements IMogoMap {
|
|||||||
}
|
}
|
||||||
mogoMarkers.add( new AMapMarkerWrapper( marker ) );
|
mogoMarkers.add( new AMapMarkerWrapper( marker ) );
|
||||||
}
|
}
|
||||||
|
MogoMarkersHandler.getInstance().add( tag, mogoMarkers );
|
||||||
return mogoMarkers;
|
return mogoMarkers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ public class LocationClient implements IMogoLocationClient {
|
|||||||
if ( mClient != null ) {
|
if ( mClient != null ) {
|
||||||
mClient.setLocationOption( option );
|
mClient.setLocationOption( option );
|
||||||
}
|
}
|
||||||
|
mClient.startLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.mogo.map.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import com.amap.api.maps.model.LatLng;
|
|||||||
import com.amap.api.maps.model.Marker;
|
import com.amap.api.maps.model.Marker;
|
||||||
import com.amap.api.maps.model.MarkerOptions;
|
import com.amap.api.maps.model.MarkerOptions;
|
||||||
import com.mogo.map.MogoLatLng;
|
import com.mogo.map.MogoLatLng;
|
||||||
|
import com.mogo.map.marker.IMogoInfoWindowAdapter;
|
||||||
import com.mogo.map.marker.IMogoMarker;
|
import com.mogo.map.marker.IMogoMarker;
|
||||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||||
import com.mogo.map.marker.MogoMarkerOptions;
|
import com.mogo.map.marker.MogoMarkerOptions;
|
||||||
@@ -26,10 +27,14 @@ public class AMapMarkerWrapper implements IMogoMarker {
|
|||||||
private Marker mMarker;
|
private Marker mMarker;
|
||||||
private Object mObject;
|
private Object mObject;
|
||||||
private IMogoMarkerClickListener mMogoMarkerClickListener;
|
private IMogoMarkerClickListener mMogoMarkerClickListener;
|
||||||
|
private IMogoInfoWindowAdapter mMogoInfoWindowAdapter;
|
||||||
|
|
||||||
|
private boolean mIsDestroy = false;
|
||||||
|
|
||||||
public AMapMarkerWrapper( Marker mMarker ) {
|
public AMapMarkerWrapper( Marker mMarker ) {
|
||||||
this.mMarker = mMarker;
|
this.mMarker = mMarker;
|
||||||
if ( mMarker != null ) {
|
if ( mMarker != null ) {
|
||||||
|
// 设置高德 marker 的object对象为 IMogoMarker 实例。!!!!
|
||||||
mMarker.setObject( this );
|
mMarker.setObject( this );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,14 +43,18 @@ public class AMapMarkerWrapper implements IMogoMarker {
|
|||||||
public void destroy() {
|
public void destroy() {
|
||||||
if ( mMarker != null ) {
|
if ( mMarker != null ) {
|
||||||
mMarker.destroy();
|
mMarker.destroy();
|
||||||
|
mMarker.setObject( null );
|
||||||
|
mMarker = null;
|
||||||
}
|
}
|
||||||
|
mMogoInfoWindowAdapter = null;
|
||||||
|
mMogoMarkerClickListener = null;
|
||||||
|
mObject = null;
|
||||||
|
mIsDestroy = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if ( mMarker != null ) {
|
destroy();
|
||||||
mMarker.remove();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -216,4 +225,19 @@ public class AMapMarkerWrapper implements IMogoMarker {
|
|||||||
public IMogoMarkerClickListener getOnMarkerClickListener() {
|
public IMogoMarkerClickListener getOnMarkerClickListener() {
|
||||||
return mMogoMarkerClickListener;
|
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,14 @@
|
|||||||
|
package com.mogo.map.marker;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-24
|
||||||
|
* <p>
|
||||||
|
* 自定义 infowindow 适配器
|
||||||
|
*/
|
||||||
|
public interface IMogoInfoWindowAdapter {
|
||||||
|
|
||||||
|
View getInfoWindow( IMogoMarker marker );
|
||||||
|
}
|
||||||
@@ -160,4 +160,15 @@ public interface IMogoMarker {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
IMogoMarkerClickListener getOnMarkerClickListener();
|
IMogoMarkerClickListener getOnMarkerClickListener();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置自定义infowindow代理对象
|
||||||
|
*
|
||||||
|
* @param adapter
|
||||||
|
*/
|
||||||
|
void setInfoWindowAdapter( IMogoInfoWindowAdapter adapter );
|
||||||
|
|
||||||
|
IMogoInfoWindowAdapter getInfoWindowAdapter();
|
||||||
|
|
||||||
|
boolean isDestroyed();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package com.mogo.map.marker;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2019-12-24
|
||||||
|
* <p>
|
||||||
|
* 管理地图上的所有marker
|
||||||
|
*/
|
||||||
|
public class MogoMarkersHandler {
|
||||||
|
|
||||||
|
private static volatile MogoMarkersHandler sInstance;
|
||||||
|
|
||||||
|
public static MogoMarkersHandler getInstance() {
|
||||||
|
if ( sInstance == null ) {
|
||||||
|
synchronized ( MogoMarkersHandler.class ) {
|
||||||
|
if ( sInstance == null ) {
|
||||||
|
sInstance = new MogoMarkersHandler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map< String, List< IMogoMarker > > mServicesMarkers = new HashMap<>();
|
||||||
|
|
||||||
|
private MogoMarkersHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void release() {
|
||||||
|
sInstance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void removeAll() {
|
||||||
|
final Collection< List< IMogoMarker > > mogoMarkers = mServicesMarkers.values();
|
||||||
|
for ( List< IMogoMarker > mogoMarkerList : mogoMarkers ) {
|
||||||
|
if ( mogoMarkerList != null && !mogoMarkerList.isEmpty() ) {
|
||||||
|
for ( IMogoMarker mogoMarker : mogoMarkerList ) {
|
||||||
|
try {
|
||||||
|
mogoMarker.destroy();
|
||||||
|
} catch ( Exception e ) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mServicesMarkers.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void remove( String tag ) {
|
||||||
|
List< IMogoMarker > mogoMarkerList = mServicesMarkers.remove( tag );
|
||||||
|
if ( mogoMarkerList != null && !mogoMarkerList.isEmpty() ) {
|
||||||
|
for ( IMogoMarker mogoMarker : mogoMarkerList ) {
|
||||||
|
try {
|
||||||
|
mogoMarker.destroy();
|
||||||
|
} catch ( Exception e ) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mogoMarkerList.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public synchronized void add( String tag, IMogoMarker marker ) {
|
||||||
|
if ( marker == null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( !mServicesMarkers.containsKey( tag ) ) {
|
||||||
|
mServicesMarkers.put( tag, new ArrayList< IMogoMarker >() );
|
||||||
|
}
|
||||||
|
mServicesMarkers.get( tag ).add( marker );
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add( String tag, List< IMogoMarker > markers ) {
|
||||||
|
if ( markers == null || markers.isEmpty() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( !mServicesMarkers.containsKey( tag ) ) {
|
||||||
|
mServicesMarkers.put( tag, new ArrayList< IMogoMarker >() );
|
||||||
|
}
|
||||||
|
mServicesMarkers.get( tag ).addAll( markers );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,7 +27,7 @@ import java.util.List;
|
|||||||
public interface IMogoMapService extends IProvider, IMogoMapListenerRegister {
|
public interface IMogoMapService extends IProvider, IMogoMapListenerRegister {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取定位服务实例
|
* 获取定位服务实例,全局唯一
|
||||||
*
|
*
|
||||||
* @param context
|
* @param context
|
||||||
* @return
|
* @return
|
||||||
@@ -37,18 +37,20 @@ public interface IMogoMapService extends IProvider, IMogoMapListenerRegister {
|
|||||||
/**
|
/**
|
||||||
* 添加marker
|
* 添加marker
|
||||||
*
|
*
|
||||||
|
* @param tag 标识调用者
|
||||||
* @param options
|
* @param options
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
IMogoMarker addMarker( MogoMarkerOptions options );
|
IMogoMarker addMarker( String tag, MogoMarkerOptions options );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加多个marker
|
* 添加多个marker
|
||||||
*
|
*
|
||||||
|
* @param tag 标识调用者
|
||||||
* @param options
|
* @param options
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List< IMogoMarker > addMarkers( ArrayList< MogoMarkerOptions > options, boolean moveToCenter );
|
List< IMogoMarker > addMarkers( String tag, ArrayList< MogoMarkerOptions > options, boolean moveToCenter );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取关键字搜索地址服务
|
* 获取关键字搜索地址服务
|
||||||
@@ -87,4 +89,16 @@ public interface IMogoMapService extends IProvider, IMogoMapListenerRegister {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
IMogoPoiSearch getPoiSearch( Context context, MogoPoiSearchQuery query );
|
IMogoPoiSearch getPoiSearch( Context context, MogoPoiSearchQuery query );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除某一个类、某个模块的markers
|
||||||
|
*
|
||||||
|
* @param tag
|
||||||
|
*/
|
||||||
|
void removeMarkers( String tag );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除地图上所有markers
|
||||||
|
*/
|
||||||
|
void removeMarkers();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ import com.mogo.map.listener.MogoMapListenerHandler;
|
|||||||
import com.mogo.map.location.IMogoLocationClient;
|
import com.mogo.map.location.IMogoLocationClient;
|
||||||
import com.mogo.map.location.MogoLocationClient;
|
import com.mogo.map.location.MogoLocationClient;
|
||||||
import com.mogo.map.marker.IMogoMarker;
|
import com.mogo.map.marker.IMogoMarker;
|
||||||
|
import com.mogo.map.marker.MogoMarker;
|
||||||
import com.mogo.map.marker.MogoMarkerOptions;
|
import com.mogo.map.marker.MogoMarkerOptions;
|
||||||
|
import com.mogo.map.marker.MogoMarkersHandler;
|
||||||
import com.mogo.map.search.geo.IMogoGeoSearch;
|
import com.mogo.map.search.geo.IMogoGeoSearch;
|
||||||
import com.mogo.map.search.inputtips.IMogoInputtipsSearch;
|
import com.mogo.map.search.inputtips.IMogoInputtipsSearch;
|
||||||
import com.mogo.map.search.geo.MogoGeoSearch;
|
import com.mogo.map.search.geo.MogoGeoSearch;
|
||||||
@@ -39,18 +41,18 @@ public class MogoMapService implements IMogoMapService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMogoMarker addMarker( MogoMarkerOptions options ) {
|
public IMogoMarker addMarker( String tag, MogoMarkerOptions options ) {
|
||||||
try {
|
try {
|
||||||
return MogoMap.getInstance().getMogoMap().addMarker( options );
|
return MogoMap.getInstance().getMogoMap().addMarker( tag, options );
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List< IMogoMarker > addMarkers( ArrayList< MogoMarkerOptions > options, boolean moveToCenter ) {
|
public List< IMogoMarker > addMarkers( String tag, ArrayList< MogoMarkerOptions > options, boolean moveToCenter ) {
|
||||||
try {
|
try {
|
||||||
return MogoMap.getInstance().getMogoMap().addMarkers( options, moveToCenter );
|
return MogoMap.getInstance().getMogoMap().addMarkers( tag, options, moveToCenter );
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -81,6 +83,16 @@ public class MogoMapService implements IMogoMapService {
|
|||||||
return new MogoPoiSearch( context, query );
|
return new MogoPoiSearch( context, query );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeMarkers( String tag ) {
|
||||||
|
MogoMarkersHandler.getInstance().remove( tag );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeMarkers() {
|
||||||
|
MogoMarkersHandler.getInstance().removeAll();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init( Context context ) {
|
public void init( Context context ) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user