代码优化
This commit is contained in:
@@ -15,6 +15,7 @@ import android.view.ViewGroup;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mogo.cloud.commons.utils.CoordinateUtils;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.map.IMogoMap;
|
||||
import com.mogo.map.IMogoMapView;
|
||||
@@ -23,6 +24,7 @@ import com.mogo.map.impl.custom.location.GpsTester;
|
||||
import com.mogo.map.impl.custom.navi.NaviClient;
|
||||
import com.mogo.map.impl.custom.utils.MogoMapUtils;
|
||||
import com.mogo.map.impl.custom.utils.ObjectUtils;
|
||||
import com.mogo.map.impl.custom.utils.PointInterpolatorUtil;
|
||||
import com.mogo.map.listener.MogoMapListenerHandler;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.uicontroller.CarCursorOption;
|
||||
@@ -44,6 +46,8 @@ import com.zhidaoauto.map.sdk.open.abs.OnMapTouchListener;
|
||||
import com.zhidaoauto.map.sdk.open.camera.CameraPosition;
|
||||
import com.zhidaoauto.map.sdk.open.camera.CameraUpdateFactory;
|
||||
import com.zhidaoauto.map.sdk.open.camera.LatLngBounds;
|
||||
import com.zhidaoauto.map.sdk.open.data.MapDataApi;
|
||||
import com.zhidaoauto.map.sdk.open.data.SinglePointRoadInfo;
|
||||
import com.zhidaoauto.map.sdk.open.location.LocationListener;
|
||||
import com.zhidaoauto.map.sdk.open.location.MyLocationStyle;
|
||||
import com.zhidaoauto.map.sdk.open.location.RTKAutopilotLocationBean;
|
||||
@@ -1014,4 +1018,16 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] matchRoad( double lon, double lat, double angle, boolean isRTK ) {
|
||||
SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad( ( ( float ) lon ), ( ( float ) lat ), ( ( float ) angle ), !isRTK, isRTK );
|
||||
if ( singlePointRoadInfo != null
|
||||
&& singlePointRoadInfo.getCoords() != null
|
||||
&& !singlePointRoadInfo.getCoords().isEmpty() ) {
|
||||
double matchedPoint[] = PointInterpolatorUtil.mergeToRoad(lon, lat, singlePointRoadInfo.getCoords());
|
||||
return CoordinateUtils.transformWgsToGcj( matchedPoint[1], matchedPoint[0] );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,4 +313,12 @@ public class AMapUIController implements IMogoMapUIController {
|
||||
mClient.openVrMode( zoomGestureEnable );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] matchRoad( double lon, double lat, double angle, boolean isRTK ) {
|
||||
if ( mClient != null ) {
|
||||
return mClient.matchRoad( lon, lat, angle, isRTK );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.mogo.module.common.utils;
|
||||
package com.mogo.map.impl.custom.utils;
|
||||
|
||||
import com.mogo.cloud.commons.utils.CoordinateUtils;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidaoauto.map.sdk.open.query.LonLatPoint;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -38,41 +39,41 @@ public class PointInterpolatorUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static MogoLatLng mergeToRoad(MogoLatLng current, List<MogoLatLng> road) {
|
||||
public static double[] mergeToRoad(double lon, double lat, List< LonLatPoint > road) {
|
||||
closeStart = 0;
|
||||
closeEnd = road.size() - 1;
|
||||
getCloseTwoPoint(current, road);
|
||||
MogoLatLng start = road.get(closeStart);
|
||||
MogoLatLng end = road.get(closeEnd);
|
||||
return getFoot(current, start, end);
|
||||
getCloseTwoPoint(lon, lat, road);
|
||||
LonLatPoint start = road.get(closeStart);
|
||||
LonLatPoint end = road.get(closeEnd);
|
||||
return getFoot(lon, lat, start, end);
|
||||
}
|
||||
|
||||
private static int closeStart = 0;
|
||||
private static int closeEnd = 0;
|
||||
|
||||
private static void getCloseTwoPoint(MogoLatLng current, List<MogoLatLng> road) {
|
||||
private static void getCloseTwoPoint(double lon, double lat, List<LonLatPoint> road) {
|
||||
if (closeEnd - closeStart == 1) {
|
||||
return;
|
||||
}
|
||||
MogoLatLng start = road.get(closeStart);
|
||||
MogoLatLng end = road.get(closeEnd);
|
||||
float startDistance = CoordinateUtils.calculateLineDistance(start.lon, start.lat, current.lon, current.lat);
|
||||
float endDistance = CoordinateUtils.calculateLineDistance(end.lon, end.lat, current.lon, current.lat);
|
||||
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;
|
||||
}
|
||||
getCloseTwoPoint(current, road);
|
||||
getCloseTwoPoint(lon, lat, road);
|
||||
}
|
||||
|
||||
private static MogoLatLng getFoot(MogoLatLng pt, MogoLatLng beginPt, MogoLatLng endPt) {
|
||||
double dx = beginPt.lat - endPt.lat;
|
||||
double dy = beginPt.lon - endPt.lon;
|
||||
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 = (pt.lat - beginPt.lat) * (beginPt.lat - endPt.lat) +
|
||||
(pt.lon - beginPt.lon) * (beginPt.lon - endPt.lon);
|
||||
double u = (lat - beginPt.getLatitude()) * (beginPt.getLatitude() - endPt.getLatitude()) +
|
||||
(lon - beginPt.getLongitude()) * (beginPt.getLongitude() - endPt.getLongitude());
|
||||
u = u / (dx * dx + dy * dy);
|
||||
return new MogoLatLng(beginPt.lat + u * dx, beginPt.lon + u * dy);
|
||||
return new double[]{ beginPt.getLongitude() + u * dy, beginPt.getLatitude() + u * dx};
|
||||
}
|
||||
}
|
||||
@@ -274,4 +274,17 @@ public interface IMogoMapUIController {
|
||||
default void openVrMode( boolean zoomGestureEnable ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 将一个点匹配到车道的中心点
|
||||
*
|
||||
* @param lon
|
||||
* @param lat
|
||||
* @param angle
|
||||
* @param isRTK
|
||||
* @return
|
||||
*/
|
||||
default double[] matchRoad( double lon, double lat, double angle, boolean isRTK ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,4 +353,13 @@ public class MogoMapUIController implements IMogoMapUIController {
|
||||
mDelegate.openVrMode( zoomGestureEnable );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] matchRoad( double lon, double lat, double angle, boolean isRTK ) {
|
||||
initDelegate();
|
||||
if ( mDelegate != null ) {
|
||||
return mDelegate.matchRoad( lon, lat, angle, isRTK );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mogo.module.common.drawer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
@@ -13,7 +14,6 @@ import com.mogo.module.common.R;
|
||||
import com.mogo.module.common.constants.DataTypes;
|
||||
import com.mogo.realtime.entity.ADASRecognizedResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -92,7 +92,20 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
continue;
|
||||
}
|
||||
|
||||
final long start = System.currentTimeMillis();
|
||||
double[] matchedPoint = matchRoad( recognizedListResult.lon,
|
||||
recognizedListResult.lat,
|
||||
recognizedListResult.heading,
|
||||
recognizedListResult.dataAccuracy == 1
|
||||
);
|
||||
Log.i("match-road-timer", "cost " + (System.currentTimeMillis() - start) + "ms");
|
||||
if ( matchedPoint != null ) {
|
||||
recognizedListResult.lon = matchedPoint[0];
|
||||
recognizedListResult.lat = matchedPoint[1];
|
||||
}
|
||||
|
||||
IMogoMarker marker = mAdasRecognizedMarkersCaches.remove( uniqueKey );
|
||||
|
||||
ADASRecognizedResult lastPosition = mLastPositions.put( uniqueKey, recognizedListResult );
|
||||
if ( marker == null || marker.isDestroyed() ) {
|
||||
marker = drawAdasRecognizedDataMarker( recognizedListResult );
|
||||
@@ -101,17 +114,14 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
}
|
||||
}
|
||||
newAdasRecognizedMarkersCaches.put( uniqueKey, marker );
|
||||
if ( lastPosition != null && !DebugConfig.isNotSmooth() ) {
|
||||
List< MogoLatLng > points = new ArrayList<>();
|
||||
if ( lastPosition != null ) {
|
||||
MogoLatLng endLatLon = new MogoLatLng( recognizedListResult.lat, recognizedListResult.lon );
|
||||
points.add( new MogoLatLng( lastPosition.lat, lastPosition.lon ) );
|
||||
points.add( endLatLon );
|
||||
long interval = recognizedListResult.systemTime - lastPosition.systemTime;
|
||||
if ( interval < 45 ) {
|
||||
interval = 45;
|
||||
}
|
||||
interval -= 25;
|
||||
marker.startSmoothInMs( points, interval );
|
||||
marker.addDynamicAnchorPosition( endLatLon, interval );
|
||||
} else {
|
||||
marker.setRotateAngle( ( ( float ) recognizedListResult.heading ) );
|
||||
marker.setPosition( recognizedListResult.lat, recognizedListResult.lon );
|
||||
|
||||
@@ -9,7 +9,9 @@ import android.text.TextUtils;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mogo.cloud.commons.utils.CoordinateUtils;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.constants.AdasRecognizedType;
|
||||
@@ -177,4 +179,22 @@ class BaseDrawer {
|
||||
}
|
||||
mMarkerCachesResMd5Values.put( id, md5 );
|
||||
}
|
||||
|
||||
/**
|
||||
* 道路匹配到车道中心点
|
||||
*
|
||||
* @param lon
|
||||
* @param lat
|
||||
* @param angle
|
||||
* @param isRtk
|
||||
* @return
|
||||
*/
|
||||
protected double[] matchRoad( double lon, double lat, double angle, boolean isRtk ) {
|
||||
double amap[] = CoordinateUtils.transformGcj02toWgs84( lat, lon );
|
||||
return MogoApisHandler.getInstance()
|
||||
.getApis()
|
||||
.getMapServiceApi()
|
||||
.getMapUIController()
|
||||
.matchRoad( amap[0], amap[1], angle, isRtk );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@ import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.R;
|
||||
import com.mogo.module.common.api.CallChatApi;
|
||||
import com.mogo.module.common.constants.DataTypes;
|
||||
import com.mogo.module.common.utils.PointInterpolatorUtil;
|
||||
import com.mogo.realtime.entity.CloudLocationInfo;
|
||||
import com.mogo.realtime.entity.CloudRoadData;
|
||||
import com.mogo.realtime.entity.MogoSnapshotSetData;
|
||||
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
|
||||
@@ -32,13 +30,14 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/10/28
|
||||
*
|
||||
* 云端数据绘制
|
||||
*/
|
||||
public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClickListener, IMogoStatusChangedListener {
|
||||
public
|
||||
/*
|
||||
* @author congtaowang
|
||||
* @since 2020/10/28
|
||||
*
|
||||
* 云端数据绘制
|
||||
*/
|
||||
class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClickListener, IMogoStatusChangedListener {
|
||||
|
||||
private static final String TAG = "SnapshotSetDataDrawer";
|
||||
|
||||
@@ -162,6 +161,16 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
|
||||
continue;
|
||||
}
|
||||
|
||||
double[] matchedPoint = matchRoad( cloudRoadData.getLon(),
|
||||
cloudRoadData.getLat(),
|
||||
cloudRoadData.getHeading(),
|
||||
true
|
||||
);
|
||||
if ( matchedPoint != null ) {
|
||||
cloudRoadData.setLon( matchedPoint[0] );
|
||||
cloudRoadData.setLat( matchedPoint[1] );
|
||||
}
|
||||
|
||||
IMogoMarker marker = mCloudSnapshotMarkersCaches.remove( uniqueKey );
|
||||
CloudRoadData lastPosition = mLastPositions.put( uniqueKey, cloudRoadData );
|
||||
if ( marker == null || marker.isDestroyed() ) {
|
||||
@@ -189,20 +198,11 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
|
||||
}
|
||||
}
|
||||
|
||||
if ( lastPosition != null && !DebugConfig.isNotSmooth() ) {
|
||||
if ( lastPosition != null ) {
|
||||
if ( lastPosition.equals( cloudRoadData ) ) {
|
||||
marker.setRotateAngle( ( float ) cloudRoadData.getHeading() );
|
||||
marker.setPosition( cloudRoadData.getLat(), cloudRoadData.getLon() );
|
||||
} else {
|
||||
List< MogoLatLng > points = new ArrayList<>();
|
||||
points.add( new MogoLatLng( lastPosition.getLat(), lastPosition.getLon() ) );
|
||||
if ( cloudRoadData.getCoordinates() != null && !cloudRoadData.getCoordinates().isEmpty() ) {
|
||||
for ( CloudLocationInfo coordinate : cloudRoadData.getCoordinates() ) {
|
||||
points.add( new MogoLatLng( coordinate.getLat(), coordinate.getLon() ) );
|
||||
}
|
||||
} else {
|
||||
points.add( new MogoLatLng( cloudRoadData.getLat(), cloudRoadData.getLon() ) );
|
||||
}
|
||||
long interval = cloudRoadData.getSystemTime() - lastPosition.getSystemTime();
|
||||
long interval2 = cloudRoadData.getSatelliteTime() - lastPosition.getSatelliteTime();
|
||||
interval2 = interval < interval2 || interval2 == 0 ? interval : interval2;
|
||||
@@ -210,8 +210,7 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
|
||||
interval2 = 45;
|
||||
}
|
||||
interval2 -= 25;
|
||||
PointInterpolatorUtil.interpolate(points);
|
||||
marker.startSmoothInMs( points, interval2 );
|
||||
marker.addDynamicAnchorPosition( new MogoLatLng( cloudRoadData.getLat(), cloudRoadData.getLon() ), interval2 );
|
||||
}
|
||||
} else {
|
||||
marker.setRotateAngle( ( float ) cloudRoadData.getHeading() );
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -557,7 +557,7 @@ public class MockIntentHandler implements IntentHandler {
|
||||
break;
|
||||
case 47:
|
||||
mLocationMockHandler.sendEmptyMessageDelayed( 1, 100L );
|
||||
mLocationMockHandler.sendEmptyMessageDelayed( 2, 100L );
|
||||
mLocationMockHandler.sendEmptyMessageDelayed( 2, 200L );
|
||||
mLocationMockHandler.sendEmptyMessageDelayed( 3, 100L );
|
||||
break;
|
||||
}
|
||||
@@ -646,7 +646,6 @@ public class MockIntentHandler implements IntentHandler {
|
||||
}
|
||||
|
||||
private BufferedReader br2;
|
||||
private int count = 1;
|
||||
|
||||
private boolean handleMockSnapshotIntent() throws Exception {
|
||||
if ( br2 == null ) {
|
||||
@@ -658,16 +657,14 @@ public class MockIntentHandler implements IntentHandler {
|
||||
}
|
||||
MogoSnapshotSetData data = new MogoSnapshotSetData();
|
||||
List< CloudRoadData > allList = new ArrayList<>();
|
||||
if ( ++count % 300 != 0 ) {
|
||||
CloudRoadData cloudRoadData = GsonUtil.objectFromJson( line, CloudRoadData.class );
|
||||
if ( cloudRoadData == null ) {
|
||||
return false;
|
||||
}
|
||||
double[] coor = CoordinateUtils.transformWgsToGcj( cloudRoadData.getLat(), cloudRoadData.getLon() );
|
||||
cloudRoadData.setLon( coor[0] );
|
||||
cloudRoadData.setLat( coor[1] );
|
||||
allList.add( cloudRoadData );
|
||||
CloudRoadData cloudRoadData = GsonUtil.objectFromJson( line, CloudRoadData.class );
|
||||
if ( cloudRoadData == null ) {
|
||||
return false;
|
||||
}
|
||||
double[] coor = CoordinateUtils.transformWgsToGcj( cloudRoadData.getLat(), cloudRoadData.getLon() );
|
||||
cloudRoadData.setLon( coor[0] );
|
||||
cloudRoadData.setLat( coor[1] );
|
||||
allList.add( cloudRoadData );
|
||||
data.setAllList( allList );
|
||||
|
||||
final long start = System.currentTimeMillis();
|
||||
@@ -688,21 +685,19 @@ public class MockIntentHandler implements IntentHandler {
|
||||
throw new Exception( "end of file 3." );
|
||||
}
|
||||
List< ADASRecognizedResult > allList = new ArrayList<>();
|
||||
if ( ++count % 300 != 0 ) {
|
||||
ADASRecognizedResult adasRecognizedResult = GsonUtil.objectFromJson( line, ADASRecognizedResult.class );
|
||||
if ( adasRecognizedResult == null ) {
|
||||
return false;
|
||||
}
|
||||
double[] coor = CoordinateUtils.transformWgsToGcj( adasRecognizedResult.lat, adasRecognizedResult.lon );
|
||||
adasRecognizedResult.lon = coor[0];
|
||||
adasRecognizedResult.lat = coor[1];
|
||||
allList.add( adasRecognizedResult );
|
||||
ADASRecognizedResult adasRecognizedResult = GsonUtil.objectFromJson( line, ADASRecognizedResult.class );
|
||||
if ( adasRecognizedResult == null ) {
|
||||
return false;
|
||||
}
|
||||
double[] coor = CoordinateUtils.transformWgsToGcj( adasRecognizedResult.lat, adasRecognizedResult.lon );
|
||||
adasRecognizedResult.lon = coor[0];
|
||||
adasRecognizedResult.lat = coor[1];
|
||||
allList.add( adasRecognizedResult );
|
||||
|
||||
final long start = System.currentTimeMillis();
|
||||
AdasRecognizedResultDrawer.getInstance().renderAdasRecognizedResult( allList );
|
||||
Log.i( "mock-timer-adas", "cost " + ( System.currentTimeMillis() - start ) + "ms" );
|
||||
mLocationMockHandler.sendEmptyMessageDelayed( 3, 100L );
|
||||
mLocationMockHandler.sendEmptyMessageDelayed( 3, 200L );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user