diff --git a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/scenario/scene/airoad/AiRoadMarker.kt b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/scenario/scene/airoad/AiRoadMarker.kt index f63ef682d9..68f996cfd0 100644 --- a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/scenario/scene/airoad/AiRoadMarker.kt +++ b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/scenario/scene/airoad/AiRoadMarker.kt @@ -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() - 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 = 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() + 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 = 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() + (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() - (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() { diff --git a/libraries/mogo-map/src/main/java/com/mogo/map/AMapViewWrapper.kt b/libraries/mogo-map/src/main/java/com/mogo/map/AMapViewWrapper.kt index 8fc2207970..5ece6c9b4c 100644 --- a/libraries/mogo-map/src/main/java/com/mogo/map/AMapViewWrapper.kt +++ b/libraries/mogo-map/src/main/java/com/mogo/map/AMapViewWrapper.kt @@ -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) } } }