[6.5.0] feat: 增加公交站点管理类;

This commit is contained in:
aibingbing
2024-06-28 19:36:31 +08:00
parent 6ff58cf654
commit 915547f5e6
5 changed files with 182 additions and 8 deletions

View File

@@ -14,6 +14,7 @@ import com.mogo.eagle.function.biz.dispatch.DispatchAutoPilotManager.Companion.d
import com.mogo.eagle.function.biz.monitoring.CronTaskManager.Companion.cronTaskManager
import com.mogo.eagle.function.biz.notice.NoticeSocketManager.Companion.noticeSocketManager
import com.mogo.eagle.function.biz.notice.network.NoticeNetWorkManager
import com.mogo.eagle.function.biz.v2x.busstation.BusStationEventManager
import com.mogo.eagle.function.biz.v2x.obu.V2xObuEventManager
import com.mogo.eagle.function.biz.v2x.overview.OverViewDataManager
import com.mogo.eagle.function.biz.v2x.overview.db.OverviewDb
@@ -54,6 +55,7 @@ class FuncBizProvider : IMoGoFuncBizProvider {
V2NIdentifyDrawer.init()
// RedLightWarningManager.INSTANCE.listenTrafficLight()
V2XEventAnalyticsManager.init()
BusStationEventManager.init()
}
override fun feedBackNoticeTraffic(infoId: String, sn: String, accept: Int) {
@@ -126,6 +128,7 @@ class FuncBizProvider : IMoGoFuncBizProvider {
dispatchAutoPilotManager.release()
cronTaskManager.release()
BusStationEventManager.unInit()
VipCarManager.INSTANCE.destroy()
if(!(AppIdentityModeUtils.isBus(FunctionBuildConfig.appIdentityMode)

View File

@@ -0,0 +1,106 @@
package com.mogo.eagle.function.biz.v2x.busstation
import android.util.Pair
import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationWGS84Listener
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
import com.mogo.map.MogoData
import com.mogo.map.entities.BusStation
import com.zhidaoauto.map.data.point.LonLatPoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.math.sin
/**
* 计算通过公交站点 管理类
*/
object BusStationEventManager : IMoGoChassisLocationWGS84Listener {
const val TAG = "BusStationEventManager"
private val mScope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
private val isCalculateNearByStation = AtomicBoolean(false)
private val farthestLocationList = ArrayList<LonLatPoint>()
private val busStationListNearBy = LinkedHashMap<String, BusStation>()
fun init() {
CallerChassisLocationWGS84ListenerManager.addListener(TAG, 1, this)
}
fun unInit() {
CallerChassisLocationWGS84ListenerManager.removeListener(TAG)
mScope?.cancel()
}
override fun onChassisLocationWGS84(gnssInfo: MogoLocation) {
if (!isCalculateNearByStation.get()) {
isCalculateNearByStation.set(true)
calculateNearByStation(gnssInfo, 15, 10)
isCalculateNearByStation.set(false)
}
}
/**
* @param gnssInfo 当前经纬度
* @param segment 段总数
* @param metersPreSegment 每段多少米
*/
private fun calculateNearByStation(
gnssInfo: MogoLocation,
segmentSum: Int,
metersPreSegment: Int
) {
mScope.launch {
farthestLocationList.clear()
val heading = gnssInfo.heading
//每10米一个点获取150米范围内的坐标点
for (index in 1..segmentSum) {
val newPoint = calculateNewPoint(
gnssInfo.longitude,
gnssInfo.latitude,
heading,
index * metersPreSegment * 1.0
)
newPoint?.also {
farthestLocationList.add(LonLatPoint(it.first, it.second))
}
}
MogoData.mogoMapData.get()?.also { iMogoData ->
val busStationList = iMogoData.getBusStation(farthestLocationList)
Logger.d(
TAG,
"calculateNearByStation --> 查询出附近公交站点 ${busStationList.size}"
)
busStationList.forEach {
busStationListNearBy[it.getBusStationId()] = it
}
}
}
}
/**
* 根据当前经纬度和方向,计算距离 distance 米处的坐标
*/
private fun calculateNewPoint(
x: Double,
y: Double,
angle: Double,
distance: Double
): Pair<Double, Double>? {
if (distance == 0.0) {
return null
}
val radian = Math.toRadians(angle)
val radianCandle = Math.toRadians(angle)
val nX = x + distance * sin(radian) / 100000.0
val nY = y + distance * sin(radianCandle) / 100000.0
return Pair.create(nX, nY)
}
}