diff --git a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/V2XEventManager.kt b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/V2XEventManager.kt index 3e1b9d9c51..b5520f7be9 100644 --- a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/V2XEventManager.kt +++ b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/V2XEventManager.kt @@ -136,7 +136,7 @@ object V2XEventManager : IMoGoMapLocationListener, IMoGoTokenCallback, IV2XCallb private fun registerListener() { V2XManager.addCallback(this) CallerMapLocationListenerManager.addListener(TAG, this, false) - BridgeApi.registerCenter()?.let { + BridgeApi.registerCenter()?.let { it-> it.registerMogoMapListener(MODULE_NAME, this) it.registerMogoMarkerClickListener( CARD_TYPE_ROAD_CONDITION, @@ -157,7 +157,7 @@ object V2XEventManager : IMoGoMapLocationListener, IMoGoTokenCallback, IV2XCallb private fun unRegisterListener() { V2XManager.removeCallback(this) CallerMapLocationListenerManager.removeListener(TAG, false) - BridgeApi.registerCenter()?.let { + BridgeApi.registerCenter()?.let { it-> it.unregisterMogoMapListener(MODULE_NAME) it.unregisterMogoMarkerClickListener(CARD_TYPE_ROAD_CONDITION) } diff --git a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/scenario/scene/airoad/AiRoadMarker.kt b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/scenario/scene/airoad/AiRoadMarker.kt index 5adc3dda75..6755da11f0 100644 --- a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/scenario/scene/airoad/AiRoadMarker.kt +++ b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/scenario/scene/airoad/AiRoadMarker.kt @@ -10,6 +10,7 @@ import androidx.lifecycle.* import androidx.lifecycle.Lifecycle.Event import androidx.lifecycle.Lifecycle.Event.ON_CREATE import androidx.lifecycle.Lifecycle.Event.ON_DESTROY +import com.mogo.cloud.commons.utils.CoordinateUtils import com.mogo.commons.utils.DrivingDirectionUtils import com.mogo.eagle.core.data.map.* import com.mogo.eagle.core.data.map.MapRoadInfo.StopLine @@ -69,6 +70,20 @@ object AiRoadMarker { } } + private val checkV2NExpiredTask = Runnable { + val poi = this.marker.get() + val car = this.carLocation.get() + if (poi != null && car != null) { + val distance = CoordinateUtils.calculateLineDistance(car.first, car.second, poi.poi_lon, poi.poi_lat) + Logger.d(TAG, "receive --- checkV2N --- distance: $distance") + if (distance > 200) { + unMarker(poi) + }else{ + checkV2NExpired() + } + } + } + private val onClearAllMarker = object : OnClearAllMarker { override fun onClearAllMarkers() { @@ -355,6 +370,27 @@ object AiRoadMarker { handler.postDelayed(checkExpiredTask, 10000) } + fun receiveV2N(marker: Marker) { + Logger.d(TAG, "receive --- 1 ---") + val car = this.carLocation.get() + if (car != null) { + val distance = DrivingDirectionUtils.distance(car.first, car.second, marker.poi_lon, marker.poi_lat) * 10000 + Logger.d(TAG, "receive --- 2 ---:car:[${car.first}, ${car.second}] -> poi:[${marker.poi_lon}, ${marker.poi_lat}] --> distance:$distance") + if (distance < 500) { + checkV2NExpired() + } else { + handler.removeCallbacks(checkV2NExpiredTask) + } + } else { + checkV2NExpired() + } + } + + private fun checkV2NExpired() { + handler.removeCallbacks(checkV2NExpiredTask) + handler.postDelayed(checkV2NExpiredTask, 5000) + } + data class Marker( val poi_lat: Double, val poi_lon: Double, diff --git a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/scenario/scene/road/V2XAiRoadEventMarker.kt b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/scenario/scene/road/V2XAiRoadEventMarker.kt index dc5a0f426d..980b86d9d7 100644 --- a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/scenario/scene/road/V2XAiRoadEventMarker.kt +++ b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/scenario/scene/road/V2XAiRoadEventMarker.kt @@ -79,6 +79,7 @@ object V2XAiRoadEventMarker { options.zIndex(75000f) options.maxIndex(800000f) val line = overlayManager.addPolyline(options) + current.set(Pair(line, null)) if (line != null) { line.isVisible = true } diff --git a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/utils/EntityUtils.kt b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/utils/EntityUtils.kt index 5d537143e0..c52c20373c 100644 --- a/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/utils/EntityUtils.kt +++ b/core/function-impl/mogo-core-function-v2x/src/main/java/com/mogo/eagle/core/function/v2x/events/utils/EntityUtils.kt @@ -1,7 +1,6 @@ package com.mogo.eagle.core.function.v2x.events.utils import androidx.core.util.Pair -import com.mogo.cloud.commons.utils.CoordinateUtils import com.mogo.eagle.core.data.enums.EventTypeEnum.Companion.isRoadEvent import com.mogo.eagle.core.data.map.entity.MarkerExploreWay import com.mogo.eagle.core.data.map.entity.MarkerLocation @@ -84,7 +83,10 @@ fun Road.RW_PB.toRoadMarker(): V2XMarkerCardResult = l3.poiType = this.roadwork?.poiType?.toString() l3.generateTime = this.roadwork?.detectTime ?: 0L l3.location = V2XMarkerLocation().also { l4 -> - val p = MogoMap.getInstance().mogoMap.switchLonLat(this.roadwork?.center?.point?.lon ?: 0.0,this.roadwork?.center?.point?.lat ?: 0.0) + val p = MogoMap.getInstance().mogoMap.switchLonLat( + this.roadwork?.center?.point?.lon ?: 0.0, + this.roadwork?.center?.point?.lat ?: 0.0 + ) l4.lon = p.lon l4.lat = p.lat l4.angle = this.roadwork?.center?.road?.bearing?.toDouble() ?: 0.0 @@ -117,13 +119,18 @@ fun MessagePad.TrackedObject.toRoadMarker(poiType: String): V2XMarkerCardResult l3.poiType = poiType l3.generateTime = 0L l3.location = V2XMarkerLocation().also { l4 -> - val p = MogoMap.getInstance().mogoMap.switchLonLat(this.longitude,this.latitude) + val p = + MogoMap.getInstance().mogoMap.switchLonLat(this.longitude, this.latitude) l4.lon = p.lon l4.lat = p.lat l4.angle = this.heading } }) } + + AiRoadMarker.receiveV2N( + AiRoadMarker.Marker(this.latitude, this.longitude, this.heading, null, null, null) + ) } fun V2XMarkerCardResult.toV2XRoadEventEntity(): V2XRoadEventEntity =