[Feat]新增高精地图缓存功能

This commit is contained in:
chenfufeng
2023-02-10 19:32:22 +08:00
parent 8d6bee790a
commit 30cf22ab6c
23 changed files with 539 additions and 14 deletions

View File

@@ -0,0 +1,5 @@
package com.mogo.map.hdcache
interface IHdCacheListener {
fun onMapHdCacheProgress(cityId: Int, progress: Double)
}

View File

@@ -10,6 +10,7 @@ import androidx.annotation.RawRes;
import com.mogo.eagle.core.data.map.CenterLine;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.map.hdcache.IHdCacheListener;
import org.json.JSONObject;
@@ -340,4 +341,11 @@ public interface IMogoMapUIController {
*/
void setAllGesturesEnabled(boolean isEnable);
void cacheHDDataByCity(IHdCacheListener listener);
/**
* 当前城市离线数据是否已缓存
* @return
*/
boolean isCityDataCached();
}

View File

@@ -26,6 +26,7 @@ import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import com.mogo.commons.constants.SharedPrefsConstants;
@@ -46,7 +47,9 @@ import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr;
import com.mogo.eagle.core.utilcode.mogo.toast.TipToast;
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
import com.mogo.map.hdcache.IHdCacheListener;
import com.mogo.map.listener.MogoMapListenerHandler;
import com.mogo.map.location.GDLocationClient;
import com.mogo.map.navi.MogoCarLocationChangedListenerRegister;
import com.mogo.map.uicontroller.CarCursorOption;
import com.mogo.map.uicontroller.EnumMapUI;
@@ -54,6 +57,7 @@ import com.mogo.map.uicontroller.IMogoMapUIController;
import com.mogo.map.uicontroller.MapCameraPosition;
import com.mogo.map.uicontroller.MapControlResult;
import com.mogo.map.uicontroller.VisualAngleMode;
import com.mogo.map.utils.HDMapUtils;
import com.mogo.map.utils.MogoMapUtils;
import com.mogo.map.utils.ObjectUtils;
import com.mogo.map.utils.ResIdCache;
@@ -70,6 +74,7 @@ import com.zhidaoauto.map.sdk.open.abs.log.ILog;
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.CityInfo;
import com.zhidaoauto.map.sdk.open.data.MapDataApi;
import com.zhidaoauto.map.sdk.open.location.LocationClient;
import com.zhidaoauto.map.sdk.open.location.LocationListener;
@@ -126,6 +131,7 @@ public class AMapViewWrapper implements IMogoMapView,
private boolean mIsDelayed = false;
private final LocationListener mGpsLocationListener = location -> CallerMapLocationListenerManager.INSTANCE.invokeMapLocationChangeListener(ObjectUtils.fromLocation(location), 0, true);
private IHdCacheListener hdCacheListener;
public AMapViewWrapper(MapAutoView mMapView) {
CallerLogger.INSTANCE.i(M_MAP + TAG, "autoop--AMapViewWrapper: init");
@@ -1169,4 +1175,47 @@ public class AMapViewWrapper implements IMogoMapView,
mMapView.getMapAutoViewHelper().setAllGesturesEnabled(isEnable);
}
}
@Override
public void cacheHDDataByCity(IHdCacheListener listener) {
if (mMapView.getMapAutoViewHelper() != null) {
String gdCityCode = GDLocationClient.getInstance(getContext()).getLastCityCode();
Integer id = HDMapUtils.getHDCityCode(gdCityCode);
if (id != null) {
hdCacheListener = listener;
mMapView.getMapAutoViewHelper().cacheHDDataByCity(id, (cityId, progress) -> {
if (Thread.currentThread() == Looper.getMainLooper().getThread()) {
if (hdCacheListener != null) {
hdCacheListener.onMapHdCacheProgress(cityId, progress * 100);
}
} else {
UiThreadHandler.post(() -> {
if (hdCacheListener != null) {
hdCacheListener.onMapHdCacheProgress(cityId, progress * 100);
}
});
}
});
}
}
}
@Override
public boolean isCityDataCached() {
if (mMapView.getMapAutoViewHelper() != null) {
String gdCityCode = GDLocationClient.getInstance(getContext()).getLastCityCode();
Integer id = HDMapUtils.getHDCityCode(gdCityCode);
if (id != null) {
List<CityInfo> cityInfoList = mMapView.getMapAutoViewHelper().getAllCityCode();
if (cityInfoList != null) {
for (CityInfo cityInfo : cityInfoList) {
if (id == cityInfo.getCityCode()) {
return cityInfo.isCache;
}
}
}
}
}
return true;
}
}

View File

@@ -3,14 +3,13 @@ package com.mogo.map;
import android.graphics.Point;
import android.graphics.Rect;
import android.location.Location;
import android.util.Log;
import android.view.View;
import com.mogo.eagle.core.data.map.CenterLine;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.map.hdcache.IHdCacheListener;
import com.mogo.map.uicontroller.CarCursorOption;
import com.mogo.map.uicontroller.EnumMapUI;
import com.mogo.map.uicontroller.IMogoMapUIController;
import com.mogo.map.uicontroller.MapCameraPosition;
import com.mogo.map.uicontroller.MapControlResult;
@@ -444,4 +443,19 @@ public class MogoMapUIController implements IMogoMapUIController {
mDelegate.setAllGesturesEnabled(isEnable);
}
}
@Override
public void cacheHDDataByCity(IHdCacheListener listener) {
if (mDelegate != null) {
mDelegate.cacheHDDataByCity(listener);
}
}
@Override
public boolean isCityDataCached() {
if (mDelegate != null) {
return mDelegate.isCityDataCached();
}
return true;
}
}

View File

@@ -8,6 +8,7 @@ import android.view.View;
import com.mogo.eagle.core.data.map.CenterLine;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.map.hdcache.IHdCacheListener;
import com.zhidaoauto.map.sdk.open.MapAutoApi;
import org.json.JSONObject;
@@ -375,4 +376,19 @@ public class AMapUIController implements IMogoMapUIController {
mClient.setAllGesturesEnabled(isEnable);
}
}
@Override
public void cacheHDDataByCity(IHdCacheListener listener) {
if (mClient != null) {
mClient.cacheHDDataByCity(listener);
}
}
@Override
public boolean isCityDataCached() {
if (mClient != null) {
return mClient.isCityDataCached();
}
return true;
}
}

View File

@@ -0,0 +1,27 @@
package com.mogo.map.utils
object HDMapUtils {
private val cityCodeMap by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
val map = HashMap<String, Int>()
map["0831"] = 5115// 宜宾市
map["0512"] = 3205// 苏州市
map["0872"] = 5329// 大理市
map["0711"] = 4207// 鄂州市
map["028"] = 5101// 成都市
map["0931"] = 6201// 兰州市
map["0535"] = 3706// 烟台市
map["027"] = 4201// 武汉市
map["010"] = 1101// 北京市
map["0734"] = 4304// 衡阳市
map
}
/**
* gdCityCode: 高德CityCode
* return: 高精地图CityCode
*/
@JvmStatic
fun getHDCityCode(gdCityCode: String?): Int? {
return cityCodeMap[gdCityCode]
}
}