[6.5.0][Fix]新增清除所有Marker和Polyline的接口

This commit is contained in:
chenfufeng
2024-07-23 10:58:23 +08:00
parent 674efede33
commit a8f9e3e827

View File

@@ -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<Point>()
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<Point>) {
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<MarkerOptions>).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<MarkerOptions>).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<MarkerOptions>).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()
}
}