[3.2.0][Opt]全览地图轨迹数据支持线程安全
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.mogo.eagle.core.function.smp
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.amap.api.maps.CoordinateConverter
|
||||
import com.amap.api.maps.model.LatLng
|
||||
import com.mogo.eagle.core.utilcode.util.CoordinateUtils
|
||||
@@ -60,19 +61,28 @@ object MarkerDrawerManager {
|
||||
private fun getLoopCalCarObservable(): Observable<Int> {
|
||||
return Observable.create(ObservableOnSubscribe { emitter ->
|
||||
if (emitter.isDisposed) return@ObservableOnSubscribe
|
||||
loopRouteAndWipe(planningPoints, lonLatHeading.first, lonLatHeading.second, lonLatHeading.third)
|
||||
loopRouteAndWipe(
|
||||
planningPoints,
|
||||
lonLatHeading.first,
|
||||
lonLatHeading.second,
|
||||
lonLatHeading.third
|
||||
)
|
||||
emitter.onComplete()
|
||||
})
|
||||
}
|
||||
|
||||
private fun loopRouteAndWipe(routePoints: List<LatLng>?, lon: Double, lat: Double, heading: Double) {
|
||||
private fun loopRouteAndWipe(
|
||||
routePoints: List<LatLng>?,
|
||||
lon: Double,
|
||||
lat: Double,
|
||||
heading: Double
|
||||
) {
|
||||
if (routePoints != null && routePoints.isNotEmpty()) {
|
||||
val newPointList = ArrayList<LatLng>()
|
||||
val arrivedIndex: Int = getArrivedPointIndex(routePoints, newPointList, lon, lat, heading)
|
||||
if (arrivedIndex != -1 && lastArrivedIndex != arrivedIndex) {
|
||||
callback?.onLocationChanged(newPointList, arrivedIndex)
|
||||
lastArrivedIndex = arrivedIndex
|
||||
}
|
||||
val locationIndex: Int =
|
||||
getCarLocationIndex(routePoints, newPointList, lon, lat, heading)
|
||||
Log.d("MarkerDrawerManager", "自车在轨迹集合中的索引为:$locationIndex")
|
||||
callback?.onLocationChanged(newPointList, locationIndex)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +100,7 @@ object MarkerDrawerManager {
|
||||
* @param realLat
|
||||
* @return 返回已经到达点的index
|
||||
*/
|
||||
private fun getArrivedPointIndex(
|
||||
private fun getCarLocationIndex(
|
||||
routePoints: List<LatLng>,
|
||||
newPoints: MutableList<LatLng>,
|
||||
realLon: Double,
|
||||
@@ -112,12 +122,21 @@ object MarkerDrawerManager {
|
||||
if (baseDiffDis > diff) {
|
||||
baseDiffDis = diff
|
||||
// 距离最近的时候判断是否走过
|
||||
if (DrivingDirectionUtils.getDegreeOfCar2Poi2(realLon, realLat, latLng.longitude, latLng.latitude, heading) >= 90) {
|
||||
if (DrivingDirectionUtils.getDegreeOfCar2Poi2(
|
||||
realLon,
|
||||
realLat,
|
||||
latLng.longitude,
|
||||
latLng.latitude,
|
||||
heading
|
||||
) >= 90
|
||||
) {
|
||||
currentIndex = if (i < lastArrivedIndex) {
|
||||
lastArrivedIndex
|
||||
} else {
|
||||
lastArrivedIndex = i
|
||||
i
|
||||
}
|
||||
Log.d("MarkerDrawerManager", "已走过的点的索引为:$currentIndex")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ import com.mogo.eagle.core.function.smp.MarkerDrawerManager.planningPoints
|
||||
import com.mogo.eagle.core.function.smp.MarkerDrawerManager.startLoopCalCarLocation
|
||||
import com.mogo.eagle.core.function.smp.MarkerDrawerManager.updateRoutePoints
|
||||
import com.mogo.eagle.core.function.smp.V2XMarkerView
|
||||
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
|
||||
import com.mogo.eagle.core.utilcode.mogo.MapAssetStyleUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
@@ -124,6 +123,9 @@ class OverMapView @JvmOverloads constructor(
|
||||
var siteMarkerList: ArrayList<Marker>? = null
|
||||
var siteNameList: ArrayList<Marker>? = null
|
||||
|
||||
@Volatile
|
||||
private var isInit = false
|
||||
|
||||
companion object {
|
||||
const val TAG = "OverMapView"
|
||||
}
|
||||
@@ -329,6 +331,7 @@ class OverMapView @JvmOverloads constructor(
|
||||
MarkerDrawerManager.stopLoopCalCarLocation()
|
||||
planningPoints.clear()
|
||||
lastArrivedIndex = -1
|
||||
isInit = false
|
||||
}
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
@@ -460,34 +463,42 @@ class OverMapView @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
fun handlePlanningData(locationList: List<MessagePad.Location>?) {
|
||||
if (locationList.isNullOrEmpty()) return
|
||||
val list: List<MessagePad.Location> = locationList
|
||||
// 转成高德坐标系并存储
|
||||
updateRoutePoints(list, mContext!!)
|
||||
val planningPointList: List<LatLng> = planningPoints
|
||||
UiThreadHandler.post {
|
||||
displayCustomOverView()
|
||||
drawStartAndEndMarker(planningPointList)
|
||||
if (locationList.isNullOrEmpty()) {
|
||||
Log.d(TAG, "全局路径规划轨迹为空")
|
||||
return
|
||||
}
|
||||
callback = object : MarkerDrawerManager.Callback {
|
||||
override fun onLocationChanged(planningPoints: List<LatLng>, locIndex: Int) {
|
||||
// 每1s刷新一下轨迹线
|
||||
UiThreadHandler.post {
|
||||
if (planningPoints.isNotEmpty()) {
|
||||
drawPolyline(planningPoints, locIndex)
|
||||
}
|
||||
val list: List<MessagePad.Location> = locationList
|
||||
ThreadUtils.getSinglePool().submit {
|
||||
lastArrivedIndex = -1
|
||||
// 转成高德坐标系并存储
|
||||
updateRoutePoints(list, mContext!!)
|
||||
val planningPointList: List<LatLng> = planningPoints
|
||||
UiThreadHandler.post {
|
||||
displayCustomOverView()
|
||||
drawStartAndEndMarker(planningPointList)
|
||||
|
||||
if (geoHashInfMap.isNullOrEmpty()) {
|
||||
UiThreadHandler.postDelayed({
|
||||
drawInfrastructureMarkers(locationList)
|
||||
}, 1000)
|
||||
} else {
|
||||
drawInfrastructureMarkers(locationList)
|
||||
}
|
||||
}
|
||||
}
|
||||
startLoopCalCarLocation()
|
||||
UiThreadHandler.post {
|
||||
if (geoHashInfMap.isNullOrEmpty()) {
|
||||
UiThreadHandler.postDelayed({
|
||||
drawInfrastructureMarkers(locationList)
|
||||
}, 1000)
|
||||
} else {
|
||||
drawInfrastructureMarkers(locationList)
|
||||
if (!isInit) {
|
||||
callback = object : MarkerDrawerManager.Callback {
|
||||
override fun onLocationChanged(planningPoints: List<LatLng>, locIndex: Int) {
|
||||
// 每1s刷新一下轨迹线
|
||||
UiThreadHandler.post {
|
||||
if (planningPoints.isNotEmpty()) {
|
||||
drawPolyline(planningPoints, locIndex)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
startLoopCalCarLocation()
|
||||
isInit = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user