From a8f9e3e827a5dbbf1c03001b213fd7201c00678a Mon Sep 17 00:00:00 2001 From: chenfufeng Date: Tue, 23 Jul 2024 10:58:23 +0800 Subject: [PATCH] =?UTF-8?q?[6.5.0][Fix]=E6=96=B0=E5=A2=9E=E6=B8=85?= =?UTF-8?q?=E9=99=A4=E6=89=80=E6=9C=89Marker=E5=92=8CPolyline=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/function/view/TravelRealityView.kt | 120 ++++++++++++------ 1 file changed, 81 insertions(+), 39 deletions(-) diff --git a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/TravelRealityView.kt b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/TravelRealityView.kt index 949136fd94..6d74725598 100644 --- a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/TravelRealityView.kt +++ b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/TravelRealityView.kt @@ -77,11 +77,12 @@ class TravelRealityView @JvmOverloads constructor( private const val UPDATE_VIDEO_MARKER = 11 // private const val CLEAR_POLY_LINE = 12 - private const val CLEAR_ROAD_EVENT = 13 - private const val CLEAR_CROSS_DEVICE = 14 +// private const val CLEAR_ROAD_EVENT = 13 +// private const val CLEAR_CROSS_DEVICE = 14 // private const val CLEAR_ROAD_TRAJECTORY = 15 - private const val CLEAR_END_MARKER = 16 - private const val CLEAR_VIDEO_MARKER = 17 +// private const val CLEAR_END_MARKER = 16 +// private const val CLEAR_VIDEO_MARKER = 17 + private const val CLEAR_ALL_DATA = 18 } private var mContext: Context? = null @@ -270,6 +271,17 @@ class TravelRealityView @JvmOverloads constructor( this.listener = listener } + /** + * 清除所有Marker和Polyline + */ + fun clearAllMarkersAndPolyline() { + // 清除之前的所有Marker + Message.obtain().apply { + what = CLEAR_ALL_DATA + nonFrequentHandler?.sendMessage(this) + } + } + private fun initView(context: Context) { mContext = context val mapView = @@ -1101,8 +1113,6 @@ class TravelRealityView @JvmOverloads constructor( // nonFrequentHandler?.removeCallbacksAndMessages(null) Log.d(TAG, "取消之前的网络请求!") travelNetWorkModel.cancelAllRequest() - // 清除之前的所有Marker - clearAllMarkers() val pointList = ArrayList() globalPath.wayPointsList.forEach { loc -> @@ -1120,21 +1130,6 @@ class TravelRealityView @JvmOverloads constructor( } } - private fun clearAllMarkers() { - Message.obtain().apply { - what = CLEAR_ROAD_EVENT - nonFrequentHandler?.sendMessage(this) - } - Message.obtain().apply { - what = CLEAR_CROSS_DEVICE - nonFrequentHandler?.sendMessage(this) - } - Message.obtain().apply { - what = CLEAR_VIDEO_MARKER - nonFrequentHandler?.sendMessage(this) - } - } - private fun requestData(pointList: ArrayList) { if (!isCrossDeviceReq) { Log.d(TAG, "请求获取路口设备!") @@ -1202,7 +1197,7 @@ class TravelRealityView @JvmOverloads constructor( } DRAW_ROAD_EVENT -> { - removeMessages(CLEAR_ROAD_EVENT) +// removeMessages(CLEAR_ROAD_EVENT) removeMessages(DRAW_ROAD_EVENT) if (isMapDestroyed) return (msg.obj as ArrayList).apply { @@ -1210,14 +1205,14 @@ class TravelRealityView @JvmOverloads constructor( } } - CLEAR_ROAD_EVENT -> { - removeMessages(CLEAR_ROAD_EVENT) - if (isMapDestroyed) return - realClearEventMarkers() - } +// CLEAR_ROAD_EVENT -> { +// removeMessages(CLEAR_ROAD_EVENT) +// if (isMapDestroyed) return +// realClearEventMarkers() +// } DRAW_CROSS_DEVICE -> { - removeMessages(CLEAR_CROSS_DEVICE) +// removeMessages(CLEAR_CROSS_DEVICE) removeMessages(DRAW_CROSS_DEVICE) if (isMapDestroyed) return (msg.obj as ArrayList).apply { @@ -1225,11 +1220,11 @@ class TravelRealityView @JvmOverloads constructor( } } - CLEAR_CROSS_DEVICE -> { - removeMessages(CLEAR_CROSS_DEVICE) - if (isMapDestroyed) return - realClearCrossDeviceMarkers() - } +// CLEAR_CROSS_DEVICE -> { +// removeMessages(CLEAR_CROSS_DEVICE) +// if (isMapDestroyed) return +// realClearCrossDeviceMarkers() +// } DRAW_ROAD_RANGE -> { removeMessages(DRAW_ROAD_RANGE) @@ -1268,7 +1263,7 @@ class TravelRealityView @JvmOverloads constructor( } DRAW_LIVE_DETAIL -> { - removeMessages(CLEAR_VIDEO_MARKER) +// removeMessages(CLEAR_VIDEO_MARKER) removeMessages(DRAW_LIVE_DETAIL) if (isMapDestroyed) return (msg.obj as ArrayList).apply { @@ -1276,11 +1271,11 @@ class TravelRealityView @JvmOverloads constructor( } } - CLEAR_VIDEO_MARKER -> { - removeMessages(CLEAR_VIDEO_MARKER) - if (isMapDestroyed) return - realClearLiveMarkers() - } +// CLEAR_VIDEO_MARKER -> { +// removeMessages(CLEAR_VIDEO_MARKER) +// if (isMapDestroyed) return +// realClearLiveMarkers() +// } DRAW_END_MARKER -> { removeMessages(DRAW_END_MARKER) @@ -1293,6 +1288,12 @@ class TravelRealityView @JvmOverloads constructor( if (isMapDestroyed) return realUpdateVideoMarker(msg.obj as MarkerOptions) } + + CLEAR_ALL_DATA -> { + removeMessages(CLEAR_ALL_DATA) + if (isMapDestroyed) return + realClearAllMarkersAndPolyline() + } } } catch (e: Exception) { e.printStackTrace() @@ -1471,6 +1472,7 @@ class TravelRealityView @JvmOverloads constructor( private fun realDrawEndMarker(options: MarkerOptions) { Log.d(TAG, "realDrawEndMarker") mEndMarker?.destroy() + mEndMarker = null if (endPointDrawable != -1) { mEndMarker = mAMap?.addMarker( options @@ -1482,4 +1484,44 @@ class TravelRealityView @JvmOverloads constructor( private fun realDrawRoadRange(polylineOptions: PolylineOptions) { // mAMap?.addPolyline(polylineOptions) } + + private fun realClearAllMarkersAndPolyline() { + Log.d(TAG, "realClearAllMarkersAndPolyline") + // 清除终点 + mEndMarker?.destroy() + mEndMarker = null + // 清除道路事件icon + eventMarkerList.forEach { + it.destroy() + } + eventMarkerList.clear() + + // 清除全息路口icon + deviceMarkerList.forEach { + it.destroy() + } + deviceMarkerList.clear() + + // 清除卡片Marker + liveMarkerList.forEach { + it.destroy() + } + liveMarkerList.clear() + + // 清除全局轨迹 + globalPolyline?.remove() + globalPolyline = null + + // 清除智慧道路范围 + trajectoryPolylineList.forEach { + it.remove() + } + trajectoryPolylineList.clear() + + // 清除智慧道路内轨迹 + globalPolylineList.forEach { + it.remove() + } + globalPolylineList.clear() + } } \ No newline at end of file