opt: main page, add polyline api, add back to launcher logic; bugfix: map resume when back to mainactivity
This commit is contained in:
@@ -7,6 +7,7 @@ import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.os.Trace;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.animation.Interpolator;
|
||||
@@ -319,7 +320,9 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
@Override
|
||||
public void onLockMap( boolean isLock ) {
|
||||
Logger.d( TAG, "lock status = %s", isLock );
|
||||
Trace.beginSection( "timer.onCameraChangeFinish" );
|
||||
MogoMapListenerHandler.getInstance().onLockMap( isLock );
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -418,7 +421,6 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean checkAMapView() {
|
||||
if ( mMapView == null ) {
|
||||
Logger.e( TAG, "高德mapView实例为空,请检查" );
|
||||
@@ -549,17 +551,19 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
@Override
|
||||
public void onCameraChangeFinish( CameraPosition cameraPosition ) {
|
||||
if ( cameraPosition != null ) {
|
||||
MogoMapListenerHandler.getInstance()
|
||||
.onMapChanged( ObjectUtils.fromAMap( cameraPosition.target ), cameraPosition.zoom,
|
||||
cameraPosition.tilt, cameraPosition.bearing );
|
||||
Trace.beginSection( "timer.onCameraChangeFinish" );
|
||||
MogoMapListenerHandler.getInstance().onMapChanged( ObjectUtils.fromAMap( cameraPosition.target ),
|
||||
cameraPosition.zoom,
|
||||
cameraPosition.tilt,
|
||||
cameraPosition.bearing );
|
||||
Trace.endSection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getCameraNorthEastPosition() {
|
||||
try {
|
||||
return ObjectUtils.fromAMap(
|
||||
mMapView.getMap().getProjection().getVisibleRegion().latLngBounds.northeast );
|
||||
return ObjectUtils.fromAMap( mMapView.getMap().getProjection().getVisibleRegion().latLngBounds.northeast );
|
||||
} catch ( Exception e ) {
|
||||
|
||||
}
|
||||
@@ -569,8 +573,7 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
@Override
|
||||
public MogoLatLng getCameraSouthWestPosition() {
|
||||
try {
|
||||
return ObjectUtils.fromAMap(
|
||||
mMapView.getMap().getProjection().getVisibleRegion().latLngBounds.southwest );
|
||||
return ObjectUtils.fromAMap( mMapView.getMap().getProjection().getVisibleRegion().latLngBounds.southwest );
|
||||
} catch ( Exception e ) {
|
||||
|
||||
}
|
||||
|
||||
@@ -6,16 +6,21 @@ import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.CameraUpdateFactory;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.amap.api.maps.model.MarkerOptions;
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.maps.model.PolylineOptions;
|
||||
import com.amap.api.navi.AMapNaviView;
|
||||
import com.mogo.map.IMogoMap;
|
||||
import com.mogo.map.IMogoUiSettings;
|
||||
import com.mogo.map.impl.amap.marker.AMapInfoWindowAdapter;
|
||||
import com.mogo.map.impl.amap.marker.AMapMarkerWrapper;
|
||||
import com.mogo.map.impl.amap.overlay.AMapPolylineWrapper;
|
||||
import com.mogo.map.impl.amap.uicontroller.AMapUIController;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.map.marker.MogoMarkersHandler;
|
||||
import com.mogo.map.overlay.IMogoPolyline;
|
||||
import com.mogo.map.overlay.MogoPolylineOptions;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
@@ -219,6 +224,19 @@ public class AMapWrapper implements IMogoMap {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoPolyline addPolyline( MogoPolylineOptions options ) {
|
||||
if ( checkAMap() ) {
|
||||
PolylineOptions polylineOptions = ObjectUtils.fromMogo( options );
|
||||
if ( polylineOptions == null ) {
|
||||
return null;
|
||||
}
|
||||
Polyline polyline = mAMap.addPolyline( polylineOptions );
|
||||
return new AMapPolylineWrapper( polyline, options );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean checkAMap() {
|
||||
if ( mAMap == null ) {
|
||||
Logger.e( TAG, "高德map实例为空,请检查" );
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mogo.map.impl.amap.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Trace;
|
||||
|
||||
import com.amap.api.location.AMapLocation;
|
||||
import com.amap.api.location.AMapLocationClient;
|
||||
@@ -139,6 +140,7 @@ public class ALocationClient implements IMogoLocationClient {
|
||||
aMapLocation.getLongitude() == 0.0D ) {
|
||||
return;
|
||||
}
|
||||
Trace.beginSection("timer.onLocationChanged");
|
||||
mLastLocation = ObjectUtils.fromAMap( aMapLocation );
|
||||
synchronized ( sListeners ) {
|
||||
Iterator< IMogoLocationListener > listenerIterator = sListeners.iterator();
|
||||
@@ -146,6 +148,7 @@ public class ALocationClient implements IMogoLocationClient {
|
||||
listenerIterator.next().onLocationChanged( mLastLocation.clone() );
|
||||
}
|
||||
}
|
||||
Trace.endSection();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mogo.map.impl.amap.navi;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Trace;
|
||||
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.navi.AMapNavi;
|
||||
@@ -178,8 +179,10 @@ public class NaviListenerAdapter extends AMapNaviListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void onNaviInfoUpdate( NaviInfo naviInfo ) {
|
||||
Trace.beginSection( "NaviListenerAdapter.onNaviInfoUpdate" );
|
||||
MogoNaviListenerHandler.getInstance().onNaviInfoUpdate( ObjectUtils.fromAMap( mContext, naviInfo ) );
|
||||
mNaviOverlayHelper.handleNaviInfoUpdate( naviInfo );
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -201,8 +204,10 @@ public class NaviListenerAdapter extends AMapNaviListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void onLocationChange( AMapNaviLocation aMapNaviLocation ) {
|
||||
Trace.beginSection( "NaviListenerAdapter.onLocationChange" );
|
||||
super.onLocationChange( aMapNaviLocation );
|
||||
mNaviOverlayHelper.handlePassedLocation( aMapNaviLocation );
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
public void stopNavi() {
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
package com.mogo.map.impl.amap.overlay;
|
||||
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.maps.model.PolylineOptions;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.overlay.IMogoPolyline;
|
||||
import com.mogo.map.overlay.MogoPolylineOptions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-03-10
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class AMapPolylineWrapper implements IMogoPolyline {
|
||||
|
||||
private Polyline mPolyline;
|
||||
private MogoPolylineOptions mOptions;
|
||||
private boolean mIsDestroyed = false;
|
||||
|
||||
public AMapPolylineWrapper( Polyline mPolyline,
|
||||
MogoPolylineOptions mOptions ) {
|
||||
this.mPolyline = mPolyline;
|
||||
this.mOptions = mOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.remove();
|
||||
}
|
||||
mIsDestroyed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
if ( mPolyline != null ) {
|
||||
return mPolyline.getId();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPoints( List< MogoLatLng > lonLats ) {
|
||||
if ( lonLats == null || lonLats.isEmpty() ) {
|
||||
mPolyline.setPoints( new ArrayList< LatLng >() );
|
||||
return;
|
||||
}
|
||||
ArrayList< LatLng > points = new ArrayList<>();
|
||||
for ( MogoLatLng lonLat : lonLats ) {
|
||||
LatLng latLng = ObjectUtils.fromMogo2( lonLat );
|
||||
if ( latLng == null ) {
|
||||
continue;
|
||||
}
|
||||
points.add( latLng );
|
||||
}
|
||||
mPolyline.setPoints( points );
|
||||
}
|
||||
|
||||
@Override
|
||||
public List< MogoLatLng > getPoints() {
|
||||
if ( mPolyline == null ) {
|
||||
return null;
|
||||
}
|
||||
ArrayList< MogoLatLng > lonLats = new ArrayList<>();
|
||||
List< LatLng > points = mPolyline.getPoints();
|
||||
if ( points != null ) {
|
||||
for ( LatLng latLng : points ) {
|
||||
MogoLatLng lonLat = ObjectUtils.fromAMap( latLng );
|
||||
if ( lonLat == null ) {
|
||||
continue;
|
||||
}
|
||||
lonLats.add( lonLat );
|
||||
}
|
||||
}
|
||||
return lonLats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGeodesic( boolean draw ) {
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.setGeodesic( draw );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGeodesic() {
|
||||
return mPolyline == null ? false : mPolyline.isGeodesic();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDottedLine( boolean dottedLine ) {
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.setDottedLine( dottedLine );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDottedLine() {
|
||||
return mPolyline == null ? false : mPolyline.isDottedLine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidth( float width ) {
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.setWidth( width );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWidth() {
|
||||
if ( mPolyline != null ) {
|
||||
return mPolyline.getWidth();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor( int color ) {
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.setColor( color );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
if ( mPolyline != null ) {
|
||||
return mPolyline.getColor();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setZIndex( float zIndex ) {
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.setZIndex( zIndex );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getZIndex() {
|
||||
if ( mPolyline != null ) {
|
||||
return mPolyline.getZIndex();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible( boolean visible ) {
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.setVisible( visible );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
if ( mPolyline != null ) {
|
||||
return mPolyline.isVisible();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransparency( float transparency ) {
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.setTransparency( transparency );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOption( MogoPolylineOptions option ) {
|
||||
PolylineOptions target = ObjectUtils.fromMogo( option );
|
||||
if ( target == null ) {
|
||||
return;
|
||||
}
|
||||
mOptions = option;
|
||||
if ( mPolyline != null ) {
|
||||
mPolyline.setOptions( target );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDestroyed() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ 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.maps.model.PolylineOptions;
|
||||
import com.amap.api.navi.model.AMapCongestionLink;
|
||||
import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
|
||||
import com.amap.api.navi.model.AimLessModeCongestionInfo;
|
||||
@@ -46,6 +47,7 @@ import com.mogo.map.navi.MogoCongestionLink;
|
||||
import com.mogo.map.navi.MogoNaviInfo;
|
||||
import com.mogo.map.navi.MogoNaviListenerHandler;
|
||||
import com.mogo.map.navi.MogoTraffic;
|
||||
import com.mogo.map.overlay.MogoPolylineOptions;
|
||||
import com.mogo.map.search.geo.MogoAoiItem;
|
||||
import com.mogo.map.search.geo.MogoBusinessArea;
|
||||
import com.mogo.map.search.geo.MogoCrossroad;
|
||||
@@ -704,4 +706,31 @@ public class ObjectUtils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PolylineOptions fromMogo( MogoPolylineOptions options ) {
|
||||
if ( options == null ) {
|
||||
return null;
|
||||
}
|
||||
PolylineOptions target = new PolylineOptions();
|
||||
if ( options.getPoints() != null ) {
|
||||
List< LatLng > points = new ArrayList<>();
|
||||
for ( MogoLatLng point : options.getPoints() ) {
|
||||
points.add( fromMogo2( point ) );
|
||||
}
|
||||
target.addAll( points );
|
||||
}
|
||||
target.width( options.getWidth() );
|
||||
target.color( options.getColor() );
|
||||
target.zIndex( options.getWidth() );
|
||||
target.visible( options.isVisible() );
|
||||
target.geodesic( options.isGeodesic() );
|
||||
target.setDottedLine( options.isDottedLine() );
|
||||
target.useGradient( options.isGradient() );
|
||||
target.transparency( options.getTransparency() );
|
||||
target.aboveMaskLayer( options.isAboveMaskLayer() );
|
||||
target.lineCapType( PolylineOptions.LineCapType.LineCapRound );
|
||||
target.lineJoinType( PolylineOptions.LineJoinType.LineJoinRound );
|
||||
target.setDottedLineType( PolylineOptions.DOTTEDLINE_TYPE_CIRCLE );
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user