[3.2.0][Opt]优化全览地图视角切换和绘制逻辑
详情: 1. 处理定位和轨迹相差过远,甚至车定位飘到国外的情况 2. 优化车已走过轨迹在对向车道距离过近时出现的跳跃现象
This commit is contained in:
@@ -129,6 +129,8 @@ object MarkerDrawerManager {
|
||||
heading: Double
|
||||
): Int {
|
||||
var currentIndex = 0 //记录疑似点
|
||||
// 是否超过200KM
|
||||
var isLongDistance = false
|
||||
if (routePoints.isNotEmpty()) {
|
||||
//基础点
|
||||
val baseLatLng = routePoints[0]
|
||||
@@ -136,11 +138,15 @@ object MarkerDrawerManager {
|
||||
var baseDiffDis = CoordinateUtils.calculateLineDistance(
|
||||
realLon, realLat, baseLatLng.longitude, baseLatLng.latitude
|
||||
) // lon,lat, prelon, prelat
|
||||
if (baseDiffDis > 200000) {
|
||||
isLongDistance = true
|
||||
}
|
||||
val size = routePoints.size
|
||||
for (i in 1 until size) {
|
||||
val latLng = routePoints[i]
|
||||
// 深拷贝数据用于高德地图上轨迹线的绘制
|
||||
newPoints.add(LatLng(latLng.latitude, latLng.longitude))
|
||||
if (isLongDistance) continue
|
||||
val diff = CoordinateUtils.calculateLineDistance(
|
||||
realLon, realLat, latLng.longitude, latLng.latitude
|
||||
)
|
||||
@@ -160,15 +166,20 @@ object MarkerDrawerManager {
|
||||
}
|
||||
}
|
||||
Log.d("MarkerDrawerManager", "当次计算已走过的点的索引为:$currentIndex,存储的上次索引为:$lastArrivedIndex")
|
||||
if (currentIndex < lastArrivedIndex) {
|
||||
if (lastArrivedIndex < size) {
|
||||
currentIndex = lastArrivedIndex
|
||||
if (!isLongDistance) {
|
||||
// 过滤缓存的非当次轨迹的索引,并且出现车已走过索引跳跃过大时视为无效复用上一次计算结果
|
||||
if (currentIndex < lastArrivedIndex || (lastArrivedIndex >= 0 && currentIndex - lastArrivedIndex >= 10)) {
|
||||
if (lastArrivedIndex < size) {
|
||||
currentIndex = lastArrivedIndex
|
||||
}
|
||||
} else {
|
||||
lastArrivedIndex = currentIndex
|
||||
}
|
||||
if (size >= 2) {
|
||||
newPoints.add(currentIndex + 1, LatLng(realLat, realLon))
|
||||
return currentIndex + 1
|
||||
}
|
||||
} else {
|
||||
lastArrivedIndex = currentIndex
|
||||
}
|
||||
newPoints.add(currentIndex + 1, LatLng(realLat, realLon))
|
||||
return currentIndex + 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -15,10 +15,7 @@ import android.widget.TextView
|
||||
import androidx.annotation.MainThread
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import ch.hsr.geohash.GeoHash
|
||||
import com.amap.api.maps.AMap
|
||||
import com.amap.api.maps.CameraUpdate
|
||||
import com.amap.api.maps.CameraUpdateFactory
|
||||
import com.amap.api.maps.TextureMapView
|
||||
import com.amap.api.maps.*
|
||||
import com.amap.api.maps.model.*
|
||||
import com.mogo.eagle.core.data.map.Infrastructure
|
||||
import com.mogo.eagle.core.data.map.MogoLocation
|
||||
@@ -359,10 +356,7 @@ class OverMapView @JvmOverloads constructor(
|
||||
resources.getDrawable(R.drawable.transparent_background, null)
|
||||
.toBitmap(AutoSizeUtils.dp2px(context, 32f), AutoSizeUtils.dp2px(context, 230f))
|
||||
)
|
||||
CallerPlanningRottingListenerManager.addListener(TAG, this)
|
||||
initAMapView(context)
|
||||
// 注册定位监听
|
||||
CallerChassisLocationGCJ02ListenerManager.addListener(TAG, this)
|
||||
//设置全览模式
|
||||
overLayerView?.setOnClickListener { displayCustomOverView() }
|
||||
overLayerView?.let {
|
||||
@@ -407,6 +401,9 @@ class OverMapView @JvmOverloads constructor(
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
CallerPlanningRottingListenerManager.addListener(TAG, this)
|
||||
// 注册定位监听
|
||||
CallerChassisLocationGCJ02ListenerManager.addListener(TAG, this)
|
||||
CallerFuncBizListenerManager.addListener(TAG, object : IFuncBizProvider {
|
||||
override fun onInfStructures(map: HashMap<String, ArrayList<Infrastructure>>?) {
|
||||
geoHashInfMap = map
|
||||
@@ -718,14 +715,16 @@ class OverMapView @JvmOverloads constructor(
|
||||
*/
|
||||
private fun drawCarMarker(location: MogoLocation?) {
|
||||
if (location == null) return
|
||||
if (mCarMarker != null) {
|
||||
val currentLatLng = LatLng(location.latitude, location.longitude)
|
||||
mCarMarker!!.rotateAngle = (360 - location.heading).toFloat()
|
||||
mCarMarker!!.position = currentLatLng
|
||||
mCarMarker!!.setToTop()
|
||||
if (mCompassMarker != null) {
|
||||
mCompassMarker!!.rotateAngle = (360 - location.heading).toFloat()
|
||||
mCompassMarker!!.position = currentLatLng
|
||||
singlePool.execute {
|
||||
if (mCarMarker != null) {
|
||||
val currentLatLng = LatLng(location.latitude, location.longitude)
|
||||
mCarMarker!!.rotateAngle = (360 - location.heading).toFloat()
|
||||
mCarMarker!!.position = currentLatLng
|
||||
mCarMarker!!.setToTop()
|
||||
if (mCompassMarker != null) {
|
||||
mCompassMarker!!.rotateAngle = (360 - location.heading).toFloat()
|
||||
mCompassMarker!!.position = currentLatLng
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -780,6 +779,7 @@ class OverMapView @JvmOverloads constructor(
|
||||
texIndexList.add(i - 1)
|
||||
}
|
||||
if (mAMap != null && coordinates.size > 2) {
|
||||
// Log.d(TAG, "绘制时轨迹点数为:${coordinates.size},纹理数为:${textureList.size},车辆index为:$locIndex")
|
||||
//设置线段纹理
|
||||
val polylineOptions = PolylineOptions()
|
||||
polylineOptions.addAll(coordinates)
|
||||
@@ -890,12 +890,15 @@ class OverMapView @JvmOverloads constructor(
|
||||
|
||||
override fun onChassisLocationGCJ02(gnssInfo: MogoLocation?) {
|
||||
gnssInfo?.let {
|
||||
mLocation = it
|
||||
lonLatHeading = Triple(it.longitude, it.latitude, it.heading)
|
||||
drawCarMarker(it)
|
||||
if (isFirstLocation) {
|
||||
displayCustomOverView()
|
||||
isFirstLocation = false
|
||||
// 在中国境内
|
||||
if (CoordinateConverter.isAMapDataAvailable(it.latitude, it.longitude)) {
|
||||
mLocation = it
|
||||
lonLatHeading = Triple(it.longitude, it.latitude, it.heading)
|
||||
drawCarMarker(it)
|
||||
if (isFirstLocation) {
|
||||
displayCustomOverView()
|
||||
isFirstLocation = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user