增加自动缩放接口

This commit is contained in:
jiaguofeng
2020-06-22 19:40:57 +08:00
parent 1a1bdc7a94
commit a407383baf
2 changed files with 93 additions and 83 deletions

View File

@@ -34,6 +34,10 @@ import com.zhidaoauto.map.sdk.open.abs.OnMapClickListener;
import com.zhidaoauto.map.sdk.open.abs.OnMapLoadedListener;
import com.zhidaoauto.map.sdk.open.abs.OnMapTouchListener;
import com.zhidaoauto.map.sdk.open.camera.CameraPosition;
import com.zhidaoauto.map.sdk.open.camera.CameraUpdate;
import com.zhidaoauto.map.sdk.open.camera.CameraUpdateFactory;
import com.zhidaoauto.map.sdk.open.camera.LatLngBounds;
import com.zhidaoauto.map.sdk.open.camera.MapCameraMessage;
import com.zhidaoauto.map.sdk.open.location.LocationListener;
import com.zhidaoauto.map.sdk.open.location.MyLocationStyle;
import com.zhidaoauto.map.sdk.open.marker.BitmapDescriptorFactory;
@@ -548,14 +552,15 @@ public class AMapViewWrapper implements IMogoMapView, IMogoMapUIController, Loca
return;
}
try {
// if ( DebugConfig.isDebug() ) {
// Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
// }
// LatLngBounds latLngBounds = MogoMapUtils.getLatLngBounds( carPosition, lonLats, lockCarPosition );
// if ( !lockCarPosition ) {
// loseLockMode();
// }
// mMapView.getMapAutoViewHelper().moveCamera( new CameraUpdate(new MapCameraMessage( latLngBounds, bound.left, bound.right, bound.top, bound.bottom ) ));
if ( DebugConfig.isDebug() ) {
Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
}
LatLngBounds latLngBounds = MogoMapUtils.getLatLngBounds( carPosition, lonLats, lockCarPosition );
if ( !lockCarPosition ) {
loseLockMode();
}
mMapView.getMapAutoViewHelper().setLocation(ObjectUtils.fromMogo(carPosition));
mMapView.getMapAutoViewHelper().moveCamera( CameraUpdateFactory.INSTANCE.newLatLngBounds( latLngBounds, bound.left, bound.right, bound.top, bound.bottom ) );
} catch (Exception e) {
Logger.e(TAG, e, "%s error.", tag);
}

View File

