[base_3.4.0-map-sdk]

This commit is contained in:
zhongchao
2023-08-18 18:42:12 +08:00
parent 10b5933c03
commit fc25630dc4
43 changed files with 644 additions and 790 deletions

View File

@@ -1,23 +1,35 @@
package com.mogo.map
import android.util.Pair
import com.mogo.eagle.core.data.map.CenterLine
import com.mogo.map.utils.ObjectUtils
import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.i
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_MAP
import com.mogo.map.MogoData.Companion.mogoMapData
import com.mogo.map.location.GDLocationClient.Companion.gdLocationClient
import com.mogo.map.utils.HDMapUtils.getHDCityCode
import com.zhidaoauto.map.data.road.CenterLine
import com.zhidaoauto.map.data.road.RoadRectInfos
import com.zhidaoauto.map.data.routeinfo.RoadInfo
import com.zhidaoauto.map.sdk.open.MapAutoApi
import com.zhidaoauto.map.sdk.open.abs.IResult
import com.zhidaoauto.map.sdk.open.abs.OnHdDataDownByCityListener
import com.zhidaoauto.map.sdk.open.data.CityInfo
import com.zhidaoauto.map.sdk.open.data.MapDataApi
import com.zhidaoauto.map.sdk.open.road.RoadRectInfos
import com.zhidaoauto.map.sdk.open.routeinfo.RoadInfo
/**
* 地图数据工具
*/
object MapDataWrapper {
object MapDataWrapper : IMogoData {
private const val TAG = "MapDataWrapper"
fun init() {
mogoMapData.init(this)
}
/**
* 设置debug模式
*/
fun setDebugMode(debugMode: Boolean) {
override fun setDebugMode(debugMode: Boolean) {
MapAutoApi.setDebugMode(debugMode)
}
@@ -29,17 +41,22 @@ object MapDataWrapper {
* @param call 回调
*/
@Synchronized
fun getCenterLineInfo(lon: Double, lat: Double, angle: Float,call:((Int, CenterLine?) -> Unit)){
override fun getCenterLineInfo(
lon: Double,
lat: Double,
angle: Float,
call: ((CenterLine?) -> Unit)
) {
MapDataApi.getCenterLineInfo(
lon,
lat,
angle,
object : IResult<com.zhidaoauto.map.sdk.open.road.CenterLine> {
object : IResult<CenterLine> {
override fun result(
code: Int,
result: com.zhidaoauto.map.sdk.open.road.CenterLine?
result: CenterLine?
) {
call.invoke(0,ObjectUtils.transformCenterLine(result))
call.invoke(result)
}
})
}
@@ -51,36 +68,18 @@ object MapDataWrapper {
* @param angle 角度
* @param call 回调
*/
fun getCenterLineRangeInfo(
override fun getCenterLineRangeInfo(
lon: Double,
lat: Double,
angle: Float,
distance: Float,
call:((Int,com.mogo.map.center.CenterLine?) -> Unit)
call: ((CenterLine?) -> Unit)
) {
try {
MapDataApi.getCenterLineRangeInfo(
lon,
lat,
angle,
distance,
object : IResult<com.zhidaoauto.map.sdk.open.road.CenterLine> {
override fun result(
code: Int,
info: com.zhidaoauto.map.sdk.open.road.CenterLine?
) {
var ret: com.mogo.map.center.CenterLine? = null
if (info != null) {
ret = com.mogo.map.center.CenterLine(
info.id,
info.tile_id,
info.road_id,
info.lane_id,
convert(info.points),
info.angle?:0.0
)
}
call.invoke(code,ret)
MapDataApi.getCenterLineRangeInfo(lon, lat, angle, distance,
object : IResult<CenterLine> {
override fun result(code: Int, result: CenterLine?) {
call.invoke(result)
}
})
} catch (t: Throwable) {
@@ -88,17 +87,6 @@ object MapDataWrapper {
}
}
private fun convert(points: List<LonLatPoint>?): List<Pair<Double, Double>> {
if (points == null || points.isEmpty()) {
return emptyList()
}
val ret: MutableList<Pair<Double, Double>> = ArrayList(points.size)
for (p in points) {
ret.add(Pair.create(p.longitude, p.latitude))
}
return ret
}
/**
* 获取车道限速
* @param lon 经度
@@ -106,10 +94,10 @@ object MapDataWrapper {
* @param angle 角度
* @param call 回调
*/
fun getLimitSpeed(lon: Double, lat: Double, angle: Float,call : ((Int) -> Unit)) {
override fun getLimitSpeed(lon: Double, lat: Double, angle: Float, call: ((Int) -> Unit)) {
MapDataApi.getLimitSpeed(lon, lat, angle, object : IResult<RoadInfo> {
override fun result(code: Int, result: RoadInfo?) {
call.invoke(result?.speed?:0)
call.invoke(result?.speed ?: 0)
}
})
}
@@ -121,20 +109,40 @@ object MapDataWrapper {
* @param angle 角度
* @param call 回调
*/
fun getRoadAngle(lon: Double, lat: Double, angle: Float,call : IResult<Double>) {
override fun getRoadAngle(lon: Double, lat: Double, angle: Float, call: ((Double) -> Unit)) {
MapDataApi.getRoadRectInfo(lon, lat, angle, object : IResult<RoadRectInfos> {
override fun result(code: Int, result: RoadRectInfos?) {
call.result(code,result?.angle?:0.0)
call.invoke(result?.angle ?: 0.0)
}
})
}
/**
* 获取道路宽度
*/
override fun getRoadWidth(
lon: Double,
lat: Double,
angle: Float,
isGpsLocation: Boolean,
isRTK: Boolean
): Float {
val singlePointRoadInfo =
MapDataApi.getSinglePointMatchRoad(lon, lat, angle, isGpsLocation, isRTK)
return singlePointRoadInfo?.laneWidth ?: 0.0f
}
/**
* 获取行车方向
*
* @return
*/
fun getAngle(startLon: Double, startLat: Double, endLon: Double, endLat: Double): Float {
override fun getAngle(
startLon: Double,
startLat: Double,
endLon: Double,
endLat: Double
): Float {
return MapAutoApi.getAngle(startLon, startLat, endLon, endLat)
}
@@ -145,8 +153,84 @@ object MapDataWrapper {
* @param lat 纬度
* @return 瓦片id
*/
fun getTileId(lon: Double, lat: Double): Long {
override fun getTileId(lon: Double, lat: Double): Long {
return MapAutoApi.getTileID(lon, lat, 13) // 13为默认获取瓦片层级级别
}
/**
* 通过cityCode获取HDMap对应缓存城市
*/
override fun cacheHDDataByCity(
progress: (cityId: Int, progress: Double) -> Unit,
result: (cityId: Int, state: Int) -> Unit
) {
val gdCityCode = gdLocationClient.lastCityCode
i(M_MAP + TAG, "gdCityCode is:$gdCityCode")
val id = getHDCityCode(gdCityCode)
id?.let {
MapDataApi.cacheHDDataByCity(it, object : OnHdDataDownByCityListener {
override fun onMapHDDataCacheProgressByCity(id: Int, p: Double) {
progress.invoke(id, p)
}
override fun onMapHDDataCacheStateByCity(id: Int, state: Int) {
result.invoke(id, state)
}
})
}
}
/**
* 通过经纬度信息获取HDMap对应缓存城市
*/
override fun cacheHDDataByCityByLonLat(
location: MogoLocation,
progress: (cityId: Int, progress: Double) -> Unit,
result: (cityId: Int, state: Int) -> Unit
) {
i(M_MAP + TAG, "location lon is:" + location.longitude + ",lat is:" + location.latitude)
MapDataApi.cacheHDDataByCityByLonLat(
location.longitude, location.latitude,
object : OnHdDataDownByCityListener {
override fun onMapHDDataCacheProgressByCity(id: Int, p: Double) {
progress.invoke(id, p)
}
override fun onMapHDDataCacheStateByCity(id: Int, state: Int) {
result.invoke(id, state)
}
})
}
/**
* 当前城市离线数据是否已缓存
*/
override fun isCityDataCached(cache: ((Boolean) -> Unit)) {
val cityCode = gdLocationClient.lastCityCode
i(M_MAP + TAG, "gdCityCode is:$cityCode")
val id = getHDCityCode(cityCode)
if (id != null) {
MapDataApi.getAllCityCode(object : IResult<ArrayList<CityInfo>> {
override fun result(code: Int, result: ArrayList<CityInfo>?) {
if (result != null) {
for (cityInfo in result) {
if (id == cityInfo.cityCode) {
cache.invoke(cityInfo.isCache)
}
}
}
}
})
} else {
cache.invoke(false)
}
}
override fun cancelDownloadCacheData() {
MapDataApi.cancelCacheHDData()
}
}