Merge branch 'dev_minibus-d_230425_3.2.0' into code_opt_3.3.0

# Conflicts:
#	core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/config/CloudPoiManager.java
This commit is contained in:
donghongyu
2023-06-05 16:15:36 +08:00
31 changed files with 368 additions and 491 deletions

View File

@@ -86,12 +86,33 @@ object MarkerDrawerManager {
}
}
fun updateRoutePoints(routePoints: List<MessagePad.Location>?, context: Context) {
/**
* 存储全局轨迹用于轮询计算车已走过的轨迹index
*/
fun updateGDRoutePoints(routePoints: List<LatLng>?) {
if (routePoints == null || routePoints.isEmpty()) return
val latLngModels = coordinateConverterWgsToGcjListCommon(context, routePoints)
planningPoints.clear()
planningPoints.addAll(latLngModels)
// float remainingSumLength = calculateRemainingSumLength(mRoutePoints);
synchronized(this) {
planningPoints.clear()
planningPoints.addAll(routePoints)
}
}
fun resetStatus() {
synchronized(this) {
planningPoints.clear()
}
lastArrivedIndex = -1
}
/**
* 转为高德定位对象
*/
fun change2GDPoints(routePoints: List<MessagePad.Location>?, context: Context): List<LatLng> {
return if (routePoints == null || routePoints.isEmpty()) {
emptyList()
} else {
coordinateConverterWgsToGcjListCommon(context, routePoints)
}
}
/**
@@ -100,6 +121,7 @@ object MarkerDrawerManager {
* @param realLat
* @return 返回已经到达点的index
*/
@Synchronized
private fun getCarLocationIndex(
routePoints: List<LatLng>,
newPoints: MutableList<LatLng>,
@@ -108,14 +130,24 @@ object MarkerDrawerManager {
heading: Double
): Int {
var currentIndex = 0 //记录疑似点
// 是否超过200KM
var isLongDistance = false
if (routePoints.isNotEmpty()) {
//基础点
val baseLatLng = routePoints[0]
newPoints.add(baseLatLng)
var baseDiffDis = CoordinateUtils.calculateLineDistance(
realLon, realLat, baseLatLng.longitude, baseLatLng.latitude
) // lon,lat, prelon, prelat
for (i in 1 until routePoints.size) {
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
)
@@ -135,14 +167,20 @@ object MarkerDrawerManager {
}
}
Log.d("MarkerDrawerManager", "当次计算已走过的点的索引为:$currentIndex,存储的上次索引为:$lastArrivedIndex")
if (currentIndex < lastArrivedIndex) {
currentIndex = lastArrivedIndex
} else {
lastArrivedIndex = currentIndex
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
}
}
newPoints.addAll(routePoints)
newPoints.add(currentIndex + 1, LatLng(realLat, realLon))
return currentIndex + 1
}
return 0
}

View File

