Files
MoGoEagleEye/libraries/mogo-map/src/main/java/com/mogo/map/MapDataWrapper.kt
2023-09-11 15:36:07 +08:00

236 lines
6.8 KiB
Kotlin
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.mogo.map
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
/**
* 地图数据工具
*/
object MapDataWrapper : IMogoData {
private const val TAG = "MapDataWrapper"
fun init() {
mogoMapData.init(this)
}
/**
* 设置debug模式
*/
override fun setDebugMode(debugMode: Boolean) {
MapAutoApi.setDebugMode(debugMode)
}
/**
* 获取车道中心线数据
* @param lon 经度
* @param lat 纬度
* @param angle 角度
* @param call 回调
*/
@Synchronized
override fun getCenterLineInfo(
lon: Double,
lat: Double,
angle: Float,
call: ((CenterLine?) -> Unit)
) {
MapDataApi.getCenterLineInfo(
lon,
lat,
angle,
object : IResult<CenterLine> {
override fun result(
code: Int,
result: CenterLine?
) {
call.invoke(result)
}
})
}
/**
* 按距离获取道路数据
* @param lon 经度
* @param lat 纬度
* @param angle 角度
* @param call 回调
*/
override fun getCenterLineRangeInfo(
lon: Double,
lat: Double,
angle: Float,
distance: Float,
call: ((CenterLine?) -> Unit)
) {
try {
MapDataApi.getCenterLineRangeInfo(lon, lat, angle, distance,false,6,
object : IResult<CenterLine> {
override fun result(code: Int, result: CenterLine?) {
call.invoke(result)
}
})
} catch (t: Throwable) {
t.printStackTrace()
}
}
/**
* 获取车道限速
* @param lon 经度
* @param lat 纬度
* @param angle 角度
* @param call 回调
*/
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)
}
})
}
/**
* 获取道路角度
* @param lon 经度
* @param lat 纬度
* @param angle 角度
* @param call 回调
*/
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.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
*/
override fun getAngle(
startLon: Double,
startLat: Double,
endLon: Double,
endLat: Double
): Float {
return MapAutoApi.getAngle(startLon, startLat, endLon, endLat)
}
/**
* 获取瓦片id
*
* @param lon 经度
* @param lat 纬度
* @return 瓦片id
*/
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()
}
}