add api
This commit is contained in:
@@ -1,2 +1,15 @@
|
||||
<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)对象。
|
||||
*
|
||||
* @param tag 标识服务
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
IMogoMarker addMarker( MogoMarkerOptions options );
|
||||
IMogoMarker addMarker( String tag, MogoMarkerOptions options );
|
||||
|
||||
/**
|
||||
* 在地图上添一组图片标记(marker)对象,并设置是否改变地图状态以至于所有的marker对象都在当前地图可视区域范围内显示。
|
||||
*
|
||||
* @param tag 标识服务
|
||||
* @param options
|
||||
* @param moveToCenter
|
||||
* @return
|
||||
*/
|
||||
ArrayList< IMogoMarker > addMarkers( ArrayList< MogoMarkerOptions > options, boolean moveToCenter );
|
||||
ArrayList< IMogoMarker > addMarkers( String tag, ArrayList< MogoMarkerOptions > options, boolean moveToCenter );
|
||||
|
||||
/**
|
||||
* 从地图上删除所有的overlay(marker,circle,polyline 等对象)。
|
||||
|
||||
@@ -93,7 +93,7 @@ public class AMapUiSettingsWrapper implements IUiSettings {
|
||||
public void setLogoEnable( boolean enabled ) {
|
||||
if ( mUiSettings != null ) {
|
||||
try {
|
||||
Method method = mUiSettings.getClass().getMethod( "setLogoEnable", Boolean.class );
|
||||
Method method = mUiSettings.getClass().getMethod( "setLogoEnable", boolean.class );
|
||||
method.setAccessible( true );
|
||||
method.invoke( mUiSettings, enabled );
|
||||
} catch ( Exception e ) {
|
||||
|
||||
@@ -3,14 +3,14 @@ package com.mogo.map.amap;
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.amap.api.maps.model.MarkerOptions;
|
||||
import com.amap.api.maps.model.Poi;
|
||||
import com.mogo.map.IMogoMap;
|
||||
import com.mogo.map.IUiSettings;
|
||||
import com.mogo.map.amap.marker.AMapInfoWindowAdapter;
|
||||
import com.mogo.map.amap.marker.AMapMarkerWrapper;
|
||||
import com.mogo.map.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.utils.TipToast;
|
||||
import com.mogo.map.marker.MogoMarkersHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -27,6 +27,8 @@ public class AMapWrapper implements IMogoMap {
|
||||
|
||||
public AMapWrapper( AMap map ) {
|
||||
this.mAMap = map;
|
||||
// 设置实现自定义 info window
|
||||
mAMap.setInfoWindowAdapter( new AMapInfoWindowAdapter() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,7 +40,7 @@ public class AMapWrapper implements IMogoMap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoMarker addMarker( MogoMarkerOptions options ) {
|
||||
public IMogoMarker addMarker( String tag, MogoMarkerOptions options ) {
|
||||
if ( mAMap == null ) {
|
||||
return null;
|
||||
}
|
||||
@@ -46,12 +48,13 @@ public class AMapWrapper implements IMogoMap {
|
||||
if ( markerOptions == 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
|
||||
public ArrayList< IMogoMarker > addMarkers( ArrayList< MogoMarkerOptions > options, boolean moveToCenter ) {
|
||||
|
||||
public ArrayList< IMogoMarker > addMarkers( String tag, ArrayList< MogoMarkerOptions > options, boolean moveToCenter ) {
|
||||
if ( mAMap == null ) {
|
||||
return null;
|
||||
}
|
||||
@@ -87,6 +90,7 @@ public class AMapWrapper implements IMogoMap {
|
||||
}
|
||||
mogoMarkers.add( new AMapMarkerWrapper( marker ) );
|
||||
}
|
||||
MogoMarkersHandler.getInstance().add( tag, mogoMarkers );
|
||||
return mogoMarkers;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ public class LocationClient implements IMogoLocationClient {
|
||||
if ( mClient != null ) {
|
||||
mClient.setLocationOption( option );
|
||||
}
|
||||
mClient.startLocation();
|
||||
}
|
||||
|
||||
@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.MarkerOptions;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.marker.IMogoInfoWindowAdapter;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
@@ -26,10 +27,14 @@ public class AMapMarkerWrapper implements IMogoMarker {
|
||||
private Marker mMarker;
|
||||
private Object mObject;
|
||||
private IMogoMarkerClickListener mMogoMarkerClickListener;
|
||||
private IMogoInfoWindowAdapter mMogoInfoWindowAdapter;
|
||||
|
||||
private boolean mIsDestroy = false;
|
||||
|
||||
public AMapMarkerWrapper( Marker mMarker ) {
|
||||
this.mMarker = mMarker;
|
||||
if ( mMarker != null ) {
|
||||
// 设置高德 marker 的object对象为 IMogoMarker 实例。!!!!
|
||||
mMarker.setObject( this );
|
||||
}
|
||||
}
|
||||
@@ -38,14 +43,18 @@ public class AMapMarkerWrapper implements IMogoMarker {
|
||||
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() {
|
||||
if ( mMarker != null ) {
|
||||
mMarker.remove();
|
||||
}
|
||||
destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -216,4 +225,19 @@ public class AMapMarkerWrapper implements IMogoMarker {
|
||||
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,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
|
||||
*/
|
||||
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 );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user