@@ -1,7 +1,14 @@
package com.mogo.map.impl.custom.utils;
import android.util.Log;
import com.mogo.map.MogoLatLng;
import com.mogo.map.exception.MogoMapException;
import com.zhidaoauto.map.sdk.open.camera.LatLngBounds;
import com.zhidaoauto.map.sdk.open.query.LonLatPoint;
import java.util.List;
/**
* @author congtaowang
* @since 2020-03-04
@@ -12,81 +19,79 @@ public class MogoMapUtils {
private static final String TAG = "MogoMapUtils";
// public static LatLngBounds getLatLngBounds( MogoLatLng carPosition, List< MogoLatLng > lonLats, boolean lockCarPosition ) throws Exception {
//
// if ( lonLats == null || lonLats.isEmpty() ) {
// throw new MogoMapException( "经纬度不能为null或空集合" );
// }
// LatLngBounds.Builder builder = new LatLngBounds.Builder();
// for ( MogoLatLng lonLat : lonLats ) {
// builder.include( ObjectUtils.fromMogo2( lonLat ) );
// }
// if ( carPosition != null && !lockCarPosition ) {
// builder.include( ObjectUtils.fromMogo2( carPosition ) );
// }
// LatLngBounds latLngBounds = builder.build();
// if ( !lockCarPosition ) {
// return latLngBounds;
// }
//
// if ( carPosition == null ) {
// throw new MogoMapException( "自车位置经纬度信息不能为空" );
// }
//
// if ( latLngBounds.northeast == null && latLngBounds.southwest == null ) {
// return null;
// }
//
// double south = 0.0;
// double west = 0.0;
//
// double east = 0.0;
// double north = 0.0;
//
// double dLat = 0.0;
// double dLon = 0.0;
//
// if ( latLngBounds.northeast == null ) {
// dLat = Math.abs( carPosition.lat - latLngBounds.southwest.latitude );
// dLon = Math.abs( carPosition.lng - latLngBounds.southwest.longitude );
// } else if ( latLngBounds.southwest == null ) {
// dLat = Math.abs( carPosition.lat - latLngBounds.northeast.latitude );
// dLon = Math.abs( carPosition.lng - latLngBounds.northeast.longitude );
// } else {
// final double dLat1 = Math.abs( carPosition.lat - latLngBounds.southwest.latitude );
// final double dLon1 = Math.abs( carPosition.lng - latLngBounds.southwest.longitude );
// final double dLat2 = Math.abs( carPosition.lat - latLngBounds.northeast.latitude );
// final double dLon2 = Math.abs( carPosition.lng - latLngBounds.northeast.longitude );
// dLat = dLat1 > dLat2 ? dLat1 : dLat2;
// dLon = dLon1 > dLon2 ? dLon1 : dLon2;
// }
//
// west = carPosition.lat - dLat;
// south = carPosition.lng + dLon;
//
// east = carPosition.lat + dLat;
// north = carPosition.lng - dLon;
//
// if ( south == 0.0 || west == 0.0 || east == 0.0 || north == 0.0 ) {
// return null;
// }
//
// if ( east < west ) {
// double tmp = east;
// east = west;
// west = tmp;
// }
//
// if( north < south ){
// double tmp = north;
// north = south;
// south = tmp;
// }
//
// Logger.d( TAG, "west = %s, east = %s, north = %s, south = %s", west, east, north, south );
//
// return new LatLngBounds.Builder().include( new LatLng( east, north ) ).include( new LatLng( west, south ) ).build();
// }
public static LatLngBounds getLatLngBounds(MogoLatLng carPosition, List< MogoLatLng > lonLats, boolean lockCarPosition ) throws Exception {
if ( lonLats == null || lonLats.isEmpty() ) {
throw new MogoMapException( "经纬度不能为null或空集合" );
}
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for ( MogoLatLng lonLat : lonLats ) {
builder.include( ObjectUtils.fromMogo( lonLat ) );
}
if ( carPosition != null && !lockCarPosition ) {
builder.include( ObjectUtils.fromMogo( carPosition ) );
}
LatLngBounds latLngBounds = builder.build();
if ( !lockCarPosition ) {
return latLngBounds;
}
if ( carPosition == null ) {
throw new MogoMapException( "自车位置经纬度信息不能为空" );
}
if ( latLngBounds.getNortheast() == null && latLngBounds.getSouthwest() == null ) {
return null;
}
double south = 0.0;
double west = 0.0;
double east = 0.0;
double north = 0.0;
double dLat = 0.0;
double dLon = 0.0;
if ( latLngBounds.getNortheast() == null ) {
dLat = Math.abs( carPosition.lat - latLngBounds.getSouthwest().getLatitude() );
dLon = Math.abs( carPosition.lng - latLngBounds.getSouthwest().getLongitude() );
} else if ( latLngBounds.getSouthwest() == null ) {
dLat = Math.abs( carPosition.lat - latLngBounds.getNortheast().getLatitude() );
dLon = Math.abs( carPosition.lng - latLngBounds.getNortheast().getLongitude() );
} else {
final double dLat1 = Math.abs( carPosition.lat - latLngBounds.getSouthwest().getLatitude() );
final double dLon1 = Math.abs( carPosition.lng - latLngBounds.getSouthwest().getLongitude() );
final double dLat2 = Math.abs( carPosition.lat - latLngBounds.getNortheast().getLatitude() );
final double dLon2 = Math.abs( carPosition.lng - latLngBounds.getNortheast().getLongitude() );
dLat = dLat1 > dLat2 ? dLat1 : dLat2;
dLon = dLon1 > dLon2 ? dLon1 : dLon2;
}
west = carPosition.lat - dLat;
south = carPosition.lng + dLon;
east = carPosition.lat + dLat;
north = carPosition.lng - dLon;
if ( south == 0.0 || west == 0.0 || east == 0.0 || north == 0.0 ) {
return null;
}
if ( east < west ) {
double tmp = east;
east = west;
west = tmp;
}
if( north < south ){
double tmp = north;
north = south;
south = tmp;
}
return new LatLngBounds.Builder().include( new LonLatPoint( east, north ) ).include( new LonLatPoint( west, south ) ).build();
}
public static float calculateLineDistance(LonLatPoint var0, LonLatPoint var1) {
if (var0 != null && var1 != null) {