From d974f9913b91518f8d41240ca53b59e4697f4ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Fri, 30 Oct 2020 14:33:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E6=B2=89VR=E5=9C=BA=E6=99=AF=E7=9A=84?= =?UTF-8?q?Marker=E7=BB=98=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/common/constants/DataTypes.java | 5 + .../drawer/PushRoadConditionDrawer.java | 102 ++++++++++++++++++ .../common/drawer/marker/MapVrMarkerView.java | 88 +++++++++++++++ .../scene/pushVR/V2XPushVREventMarker.java | 42 ++------ 4 files changed, 201 insertions(+), 36 deletions(-) create mode 100644 modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/PushRoadConditionDrawer.java create mode 100644 modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/MapVrMarkerView.java diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/constants/DataTypes.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/constants/DataTypes.java index a7c1934848..bce9c3fdc7 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/constants/DataTypes.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/constants/DataTypes.java @@ -17,4 +17,9 @@ class DataTypes { * 云端下发数据 */ public static final String TYPE_MARKER_CLOUD_DATA = "TYPE_MARKER_CLOUD_DATA"; + + /** + * Push 事件场景 VR + */ + public static final String TYPE_MARKER_PUSH_DATA = "TYPE_MARKER_PUSH_DATA"; } diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/PushRoadConditionDrawer.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/PushRoadConditionDrawer.java new file mode 100644 index 0000000000..a281288538 --- /dev/null +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/PushRoadConditionDrawer.java @@ -0,0 +1,102 @@ +package com.mogo.module.common.drawer; + +import com.mogo.commons.AbsMogoApplication; +import com.mogo.map.MogoLatLng; +import com.mogo.map.marker.IMogoMarker; +import com.mogo.map.marker.MogoMarkerOptions; +import com.mogo.map.overlay.IMogoPolyline; +import com.mogo.module.common.MogoApisHandler; +import com.mogo.module.common.constants.DataTypes; +import com.mogo.module.common.drawer.marker.MapVrMarkerView; +import com.mogo.module.common.entity.V2XPushMessageEntity; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author donghongyu + * @since 2020/10/30 + * TODO 推送路况信息绘制,用于演示 + */ +public class PushRoadConditionDrawer { + + private static final String TAG = "OnlineCarDrawer"; + private static volatile PushRoadConditionDrawer sInstance; + + private static IMogoPolyline mMogoPolyline; + private static IMogoMarker mMogoMarker; + + private PushRoadConditionDrawer() { + } + + public static PushRoadConditionDrawer getInstance() { + if (sInstance == null) { + synchronized (PushRoadConditionDrawer.class) { + if (sInstance == null) { + sInstance = new PushRoadConditionDrawer(); + } + } + } + return sInstance; + } + + public synchronized void release() { + clearMarker(); + clearPolyline(); + mMogoPolyline = null; + mMogoMarker = null; + sInstance = null; + } + + + private Object readResolve() { + // 阻止反序列化,必须实现 Serializable 接口 + return sInstance; + } + + + /** + * 绘制路况事件Marker移动轨迹 + */ + public void drawRoadConditionMarker(V2XPushMessageEntity entity) { + // 道路事件 + MogoMarkerOptions options = new MogoMarkerOptions() + .object(entity) + .latitude(entity.getLat()) + .longitude(entity.getLon()); + options.anchor(0.5f, 0.5f); + + options.icon(MapVrMarkerView.getInstance().getBitmap(entity.getSceneId())); + + mMogoMarker = + MogoApisHandler + .getInstance() + .getApis() + .getMapServiceApi() + .getMarkerManager(AbsMogoApplication.getApp()) + .addMarker(DataTypes.TYPE_MARKER_PUSH_DATA, options); + + List points = new ArrayList<>(); + + for (double[] doubles : entity.getMoveTrack()) { + points.add(new MogoLatLng(doubles[1], doubles[0])); + } + + mMogoMarker.startSmooth(points, 10); + } + + + public void clearMarker() { + if (mMogoMarker != null) { + mMogoMarker.remove(); + } + } + + public void clearPolyline() { + if (mMogoPolyline != null) { + mMogoPolyline.remove(); + mMogoPolyline = null; + } + } + +} diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/MapVrMarkerView.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/MapVrMarkerView.java new file mode 100644 index 0000000000..82a7c80d2a --- /dev/null +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/MapVrMarkerView.java @@ -0,0 +1,88 @@ +package com.mogo.module.common.drawer.marker; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.view.View; + +import com.mogo.commons.AbsMogoApplication; +import com.mogo.map.marker.IMogoMarker; +import com.mogo.module.common.R; + +import java.lang.ref.SoftReference; +import java.util.HashMap; +import java.util.Map; + +/** + * VR 模式的Marker绘制 + */ +public class MapVrMarkerView implements IMarkerView { + private String TAG = "MapVrMarkerView"; + + + private static Map> sRef = new HashMap<>(); + private static Map> sTypedRef = new HashMap<>(); + + private static final class InstanceHolder { + private static final MapVrMarkerView INSTANCE = new MapVrMarkerView(); + } + + public static MapVrMarkerView getInstance() { + return MapVrMarkerView.InstanceHolder.INSTANCE; + } + + private Object readResolve() { + // 阻止反序列化,必须实现 Serializable 接口 + return MapVrMarkerView.InstanceHolder.INSTANCE; + } + + @Override + public View getView() { + return null; + } + + @Override + public void setMarker(IMogoMarker marker) { + + } + + @Override + public Bitmap getBitmap(int vehicleType) { + return null; + } + + + /** + * TODO 都是模拟数据 + * 获取VR道路事件 + */ + public Bitmap getBitmap(String sceneId) { + sRef.put(sceneId, new SoftReference<>(BitmapFactory.decodeResource(AbsMogoApplication.getApp().getResources(), R.drawable.icon_map_marker_car_type_taxi))); + switch (sceneId) { + case "200001"://后方VIP车辆提示 +// bitmap = ImageUtil.createBitmap(V2XUtils.getApp(), +// R.drawable.v2x_duixiang_laiche_che); + break; + case "200002"://前车急刹 + break; + case "200003"://后方危险车辆预警 + break; + case "200004"://逆向车辆路线预判 +// bitmap = ImageUtil.createBitmap(V2XUtils.getApp(), +// R.drawable.v2x_duixiang_laiche_che); + break; + case "200005"://VIP变灯通行 + break; + case "200006"://障碍物绕行 + break; + case "200007"://行人预警,行人路线预测 + break; + case "200008"://拥堵路线推荐 + break; + case "200009"://双闪车辆,自动绕行 + break; + } + + return sRef.get(sceneId).get(); + } + +} diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/pushVR/V2XPushVREventMarker.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/pushVR/V2XPushVREventMarker.java index 9bef9c7a88..aa18f70f8b 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/pushVR/V2XPushVREventMarker.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/pushVR/V2XPushVREventMarker.java @@ -1,26 +1,19 @@ package com.mogo.module.v2x.scenario.scene.pushVR; -import android.util.Log; - -import com.mogo.map.MogoLatLng; import com.mogo.map.marker.IMogoMarker; -import com.mogo.map.marker.MogoMarkerOptions; import com.mogo.map.overlay.IMogoPolyline; import com.mogo.map.overlay.MogoPolylineOptions; +import com.mogo.module.common.drawer.PushRoadConditionDrawer; import com.mogo.module.common.entity.V2XPushMessageEntity; import com.mogo.module.v2x.V2XConst; import com.mogo.module.v2x.V2XServiceManager; -import com.mogo.module.v2x.marker.V2XMarkerAdapter; import com.mogo.module.v2x.scenario.view.IV2XMarker; import com.mogo.module.v2x.utils.MarkerUtils; import com.mogo.utils.logger.Logger; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; -import static com.mogo.module.v2x.V2XConst.V2X_EVENT_ALARM_POI; - /** * author : donghongyu * e-mail : 1358506549@qq.com @@ -46,7 +39,9 @@ public class V2XPushVREventMarker implements IV2XMarker { if (mMogoPolyline != null) { mMogoPolyline.remove(); } - drawableEventMarker(entity); + + // 绘制事件点Marker + PushRoadConditionDrawer.getInstance().drawRoadConditionMarker(entity); // 绘制引导线 drawablePloyLine(entity); @@ -56,31 +51,6 @@ public class V2XPushVREventMarker implements IV2XMarker { } } - /** - * 绘制事件点 - * - * @param entity - */ - void drawableEventMarker(V2XPushMessageEntity entity) { - // 道路事件 - MogoMarkerOptions optionsRipple = new MogoMarkerOptions() - .object(entity) - .latitude(entity.getLat()) - .longitude(entity.getLon()); - optionsRipple.anchor(0.5f, 0.5f); - - optionsRipple.icon(V2XMarkerAdapter.getV2XVRRoadEventViewPng(entity)); - mAlarmInfoMarker = V2XServiceManager.getMarkerManager().addMarker(V2X_EVENT_ALARM_POI, optionsRipple); - - List points = new ArrayList<>(); - - for (double[] doubles : entity.getMoveTrack()) { - points.add(new MogoLatLng(doubles[1], doubles[0])); - } - - mAlarmInfoMarker.startSmooth(points, 10); - } - /** * 绘制引导线 * @@ -97,7 +67,7 @@ public class V2XPushVREventMarker implements IV2XMarker { colors.add(0xFFFA8C34); // 线条粗细,渐变,渐变色值 - options.width(15).useGradient(true).color(0xFFFA8C34); + options.width(15).useGradient(true).color(0xFF1F7EFF); for (double[] doubles : entity.getPolyline()) { options.add(doubles[0], doubles[1]); @@ -123,7 +93,7 @@ public class V2XPushVREventMarker implements IV2XMarker { colors.add(0xFFCB253A); // 线条粗细,渐变,渐变色值 - options.width(15).useGradient(true).color(0xFFCB253A); + options.width(15).useGradient(true).color(0xFFEF3A3A); for (double[] doubles : entity.getRecommendPolyline()) { options.add(doubles[0], doubles[1]);