添加道路缓存
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user