[6.1.0][Fix]解决车原地掉头过程中画线的问题

This commit is contained in:
chenfufeng
2023-10-10 18:51:08 +08:00
parent ab04465794
commit 3893dc55a8
2 changed files with 30 additions and 47 deletions

View File

@@ -84,11 +84,11 @@ object MarkerDrawerManager {
lat: Double,
heading: Double
) {
if (!isStopCalculate && routePoints != null && routePoints.isNotEmpty()) {
if (!isStopCalculate && !routePoints.isNullOrEmpty()) {
val newPointList = ArrayList<LatLng>()
val locationIndex: Int =
getCarLocationIndex(routePoints, newPointList, lon, lat, heading)
Log.d("MarkerDrawerManager", "自车在轨迹集合中的索引为:$locationIndex")
Log.d("MarkerDrawerManager", "准备去绘制的自车在轨迹集合中的索引为:$locationIndex")
callback?.onLocationChanged(newPointList, locationIndex)
}
}
@@ -137,6 +137,7 @@ object MarkerDrawerManager {
var distance = 0.0
var tmpDistance: Double
var angle = 0.0
if (routePoints.size <= 1) return 0
routePoints.forEachIndexed { index, latLng ->
newPoints.add(LatLng(latLng.latitude, latLng.longitude))
when (index) {
@@ -144,14 +145,15 @@ object MarkerDrawerManager {
distance = LocationUtils.pointToLine(
latLng.longitude,
latLng.latitude,
routePoints[index + 1].longitude,
routePoints[index + 1].latitude,
routePoints[1].longitude,
routePoints[1].latitude,
realLon,
realLat
)
if (distance > 200000) {
isLongDistance = true
}
Log.d("MarkerDrawerManager", "计算车坐标距离0-1线段的距离为:$distance")
}
routePoints.size - 1 -> {}
@@ -173,53 +175,26 @@ object MarkerDrawerManager {
routePoints[index + 1].longitude,
routePoints[index + 1].latitude
)
Log.d(
"MarkerDrawerManager",
"index为:$index,车航向角为:$heading,到此路段的距离为:$tmpDistance,路段角度为:$angle"
)
if (getAngleDiff(angle, heading) < 90) {
if (index < currentIndex) {
return@forEachIndexed
} else {
distance = tmpDistance
currentIndex = index
}
distance = tmpDistance
currentIndex = index
}
}
}
}
}
Log.d(
"MarkerDrawerManager", "起点为:(${newPoints[0].longitude},${newPoints[0].latitude}),终点为:(${newPoints.last().longitude},${newPoints.last().latitude})"
)
if (!isLongDistance && currentIndex > 0) {
val size = routePoints.size
// // 对于非法结果,需要纠正
// if (currentIndex < lastArrivedIndex || (lastArrivedIndex > 0 && currentIndex - lastArrivedIndex > 5)) {
// val lastNextIndex = lastArrivedIndex + 1
// var isLastNextArrived = false
// if (lastNextIndex in 0 until size) {
// if (DrivingDirectionUtils.getDegreeOfCar2Poi2(
// realLon,
// realLat,
// routePoints[lastNextIndex].longitude,
// routePoints[lastNextIndex].latitude,
// heading
// ) >= 90
// ) {
// isLastNextArrived = true
// }
// }
//
// if (isLastNextArrived) {
// currentIndex = lastNextIndex
// lastArrivedIndex = currentIndex
// } else {
// if (lastArrivedIndex in 0 until size) {
// currentIndex = lastArrivedIndex
// }
// }
// } else {
// lastArrivedIndex = currentIndex
// }
if (size >= 2) {
Log.d("MarkerDrawerManager", "最终绘制的已走过index为:$currentIndex,车所在位置为:${currentIndex + 1}")
Log.d(
"MarkerDrawerManager",
"计算出来的已走过index为:$currentIndex,车所在位置为:${currentIndex + 1}"
)
newPoints.add(currentIndex + 1, LatLng(realLat, realLon))
return currentIndex + 1
}

View File

@@ -24,10 +24,12 @@ import com.mogo.eagle.core.data.map.Infrastructure
import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.data.v2x.Center
import com.mogo.eagle.core.data.v2x.V2XEventData
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener
import com.mogo.eagle.core.function.api.autopilot.IMoGoPlanningRottingListener
import com.mogo.eagle.core.function.api.autopilot.IMoGoV2XListener
import com.mogo.eagle.core.function.api.biz.IFuncBizProvider
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager
import com.mogo.eagle.core.function.call.autopilot.CallerPlanningRottingListenerManager
import com.mogo.eagle.core.function.call.autopilot.CallerV2XListenerManager
@@ -61,7 +63,7 @@ class OverMapView @JvmOverloads constructor(
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : RelativeLayout(context, attrs, defStyleAttr), IMoGoChassisLocationGCJ02Listener,
IMoGoPlanningRottingListener, IMoGoV2XListener {
IMoGoPlanningRottingListener, IMoGoV2XListener, IMoGoAutopilotStatusListener {
// =============自定义属性相关=============
private var mapStylePath: String? = null
@@ -461,6 +463,7 @@ class OverMapView @JvmOverloads constructor(
override fun onAttachedToWindow() {
super.onAttachedToWindow()
CallerPlanningRottingListenerManager.addListener(TAG, this)
CallerAutoPilotStatusListenerManager.addListener(TAG, this)
// 注册定位监听
CallerChassisLocationGCJ02ListenerManager.addListener(TAG, this)
CallerFuncBizListenerManager.addListener(TAG, object : IFuncBizProvider {
@@ -489,6 +492,7 @@ class OverMapView @JvmOverloads constructor(
}
}
}
MarkerDrawerManager.isStopCalculate = CallerAutoPilotStatusListenerManager.getState() != 2
}
private fun setUpMap() {
@@ -581,6 +585,7 @@ class OverMapView @JvmOverloads constructor(
* 绘制全局轨迹线
*/
fun drawPolyLine(coordinates: List<LatLng>, locIndex: Int) {
if (locIndex < 0) return
Message.obtain().apply {
what = DRAW_POLY_LINE
obj = Pair(coordinates, locIndex)
@@ -656,6 +661,7 @@ class OverMapView @JvmOverloads constructor(
CallerChassisLocationGCJ02ListenerManager.removeListener(TAG)
CallerPlanningRottingListenerManager.removeListener(TAG)
CallerV2XListenerManager.removeListener(TAG)
CallerAutoPilotStatusListenerManager.removeListener(TAG)
frequentHandler?.looper?.quitSafely()
nonFrequentHandler?.looper?.quitSafely()
frequentHandler = null
@@ -666,6 +672,11 @@ class OverMapView @JvmOverloads constructor(
return false
}
override fun onAutopilotStatusResponse(state: Int) {
// 非自动驾驶状态时停止绘制全局轨迹,降低性能损耗
MarkerDrawerManager.isStopCalculate = state != 2
}
/**
* 绘制新基建Markers(比如:摄像头)
*
@@ -1151,9 +1162,9 @@ class OverMapView @JvmOverloads constructor(
} else {
lastTime = System.currentTimeMillis()
}
MarkerDrawerManager.stopLoopCalCarLocation()
globalPathResp?.let {
ThreadUtils.getSinglePool().execute {
MarkerDrawerManager.stopLoopCalCarLocation()
handlePlanningData(it.wayPointsList)
}
}
@@ -1261,8 +1272,6 @@ class OverMapView @JvmOverloads constructor(
when (msg.what) {
DRAW_SITE_LINE -> {
removeMessages(DRAW_SITE_LINE)
// 绘制站点轨迹线时停止绘制全局轨迹,降低性能损耗
MarkerDrawerManager.isStopCalculate = true
(msg.obj as Pair<List<LatLng>, Bitmap>).apply {
realDrawSitePolyline(first, second)
}
@@ -1296,7 +1305,6 @@ class OverMapView @JvmOverloads constructor(
CLEAR_SITE_POLYLINE -> {
removeMessages(CLEAR_SITE_POLYLINE)
MarkerDrawerManager.isStopCalculate = false
realClearSitePolyline()
}