[VisualAngle]实现地图sdk路口相关回调;处理十字路口视角切换逻辑
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package com.mogo.eagle.core.data.map
|
||||
|
||||
class MapRoadInfo {
|
||||
|
||||
class StopLine {
|
||||
/**
|
||||
* 停止线的长度
|
||||
*/
|
||||
var distance: Double = 0.0
|
||||
|
||||
/**
|
||||
* 车道ID
|
||||
*/
|
||||
var laneId: String = ""
|
||||
|
||||
/**
|
||||
* 停止线上的点
|
||||
*/
|
||||
var points: List<MogoLatLng> = emptyList()
|
||||
|
||||
/**
|
||||
* 道路ID
|
||||
*/
|
||||
var roadId: String = ""
|
||||
|
||||
/**
|
||||
* 瓦片ID
|
||||
*/
|
||||
var tieId: String = ""
|
||||
|
||||
/**
|
||||
* 自车到停止线的距离
|
||||
*/
|
||||
var distanceOfCarToStopLine: Double = 0.0
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,16 @@ public class MogoLatLng implements Parcelable {
|
||||
public final double lat;
|
||||
public final double lon;
|
||||
|
||||
public double angle;
|
||||
|
||||
public int duration;
|
||||
|
||||
public double speed;
|
||||
|
||||
public double altitude;
|
||||
|
||||
public String provider;
|
||||
|
||||
public MogoLatLng( double lat, double lon ) {
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.mogo.eagle.core.function.call.map
|
||||
|
||||
import com.mogo.eagle.core.data.map.MapRoadInfo.StopLine
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
object CallerMapRoadListenerManager {
|
||||
|
||||
interface OnRoadListener {
|
||||
|
||||
fun onRoadIdInfo(roadId: String)
|
||||
|
||||
fun onStopLineInfo(info: StopLine)
|
||||
}
|
||||
|
||||
private val listeners by lazy {
|
||||
ConcurrentHashMap<String, OnRoadListener>()
|
||||
}
|
||||
|
||||
fun registerRoadListener(tag: String, listener: OnRoadListener) {
|
||||
if (listeners.contains(tag)) {
|
||||
return
|
||||
}
|
||||
listeners[tag] = listener
|
||||
}
|
||||
|
||||
fun unRegisterRoadListener(tag: String) {
|
||||
if (!listeners.contains(tag)) {
|
||||
return
|
||||
}
|
||||
listeners.remove(tag)
|
||||
}
|
||||
|
||||
|
||||
fun invokeListenersOnRoadIdGet(roadId: String) {
|
||||
listeners.forEach { entry ->
|
||||
entry.value.onRoadIdInfo(roadId)
|
||||
}
|
||||
}
|
||||
|
||||
fun invokeListenersOnStopLineGet(stopLine: StopLine) {
|
||||
listeners.forEach { entry ->
|
||||
entry.value.onStopLineInfo(stopLine)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,10 @@ import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.SystemClock
|
||||
import android.util.Log
|
||||
import com.mogo.eagle.core.data.map.MapRoadInfo.StopLine
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng
|
||||
import com.mogo.eagle.core.function.call.map.CallerMapRoadListenerManager.OnRoadListener
|
||||
import com.mogo.eagle.core.function.call.map.CallerVisualAngleManager.Scene.CrossRoad
|
||||
import com.mogo.eagle.core.function.call.map.CallerVisualAngleManager.Scene.Default
|
||||
import com.mogo.eagle.core.function.call.map.CallerVisualAngleManager.Scene.LowSpeed
|
||||
import com.mogo.eagle.core.utilcode.kotlin.safeCancel
|
||||
@@ -23,7 +26,11 @@ object CallerVisualAngleManager {
|
||||
|
||||
private const val TAG = "VisualAngle"
|
||||
|
||||
private const val MaxDisplayThreshold = 20_000 //最大展示阈值
|
||||
private const val MaxDisplayThreshold = 30_000 //最大展示阈值
|
||||
|
||||
@Volatile
|
||||
private var hasCrossRoad = false
|
||||
|
||||
|
||||
private var scope: CoroutineScope = acquireScope()
|
||||
@Synchronized
|
||||
@@ -47,6 +54,30 @@ object CallerVisualAngleManager {
|
||||
val priority: Int
|
||||
}
|
||||
|
||||
init {
|
||||
CallerMapRoadListenerManager.registerRoadListener("VisualAngleChange", object : OnRoadListener {
|
||||
|
||||
private var roadId = ""
|
||||
|
||||
override fun onRoadIdInfo(roadId: String) {}
|
||||
|
||||
override fun onStopLineInfo(info: StopLine) {
|
||||
if (!hasCrossRoad && info.distanceOfCarToStopLine <= 30.0) {
|
||||
hasCrossRoad = true
|
||||
changeVisualAngle(CrossRoad)
|
||||
}
|
||||
val oldRoadId = this.roadId
|
||||
if (oldRoadId != roadId) {
|
||||
if (hasCrossRoad) {
|
||||
hasCrossRoad = false
|
||||
changeVisualAngle(Default())
|
||||
}
|
||||
}
|
||||
this.roadId = info.roadId
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
sealed class Scene private constructor(): IAttach {
|
||||
|
||||
/**
|
||||
@@ -146,16 +177,14 @@ object CallerVisualAngleManager {
|
||||
|
||||
@OptIn(InternalCoroutinesApi::class)
|
||||
fun changeVisualAngle(scene: Scene) {
|
||||
val triggerTime = SystemClock.elapsedRealtime()
|
||||
val triggerTime = TimeUnit.MILLISECONDS.toSeconds(SystemClock.elapsedRealtime())
|
||||
scope.launch {
|
||||
val displayed = getDisplayed()
|
||||
if (displayed == null) {
|
||||
val top = getTop() //堆顶
|
||||
if (top != null && top.target.priority > scene.priority) {
|
||||
doChangeAngle(top)
|
||||
synchronized(heap) {
|
||||
heap += Record(scene, triggerTime = triggerTime)
|
||||
}
|
||||
heap += Record(scene, triggerTime = triggerTime)
|
||||
} else {
|
||||
doChangeAngle(Record(scene, triggerTime = triggerTime))
|
||||
}
|
||||
@@ -167,9 +196,7 @@ object CallerVisualAngleManager {
|
||||
}
|
||||
if (scene is Default) {
|
||||
Log.d(TAG, "恢复到默认视图,之前展示的视图:$displayed")
|
||||
synchronized(heap) {
|
||||
heap -= displayed
|
||||
}
|
||||
heap -= displayed
|
||||
launch {
|
||||
val delay = scene.unit.toMillis(scene.delay)
|
||||
Log.d(TAG, "默认视图开启延时倒计时, 倒计时时间:${delay} ms.")
|
||||
|
||||
@@ -21,10 +21,12 @@ import android.view.View;
|
||||
import com.mogo.commons.constants.SharedPrefsConstants;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.eagle.core.data.config.HdMapBuildConfig;
|
||||
import com.mogo.eagle.core.data.map.MapRoadInfo;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.eagle.core.data.map.MogoLocation;
|
||||
import com.mogo.eagle.core.function.call.map.CallerMapDataCollectorManager;
|
||||
import com.mogo.eagle.core.function.call.map.CallerMapLocationListenerManager;
|
||||
import com.mogo.eagle.core.function.call.map.CallerMapRoadListenerManager;
|
||||
import com.mogo.eagle.core.function.call.map.CallerMapStyleListenerManager;
|
||||
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager;
|
||||
import com.mogo.eagle.core.function.call.map.CallerVisualAngleManager;
|
||||
@@ -75,6 +77,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -173,18 +176,78 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
@Override
|
||||
public void onRoadIdInfo(@androidx.annotation.Nullable String s) {
|
||||
Log.d(TAG, "-- onRoadIdInfo --RoadId:" + s);
|
||||
mRoadId = s;
|
||||
if (s != null) {
|
||||
CallerMapRoadListenerManager.INSTANCE.invokeListenersOnRoadIdGet(s);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopLineInfo(@androidx.annotation.Nullable StopLine stopLine) {
|
||||
Log.d(TAG, "-- onStopLineInfo:" + (stopLine != null ? stopLine.toString() : null) + "-> road_id:" + mRoadId);
|
||||
if (stopLine != null && mRoadId != null && TextUtils.equals(mRoadId, stopLine.road_id)) {
|
||||
MogoLocation location = CallerMapLocationListenerManager.INSTANCE.getCurrentLocation();
|
||||
//MapAutoApi.INSTANCE.
|
||||
Log.d(TAG, "-- onStopLineInfo -- 1 --:" + (stopLine != null ? stopLine.toString() : null) + "-> road_id:" + mRoadId);
|
||||
MogoLocation carLoc = CallerMapLocationListenerManager.INSTANCE.getCurrentLocation();
|
||||
if (stopLine != null) {
|
||||
ArrayList<LonLatPoint> points = stopLine.points;
|
||||
if (points != null && carLoc != null) {
|
||||
MapRoadInfo.StopLine stopInfo = convert(stopLine);
|
||||
LonLatPoint match = new LonLatPoint();
|
||||
double ret = MapDataApi.INSTANCE.GetDisFromPointToLine(convert(carLoc), points, match, 1);
|
||||
Log.d(TAG, "-- onStopLineInfo --- ret: "+ ret);
|
||||
double distanceOfCarToStopLine = 0.0;
|
||||
if (Double.compare(ret, -1.0) != 0) {
|
||||
distanceOfCarToStopLine = MapTools.INSTANCE.distance(carLoc.getLatitude(), carLoc.getLongitude(), match.getLatitude(), match.getLongitude());
|
||||
} else {
|
||||
LonLatPoint p1 = points.isEmpty() ? null : points.get(0);
|
||||
LonLatPoint p2 = points.isEmpty() ? null : points.get(points.size() - 1);
|
||||
LonLatPoint aim = p1 != null && p2 != null ? new LonLatPoint((p1.longitude + p2.longitude) / 2, (p1.altitude + p2.altitude) / 2, (p1.angle + p2.angle) / 2) : (p1 != null ? p1 : p2);
|
||||
if (aim != null) {
|
||||
distanceOfCarToStopLine = MapTools.INSTANCE.distance(carLoc.getAltitude(), carLoc.getLongitude(), aim.getLatitude(), aim.getLongitude());
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "-- onStopLineInfo --- distance: "+ distanceOfCarToStopLine);
|
||||
stopInfo.setDistanceOfCarToStopLine(distanceOfCarToStopLine);
|
||||
Log.d(TAG, "-- :");
|
||||
CallerMapRoadListenerManager.INSTANCE.invokeListenersOnStopLineGet(stopInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private @NotNull LonLatPoint convert(MogoLocation location) {
|
||||
LonLatPoint point = new LonLatPoint();
|
||||
point.latitude = location.getLatitude();
|
||||
point.longitude = location.getLongitude();
|
||||
point.altitude = location.getAltitude();
|
||||
point.angle = location.getBearing();
|
||||
point.speed = location.getSpeed();
|
||||
point.angle = location.getBearing();
|
||||
point.provider = location.getProvider();
|
||||
return point;
|
||||
}
|
||||
|
||||
private MapRoadInfo.StopLine convert(StopLine line) {
|
||||
MapRoadInfo.StopLine ret = new MapRoadInfo.StopLine();
|
||||
ret.setDistance(line.distance);
|
||||
ret.setLaneId(line.lane_id);
|
||||
ret.setRoadId(line.road_id);
|
||||
ret.setTieId(line.tile_id);
|
||||
ArrayList<LonLatPoint> points = line.points;
|
||||
if (points != null && points.size() > 0) {
|
||||
List<MogoLatLng> newPoints = new ArrayList<>();
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
LonLatPoint lonLatPoint = points.get(i);
|
||||
MogoLatLng latLng = new MogoLatLng(lonLatPoint.latitude, lonLatPoint.longitude);
|
||||
latLng.duration = lonLatPoint.duration;
|
||||
latLng.angle = lonLatPoint.angle;
|
||||
latLng.speed = lonLatPoint.speed;
|
||||
latLng.altitude = lonLatPoint.altitude;
|
||||
latLng.provider = lonLatPoint.provider;
|
||||
newPoints.add(latLng);
|
||||
}
|
||||
ret.setPoints(newPoints);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
private Context getContext() {
|
||||
return mMapView.getContext();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user