下沉VR场景的Marker绘制
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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<MogoLatLng> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String, SoftReference<Bitmap>> sRef = new HashMap<>();
|
||||
private static Map<String, SoftReference<Bitmap>> 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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<V2XPushMessageEntity> {
|
||||
if (mMogoPolyline != null) {
|
||||
mMogoPolyline.remove();
|
||||
}
|
||||
drawableEventMarker(entity);
|
||||
|
||||
// 绘制事件点Marker
|
||||
PushRoadConditionDrawer.getInstance().drawRoadConditionMarker(entity);
|
||||
|
||||
// 绘制引导线
|
||||
drawablePloyLine(entity);
|
||||
@@ -56,31 +51,6 @@ public class V2XPushVREventMarker implements IV2XMarker<V2XPushMessageEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制事件点
|
||||
*
|
||||
* @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<MogoLatLng> 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<V2XPushMessageEntity> {
|
||||
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<V2XPushMessageEntity> {
|
||||
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]);
|
||||
|
||||
Reference in New Issue
Block a user