Merge branch 'dev_robotaxi-d_230912_6.1.0' into base_3.4.0-map-sdk

This commit is contained in:
zhongchao
2023-09-26 17:43:46 +08:00
4 changed files with 132 additions and 109 deletions

View File

@@ -131,89 +131,91 @@ class AiRoadMarker {
l2: CenterLine?,
heading: Double
) {
if (countDown.get() != 2) {
return
}
if (l1 == null || l2 == null) {
V2XBizTrace.onAck("$TAG --- marker --- 3 --- line null return ----", "")
return
}
if (l1.points.isEmpty() || l2.points.isEmpty()) {
V2XBizTrace.onAck("$TAG --- marker --- 3 --- line points null return ----", "")
return
}
V2XBizTrace.onAck("$TAG --- marker --- 4 --- l2:", l2)
val points = LinkedList<MogoLatLng>()
if (l2.points.isNotEmpty()) {
points.addAll(l2.points.reversed().map {
MogoLatLng(it.latitude, it.longitude)
})
}
val centerX = marker.poi_lon
val centerY = marker.poi_lat
V2XBizTrace.onAck("$TAG --- marker --- 5 --- marker:", marker)
val farthestPoint = marker.polygon?.let {
var find: Pair<Double, Double> = Pair(centerX, centerY)
var min = Long.MAX_VALUE
for (p in it) {
val angle = DrivingDirectionUtils.getDegreeOfCar2Poi2(
centerX,
centerY,
p.first,
p.second,
heading
)
if (angle < min) {
min = angle
find = p
v2nDrawHandler.post {
if (countDown.get() != 2) {
return@post
}
if (l1 == null || l2 == null) {
V2XBizTrace.onAck("$TAG --- marker --- 3 --- line null return ----", "")
return@post
}
if (l1.points.isEmpty() || l2.points.isEmpty()) {
V2XBizTrace.onAck("$TAG --- marker --- 3 --- line points null return ----", "")
return@post
}
V2XBizTrace.onAck("$TAG --- marker --- 4 --- l2:", l2)
val points = LinkedList<MogoLatLng>()
if (l2.points.isNotEmpty()) {
points.addAll(l2.points.reversed().map {
MogoLatLng(it.latitude, it.longitude)
})
}
val centerX = marker.poi_lon
val centerY = marker.poi_lat
V2XBizTrace.onAck("$TAG --- marker --- 5 --- marker:", marker)
val farthestPoint = marker.polygon?.let {
var find: Pair<Double, Double> = Pair(centerX, centerY)
var min = Long.MAX_VALUE
for (p in it) {
val angle = DrivingDirectionUtils.getDegreeOfCar2Poi2(
centerX,
centerY,
p.first,
p.second,
heading
)
if (angle < min) {
min = angle
find = p
}
}
MogoLatLng(find.second, find.first)
} ?: MogoLatLng(centerY, centerX)
marker.farthestPoint = Pair(farthestPoint.lon, farthestPoint.lat)
V2XBizTrace.onAck("$TAG --- marker --- 6 --- marker:", marker)
if (l1.points.isNotEmpty()) {
for (l in l1.points) {
if (DrivingDirectionUtils.getDegreeOfCar2Poi2(
farthestPoint.lon,
farthestPoint.lat,
l.longitude,
l.latitude,
(heading + 180)
) < 90L
) {
points.add(l.let { MogoLatLng(it.latitude, it.longitude) })
}
}
}
MogoLatLng(find.second, find.first)
} ?: MogoLatLng(centerY, centerX)
marker.farthestPoint = Pair(farthestPoint.lon, farthestPoint.lat)
V2XBizTrace.onAck("$TAG --- marker --- 6 --- marker:", marker)
if (l1.points.isNotEmpty()) {
for (l in l1.points) {
if (DrivingDirectionUtils.getDegreeOfCar2Poi2(
farthestPoint.lon,
farthestPoint.lat,
l.longitude,
l.latitude,
(heading + 180)
) < 90L
) {
points.add(l.let { MogoLatLng(it.latitude, it.longitude) })
}
if (points.size <= 1) {
return@post
}
val evaluator = ArgbEvaluator()
val interceptor = DecelerateInterpolator(1.5f)
val total = points.size
val colors = ArrayList<Int>()
(0..total).forEach { i ->
colors += evaluator.evaluate(
interceptor.getInterpolation(i * 1f / total),
START_COLOR,
END_COLOR
) as Int
}
builder.points(points)
builder.colors(colors)
builder.setVisible(true)
V2XBizTrace.onAck("$TAG --- marker --- 7 --- points:", "${points.size}")
val line = overlayManager?.showOrUpdateLine(builder.build())
if (line != null) {
this.line.set(line)
wrapper.addLine(line)
}
wrapper.onRemoved = { id ->
aiMakers.remove(id)
}
MarkerRemoveManager.addMarker(wrapper)
countDown.set(0)
}
if (points.size <= 1) {
return
}
val evaluator = ArgbEvaluator()
val interceptor = DecelerateInterpolator(1.5f)
val total = points.size
val colors = ArrayList<Int>()
(0..total).forEach { i ->
colors += evaluator.evaluate(
interceptor.getInterpolation(i * 1f / total),
START_COLOR,
END_COLOR
) as Int
}
builder.points(points)
builder.colors(colors)
builder.setVisible(true)
V2XBizTrace.onAck("$TAG --- marker --- 7 --- points:", "${points.size}")
val line = overlayManager?.showOrUpdateLine(builder.build())
if (line != null) {
this.line.set(line)
wrapper.addLine(line)
}
wrapper.onRemoved = { id ->
aiMakers.remove(id)
}
MarkerRemoveManager.addMarker(wrapper)
countDown.set(0)
}
private fun removeLine() {

View File

@@ -12,7 +12,7 @@ interface IMogoData {
* @param lon 经度
* @param lat 纬度
* @param angle 角度
* @param call 回调
* @param call 回调(主线程)
*/
fun getCenterLineInfo(lon: Double, lat: Double, angle: Float, call: ((CenterLine?) -> Unit))
@@ -21,7 +21,7 @@ interface IMogoData {
* @param lon 经度
* @param lat 纬度
* @param angle 角度
* @param call 回调
* @param call 回调(主线程)
*/
fun getCenterLineRangeInfo(
lon: Double,
@@ -36,7 +36,7 @@ interface IMogoData {
* @param lon 经度
* @param lat 纬度
* @param angle 角度
* @param call 回调
* @param call 回调(主线程)
*/
fun getLimitSpeed(lon: Double, lat: Double, angle: Float, call: ((Int) -> Unit))
@@ -45,7 +45,7 @@ interface IMogoData {
* @param lon 经度
* @param lat 纬度
* @param angle 角度
* @param call 回调
* @param call 回调(主线程)
*/
fun getRoadAngle(lon: Double, lat: Double, angle: Float, call: ((Double) -> Unit))

View File

@@ -3,6 +3,8 @@ package com.mogo.map
import android.graphics.Point
import android.graphics.Rect
import android.os.Bundle
import android.os.Handler
import android.os.HandlerThread
import android.text.TextUtils
import android.view.MotionEvent
import android.view.View
@@ -79,12 +81,20 @@ class AMapViewWrapper(mMapView: MapAutoView) : IMogoMapView, IMogoMapUIControlle
override var currentMapVisualAngle: VisualAngleMode = VisualAngleMode.MODE_MEDIUM_SIGHT
private set
//地图的接口回调操作都在主线程返回,基于此类回调,业务在使用时注意切换子线程/线程池处理
private val handler by lazy {
val thread = HandlerThread(TAG)
thread.start()
Handler(thread.looper)
}
init {
i(M_MAP + TAG, "AMapViewWrapper: init")
this.mMapView = mMapView
initViews()
initListeners()
mIMap = AMapWrapper(this.mMapView.getMapAutoViewHelper(), this.mMapView, this)
handler.post {}
}
private fun initViews() {
@@ -204,8 +214,10 @@ class AMapViewWrapper(mMapView: MapAutoView) : IMogoMapView, IMogoMapUIControlle
* @param laneId
*/
override fun onRoadIdInfo(roadId: String?, laneId: String?) {
if (roadId != null && !TextUtils.isEmpty(roadId)) {
invokeListenersOnRoadIdGet(roadId)
handler.post {
if (roadId != null && !TextUtils.isEmpty(roadId)) {
invokeListenersOnRoadIdGet(roadId)
}
}
}
@@ -214,25 +226,30 @@ class AMapViewWrapper(mMapView: MapAutoView) : IMogoMapView, IMogoMapUIControlle
//对驶入驶出路口做二次过滤,防止多次回调
if (it.status == 0 && newValue!!.status == 1) {
//径直进入路口
i("$M_MAP$TAG", "进入路口 :${newValue.cross_id}")
invokeRoadChange(0, newValue)
handler.post {
// i("$M_MAP$TAG", "进入路口 :${newValue.cross_id}")
invokeRoadChange(0, newValue)
}
}
if ((it.status == 1 && newValue!!.status == 0)) {
//径直驶出路口
i("$M_MAP$TAG", "驶出路口 上个:${oldValue.cross_id_end} , 下个:${newValue.cross_id_end}")
invokeRoadChange(1, newValue)
handler.post {
// i("$M_MAP$TAG", "驶出路口 上个:${oldValue.cross_id_end} , 下个:${newValue.cross_id_end}")
invokeRoadChange(1, newValue)
}
return@let
}
if ((newValue!!.cross_id_end.isNotEmpty() && oldValue.cross_id_end != newValue.cross_id_end)) {
//路口发生变化
i("$M_MAP$TAG", "路段发生变化 上个:${oldValue.cross_id_end} , 下个:${newValue.cross_id_end}")
invokeRoadChange(2, newValue)
handler.post {
// i("$M_MAP$TAG", "路段发生变化 上个:${oldValue.cross_id_end} , 下个:${newValue.cross_id_end}")
invokeRoadChange(2, newValue)
}
}
}
}
override fun onRoadCrossInfo(roadCross: RoadCross?) {
d(M_MAP + TAG, "onRoadCrossInfo:roadCross$roadCross")
roadCross?.let {
this.roadCross = it
}
@@ -240,9 +257,11 @@ class AMapViewWrapper(mMapView: MapAutoView) : IMogoMapView, IMogoMapUIControlle
override fun onStopLineInfo(stopLine: StopLine?) {
stopLine?.let {
if (it.road_id.isNotEmpty() && it.points.size > 0) {
d(M_MAP + TAG, "onStopLineInfo: $it")
invokeListenersOnStopLineGet(it)
handler.post {
if (it.road_id.isNotEmpty() && it.points.size > 0) {
d(M_MAP + TAG, "onStopLineInfo: $it")
invokeListenersOnStopLineGet(it)
}
}
}
}
@@ -560,20 +579,21 @@ class AMapViewWrapper(mMapView: MapAutoView) : IMogoMapView, IMogoMapUIControlle
override fun changeCurrentIcon(iconId: Int) {
if (checkAMapView()) {
val changeResult = mMapView.getMapAutoViewHelper()!!.getMyLocationStyle()!!
.myLocationIcon(iconId, true)
if (!changeResult) {
val count = reChangeIconCount.incrementAndGet()
MapTraceUtil.log(
"", ChainConstant.CHAIN_CODE_HD_MAP_ICON_SET, TAG,
mapOf("changeCurrentIcon-count" to "$count")
)
if (count >= 3) {
return
handler.post {
val changeResult = mMapView.getMapAutoViewHelper()!!.getMyLocationStyle()!!
.myLocationIcon(iconId, true)
if (!changeResult) {
val count = reChangeIconCount.incrementAndGet()
MapTraceUtil.log(
"", ChainConstant.CHAIN_CODE_HD_MAP_ICON_SET, TAG,
mapOf("changeCurrentIcon-count" to "$count")
)
if (count >= 3) {
return@post
}
handler.postDelayed({ changeCurrentIcon(iconId) },300L)
reChangeIconCount.set(0)
}
UiThreadHandler.postDelayed({ changeCurrentIcon(iconId) }, 3000L,
UiThreadHandler.MODE.QUEUE)
reChangeIconCount.set(0)
}
}
}

View File

@@ -17,6 +17,7 @@ import com.zhidaoauto.map.sdk.open.data.MapDataApi
/**
* 地图数据工具,涉及到数据调用可能会有耗时建议IO操作
* 地图call回调在主线程有需要io操作的业务建议切换线程或由MapDataWrapper线程池操作
*/
object MapDataWrapper : IMogoData {
@@ -109,7 +110,7 @@ object MapDataWrapper : IMogoData {
* @param lon 经度
* @param lat 纬度
* @param angle 角度
* @param call 回调
* @param call 回调(主线程)
*/
@Synchronized
override fun getRoadAngle(lon: Double, lat: Double, angle: Float, call: ((Double) -> Unit)) {