优化清除道路缓存逻辑

This commit is contained in:
tongchenfei
2021-03-17 14:55:43 +08:00
parent 16145c5586
commit f1b9f7481e
7 changed files with 39 additions and 5 deletions

View File

@@ -71,6 +71,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
public class AMapViewWrapper implements IMogoMapView,
IMogoMapUIController,
@@ -1044,7 +1045,13 @@ public class AMapViewWrapper implements IMogoMapView,
}
}
Map<String, RoadCacheWrapper> roadCacheMap = new ArrayMap<>();
Map<String, RoadCacheWrapper> roadCacheMap = new ConcurrentHashMap<>();
private RoadCacheWrapper noCache = new RoadCacheWrapper(null);
@Override
public void clearRoadCacheById(String id) {
roadCacheMap.remove(id);
}
@Override
public double[] matchRoad(String id, double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK) {
@@ -1068,7 +1075,7 @@ public class AMapViewWrapper implements IMogoMapView,
RoadCacheWrapper roadCache = roadCacheMap.get(id);
double matchThreshold = -1;
if (roadCache == null) {
if (roadCache == null||roadCache == noCache) {
SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad(((float) wgs[0]), ((float) wgs[1]), ((float) angle), isGpsLocation, isRTK);
if (singlePointRoadInfo != null && singlePointRoadInfo.getCoords() != null && !singlePointRoadInfo.getCoords().isEmpty()) {
Log.i("timer-matchRoad-4", "cost " + (System.currentTimeMillis() - start) + "ms roadId: " + singlePointRoadInfo.getRoadId());
@@ -1116,7 +1123,7 @@ public class AMapViewWrapper implements IMogoMapView,
} else if (matchedPoint[2] > matchThreshold && matchedPoint[2] < 1.5) {
return null;
} else {
roadCacheMap.put(id, null);
roadCacheMap.put(id, noCache);
Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms roadId: " + roadCache.getLastLat());
if (usdCache) {
return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK, false);
@@ -1126,7 +1133,7 @@ public class AMapViewWrapper implements IMogoMapView,
// return null;
}
}
roadCacheMap.put(id, null);
roadCacheMap.put(id, noCache);
return null;
}

View File

@@ -336,4 +336,11 @@ public class AMapUIController implements IMogoMapUIController {
mClient.setMarkerInfoResName( speedVal, val );
}
}
@Override
public void clearRoadCacheById(String id) {
if (mClient != null) {
mClient.clearRoadCacheById(id);
}
}
}