添加道路缓存

This commit is contained in:
tongchenfei
2021-03-09 15:43:34 +08:00
parent 662ebeb445
commit 1b98761014
11 changed files with 92 additions and 18 deletions

1
.idea/gradle.xml generated
View File

@@ -91,6 +91,7 @@
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings>
</option>
</component>

View File

@@ -214,7 +214,7 @@ public class MogoApplication extends AbsMogoApplication {
// 设置是否是第三APP登录
clientConfig.setThirdLogin(false);
// 设置是否输出日志
clientConfig.setShowDebugLog(false);
clientConfig.setShowDebugLog(true);
// 设置从蘑菇AI开放平台获取的APPKey
clientConfig.setThirdPartyAppKey("wbvpzgar");
// 设置应用服务AppId 长链、鉴权

View File

@@ -67,7 +67,7 @@ dependencies {
implementation project(':foudations:mogo-commons')
}
implementation 'com.zhidaoauto.machine:map:1.0.0-vr-8.2.2'
implementation 'com.zhidaoauto.machine:map:1.0.0-vr-8.2.4'
// implementation 'com.zhidaoauto.machine:map:1.0.0-vr-test-3.4'
}

View File

@@ -9,6 +9,7 @@ import android.location.Location;
import android.os.Bundle;
import android.os.Trace;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
@@ -1034,19 +1035,36 @@ public class AMapViewWrapper implements IMogoMapView,
}
}
Map<String, RoadCacheWrapper> roadCacheMap = new ArrayMap<>();
@Override
public double[] matchRoad( double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) {
public double[] matchRoad( String id, double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) {
double wgs[] = new double[]{lon, lat};
long start = System.currentTimeMillis();
SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad( ( ( float ) wgs[0] ), ( ( float ) wgs[1] ), ( ( float ) angle ), isGpsLocation, isRTK );
RoadCacheWrapper roadCache = roadCacheMap.get(id);
if(roadCache == null){
SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad( ( ( float ) wgs[0] ), ( ( float ) wgs[1] ), ( ( float ) angle ), isGpsLocation, isRTK );
if (singlePointRoadInfo != null && singlePointRoadInfo.getCoords() != null && !singlePointRoadInfo.getCoords().isEmpty()) {
roadCache = new RoadCacheWrapper(singlePointRoadInfo.getCoords());
}
}
Log.i("timer-matchRoad-1", "cost " + (System.currentTimeMillis() - start) + "ms");
if ( singlePointRoadInfo != null
&& singlePointRoadInfo.getCoords() != null
&& !singlePointRoadInfo.getCoords().isEmpty() ) {
if ( roadCache != null
&& roadCache.getRoad() != null
&& !roadCache.getRoad().isEmpty() ) {
start = System.currentTimeMillis();
double matchedPoint[] = PointInterpolatorUtil.mergeToRoad( wgs[0], wgs[1], singlePointRoadInfo.getCoords() );
double matchedPoint[] = PointInterpolatorUtil.mergeToRoad( wgs[0], wgs[1], roadCache.getRoad() );
double diff = CoordinateUtils.calculateLineDistance(lon, lat, roadCache.getLastLon(), roadCache.getLastLon());
if ( (roadCache.getLastDistanceDiff() == 0 || roadCache.getLastDistanceDiff() > diff)) {
roadCache.setLastDistanceDiff(diff);
roadCacheMap.put(id, roadCache);
Log.i("timer-matchRoad-3", "cost " + (System.currentTimeMillis() - start) + "ms");
return matchedPoint;
}
roadCacheMap.put(id, null);
Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms");
return matchedPoint;
return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK);
}
return null;
}

View File

@@ -0,0 +1,54 @@
package com.mogo.map.impl.custom;
import com.zhidaoauto.map.sdk.open.query.LonLatPoint;
import java.util.List;
/**
* 道路数据缓存
*
* @author tongchenfei
*/
public class RoadCacheWrapper {
private List<LonLatPoint> road;
private double lastDistanceDiff;
private int roadLength = -1;
public RoadCacheWrapper(List<LonLatPoint> road) {
this.road = road;
}
public List<LonLatPoint> getRoad() {
return road;
}
public void setRoad(List<LonLatPoint> road) {
this.road = road;
if(road!=null) {
roadLength = road.size();
}
}
public double getLastDistanceDiff() {
return lastDistanceDiff;
}
public void setLastDistanceDiff(double lastDistanceDiff) {
this.lastDistanceDiff = lastDistanceDiff;
}
public double getLastLat(){
if (roadLength != -1) {
return road.get(roadLength - 1).getLatitude();
}
return 0;
}
public double getLastLon(){
if (roadLength != -1) {
return road.get(roadLength - 1).getLongitude();
}
return 0;
}
}

View File

@@ -315,9 +315,9 @@ public class AMapUIController implements IMogoMapUIController {
}
@Override
public double[] matchRoad( double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) {
public double[] matchRoad( String id, double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) {
if ( mClient != null ) {
return mClient.matchRoad( lon, lat, angle, isGpsLocation, isRTK );
return mClient.matchRoad( id, lon, lat, angle, isGpsLocation, isRTK );
}
return null;
}

View File

@@ -285,7 +285,7 @@ public interface IMogoMapUIController {
* @param isRTK
* @return
*/
default double[] matchRoad( double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) {
default double[] matchRoad(String id, double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) {
return null;
}

View File

@@ -355,10 +355,10 @@ public class MogoMapUIController implements IMogoMapUIController {
}
@Override
public double[] matchRoad( double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) {
public double[] matchRoad( String id, double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) {
initDelegate();
if ( mDelegate != null ) {
return mDelegate.matchRoad( lon, lat, angle, isGpsLocation, isRTK );
return mDelegate.matchRoad( id, lon, lat, angle, isGpsLocation, isRTK );
}
return null;
}

View File

@@ -172,7 +172,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
return;
}
double[] matchedPoint = SnapshotSetDataDrawer.getInstance().matchRoad( recognizedListResult.lon,
double[] matchedPoint = SnapshotSetDataDrawer.getInstance().matchRoad( recognizedListResult.uuid, recognizedListResult.lon,
recognizedListResult.lat,
recognizedListResult.heading,
true

View File

@@ -199,13 +199,13 @@ class BaseDrawer {
* @param isRtk
* @return
*/
public double[] matchRoad( double lon, double lat, double angle, boolean isRtk ) {
public double[] matchRoad( String id, double lon, double lat, double angle, boolean isRtk ) {
final long start = System.currentTimeMillis();
double[] matchRoad = MogoApisHandler.getInstance()
.getApis()
.getMapServiceApi()
.getMapUIController()
.matchRoad( lon, lat, angle, true, isRtk );
.matchRoad( id, lon, lat, angle, true, isRtk );
Log.i("timer-matchRoad", "cost " + (System.currentTimeMillis() - start) + "ms");
return matchRoad;
}

View File

@@ -188,7 +188,8 @@ public class SimpleHandlerThreadPool {
}
}
double[] matchedPoint = SnapshotSetDataDrawer.getInstance().matchRoad( cloudRoadData.getWgslon(),
double[] matchedPoint = SnapshotSetDataDrawer.getInstance().matchRoad( cloudRoadData.getUniqueKey(),
cloudRoadData.getWgslon(),
cloudRoadData.getWgslat(),
cloudRoadData.getHeading(),
true