优化显示逻辑
This commit is contained in:
@@ -1024,17 +1024,17 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
private float lastRoadId;
|
||||
@Override
|
||||
public double[] matchRoad( double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) {
|
||||
double wgs[] = CoordinateUtils.transformGcj02toWgs84( lat, lon );
|
||||
double wgs[] = new double[]{lon, lat};//CoordinateUtils.transformGcj02toWgs84( lat, lon );
|
||||
SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad( ( ( float ) wgs[0] ), ( ( float ) wgs[1] ), ( ( float ) angle ), isGpsLocation, isRTK );
|
||||
if ( singlePointRoadInfo != null
|
||||
&& singlePointRoadInfo.getCoords() != null
|
||||
&& !singlePointRoadInfo.getCoords().isEmpty() ) {
|
||||
double matchedPoint[] = PointInterpolatorUtil.mergeToRoad( wgs[0], wgs[1], singlePointRoadInfo.getCoords() );
|
||||
// return CoordinateUtils.transformWgsToGcj( matchedPoint[1], matchedPoint[0] );
|
||||
double[] trans = CoordinateUtils.transformWgsToGcj(matchedPoint[1], matchedPoint[0]);
|
||||
// double[] trans = CoordinateUtils.transformWgsToGcj(matchedPoint[1], matchedPoint[0]);
|
||||
|
||||
matchedPoint[0] = trans[0];
|
||||
matchedPoint[1] = trans[1];
|
||||
// matchedPoint[0] = trans[0];
|
||||
// matchedPoint[1] = trans[1];
|
||||
// MarkerOptions options
|
||||
// = new MarkerOptions();
|
||||
// options.markerIcon( R.drawable.red )
|
||||
|
||||
@@ -509,6 +509,26 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void use3DResource( String resName ) {
|
||||
try {
|
||||
mMarker.getMarkeOptions().setVrIcon( true );
|
||||
mMarker.setMarkerOptions( mMarker.getMarkeOptions().setMarkerIconName( resName ) );
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "use3DResource" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void use2DResource( String resName ) {
|
||||
try {
|
||||
mMarker.getMarkeOptions().setVrIcon( false );
|
||||
mMarker.setMarkerOptions( mMarker.getMarkeOptions().setMarkerIconName( resName ) );
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "use3DResource" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnchorColor( String anchorColor ) {
|
||||
mMarker.setMarkerOptions( mMarker.getMarkeOptions().anchorColor( anchorColor ) );
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidaoauto.map.sdk.open.query.LonLatPoint;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -16,6 +17,35 @@ public class PointInterpolatorUtil {
|
||||
private static final String TAG = "PointInterpolatorUtil";
|
||||
private static final int DISTANCE_THRESHOLD = 2;
|
||||
|
||||
/**
|
||||
* 在两点之间插值
|
||||
*
|
||||
* @param start
|
||||
* @param end
|
||||
* @param frameInterval
|
||||
* @return
|
||||
*/
|
||||
public static List< MogoLatLng > interpolate( MogoLatLng start, MogoLatLng end, long frameInterval ) {
|
||||
if ( start == null || end == null ) {
|
||||
return null;
|
||||
}
|
||||
long locInterval = end.time - start.time;
|
||||
int interpolateFrame = ( int ) ( locInterval / frameInterval ) - 1;
|
||||
List< MogoLatLng > arrayList = new ArrayList<>();
|
||||
arrayList.add( start );
|
||||
if ( interpolateFrame > 0 ) {
|
||||
double lonStep = ( end.lon - start.lon ) / ( interpolateFrame + 1 );
|
||||
double latStep = ( end.lat - start.lat ) / ( interpolateFrame + 1 );
|
||||
for ( int i = 0; i < interpolateFrame; i++ ) {
|
||||
double lon = start.lon + lonStep * ( i + 1 );
|
||||
double lat = start.lat + latStep * ( i + 1 );
|
||||
arrayList.add( new MogoLatLng( lon, lat ) );
|
||||
}
|
||||
}
|
||||
arrayList.add( end );
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在(x1,y1) (x2,y2)中间插入一些点,使每两个点之间距离<={@link #DISTANCE_THRESHOLD},利用如下公式进行计算
|
||||
* xn = x1 + (x2 - x1)*n/a
|
||||
@@ -31,22 +61,22 @@ public class PointInterpolatorUtil {
|
||||
* @deprecated 这个方法有问题,并不能算出来想要的值
|
||||
*/
|
||||
@Deprecated
|
||||
public static void interpolate(List<MogoLatLng> points) {
|
||||
if (points.size() >= 2) {
|
||||
public static void interpolate( List< MogoLatLng > points ) {
|
||||
if ( points.size() >= 2 ) {
|
||||
// 插值
|
||||
for (int i = 0; i < points.size() - 1; i++) {
|
||||
MogoLatLng current = points.get(i);
|
||||
MogoLatLng next = points.get(i + 1);
|
||||
float distance = CoordinateUtils.calculateLineDistance(current.lon, current.lat, next.lon, next.lat);
|
||||
Logger.d(TAG, i + ": " + distance);
|
||||
if (distance > DISTANCE_THRESHOLD) {
|
||||
int inter = (int) (distance / DISTANCE_THRESHOLD) + 1;
|
||||
for (int j = 1; j < inter; j++) {
|
||||
double newLat = current.lat + (next.lat - current.lat) * j / inter;
|
||||
double newLon = current.lon + (next.lon - current.lon) * j / inter;
|
||||
Logger.d(TAG, "distance: " + distance + ", j: " + j + ", nextLat: " + next.lat + ", nextLon: " + next.lon + ", newLat: " + newLat + ", newLon: " + newLon);
|
||||
points.add(i + 1, new MogoLatLng(newLat, newLon));
|
||||
current = points.get(++i);
|
||||
for ( int i = 0; i < points.size() - 1; i++ ) {
|
||||
MogoLatLng current = points.get( i );
|
||||
MogoLatLng next = points.get( i + 1 );
|
||||
float distance = CoordinateUtils.calculateLineDistance( current.lon, current.lat, next.lon, next.lat );
|
||||
Logger.d( TAG, i + ": " + distance );
|
||||
if ( distance > DISTANCE_THRESHOLD ) {
|
||||
int inter = ( int ) ( distance / DISTANCE_THRESHOLD ) + 1;
|
||||
for ( int j = 1; j < inter; j++ ) {
|
||||
double newLat = current.lat + ( next.lat - current.lat ) * j / inter;
|
||||
double newLon = current.lon + ( next.lon - current.lon ) * j / inter;
|
||||
Logger.d( TAG, "distance: " + distance + ", j: " + j + ", nextLat: " + next.lat + ", nextLon: " + next.lon + ", newLat: " + newLat + ", newLon: " + newLon );
|
||||
points.add( i + 1, new MogoLatLng( newLat, newLon ) );
|
||||
current = points.get( ++i );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,51 +84,51 @@ public class PointInterpolatorUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static double[] mergeToRoad(double lon, double lat, List<LonLatPoint> road) {
|
||||
public static double[] mergeToRoad( double lon, double lat, List< LonLatPoint > road ) {
|
||||
closeStart = 0;
|
||||
closeEnd = road.size() - 1;
|
||||
getCloseTwoPoint(lon, lat, road);
|
||||
LonLatPoint start = road.get(closeStart);
|
||||
LonLatPoint end = road.get(closeEnd);
|
||||
Logger.d(TAG, "mergeToRoad start: " + closeStart + " end: " + closeEnd);
|
||||
getCloseTwoPoint( lon, lat, road );
|
||||
LonLatPoint start = road.get( closeStart );
|
||||
LonLatPoint end = road.get( closeEnd );
|
||||
Logger.d( TAG, "mergeToRoad start: " + closeStart + " end: " + closeEnd );
|
||||
// return getMid(start, end);
|
||||
double[] foot = getFoot(lon, lat, start, end);
|
||||
double[] foot = getFoot( lon, lat, start, end );
|
||||
|
||||
float d = CoordinateUtils.calculateLineDistance(foot[0], foot[1], lon, lat);
|
||||
Logger.d(TAG, "distance to mid line==" + d);
|
||||
float d = CoordinateUtils.calculateLineDistance( foot[0], foot[1], lon, lat );
|
||||
Logger.d( TAG, "distance to mid line==" + d );
|
||||
return new double[]{foot[0], foot[1], d};
|
||||
}
|
||||
|
||||
private static int closeStart = 0;
|
||||
private static int closeEnd = 0;
|
||||
|
||||
private static void getCloseTwoPoint(double lon, double lat, List<LonLatPoint> road) {
|
||||
if (closeEnd - closeStart == 1) {
|
||||
private static void getCloseTwoPoint( double lon, double lat, List< LonLatPoint > road ) {
|
||||
if ( closeEnd - closeStart == 1 ) {
|
||||
return;
|
||||
}
|
||||
LonLatPoint start = road.get(closeStart);
|
||||
LonLatPoint end = road.get(closeEnd);
|
||||
float startDistance = CoordinateUtils.calculateLineDistance(start.getLongitude(), start.getLatitude(), lon, lat);
|
||||
float endDistance = CoordinateUtils.calculateLineDistance(end.getLongitude(), end.getLatitude(), lon, lat);
|
||||
if (startDistance > endDistance) {
|
||||
closeStart += (closeEnd - closeStart) / 2;
|
||||
LonLatPoint start = road.get( closeStart );
|
||||
LonLatPoint end = road.get( closeEnd );
|
||||
float startDistance = CoordinateUtils.calculateLineDistance( start.getLongitude(), start.getLatitude(), lon, lat );
|
||||
float endDistance = CoordinateUtils.calculateLineDistance( end.getLongitude(), end.getLatitude(), lon, lat );
|
||||
if ( startDistance > endDistance ) {
|
||||
closeStart += ( closeEnd - closeStart ) / 2;
|
||||
} else {
|
||||
closeEnd -= (closeEnd - closeStart) / 2;
|
||||
closeEnd -= ( closeEnd - closeStart ) / 2;
|
||||
}
|
||||
getCloseTwoPoint(lon, lat, road);
|
||||
getCloseTwoPoint( lon, lat, road );
|
||||
}
|
||||
|
||||
private static double[] getFoot(double lon, double lat, LonLatPoint beginPt, LonLatPoint endPt) {
|
||||
private static double[] getFoot( double lon, double lat, LonLatPoint beginPt, LonLatPoint endPt ) {
|
||||
double dx = beginPt.getLatitude() - endPt.getLatitude();
|
||||
double dy = beginPt.getLongitude() - endPt.getLongitude();
|
||||
|
||||
double u = (lat - beginPt.getLatitude()) * (beginPt.getLatitude() - endPt.getLatitude()) +
|
||||
(lon - beginPt.getLongitude()) * (beginPt.getLongitude() - endPt.getLongitude());
|
||||
u = u / (dx * dx + dy * dy);
|
||||
double u = ( lat - beginPt.getLatitude() ) * ( beginPt.getLatitude() - endPt.getLatitude() ) +
|
||||
( lon - beginPt.getLongitude() ) * ( beginPt.getLongitude() - endPt.getLongitude() );
|
||||
u = u / ( dx * dx + dy * dy );
|
||||
return new double[]{beginPt.getLongitude() + u * dy, beginPt.getLatitude() + u * dx};
|
||||
}
|
||||
|
||||
private static double[] getMid(LonLatPoint start, LonLatPoint end) {
|
||||
return new double[]{(start.getLongitude() + end.getLongitude()) / 2, (start.getLatitude() + end.getLatitude()) / 2};
|
||||
private static double[] getMid( LonLatPoint start, LonLatPoint end ) {
|
||||
return new double[]{( start.getLongitude() + end.getLongitude() ) / 2, ( start.getLatitude() + end.getLatitude() ) / 2};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user