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 7591dfae10..0d749c3bf4 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 @@ -58,9 +58,13 @@ object AiRoadMarker { } private val checkExpiredTask = Runnable { - val marker = this@AiRoadMarker.marker.get() - if (marker != null) { - unMarker(marker) + val poi = this.marker.get() + val car = this.carLocation.get() + if (poi != null && car != null) { + val distance = DrivingDirectionUtils.distance(car.first, car.second, poi.poi_lon, poi.poi_lat) * 10000 + if (distance < 500) { + unMarker(poi) + } } } @@ -183,12 +187,6 @@ object AiRoadMarker { try { val loc = arrayOf(location.longitude, location.latitude) carLocation.set(Triple(loc[0], loc[1], location.bearing.toDouble())) -// val marker = marker.get() ?: return -// val isOutOfRange = isOutOfRange(marker.poi_lon, marker.poi_lat, carLocation.get().first, carLocation.get().second, carLocation.get().third) -// if (isOutOfRange) { -// Logger.d(TAG, "--- onLocationChanged: isOutOfRange --- ") -// unMarker(marker) -// } } catch (t: Throwable) { Logger.e(TAG, "error: ${t.message}") } @@ -326,35 +324,27 @@ object AiRoadMarker { fun unMarker(marker: Marker) { Logger.d(TAG, "--- unMarker ---") markers -= marker + this.marker.set(null) removeLine() V2XAiRoadEventMarker.removeMarkers(null) handler.removeCallbacks(checkExpiredTask) } - private fun isOutOfRange(markerLon: Double, markerLat: Double, carLon: Double, carLat: Double, carAngle: Double): Boolean { - return !isFrontOfCar(markerLon, markerLat, carLon, carLat, carAngle) - } - - private fun isFrontOfCar(markerLon: Double, markerLat: Double, carLon: Double, carLat: Double, carAngle: Double): Boolean { - val degree = DrivingDirectionUtils.getDegreeOfCar2Poi2(carLon, carLat, markerLon, markerLat, carAngle) - return degree < 90 - } - fun receive(marker: Marker) { - val cur = this.marker.get() Logger.d(TAG, "receive --- 1 ---") - if (cur == marker) { - Logger.d(TAG, "receive --- 2 ---") - val poi = this.marker.get() - val car = this.carLocation.get() - if (poi != null && car != null) { - val distance = DrivingDirectionUtils.distance(car.first, car.second, marker.poi_lon, marker.poi_lat) * 10000 - Logger.d(TAG, "receive --- 3 ---:car:[${car.first}, ${car.second}] -> poi:[${marker.poi_lon}, ${marker.poi_lat}] --> distance:$distance") - if (distance < 200) { - checkExpired() - } else { - handler.removeCallbacks(checkExpiredTask) - } + val poi = this.marker.get() + val car = this.carLocation.get() + if (poi != null && 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) { + checkExpired() + } else { + handler.removeCallbacks(checkExpiredTask) + } + } else { + if (poi != null) { + checkExpired() } } }