@@ -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
@@ -37,21 +34,18 @@ import com.mogo.eagle.core.function.map.R
import com.mogo.eagle.core.function.smp.MakerWithCount
import com.mogo.eagle.core.function.smp.MarkerDrawerManager
import com.mogo.eagle.core.function.smp.MarkerDrawerManager.callback
import com.mogo.eagle.core.function.smp.MarkerDrawerManager.change2GDPoints
import com.mogo.eagle.core.function.smp.MarkerDrawerManager.coordinateConverterWgsToGcj
import com.mogo.eagle.core.function.smp.MarkerDrawerManager.lastArrivedIndex
import com.mogo.eagle.core.function.smp.MarkerDrawerManager.lonLatHeading
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.MarkerDrawerManager.updateGDRoutePoints
import com.mogo.eagle.core.function.smp.V2XMarkerView
import com.mogo.eagle.core.utilcode.mogo.MapAssetStyleUtils
import com.mogo.eagle.core.utilcode.util.ThreadUtils
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
import com.zhidaoauto.map.sdk.open.tools.ThreadPoolUtils
import me.jessyan.autosize.utils.AutoSizeUtils
import mogo.telematics.pad.MessagePad
import mogo.v2x.MogoV2X
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import kotlin.math.pow
@@ -127,10 +121,16 @@ class OverMapView @JvmOverloads constructor(
@Volatile
private var isInit = false
@Volatile
private var isFirst = true
// 用来绘制轨迹线
private val singlePool by lazy {
Executors.newSingleThreadExecutor()
}
private var allPoints: List<LatLng>? = null
companion object {
const val TAG = "OverMapView"
}
@@ -334,8 +334,9 @@ class OverMapView @JvmOverloads constructor(
mStartMarker?.isVisible = false
mEndMarker?.isVisible = false
MarkerDrawerManager.stopLoopCalCarLocation()
planningPoints.clear()
lastArrivedIndex = -1
ThreadUtils.getIoPool().execute {
MarkerDrawerManager.resetStatus()
}
isInit = false
}
@@ -355,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 {
@@ -403,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
@@ -470,37 +471,50 @@ class OverMapView @JvmOverloads constructor(
Log.d(TAG, "全局路径规划轨迹为空")
return
}
Log.d(TAG, "全局路径规划轨迹下发")
isFirst = true
MarkerDrawerManager.resetStatus()
val list: List<MessagePad.Location> = locationList
// 转成高德坐标系并存储
updateRoutePoints(list, mContext!!)
val planningPointList: List<LatLng> = planningPoints
UiThreadHandler.post ({
displayCustomOverView()
drawStartAndEndMarker(planningPointList)
}, UiThreadHandler.MODE.QUEUE)
if (!isInit) {
callback = object : MarkerDrawerManager.Callback {
override fun onLocationChanged(planningPoints: List<LatLng>, locIndex: Int) {
// 每1s刷新一下轨迹线
UiThreadHandler.post ({
if (planningPoints.isNotEmpty()) {
drawPolyline(planningPoints, locIndex)
// 转成高德定位对象并存储
val planningPointList = change2GDPoints(list, mContext!!)
updateGDRoutePoints(planningPointList)
synchronized(this::class.java) {
if (!isInit) {
var timeStamp = 0L
callback = object : MarkerDrawerManager.Callback {
override fun onLocationChanged(points: List<LatLng>, locIndex: Int) {
if (points.isNotEmpty()) {
// 每1s刷新一下轨迹线
singlePool.execute {
if (isFirst) {
Log.d(TAG, "第一次!")
isFirst = false
allPoints = points
displayCustomOverView()
drawStartAndEndMarker(points)
}
timeStamp = System.currentTimeMillis()
drawPolyline(points, locIndex)
Log.d(TAG, "绘制轨迹线的时间为:${System.currentTimeMillis() - timeStamp}ms")
}
}
}, UiThreadHandler.MODE.QUEUE)
}
}
startLoopCalCarLocation()
isInit = true
}
startLoopCalCarLocation()
isInit = true
}
UiThreadHandler.post({
if (geoHashInfMap.isNullOrEmpty()) {
UiThreadHandler.postDelayed({
if (geoHashInfMap.isNullOrEmpty()) {
UiThreadHandler.postDelayed({
singlePool.execute {
drawInfrastructureMarkers(locationList)
}, 1000, UiThreadHandler.MODE.QUEUE)
} else {
}
}, 1000, UiThreadHandler.MODE.QUEUE)
} else {
singlePool.execute {
drawInfrastructureMarkers(locationList)
}
}, UiThreadHandler.MODE.QUEUE)
}
}
/**
@@ -662,33 +676,39 @@ class OverMapView @JvmOverloads constructor(
* 进入自定义全览模式
*/
fun displayCustomOverView() {
val linePointsLatLng = planningPoints
if (linePointsLatLng.size > 1 && mLocation != null) {
//圈定地图显示范围
//存放经纬度
val boundsBuilder = LatLngBounds.Builder()
for (i in linePointsLatLng.indices) {
boundsBuilder.include(linePointsLatLng[i])
singlePool.execute {
val linePointsLatLng = allPoints
if (linePointsLatLng != null && linePointsLatLng.size > 1 && mLocation != null) {
//圈定地图显示范围
//存放经纬度
val boundsBuilder = LatLngBounds.Builder()
for (i in linePointsLatLng.indices) {
boundsBuilder.include(linePointsLatLng[i])
}
val currentLatLng = LatLng(mLocation!!.latitude, mLocation!!.longitude)
boundsBuilder.include(currentLatLng)
val cameraPosition = CameraPosition.Builder().tilt(mTilt).build()
//第二个参数为四周留空宽度
if (mAMap != null) {
mAMap!!.moveCamera(
CameraUpdateFactory.newLatLngBoundsRect(
boundsBuilder.build(),
AutoSizeUtils.dp2px(context, leftPadding.toFloat()),
AutoSizeUtils.dp2px(context, rightPadding.toFloat()),
AutoSizeUtils.dp2px(context, topPadding.toFloat()),
AutoSizeUtils.dp2px(context, bottomPadding.toFloat())
)
)
mAMap!!.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))
}
} else {
if (mCarMarker != null && mAMap != null) {
//设置希望展示的地图缩放级别
val cameraPosition = CameraPosition.Builder()
.target(mCarMarker!!.position).tilt(mTilt).zoom(zoomLevel.toFloat()).build()
mAMap!!.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))
}
}
val currentLatLng = LatLng(mLocation!!.latitude, mLocation!!.longitude)
boundsBuilder.include(currentLatLng)
val cameraPosition = CameraPosition.Builder().tilt(mTilt).build()
//第二个参数为四周留空宽度
mAMap!!.moveCamera(
CameraUpdateFactory.newLatLngBoundsRect(
boundsBuilder.build(),
AutoSizeUtils.dp2px(context, leftPadding.toFloat()),
AutoSizeUtils.dp2px(context, rightPadding.toFloat()),
AutoSizeUtils.dp2px(context, topPadding.toFloat()),
AutoSizeUtils.dp2px(context, bottomPadding.toFloat())
)
)
mAMap!!.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))
} else {
//设置希望展示的地图缩放级别
val cameraPosition = CameraPosition.Builder()
.target(mCarMarker!!.position).tilt(mTilt).zoom(zoomLevel.toFloat()).build()
mAMap!!.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))
}
}
@@ -699,14 +719,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
}
}
}
}
@@ -718,6 +740,7 @@ class OverMapView @JvmOverloads constructor(
mStartMarker?.isVisible = false
mEndMarker?.isVisible = false
if (coordinates.size > 2) {
Log.d(TAG, "绘制起终点")
// 设置开始结束Marker位置
val startLatLng = coordinates[0]
val endLatLng = coordinates[coordinates.size - 1]
@@ -725,6 +748,8 @@ class OverMapView @JvmOverloads constructor(
mEndMarker?.position = endLatLng
mStartMarker?.isVisible = true
mEndMarker?.isVisible = true
} else {
Log.d(TAG, "不绘制起终点")
}
}
@@ -734,8 +759,7 @@ class OverMapView @JvmOverloads constructor(
* @param coordinates
* @param locIndex
*/
@MainThread
fun drawPolyline(coordinates: List<LatLng>, locIndex: Int) {
private fun drawPolyline(coordinates: List<LatLng>, locIndex: Int) {
if (textureList.size > 0) {
textureList.clear()
}
@@ -759,6 +783,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)
@@ -819,60 +844,69 @@ class OverMapView @JvmOverloads constructor(
* 站点轨迹集合被包含在地图显示范围内
*/
fun includeSitePointsAndUpdateCamera(coordinates: List<LatLng>?) {
val linePointsLatLng = planningPoints
val boundsBuilder = LatLngBounds.Builder()
var isOnlyCarLocation = true
singlePool.execute {
val linePointsLatLng = allPoints
val boundsBuilder = LatLngBounds.Builder()
var isOnlyCarLocation = true
if (linePointsLatLng.size > 1) {
// 圈定地图显示范围(自动驾驶轨迹)
for (i in linePointsLatLng.indices) {
boundsBuilder.include(linePointsLatLng[i])
if (linePointsLatLng != null && linePointsLatLng.size > 1) {
// 圈定地图显示范围(自动驾驶轨迹)
for (i in linePointsLatLng.indices) {
boundsBuilder.include(linePointsLatLng[i])
}
isOnlyCarLocation = false
}
isOnlyCarLocation = false
}
if (mLocation != null) {
// 自车坐标
boundsBuilder.include(LatLng(mLocation!!.latitude, mLocation!!.longitude))
}
coordinates?.let {
// 站点轨迹被包含在地图显示范围内
for (i in it.indices) {
boundsBuilder.include(it[i])
if (mLocation != null) {
// 自车坐标
boundsBuilder.include(LatLng(mLocation!!.latitude, mLocation!!.longitude))
}
isOnlyCarLocation = false
}
if (!isOnlyCarLocation) {
val cameraPosition = CameraPosition.Builder().tilt(mTilt).build()
//第二个参数为四周留空宽度
mAMap!!.moveCamera(
CameraUpdateFactory.newLatLngBoundsRect(
boundsBuilder.build(),
AutoSizeUtils.dp2px(context, leftPadding.toFloat()),
AutoSizeUtils.dp2px(context, rightPadding.toFloat()),
AutoSizeUtils.dp2px(context, topPadding.toFloat()),
AutoSizeUtils.dp2px(context, bottomPadding.toFloat())
)
)
mAMap!!.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))
} else {
//设置希望展示的地图缩放级别
val cameraPosition = CameraPosition.Builder()
.target(mCarMarker!!.position).tilt(mTilt).zoom(zoomLevel.toFloat()).build()
mAMap!!.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))
coordinates?.let {
// 站点轨迹被包含在地图显示范围内
for (i in it.indices) {
boundsBuilder.include(it[i])
}
isOnlyCarLocation = false
}
if (!isOnlyCarLocation) {
val cameraPosition = CameraPosition.Builder().tilt(mTilt).build()
//第二个参数为四周留空宽度
if (mAMap != null) {
mAMap!!.moveCamera(
CameraUpdateFactory.newLatLngBoundsRect(
boundsBuilder.build(),
AutoSizeUtils.dp2px(context, leftPadding.toFloat()),
AutoSizeUtils.dp2px(context, rightPadding.toFloat()),
AutoSizeUtils.dp2px(context, topPadding.toFloat()),
AutoSizeUtils.dp2px(context, bottomPadding.toFloat())
)
)
mAMap!!.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))
}
} else {
//设置希望展示的地图缩放级别
if (mCarMarker != null && mAMap != null) {
val cameraPosition = CameraPosition.Builder()
.target(mCarMarker!!.position).tilt(mTilt).zoom(zoomLevel.toFloat()).build()
mAMap!!.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))
}
}
}
}
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
}
}
}
@@ -885,7 +919,7 @@ class OverMapView @JvmOverloads constructor(
*/
override fun onAutopilotRotting(globalPathResp: MessagePad.GlobalPathResp?) {
globalPathResp?.let {
singlePool.execute {
ThreadUtils.getIoPool().execute {
handlePlanningData(it.wayPointsList)
}
}