[2.13.2]V2X新增事件代码提交

This commit is contained in:
renwj
2023-01-12 13:46:54 +08:00
parent 7c8bcd1e09
commit 026cd5e62e
22 changed files with 383 additions and 350 deletions

View File

@@ -50,7 +50,6 @@ import com.mogo.eagle.core.function.v2x.events.network.*
import com.mogo.eagle.core.function.v2x.events.observer.*
import com.mogo.eagle.core.function.v2x.events.receiver.*
import com.mogo.eagle.core.function.v2x.events.scenario.impl.*
import com.mogo.eagle.core.function.v2x.events.scenario.scene.airoad.*
import com.mogo.eagle.core.function.v2x.events.utils.*
import com.mogo.eagle.core.function.v2x.events.utils.MapUtils
import com.mogo.eagle.core.function.v2x.events.voice.*
@@ -110,7 +109,6 @@ object V2XEventManager : IMoGoMapLocationListener, IMoGoTokenCallback, IV2XCallb
BridgeApi.init(context)
if (hasInit.compareAndSet(false, true)) {
if (!V2XManager.hasInit()) {
AiRoadMarker.init(context)
V2XManager.init(V2XConfig.Builder().also {
it.aiCloudConfig(MoGoAiCloudClientConfig.getInstance())
it.context(context)

View File

@@ -75,32 +75,25 @@ public class V2XAlarmServer {
double eventBearing = eventLocation.getAngle();
double diffAngle = DrivingDirectionUtils.getAngleDiff(carBearing, eventBearing);
Log.d("RWJ", "car_bearing:" + carBearing + ",eventBearing:" + eventBearing + ",diffAngle:" + diffAngle);
if (diffAngle >= 0 && diffAngle <= 20) {
if (diffAngle <= 20) {
// 3、计算当前车辆行驶方向与事件位置之间夹角《20度保证道路事件在车辆前方
// double eventAngle = DrivingDirectionUtils.getDegreeOfCar2Poi(
// currentLocation.getLongitude(),
// currentLocation.getLatitude(),
// eventLocation.getLon(),
// eventLocation.getLat(),
// (int) currentLocation.getBearing()
// );
//
// Log.d("RWJ", "eventAngle:" + eventAngle);
// if (0 <= eventAngle && eventAngle <= 20) {
// if (showedEvents.contains(v2XRoadEventEntity)) {
// return null;
// }
// Log.d("RWJ", "showed---");
// showedEvents.add(v2XRoadEventEntity);
// return v2XRoadEventEntity;
// }
double eventAngle = DrivingDirectionUtils.getDegreeOfCar2Poi(
currentLocation.getLongitude(),
currentLocation.getLatitude(),
eventLocation.getLon(),
eventLocation.getLat(),
(int) currentLocation.getBearing()
);
if (showedEvents.contains(v2XRoadEventEntity)) {
return null;
Log.d("RWJ", "eventAngle:" + eventAngle);
if (0 <= eventAngle && eventAngle <= 20) {
if (showedEvents.contains(v2XRoadEventEntity)) {
return null;
}
Log.d("RWJ", "showed---");
showedEvents.add(v2XRoadEventEntity);
return v2XRoadEventEntity;
}
Log.d("RWJ", "showed---");
showedEvents.add(v2XRoadEventEntity);
return v2XRoadEventEntity;
}
}
}

View File

@@ -4,6 +4,7 @@ import android.content.Context;
import com.alibaba.android.arouter.facade.template.IProvider;
import com.mogo.eagle.core.data.map.entity.V2XRoadEventEntity;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.IMogoMarkerClickListener;
import com.mogo.eagle.core.function.v2x.internal.data.V2XMarkerCardResult;
@@ -37,11 +38,11 @@ public interface IMoGoV2XMarkerManager extends IProvider {
/**
* 绘制正在预警的道路事件的POI点
*
* @param context
* @param context
* @param roadEventEntity
* @return
*/
void drawableAlarmPOI(Context context, V2XRoadEventEntity roadEventEntity, IMogoMarkerClickListener clickListener);
IMogoMarker drawableAlarmPOI(Context context, V2XRoadEventEntity roadEventEntity, IMogoMarkerClickListener clickListener);
/**
* 清除 道路事件 POI

View File

@@ -56,8 +56,7 @@ public class MoGoV2XMarkerManager implements IMoGoV2XMarkerManager {
// 记录所有的:新鲜事儿的道路事件点、探路事件
private static final CopyOnWriteArraySet<V2XRoadEventEntity> mV2XRoadEventEntityArrayList = new CopyOnWriteArraySet<>();
// 上次的道路事件的预警Marker
private static IMogoMarker mAlarmInfoMarker;
@Override
public void drawableLastAllPOI() {
@@ -133,7 +132,7 @@ public class MoGoV2XMarkerManager implements IMoGoV2XMarkerManager {
}
@Override
public void drawableAlarmPOI(Context context, V2XRoadEventEntity roadEventEntity, IMogoMarkerClickListener clickListener) {
public IMogoMarker drawableAlarmPOI(Context context, V2XRoadEventEntity roadEventEntity, IMogoMarkerClickListener clickListener) {
try {
IMoGoV2XStatusManager v2xStatus = BridgeApi.INSTANCE.v2xStatus();
if (v2xStatus != null) {
@@ -148,7 +147,6 @@ public class MoGoV2XMarkerManager implements IMoGoV2XMarkerManager {
.latitude(roadEventEntity.getLocation().getLat())
.longitude(roadEventEntity.getLocation().getLon());
optionsRipple.anchor(0.5f, 0.5f);
MarkerShowEntity markerShowEntity = new MarkerShowEntity();
MarkerExploreWay markerExploreWay = roadEventEntity.getNoveltyInfo();
markerShowEntity.setBindObj(markerExploreWay);
@@ -156,22 +154,21 @@ public class MoGoV2XMarkerManager implements IMoGoV2XMarkerManager {
markerShowEntity.setTextContent(markerExploreWay.getAddr());
markerShowEntity.setMarkerLocation(markerExploreWay.getLocation());
markerShowEntity.setMarkerType(CARD_TYPE_NOVELTY);
optionsRipple.icons(V2XMarkerAdapter.getV2XRoadEventViewGif(context, roadEventEntity));
optionsRipple.period(1);
IMogoMarker ret = null;
if (MogoStatusManager.getInstance().isVrMode()) {
mAlarmInfoMarker = Objects.requireNonNull(CallerMapUIServiceManager.INSTANCE.getMarkerService()).drawMarker(markerShowEntity);
ret = Objects.requireNonNull(CallerMapUIServiceManager.INSTANCE.getMarkerService()).drawMarker(markerShowEntity);
} else {
optionsRipple.icon(V2XMarkerAdapter.getV2XRoadEventViewPng(context, roadEventEntity));
IMogoMarkerManager marker = MogoMarkerManager.getInstance(context);
if (marker != null) {
mAlarmInfoMarker = marker.addMarker(V2X_EVENT_ALARM_POI, optionsRipple);
ret = marker.addMarker(V2X_EVENT_ALARM_POI, optionsRipple);
}
}
// 当前Marker设置为最上面
if (mAlarmInfoMarker != null) {
mAlarmInfoMarker.setToTop();
if (ret != null) {
ret.setToTop();
}
// 绘制连接线
IMoGoV2XPolylineManager polylineManager = BridgeApi.INSTANCE.v2xPolyline();
@@ -183,28 +180,30 @@ public class MoGoV2XMarkerManager implements IMoGoV2XMarkerManager {
new MogoLatLng(roadEventEntity.getLocation().getLat(),
roadEventEntity.getLocation().getLon()
), context);
return ret;
} else {
CallerLogger.INSTANCE.e(M_V2X + TAG, "Location 必须进行初始化!!!!!");
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
public void clearAlarmPOI() {
boolean isRoadEventPOIShow = false;
IMoGoV2XStatusManager v2xStatus = BridgeApi.INSTANCE.v2xStatus();
if (v2xStatus != null) {
isRoadEventPOIShow = v2xStatus.isRoadEventPOIShow();
}
if (isRoadEventPOIShow) {
v2xStatus.setRoadEventPOIShow(TAG, false);
if (mAlarmInfoMarker != null) {
mAlarmInfoMarker.remove();
}
}
// boolean isRoadEventPOIShow = false;
// IMoGoV2XStatusManager v2xStatus = BridgeApi.INSTANCE.v2xStatus();
// if (v2xStatus != null) {
// isRoadEventPOIShow = v2xStatus.isRoadEventPOIShow();
// }
// if (isRoadEventPOIShow) {
// v2xStatus.setRoadEventPOIShow(TAG, false);
// if (mAlarmInfoMarker != null) {
// mAlarmInfoMarker.remove();
// }
// }
}
@Override
@@ -221,9 +220,9 @@ public class MoGoV2XMarkerManager implements IMoGoV2XMarkerManager {
@Override
public void forceClearAlarmPOI() {
if (mAlarmInfoMarker != null) {
mAlarmInfoMarker.remove();
}
// if (mAlarmInfoMarker != null) {
// mAlarmInfoMarker.remove();
// }
}
@Override

View File

@@ -0,0 +1,196 @@
package com.mogo.eagle.core.function.v2x.events.marker
import android.os.Handler
import android.os.HandlerThread
import android.util.Log
import com.mogo.cloud.commons.utils.CoordinateUtils
import com.mogo.commons.utils.DrivingDirectionUtils
import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.function.call.map.CallerMapLocationListenerManager
import com.mogo.map.marker.IMogoMarker
import com.mogo.map.overlay.IMogoPolyline
import kotlinx.coroutines.Runnable
import java.util.LinkedList
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference
data class MarkerWrapper(val id: String, val lon: Double, val lat: Double, val coordinateType: Int, var markers: ArrayList<IMogoMarker>? = null, var lines: ArrayList<IMogoPolyline>? = null) {
fun addLine(line: IMogoPolyline) {
var ll = this.lines
if (ll == null) {
ll = ArrayList()
this.lines = ll
}
ll.add(line)
}
fun addMarker(marker: IMogoMarker) {
var mm = this.markers
if (mm == null) {
mm = ArrayList()
this.markers = mm
}
mm.add(marker)
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as MarkerWrapper
if (id != other.id) return false
return true
}
override fun hashCode(): Int {
return id.hashCode()
}
}
object MarkerManager {
private const val TAG = "MarkerManager"
private val markers by lazy { LinkedList<MarkerWrapper>() }
private val toRemoveMakers by lazy { LinkedList<MarkerWrapper>() }
private val isFirstAdd by lazy { AtomicBoolean(false) }
private val elapsedDistances by lazy { ConcurrentHashMap<MarkerWrapper, Double>() }
private val lastCarLocation by lazy { AtomicReference<MogoLocation>() }
private val lastGpsLocation by lazy { AtomicReference<MogoLocation>() }
private val checkTask = object : Runnable {
override fun run() {
try {
Log.d(TAG, "--- checkTask --- 1 ---")
if (lastCarLocation.get() == null) {
return
}
Log.d(TAG, "--- checkTask --- 2 ---")
if (lastGpsLocation.get() == null) {
return
}
Log.d(TAG, "--- checkTask --- 3 ---")
val toRemove = toRemoveMakers.iterator()
val carLoc = AtomicReference<MogoLocation>()
while (toRemove.hasNext()) {
val marker = toRemove.next()
if (carLoc.get() == null) {
carLoc.set(if (marker.coordinateType == 0) {
//高德坐标
CallerMapLocationListenerManager.getCurrentLocation()
} else {
CallerMapLocationListenerManager.getCurrentGpsLocation()
})
}
val currentLocation = carLoc.get()
val lastLocation = if (marker.coordinateType == 0) lastCarLocation.get() else lastGpsLocation.get()
if (marker.coordinateType == 0) {
lastCarLocation.set(currentLocation)
} else {
lastGpsLocation.set(currentLocation)
}
if (currentLocation != null && lastLocation != null) {
val delta = CoordinateUtils.calculateLineDistance(currentLocation.longitude, currentLocation.latitude, lastLocation.longitude, lastLocation.latitude)
Log.d(TAG, "--- checkTask --- 4 ---:delta:$delta")
var elapsed = elapsedDistances[marker]
if (elapsed == null) {
elapsed = delta.toDouble()
} else {
elapsed += delta
}
Log.d(TAG, "--- checkTask --- 5 ---:delta:$delta, elapsed:${elapsed}")
if (elapsed >= 300) {
var removeMarkerError = marker.markers == null || marker.markers?.isEmpty() == true
marker.markers?.forEach {
try {
it.setVisible(false)
it.destroy()
} catch (t: Throwable) {
t.printStackTrace()
removeMarkerError = true
Log.e(TAG, "--- checkTask --- remove marker error:${t.message}")
}
}
var removeLineError = marker.lines == null || marker.lines?.isEmpty() == true
marker.lines?.forEach {
try {
it.isVisible = false
it.destroy()
} catch (t: Throwable) {
t.printStackTrace()
removeLineError = true
Log.e(TAG, "--- checkTask --- remove line error:${t.message}")
}
}
if (!removeLineError && !removeMarkerError) {
toRemove.remove()
}
synchronized(elapsedDistances) {
elapsedDistances.remove(marker)
}
} else {
elapsedDistances[marker] = elapsed
}
}
}
val iterator = markers.iterator()
while (iterator.hasNext()) {
val marker = iterator.next()
if (carLoc.get() == null) {
carLoc.set(if (marker.coordinateType == 0) {
//高德坐标
CallerMapLocationListenerManager.getCurrentLocation()
} else {
CallerMapLocationListenerManager.getCurrentGpsLocation()
})
}
val location = carLoc.get()
if (location != null) {
val angle = DrivingDirectionUtils.getDegreeOfCar2Poi2(location.longitude, location.latitude, marker.lon, marker.lat, location.bearing.toDouble())
if (angle >= 90) {
iterator.remove()
synchronized(toRemoveMakers) {
toRemoveMakers.offer(marker)
}
}
}
}
} catch (t: Throwable) {
t.printStackTrace()
} finally {
lastCarLocation.set(CallerMapLocationListenerManager.getCurrentLocation())
lastGpsLocation.set(CallerMapLocationListenerManager.getCurrentGpsLocation())
handler.postDelayed(this, 1000)
}
}
}
private val handler by lazy {
val thread = HandlerThread("check_marker_expired")
thread.start()
Handler(thread.looper)
}
fun addMarker(marker: MarkerWrapper) {
synchronized(markers) {
markers.offer(marker)
}
if (isFirstAdd.compareAndSet(false,true)) {
handler.postDelayed(checkTask, 1000)
}
}
}

View File

@@ -19,7 +19,7 @@ import java.util.concurrent.atomic.AtomicReference;
public abstract class AbsV2XScenario<T> implements IV2XScenario {
protected String TAG = "AbsV2XScenario";
private IV2XMarker mV2XMarker;
private static final AtomicReference<V2XMessageEntity> mV2XMessageEntity = new AtomicReference<>();
private final AtomicReference<V2XMessageEntity> mV2XMessageEntity = new AtomicReference<>();
protected AbsV2XScenario() {
}
@@ -28,13 +28,14 @@ public abstract class AbsV2XScenario<T> implements IV2XScenario {
@Override
public void close() {
clearPOI();
// clearPOI();
}
/**
* 释放资源
*/
public void release() {
mV2XMessageEntity.set(null);
mV2XMarker = null;
}

View File

@@ -35,6 +35,8 @@ public class V2XScenarioManager implements IV2XScenarioManager {
private static final String TAG = "V2XScenarioManager";
private AbsV2XScenario mV2XScenario = null;
private AtomicReference<V2XMessageEntity> last = new AtomicReference<>();
private V2XScenarioManager() {
}
@@ -54,6 +56,12 @@ public class V2XScenarioManager implements IV2XScenarioManager {
public void handlerMessage(V2XMessageEntity v2XMessageEntity) {
CallerLogger.INSTANCE.d(M_V2X + TAG, "处理V2X场景" + (v2XMessageEntity == null ? "null" : v2XMessageEntity.toString()));
try {
V2XMessageEntity old = last.get();
if (old != null && old.equals(v2XMessageEntity)) {
return;
}
last.set(v2XMessageEntity);
synchronized (V2XScenarioManager.class) {
// 展示
ThreadUtils.runOnUiThread(() -> {

View File

@@ -1,93 +1,65 @@
package com.mogo.eagle.core.function.v2x.events.scenario.scene.airoad
import android.animation.*
import android.content.*
import android.graphics.*
import android.os.*
import android.view.animation.*
import androidx.core.util.Pair
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
import com.mogo.eagle.core.data.map.entity.V2XRoadEventEntity
import com.mogo.eagle.core.function.api.map.listener.*
import com.mogo.eagle.core.function.api.v2x.*
import com.mogo.eagle.core.function.call.map.*
import com.mogo.eagle.core.function.call.map.CallerMapRoadListenerManager.OnRoadListener
import com.mogo.eagle.core.function.call.v2x.*
import com.mogo.eagle.core.function.v2x.events.consts.V2XConst.V2X_EVENT_ALARM_POI
import com.mogo.eagle.core.function.v2x.events.marker.MarkerManager
import com.mogo.eagle.core.function.v2x.events.marker.MarkerWrapper
import com.mogo.eagle.core.function.v2x.events.scenario.scene.road.*
import com.mogo.eagle.core.utilcode.kotlin.*
import com.mogo.eagle.core.utilcode.mogo.logger.*
import com.mogo.map.*
import com.mogo.map.overlay.*
import io.netty.util.internal.*
import java.lang.Runnable
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.*
import kotlin.collections.ArrayList
/**
* Ai云道路施工事件道路颜色标记类
*/
object AiRoadMarker {
class AiRoadMarker {
private const val TAG = "AiRoadMarker"
companion object {
@JvmField
val aiMakers = ConcurrentHashMap<String, AiRoadMarker>()
}
private val TAG = "AiRoadMarker"
private val marker by lazy { AtomicReference<Marker>() }
private val carLocation by lazy { AtomicReference<Triple<Double, Double, Double>>() }
private val overlayManager by lazy { MogoOverlayManager.getInstance() }
private val line by lazy { AtomicReference<IMogoPolyline>() }
private val START_COLOR = Color.parseColor("#002ABAD9")
private val END_COLOR = Color.parseColor("#66FF7A30")
private val roadMarker by lazy { V2XAiRoadEventMarker() }
private val line = AtomicReference<IMogoPolyline>()
private val handler by lazy {
Handler(Looper.getMainLooper())
}
private val checkExpiredTask = Runnable {
val poi = this.marker.get()
val car = this.carLocation.get()
val car = CallerMapLocationListenerManager.getCurrentGpsLocation()
if (poi != null && car != null) {
val distance = CoordinateUtils.calculateLineDistance(car.first, car.second, poi.poi_lon, poi.poi_lat)
val distance = CoordinateUtils.calculateLineDistance(car.longitude, car.latitude, poi.poi_lon, poi.poi_lat)
if (distance < 500) {
unMarker(poi)
}
}
}
private val onClearAllMarker = object : OnClearAllMarker {
override fun onClearAllMarkers() {
Logger.d(TAG, "--- onClearAllMarkers ----")
val marker = this@AiRoadMarker.marker.get()
if (marker != null) {
Logger.d(TAG, "--- onClearAllMarkers ----2")
unMarker(marker)
}
}
override fun onClearAllMarkers(tag: String) {
Logger.d(TAG, "--- onClearAllMarkers ----: tag: $tag")
val marker = this@AiRoadMarker.marker.get()
if (marker != null && tag == V2X_EVENT_ALARM_POI) {
Logger.d(TAG, "--- onClearAllMarkers ----: tag: -- 1: $tag")
unMarker(marker)
}
}
}
private val markers = ConcurrentSet<Marker>()
private val options by lazy {
MogoPolylineOptions().apply {
zIndex(40000f)
@@ -97,71 +69,21 @@ object AiRoadMarker {
}
}
fun init(ctx: Context) {
ctx.lifeCycleOwner.lifecycle.addObserver(object : LifecycleEventObserver {
override fun onStateChanged(source: LifecycleOwner, event: Event) {
if (event == ON_CREATE) {
onCreate()
}
if (event == ON_DESTROY) {
onDestroy()
}
}
})
}
private val onLocationListener = object : IMoGoMapLocationListener {
override fun onLocationChanged(location: MogoLocation?, from: Int, isGps: Boolean) {
if (location == null || !isGps) {
return
}
try {
val loc = arrayOf(location.longitude, location.latitude)
carLocation.set(Triple(loc[0], loc[1], location.bearing.toDouble()))
} catch (t: Throwable) {
Logger.e(TAG, "error: ${t.message}")
}
}
}
private fun onCreate() {
CallMarkersClearManager.addAllMarkersClearListener(TAG, onClearAllMarker)
CallerMapLocationListenerManager.addListener(TAG, onLocationListener, true)
}
private fun onDestroy() {
CallMarkersClearManager.removeAllMarkersClearListener(TAG)
CallerMapLocationListenerManager.removeListener(TAG, true)
removeLine()
}
fun marker(marker: Marker, drawMarker: Boolean, drawRoadLine: Boolean = false) {
handler.removeCallbacks(checkExpiredTask)
val location = carLocation.get() ?: return
if (markers.contains(marker)) {
Logger.d(TAG, "--- maker --- cache hit ---")
return
}
Logger.d(TAG, "--- marker ---:${marker}")
synchronized(markers) {
markers += marker
}
val location = CallerMapLocationListenerManager.getCurrentGpsLocation() ?: return
this.marker.set(marker)
val wrapper = MarkerWrapper(marker.id, marker.poi_lon, marker.poi_lat, 1, null, null)
if (drawMarker) {
marker.entity?.apply { V2XAiRoadEventMarker.drawMarkers(this) }
marker.entity?.apply { roadMarker.drawMarkers(this, wrapper) }
}
if (drawRoadLine) {
//施工中心点前方的自车行驶方向上300米距离
val l1 = MogoMap.getInstance().mogoMap.getCenterLineRangeInfo(marker.poi_lon, marker.poi_lat, location.third.toFloat(), 300f)
val l1 = MogoMap.getInstance().mogoMap.getCenterLineRangeInfo(marker.poi_lon, marker.poi_lat, location.bearing, 300f)
//施工中心点后方的自车行驶方向上300米距离
Logger.d(TAG, "--- marker --- 3 --- l1: $l1")
val l2 = MogoMap.getInstance().mogoMap.getCenterLineRangeInfo(marker.poi_lon, marker.poi_lat, location.third.toFloat(), -300f)
val l2 = MogoMap.getInstance().mogoMap.getCenterLineRangeInfo(marker.poi_lon, marker.poi_lat, location.bearing, -300f)
if (l1.points.isEmpty() || l2.points.isEmpty()) {
Logger.d(TAG, "--- marker --- 3 --- return ----")
synchronized(markers) {
markers.remove(marker)
}
return
}
Logger.d(TAG, "--- marker --- 4 --- l2: $l2")
@@ -178,7 +100,7 @@ object AiRoadMarker {
var find: Pair<Double, Double> = Pair(centerX, centerY)
var min = Long.MAX_VALUE
for (p in it) {
val angle = DrivingDirectionUtils.getDegreeOfCar2Poi2(centerX, centerY, p.first, p.second, location.third)
val angle = DrivingDirectionUtils.getDegreeOfCar2Poi2(centerX, centerY, p.first, p.second, location.bearing.toDouble())
if (angle < min) {
min = angle
find = p
@@ -190,18 +112,14 @@ object AiRoadMarker {
Logger.d(TAG, "--- marker --- 6 --- marker: $marker")
if (l1 != null && l1.points.isNotEmpty()) {
for (l in l1.points) {
if (DrivingDirectionUtils.getDegreeOfCar2Poi2(farthestPoint.lon, farthestPoint.lat, l.first, l.second, location.third + 180) < 90L) {
if (DrivingDirectionUtils.getDegreeOfCar2Poi2(farthestPoint.lon, farthestPoint.lat, l.first, l.second, (location.bearing + 180).toDouble()) < 90L) {
points.add(l.let { MogoLatLng(it.second, it.first) })
}
}
}
if (points.size <= 1) {
synchronized(markers) {
markers.remove(marker)
}
return
}
removeLine()
val evaluator = ArgbEvaluator()
val interceptor = DecelerateInterpolator(1.5f)
val total = points.size
@@ -223,8 +141,10 @@ object AiRoadMarker {
if (!line.isVisible) {
line.isVisible = true
}
} else {
removeLine()
if (line != null) {
wrapper.addLine(line)
}
MarkerManager.addMarker(wrapper)
}
}
@@ -239,22 +159,21 @@ object AiRoadMarker {
}
}
fun unMarker(marker: Marker) {
private fun unMarker(marker: Marker) {
Logger.d(TAG, "--- unMarker ---")
markers -= marker
this.marker.set(null)
removeLine()
V2XAiRoadEventMarker.removeMarkers(null)
roadMarker.removeMarkers()
handler.removeCallbacks(checkExpiredTask)
}
fun receive(marker: Marker) {
fun receive() {
Logger.d(TAG, "receive --- 1 ---")
val poi = this.marker.get()
val car = this.carLocation.get()
val car = CallerMapLocationListenerManager.getCurrentGpsLocation()
if (poi != null && car != null) {
val distance = CoordinateUtils.calculateLineDistance(car.first, car.second, marker.poi_lon, marker.poi_lat)
Logger.d(TAG, "receive --- 2 ---:car:[${car.first}, ${car.second}] -> poi:[${marker.poi_lon}, ${marker.poi_lat}] --> distance:$distance")
val distance = CoordinateUtils.calculateLineDistance(car.longitude, car.latitude, poi.poi_lon, poi.poi_lat)
Logger.d(TAG, "receive --- 2 ---:car:[${car.longitude}, ${car.latitude}] -> poi:[${poi.poi_lon}, ${poi.poi_lat}] --> distance:$distance")
if (distance < 500) {
checkExpired()
} else {

View File

@@ -1,42 +1,33 @@
package com.mogo.eagle.core.function.v2x.events.scenario.scene.road
import android.graphics.*
import android.util.*
import com.mogo.cloud.commons.utils.*
import com.mogo.commons.utils.DrivingDirectionUtils
import com.mogo.eagle.core.data.enums.EventTypeEnumNew
import com.mogo.eagle.core.data.map.*
import com.mogo.eagle.core.data.map.entity.V2XRoadEventEntity
import com.mogo.eagle.core.function.v2x.events.bridge.BridgeApi.context
import com.mogo.eagle.core.function.v2x.events.bridge.BridgeApi.v2xMarker
import com.mogo.eagle.core.function.v2x.events.marker.MarkerWrapper
import com.mogo.map.*
import com.mogo.map.marker.*
import com.mogo.map.overlay.*
import java.util.*
import java.util.concurrent.atomic.*
import kotlin.Pair
import kotlin.collections.ArrayList
object V2XAiRoadEventMarker {
class V2XAiRoadEventMarker {
private val current = AtomicReference<Pair<IMogoPolyline?, List<IMogoMarker>?>>()
private val v2xLocation = AtomicReference<MogoLocation>()
private val carLocation = AtomicReference<MogoLocation>()
private val timer = Timer()
private val timerTask by lazy { AtomicReference<TimerTask>() }
private val distance = AtomicInteger(0)
private val overlayManager by lazy { MogoOverlayManager.getInstance() }
fun drawMarkers(entity: V2XRoadEventEntity) {
removeMarkers(current.get())
timerTask.get()?.cancel()
fun drawMarkers(entity: V2XRoadEventEntity, wrapper: MarkerWrapper) {
val extra = entity.noveltyInfo.extras["polygon"]
if (extra is List<*>) {
v2xMarker()?.drawableAlarmPOI(context(), entity, null)?.also {
wrapper.addMarker(it)
}
if (extra is List<*> && entity.poiType != EventTypeEnumNew.TYPE_SOCKET_ROAD_JINGZHI.poiType) {
if (extra.size > 0) {
val polygons: MutableList<androidx.core.util.Pair<Double, Double>> = ArrayList()
for (i in extra.indices) {
@@ -52,7 +43,6 @@ object V2XAiRoadEventMarker {
polygons.add(androidx.core.util.Pair.create(second, first))
}
if (polygons.size > 0) {
v2xMarker()?.drawableAlarmPOI(context(), entity, null)
val l2 = entity.noveltyInfo?.location ?: return
v2xLocation.set(MogoLocation().also {
it.longitude = l2.lon; it.latitude = l2.lat; it.bearing = l2.angle.toFloat()
@@ -82,24 +72,17 @@ object V2XAiRoadEventMarker {
current.set(Pair(line, null))
if (line != null) {
line.isVisible = true
wrapper.addLine(line)
}
}
}
}
}
fun removeMarkers(pair: Pair<IMogoPolyline?, List<IMogoMarker>?>?) {
if (pair != null) {
realRemove(pair)
} else {
val prev = current.get()
if (prev != null) {
realRemove(prev)
val v2xMarker = v2xMarker()
v2xMarker?.also {
it.forceClearAlarmPOI()
}
}
fun removeMarkers() {
val prev = current.get()
if (prev != null) {
realRemove(prev)
}
}
@@ -115,73 +98,4 @@ object V2XAiRoadEventMarker {
}
}
}
fun onLocationChanged(location: MogoLocation) {
val markerLocation = v2xLocation.get()
carLocation.set(location)
if (markerLocation != null) {
if (isOutOfRange(
markerLocation.longitude,
markerLocation.latitude,
location.longitude,
location.latitude,
location.bearing.toDouble()
)
) {
v2xLocation.set(null)
this.distance.set(0)
timer.schedule(object : TimerTask() {
override fun run() {
val carLocation = this@V2XAiRoadEventMarker.carLocation.get()
Log.d(
"XXXXX",
"timer do action ---: marker_lon: ${markerLocation.longitude}, marker_lat: ${markerLocation.latitude}, car_lon:${carLocation.longitude}, car_lat: ${carLocation.latitude}"
)
checkDistanceIsValid(
markerLocation.longitude,
markerLocation.latitude,
carLocation
)
}
}.also { this.timerTask.set(it) }, 1000, 1000)
}
}
}
private fun checkDistanceIsValid(x1: Double, y1: Double, location: MogoLocation) {
val distance = DrivingDirectionUtils.distance(x1, y1, location.longitude, location.latitude)
Log.d("XXXXX", "distance: $distance")
if (this.distance.addAndGet(distance.toInt()) >= 100) {
Log.d("XXXXX", "remove marker")
removeMarkers(null)
this.timerTask.get()?.cancel()
}
}
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
}
}

View File

@@ -10,10 +10,11 @@ import com.mogo.eagle.core.data.map.entity.MarkerLocation;
import com.mogo.eagle.core.data.map.entity.V2XRoadEventEntity;
import com.mogo.eagle.core.function.v2x.events.bridge.BridgeApi;
import com.mogo.eagle.core.function.v2x.events.manager.IMoGoV2XMarkerManager;
import com.mogo.eagle.core.function.v2x.events.manager.IMoGoV2XPolylineManager;
import com.mogo.eagle.core.function.v2x.events.marker.MarkerWrapper;
import com.mogo.eagle.core.function.v2x.events.marker.MarkerManager;
import com.mogo.eagle.core.function.v2x.events.scenario.scene.airoad.AiRoadMarker;
import com.mogo.eagle.core.function.v2x.events.scenario.view.IV2XMarker;
import com.mogo.eagle.core.network.utils.GsonUtil;
import com.mogo.map.marker.IMogoMarker;
import java.util.ArrayList;
import java.util.List;
@@ -25,34 +26,29 @@ import java.util.Objects;
public class V2XRoadEventMarker implements IV2XMarker<V2XRoadEventEntity> {
private static AiRoadMarker.Marker mMarker;
@Override
public void drawPOI(V2XRoadEventEntity entity) {
try {
// 清除道路事件
IMoGoV2XMarkerManager marker = BridgeApi.INSTANCE.v2xMarker();
if (marker != null) {
marker.clearAlarmPOI();
if (entity != null) {
Log.d("RWJ", "V2XRoadEventMarker:" + entity.getPoiType());
if (!Objects.equals(entity.getPoiType(), EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGONG.getPoiType())
&& !Objects.equals(entity.getPoiType(), EventTypeEnumNew.FOURS_ACCIDENT_04.getPoiType())
&& !Objects.equals(entity.getPoiType(), EventTypeEnumNew.TYPE_SOCKET_ROAD_JINGZHI.getPoiType())
&& !Objects.equals(entity.getPoiType(), EventTypeEnumNew.TYPE_SOCKET_ROAD_CONGESTION.getPoiType())
&& !Objects.equals(entity.getPoiType(), EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGU.getPoiType())) {
AiRoadMarker.Marker prev = mMarker;
if (prev != null) {
AiRoadMarker.INSTANCE.unMarker(prev);
mMarker = null;
IMogoMarker iMarker = marker.drawableAlarmPOI(BridgeApi.INSTANCE.context(), entity, null);
if (iMarker != null) {
Log.d("RWJ", "V2XRoadEventMarker:" + entity.getPoiType() + "--- add Marker");
ArrayList<IMogoMarker> markers = new ArrayList<>();
markers.add(iMarker);
String id = entity.getLocation().getLon() + "_" + entity.getLocation().getLat();
MarkerManager.INSTANCE.addMarker(new MarkerWrapper(id, entity.getLocation().getLon(), entity.getLocation().getLat(), 0, markers, null));
} else {
Log.d("RWJ", "V2XRoadEventMarker:" + entity.getPoiType() + "--- return empty marker");
}
marker.drawableAlarmPOI(BridgeApi.INSTANCE.context(), entity, null);
} else {
AiRoadMarker.Marker prev = mMarker;
if (prev != null) {
AiRoadMarker.INSTANCE.unMarker(prev);
mMarker = null;
}
MarkerExploreWay noveltyInfo = entity.getNoveltyInfo();
Log.d("RWJ", "V2XRoadEventMarker -> noveltyInfo:" + noveltyInfo);
if (noveltyInfo != null && noveltyInfo.extras != null) {
@@ -86,12 +82,12 @@ public class V2XRoadEventMarker implements IV2XMarker<V2XRoadEventEntity> {
if (noveltyInfo.extras.containsKey("gps_location")) {
gpsLocation = (Pair<Double, Double>) ((List)(noveltyInfo.extras.get("gps_location"))).get(0);
}
if (!polygons.isEmpty() && gpsLocation != null) {
MarkerLocation location = noveltyInfo.getLocation();
AiRoadMarker.Marker m = new AiRoadMarker.Marker(noveltyInfo.getInfoId(), noveltyInfo.getPoiType(), gpsLocation.second, gpsLocation.first, location.getAngle(), polygons, null, entity);
mMarker = m;
AiRoadMarker.INSTANCE.marker(m, true, isDrawRoadLine(m.getPoiType()));
AiRoadMarker aiMarker = new AiRoadMarker();
aiMarker.marker(m, true, isDrawRoadLine(m.getPoiType()));
AiRoadMarker.aiMakers.put(noveltyInfo.getInfoId(), aiMarker);
}
}
}
@@ -109,16 +105,16 @@ public class V2XRoadEventMarker implements IV2XMarker<V2XRoadEventEntity> {
@Override
public void clearPOI() {
// 移除线
IMoGoV2XPolylineManager polyLineManager = BridgeApi.INSTANCE.v2xPolyline();
if (polyLineManager != null) {
polyLineManager.clearLine();
}
IMoGoV2XMarkerManager v2xMarker = BridgeApi.INSTANCE.v2xMarker();
if (v2xMarker != null) {
// 移除事件POI
v2xMarker.clearAlarmPOI();
// 绘制上次的数据
v2xMarker.drawableLastAllPOI();
}
// IMoGoV2XPolylineManager polyLineManager = BridgeApi.INSTANCE.v2xPolyline();
// if (polyLineManager != null) {
// polyLineManager.clearLine();
// }
// IMoGoV2XMarkerManager v2xMarker = BridgeApi.INSTANCE.v2xMarker();
// if (v2xMarker != null) {
// // 移除事件POI
// v2xMarker.clearAlarmPOI();
// // 绘制上次的数据
// v2xMarker.drawableLastAllPOI();
// }
}
}

View File

@@ -109,7 +109,7 @@ public class V2XRoadEventScenario extends AbsV2XScenario<V2XRoadEventEntity> imp
}
String poiType = content.getPoiType();
if (EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGONG.getPoiType().equals(poiType) ||
EventTypeEnumNew.TYPE_SOCKET_ROAD_JINGZHI.getPoiType().equals(poiType) ||
EventTypeEnumNew. TYPE_SOCKET_ROAD_JINGZHI.getPoiType().equals(poiType) ||
EventTypeEnumNew.TYPE_SOCKET_ROAD_CONGESTION.getPoiType().equals(poiType) ||
EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGU.getPoiType().equals(poiType)) {
MogoLocation carLocation = CallerMapLocationListenerManager.INSTANCE.getCurrentLocation();
@@ -150,10 +150,10 @@ public class V2XRoadEventScenario extends AbsV2XScenario<V2XRoadEventEntity> imp
@Override
public void clearPOI() {
IV2XMarker marker = getV2XMarker();
if (marker != null) {
marker.clearPOI();
}
// IV2XMarker marker = getV2XMarker();
// if (marker != null) {
// marker.clearPOI();
// }
}
@Override
@@ -164,11 +164,12 @@ public class V2XRoadEventScenario extends AbsV2XScenario<V2XRoadEventEntity> imp
CallerHmiManager.INSTANCE.showWarning(WarningDirectionEnum.ALERT_WARNING_TOP, TimeUnit.HOURS.toMillis(1));
V2XMessageEntity<V2XRoadEventEntity> entity = getV2XMessageEntity();
if (entity != null) {
if (entity.isNeedAddLine()) {
drawPOI();
}
V2XRoadEventEntity content = entity.getContent();
if (content != null) {
if (entity.isNeedAddLine() && !EventTypeEnumNew.TYPE_SOCKET_ROAD_CONGESTION.getPoiType().equals(content.getPoiType()) ) {
drawPOI();
}
MarkerExploreWay noveltyInfo = content.getNoveltyInfo();
if (noveltyInfo != null && EventTypeEnumNew.FOURS_FOG.getPoiType().equals(content.getNoveltyInfo().getPoiType())) {
CallerHmiManager.INSTANCE.displayEffects();
@@ -192,7 +193,6 @@ public class V2XRoadEventScenario extends AbsV2XScenario<V2XRoadEventEntity> imp
if (isNeedChangeAngle()) {
CallerVisualAngleManager.INSTANCE.changeVisualAngle(new CallerVisualAngleManager.Scene.Default(3, TimeUnit.SECONDS));
}
clearPOI();
release();
}
}

View File

@@ -39,13 +39,13 @@ public class V2XOptimalRouteVREventMarker implements IV2XMarker<V2XOptimalRouteD
@Override
public void clearPOI() {
// 移除线
clearLine();
// 绘制上次的数据
IMoGoV2XMarkerManager v2xMarker = BridgeApi.INSTANCE.v2xMarker();
if (v2xMarker != null) {
v2xMarker.drawableLastAllPOI();
}
// // 移除线
// clearLine();
// // 绘制上次的数据
// IMoGoV2XMarkerManager v2xMarker = BridgeApi.INSTANCE.v2xMarker();
// if (v2xMarker != null) {
// v2xMarker.drawableLastAllPOI();
// }
}
public void clearLine() {

View File

@@ -86,13 +86,13 @@ public class V2XOptimalRouteVREventScenario
@Override
public void clearPOI() {
if (getV2XMarker() != null) {
getV2XMarker().clearPOI();
}
IMoGoV2XStatusManager v2xStatus = BridgeApi.INSTANCE.v2xStatus();
if (v2xStatus != null) {
v2xStatus.setPushPOIShow(TAG, false);
}
// if (getV2XMarker() != null) {
// getV2XMarker().clearPOI();
// }
// IMoGoV2XStatusManager v2xStatus = BridgeApi.INSTANCE.v2xStatus();
// if (v2xStatus != null) {
// v2xStatus.setPushPOIShow(TAG, false);
// }
}
@Override
@@ -102,6 +102,5 @@ public class V2XOptimalRouteVREventScenario
@Override
public void onDismiss() {
clearPOI();
}
}

View File

@@ -163,6 +163,6 @@ public class V2XFrontWarningScenario extends AbsV2XScenario implements IMoGoMapL
if (mDirection != null) {
CallerHmiManager.INSTANCE.dismissWarning(mDirection);
}
clearPOI();
// clearPOI();
}
}

View File

@@ -98,14 +98,7 @@ fun Road.RW_PB.toRoadMarker(): V2XMarkerCardResult =
l3.infoId = id
})
}
AiRoadMarker.receive(
AiRoadMarker.Marker(id, EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGONG.poiType,
this.roadwork?.center?.point?.lat ?: 0.0,
this.roadwork?.center?.point?.lon ?: 0.0,
this.roadwork?.center?.road?.bearing?.toDouble() ?: 0.0,
)
)
AiRoadMarker.aiMakers[id]?.receive()
}
fun V2XRoadXData.toRoadMarker(): V2XMarkerCardResult =
@@ -136,15 +129,7 @@ fun V2XRoadXData.toRoadMarker(): V2XMarkerCardResult =
})
}
AiRoadMarker.receive(
AiRoadMarker.Marker(
this.index.toString(),
this.poiType ?: "",
this.center?.lat ?: 0.0,
this.center?.lon ?: 0.0,
this.centerRoad?.bearing ?: 0.0
)
)
AiRoadMarker.aiMakers[this.index]?.receive()
}
fun MessagePad.TrackedObject.toRoadMarker(poiType: String): V2XMarkerCardResult =
@@ -170,9 +155,7 @@ fun MessagePad.TrackedObject.toRoadMarker(poiType: String): V2XMarkerCardResult
l3.infoId = id
})
}
AiRoadMarker.receive(
AiRoadMarker.Marker(id, poiType, this.latitude, this.longitude, this.heading, null, null, null)
)
AiRoadMarker.aiMakers[id]?.receive()
}
fun V2XMarkerCardResult.toV2XRoadEventEntity(): V2XRoadEventEntity =

View File

@@ -15,7 +15,8 @@ data class V2XRoadXData(
val obstacles: List<Obstacle>? = null,
val polygon: List<Point>? = null,
val type: Int? = 0,
val detectTime: Long? = 0L
val detectTime: Long? = 0L,
val crossId: String? = null
)
@Keep
@@ -24,7 +25,8 @@ data class CenterRoad(
val laneNo: Int? = null,
val roadId: String? = null,
val roadName: String? = null,
val tileId: Int? = 0
val tileId: Int? = 0,
val heading: String? = null
)
@Keep