[Update]自定义绘制轨迹线

This commit is contained in:
chenfufeng
2022-08-03 18:56:00 +08:00
parent 1e27c6da97
commit b4328d1c6d
17 changed files with 544 additions and 207 deletions

View File

@@ -14,7 +14,6 @@ import com.amap.api.navi.model.AMapLaneInfo;
import com.amap.api.navi.model.AMapModelCross;
import com.amap.api.navi.model.AMapNaviCameraInfo;
import com.amap.api.navi.model.AMapNaviCross;
import com.amap.api.navi.model.AMapNaviInfo;
import com.amap.api.navi.model.AMapNaviLocation;
import com.amap.api.navi.model.AMapNaviRouteNotifyData;
import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
@@ -23,7 +22,6 @@ import com.amap.api.navi.model.AimLessModeCongestionInfo;
import com.amap.api.navi.model.AimLessModeStat;
import com.amap.api.navi.model.NaviInfo;
import com.amap.api.navi.model.NaviLatLng;
import com.autonavi.tbt.TrafficFacilityInfo;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.util.NetworkUtils;
import com.mogo.eagle.core.utilcode.util.ToastUtils;
@@ -279,6 +277,11 @@ public class NaviToDestinationModel implements AMapNaviListener {
}
@Override
public void onGpsSignalWeak(boolean b) {
}
@Override
public void updateCameraInfo(AMapNaviCameraInfo[] aMapCameraInfos) {
@@ -289,21 +292,11 @@ public class NaviToDestinationModel implements AMapNaviListener {
}
@Override
public void onNaviInfoUpdated(AMapNaviInfo aMapNaviInfo) {
}
@Override
public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo) {
//已过时
}
@Override
public void OnUpdateTrafficFacility(TrafficFacilityInfo trafficFacilityInfo) {
}
@Override
public void showCross(AMapNaviCross aMapNaviCross) {
//显示放大图回调

View File

@@ -38,7 +38,7 @@ ext {
// amapnavi3dmap : "com.amap.api:navi-3dmap:8.0.1_3dmap8.0.1",
// amapsearch : "com.amap.api:search:7.9.0",
// amaplocation : "com.amap.api:location:5.5.0",
amapnavi3dmap : "com.amap.api:navi-3dmap:7.2.0_3dmap7.2.0",
amapnavi3dmap : "com.amap.api:navi-3dmap:7.7.0_3dmap7.7.0",
amapsearch : "com.amap.api:search:7.1.0",
amaplocation : "com.amap.api:location:5.3.1",
// json 转换

View File

@@ -172,10 +172,11 @@ import java.util.*
}
}
/*ivCameraIcon?.setOnLongClickListener {
activity?.let { it1 -> CarcorderPreviewView.show(it1) }
ivCameraIcon?.setOnLongClickListener {
showSmallFragment()
// activity?.let { it1 -> CarcorderPreviewView.show(it1) }
true
}*/
}
ivToolsIcon?.setOnClickListener {
if (toolsViewFloat == null) {

View File

@@ -129,14 +129,26 @@ public class SteeringWheelView extends ConstraintLayout {
if (autopilotIV != null) {
Log.d(TAG, "autopilotIV != null");
if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
if (AppIdentityModeUtils.isBus(FunctionBuildConfig.appIdentityMode)) {
// TODO
autopilotIV.setImageResource(R.drawable.bg_auto);
} else {
autopilotIV.setImageResource(R.drawable.bg_auto);
}
} else if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE) {
autopilotIV.setImageResource(R.drawable.bg_auto_nor);
if (AppIdentityModeUtils.isBus(FunctionBuildConfig.appIdentityMode)) {
// TODO
} else {
autopilotIV.setImageResource(R.drawable.bg_auto_nor);
}
} else if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE) {
autopilotIV.setImageResource(R.drawable.bg_auto_nor);
if (AppIdentityModeUtils.isBus(FunctionBuildConfig.appIdentityMode)) {
// TODO
} else {
autopilotIV.setImageResource(R.drawable.bg_auto_nor);
}
}
} else {
Log.d(TAG, "autopilotIV=null");

View File

@@ -1,15 +1,17 @@
package com.mogo.eagle.core.function.overview.vm
import androidx.lifecycle.*
import com.amap.api.maps.model.LatLng
import com.mogo.eagle.core.data.map.Infrastructure
import com.mogo.eagle.core.function.overview.OverviewDao
import io.reactivex.disposables.CompositeDisposable
import kotlinx.coroutines.launch
import java.lang.Exception
class OverViewModel(
private val overviewDao: OverviewDao
) : ViewModel() {
private val _infStructures = MutableLiveData<List<Infrastructure>>()
val infStructures
get() = _infStructures

View File

@@ -2,9 +2,7 @@ package com.mogo.eagle.core.function.smp;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.location.Location;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
@@ -20,26 +18,27 @@ import androidx.annotation.Nullable;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdate;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.CoordinateConverter;
import com.amap.api.maps.TextureMapView;
import com.amap.api.maps.UiSettings;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.CustomMapStyleOptions;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.LatLngBounds;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.Polyline;
import com.amap.api.navi.AMapNavi;
import com.amap.api.maps.model.PolylineOptions;
import com.amap.api.navi.AMapNaviListener;
import com.amap.api.navi.AMapNaviView;
import com.amap.api.navi.AMapNaviViewListener;
import com.amap.api.navi.AMapNaviViewOptions;
import com.amap.api.navi.enums.NaviType;
import com.amap.api.navi.model.AMapCalcRouteResult;
import com.amap.api.navi.model.AMapLaneInfo;
import com.amap.api.navi.model.AMapModelCross;
import com.amap.api.navi.model.AMapNaviCameraInfo;
import com.amap.api.navi.model.AMapNaviCross;
import com.amap.api.navi.model.AMapNaviInfo;
import com.amap.api.navi.model.AMapNaviLocation;
import com.amap.api.navi.model.AMapNaviPathGroup;
import com.amap.api.navi.model.AMapNaviRouteNotifyData;
import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
import com.amap.api.navi.model.AMapServiceAreaInfo;
@@ -47,9 +46,7 @@ import com.amap.api.navi.model.AimLessModeCongestionInfo;
import com.amap.api.navi.model.AimLessModeStat;
import com.amap.api.navi.model.NaviInfo;
import com.amap.api.navi.model.NaviLatLng;
import com.amap.api.navi.model.RouteOverlayOptions;
import com.autonavi.tbt.TrafficFacilityInfo;
import com.elegant.utils.UiThreadHandler;
import com.amap.api.navi.model.NaviPoi;
import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo;
import com.mogo.eagle.core.data.config.FunctionBuildConfig;
import com.mogo.eagle.core.data.map.Infrastructure;
@@ -67,9 +64,9 @@ import com.mogo.eagle.core.function.overview.InfStructureManager;
import com.mogo.eagle.core.function.smp.view.ISmallMapDirectionView;
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils;
import com.mogo.eagle.core.utilcode.mogo.MapAssetStyleUtils;
import com.mogo.eagle.core.utilcode.util.ThreadUtils;
import com.mogo.module.common.utils.DrivingDirectionUtils;
import com.zhidao.support.adas.high.AdasManager;
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
import com.zhidaoauto.map.sdk.open.query.LonLatPoint;
import com.zhidaoauto.map.sdk.open.tools.MapTools;
import org.jetbrains.annotations.NotNull;
@@ -79,6 +76,7 @@ import java.util.List;
import java.util.Map;
import ch.hsr.geohash.GeoHash;
import kotlin.Pair;
import mogo.telematics.pad.MessagePad;
import mogo_msg.MogoReportMsg;
import system_master.SystemStatusInfo;
@@ -94,8 +92,7 @@ public class AMapCustomView
extends RelativeLayout
implements IMoGoMapLocationListener, ISmallMapDirectionView, AMapNaviListener, AMapNaviViewListener {
public static final String TAG = "AMapCustomView";
private AMapNaviView mAMapNaviView;
protected AMapNavi mAMapNavi;
private TextureMapView mAMapView;
private AMap mAMap;
protected NaviLatLng mStartLatlng = new NaviLatLng();
protected NaviLatLng mEndLatlng = new NaviLatLng();
@@ -116,6 +113,27 @@ public class AMapCustomView
private Map<String, ArrayList<Infrastructure>> pathMap = new HashMap();
private Map<LatLng, ArrayList<Infrastructure>> posInfMap = new HashMap();
// 独立路径导航
private NaviPoi mStartPoi = null;
private NaviPoi mEndPoi = null;
private AMapNaviPathGroup mIndependentPathGroup = null;
private List<NaviPoi> mIndependentPointList = new ArrayList<>();
// =============绘制轨迹线相关=============
private Marker mCarMarker;
private Marker mStartMarker;
private Marker mEndMarker;
private Polyline mCustomPolyline;
// 计算索引并设置对应的Bitmap
BitmapDescriptor arrivedBitmap;
BitmapDescriptor unArrivedBitmap;
// 绘制轨迹线的集合
private List<BitmapDescriptor> textureList = new ArrayList<>();
private List<Integer> texIndexList = new ArrayList<>();
private MogoLocation mLocation;
private boolean isFirstLocation = true;
public AMapCustomView(Context context) {
this(context, null);
}
@@ -136,16 +154,18 @@ public class AMapCustomView
private void initView(Context context) {
mContext = context;
View smpView = LayoutInflater.from(context).inflate(R.layout.module_overview_map_view, this);
mAMapNaviView = smpView.findViewById(R.id.aMapNaviView);
mAMapView = smpView.findViewById(R.id.aMapView);
overLayerView = findViewById(R.id.overLayer);
if(AppIdentityModeUtils.isTaxi(FunctionBuildConfig.appIdentityMode)) {
if (AppIdentityModeUtils.isTaxi(FunctionBuildConfig.appIdentityMode)) {
overLayerView.setBackground(getResources().getDrawable(R.drawable.amap_reset));
}else {
arrivedBitmap = BitmapDescriptorFactory.fromResource(R.drawable.arrow_arrived_img);
unArrivedBitmap = BitmapDescriptorFactory.fromResource(R.drawable.amap_bus_smooth_route);
// unArrivedBitmap = BitmapDescriptorFactory.fromResource(R.drawable.amap_custom_smooth_route);
} else {
overLayerView.setBackground(getResources().getDrawable(R.drawable.amap_reset_bus));
arrivedBitmap = BitmapDescriptorFactory.fromResource(R.drawable.arrow_arrived_img);
unArrivedBitmap = BitmapDescriptorFactory.fromResource(R.drawable.amap_bus_smooth_route);
}
mAMapNavi = AMapNavi.getInstance(context);
mAMapNavi.addAMapNaviListener(this);
mAMapNaviView.setAMapNaviViewListener(this);
CallerAutoPilotStatusListenerManager.INSTANCE.addListener(TAG, mGoAutopilotStatusListener);
CallerAutopilotPlanningListenerManager.INSTANCE.addListener(TAG, moGoAutopilotPlanningListener);
initAMapView(context);
@@ -153,18 +173,32 @@ public class AMapCustomView
CallerMapLocationListenerManager.INSTANCE.addListener(TAG, this);
//设置全览模式
overLayerView.setOnClickListener(v -> {
mAMapNaviView.displayOverview();
// mAMapView.displayOverview();
CallerHmiManager.INSTANCE.hideSmallFragment();
});
// 注册定位监听
CallerMapLocationListenerManager.INSTANCE.addListener(TAG, this);
CallerAutoPilotStatusListenerManager.INSTANCE.addListener(TAG, mGoAutopilotStatusListener);
CallerAutopilotPlanningListenerManager.INSTANCE.addListener(TAG, moGoAutopilotPlanningListener);
}
private void initAMapView(Context context) {
Log.d(TAG, "initAMapView");
mCameraUpdate = CameraUpdateFactory.zoomTo(zoomLevel);
mAMap = mAMapNaviView.getMap();
mAMap = mAMapView.getMap();
mAMap.setOnMapLoadedListener(() -> {
Log.d(TAG, "---onMapLoaded---");
CustomMapStyleOptions customMapStyleOptions = new CustomMapStyleOptions();
// 加载自定义样式
customMapStyleOptions.setEnable(true);
if (AppIdentityModeUtils.isTaxi(FunctionBuildConfig.appIdentityMode)) {
customMapStyleOptions.setStyleData(MapAssetStyleUtils.getAssetsStyle(getContext(), "over_view_style.data"));
customMapStyleOptions.setStyleExtraData(MapAssetStyleUtils.getAssetsExtraStyle(getContext(), "over_view_style_extra.data"));
} else {
customMapStyleOptions.setStyleData(MapAssetStyleUtils.getAssetsStyle(getContext(), "over_view_style_bus.data"));
customMapStyleOptions.setStyleExtraData(MapAssetStyleUtils.getAssetsExtraStyle(getContext(), "over_view_style_extra_bus.data"));
}
// 设置自定义样式
mAMap.setCustomMapStyle(customMapStyleOptions);
// 实时路况图层关闭必须添加在loaded结束之后,其他位置不生效
mAMap.setTrafficEnabled(false);
});
setUpMap();
customOptions();
}
@@ -195,43 +229,68 @@ public class AMapCustomView
* 自定义导航View和路况状态
*/
private void customOptions() {
AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
// AMapNaviViewOptions options = mAMapView.getViewOptions();
//关闭自动绘制路线,自行绘制路线
// options.setAutoDrawRoute(false);
//不显示导航界面
options.setLayoutVisible(false);
options.setTilt(60);
//黑夜模式
options.setNaviNight(true);
//导航全程光柱
options.setTrafficBarEnabled(false);
//隐藏摄像头
options.setCameraBubbleShow(false);
//转向箭头
options.setNaviArrowVisible(false);
// options.setLayoutVisible(false);
// options.setTilt(60);
// //黑夜模式
// options.setNaviNight(true);
// //导航全程光柱
// options.setTrafficBarEnabled(false);
// //隐藏摄像头
// options.setCameraBubbleShow(false);
// //转向箭头
// options.setNaviArrowVisible(false);
// // 算路成功后自动进入全览模式
// options.setAutoDisplayOverview(true);
//指南针
// options.setCompassEnabled(false);
// options.setTilt((int) tilt);
//自车车标
options.setCarBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.map_car_icon));
options.setFourCornersBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.amap_custom_corner));
options.setStartPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.module_small_map_view_dir_start));
options.setWayPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.icon_module_small_map_four_corners));
options.setEndPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.module_small_map_view_dir_end));
//与走过的路线
options.setAfterRouteAutoGray(true);
//路线纹理自定义
RouteOverlayOptions routeOverlayOptions = new RouteOverlayOptions();
routeOverlayOptions.setTurnArrowIs3D(false);
// 未知路段和导航路段颜色一样
routeOverlayOptions.setUnknownTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.amap_custom_smooth_route));//未知路段
routeOverlayOptions.setSmoothTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.amap_custom_smooth_route));
routeOverlayOptions.setJamTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_bad));//拥堵路段
routeOverlayOptions.setVeryJamTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_grayred));//超级拥堵路段
routeOverlayOptions.setPassRoute(BitmapFactory.decodeResource(getResources(), R.drawable.amap_custom_pass_route));//走过的路段
options.setRouteOverlayOptions(routeOverlayOptions);
mAMapNaviView.setTrafficLightsVisible(true);
mAMapNaviView.setViewOptions(options);
// RouteOverlayOptions routeOverlayOptions = new RouteOverlayOptions();
if (AppIdentityModeUtils.isTaxi(FunctionBuildConfig.appIdentityMode)) {
// TODO:("导航的配置需要删除")
mCarMarker = mAMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.map_car_icon))
.anchor(0.5f, 0.5f));
// //自车车标
// options.setCarBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.map_car_icon));
// options.setFourCornersBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.amap_custom_corner));
// 未知路段和导航路段颜色一样
// routeOverlayOptions.setUnknownTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.amap_custom_smooth_route));//未知路段
// routeOverlayOptions.setSmoothTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.amap_custom_smooth_route));
} else {
// TODO:("导航的配置需要删除")
mCarMarker = mAMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.map_bus_icon))
.anchor(0.5f, 0.5f));
// options.setCarBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.map_bus_icon));
// options.setFourCornersBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.amap_bus_corner));
// routeOverlayOptions.setUnknownTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.amap_bus_smooth_route));//未知路段
// routeOverlayOptions.setSmoothTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.amap_bus_smooth_route));
}
mStartMarker = mAMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.module_small_map_view_dir_start)));
mEndMarker = mAMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.module_small_map_view_dir_end)));
// options.setStartPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.module_small_map_view_dir_start));
// options.setWayPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.icon_module_small_map_four_corners));
// options.setEndPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.module_small_map_view_dir_end));
// //与走过的路线
// options.setAfterRouteAutoGray(true);
// routeOverlayOptions.setTurnArrowIs3D(false);
// routeOverlayOptions.setJamTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_bad));//拥堵路段
// routeOverlayOptions.setVeryJamTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_grayred));//超级拥堵路段
// routeOverlayOptions.setPassRoute(BitmapFactory.decodeResource(getResources(), R.drawable.amap_custom_pass_route));//走过的路段
// options.setRouteOverlayOptions(routeOverlayOptions);
// mAMapView.setTrafficLightsVisible(true);
// mAMapView.setViewOptions(options);
}
private final IMoGoAutopilotStatusListener mGoAutopilotStatusListener = new IMoGoAutopilotStatusListener() {
@@ -263,27 +322,24 @@ public class AMapCustomView
@Override
public void onAutopilotStatusResponse(@NotNull AutopilotStatusInfo autoPilotStatusInfo) {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
if (autoPilotStatusInfo == null) return;
int state = autoPilotStatusInfo.getState();
//0 不能自动驾驶 1 可以自动驾驶,但是在人工干预 2 自动驾驶中
if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
Log.d(TAG, "自动驾驶中 state=" + String.valueOf(state));
if (sList.size() == 0 && eList.size() == 0 && mWayPointList.size() == 0) {
Log.d(TAG, "sendGlobalPathReq");
AdasManager.getInstance().sendGlobalPathReq();
}
} else {
int type = mAMapNavi.getNaviType();
Log.d(TAG, "非自动驾驶状态,导航类型==" + String.valueOf(type));
if (type == NaviType.GPS || type == NaviType.EMULATOR) {
mAMapNavi.stopNavi();
}
}
}
});
// ThreadUtils.runOnUiThread(() -> {
// if (autoPilotStatusInfo == null) return;
// int state = autoPilotStatusInfo.getState();
// //0 不能自动驾驶 1 可以自动驾驶,但是在人工干预 2 自动驾驶中
// if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
//// Log.d(TAG, "自动驾驶中 state=" + String.valueOf(state));
// if (sList.size() == 0 && eList.size() == 0 && mWayPointList.size() == 0) {
// Log.d(TAG, "sendGlobalPathReq");
// AdasManager.getInstance().sendGlobalPathReq();
// }
// } else {
// int type = mAMapNavi.getNaviType();
// Log.d(TAG, "非自动驾驶状态,导航类型==" + String.valueOf(type));
// if (type == NaviType.GPS || type == NaviType.EMULATOR) {
// mAMapNavi.stopNavi();
// }
// }
// });
}
};
@@ -307,37 +363,62 @@ public class AMapCustomView
calculate = true;
Log.d(TAG, "onAutopilotRotting");
List list = globalPathResp.getWayPointsList();
int minCount = 2;
if (list.size() >= minCount) {
calculate = true;
MessagePad.Location sLocation = (MessagePad.Location) list.get(0);
MessagePad.Location eLocation = (MessagePad.Location) list.get(list.size() - 1);
mStartLatlng = new NaviLatLng(sLocation.getLatitude(), sLocation.getLongitude());
mEndLatlng = new NaviLatLng(eLocation.getLatitude(), eLocation.getLongitude());
sList.clear();
eList.clear();
sList.add(mStartLatlng);
eList.add(mEndLatlng);
// int minCount = 2;
// if (list.size() >= minCount && sList.size() == 0 && eList.size() == 0 && mWayPointList.size() == 0) {
// calculate = true;
// MessagePad.Location sLocation = (MessagePad.Location) list.get(0);
// MessagePad.Location eLocation = (MessagePad.Location) list.get(list.size() - 1);
// mStartLatlng = new NaviLatLng(sLocation.getLatitude(), sLocation.getLongitude());
// mEndLatlng = new NaviLatLng(eLocation.getLatitude(), eLocation.getLongitude());
// mStartPoi = new NaviPoi("", new LatLng(sLocation.getLatitude(), sLocation.getLongitude()), "");
// mEndPoi = new NaviPoi("", new LatLng(eLocation.getLatitude(), eLocation.getLongitude()), "");
// sList.clear();
// eList.clear();
// sList.add(mStartLatlng);
// eList.add(mEndLatlng);
//
// mWayPointList.clear();
// mIndependentPointList.clear();
// for (int i = 1; i < list.size() - minCount; i++) {
// MessagePad.Location wayLoc = (MessagePad.Location) list.get(i);
// NaviLatLng way = new NaviLatLng(wayLoc.getLatitude(), wayLoc.getLongitude());
// NaviPoi naviPoi = new NaviPoi("", new LatLng(wayLoc.getLatitude(), wayLoc.getLongitude()), "");
// mWayPointList.add(way);
// mIndependentPointList.add(naviPoi);
// }
// }
// int strategy = 0;
// try {
// //再次强调最后一个参数为true时代表多路径否则代表单路径
// strategy = mAMapNavi.strategyConvert(true, false, false, false, false);
// } catch (Exception e) {
// e.printStackTrace();
// }
// Log.d(TAG, "全局路径" + list.size() + ",起点:" + sList.toString() + ",终点:" + eList.toString() + ",经点:" + mWayPointList.toString());
// //指定路径绘制导航路线
// mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy);
mWayPointList.clear();
for (int i = 1; i < list.size() - minCount; i++) {
MessagePad.Location wayLoc = (MessagePad.Location) list.get(i);
NaviLatLng way = new NaviLatLng(wayLoc.getLatitude(), wayLoc.getLongitude());
mWayPointList.add(way);
}
}
int strategy = 0;
try {
//再次强调最后一个参数为true时代表多路径否则代表单路径
strategy = mAMapNavi.strategyConvert(true, false, false, false, false);
} catch (Exception e) {
e.printStackTrace();
}
Log.d(TAG, "全局路径" + list.size() + ",起点:" + sList.toString() + ",终点:" + eList.toString() + ",经点:" + mWayPointList.toString());
//指定路径绘制导航路线
mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy);
drawInfrastructureMarkers(globalPathResp);
// 转成高德坐标系并存储
MarkerDrawerManager.INSTANCE.updateRoutePoints(list, mContext);
List<LatLng> planningPointList = MarkerDrawerManager.INSTANCE.getPlanningPoints();
UiThreadHandler.post(() -> {
displayCustomOverView();
drawStartAndEndMarker(planningPointList);
});
MarkerDrawerManager.INSTANCE.setCallback((points, locIndex) -> {
UiThreadHandler.post(() -> {
// 每1s刷新一下轨迹线
if (points.size() > 0) {
drawPolyline(points , locIndex);
} else {
clearCustomPolyline();
}
});
});
MarkerDrawerManager.INSTANCE.startLoopCalCarLocation();
UiThreadHandler.post(() -> {
drawInfrastructureMarkers(globalPathResp);
});
}
};
@@ -358,53 +439,19 @@ public class AMapCustomView
@Override
public void onLocationChanged(@org.jetbrains.annotations.Nullable MogoLocation location, int from) {
}
private void removeLocation(Location latLng) {
for (LatLng l : mCoordinatesLatLng) {
if (!isPointOnCarFront(latLng, l)) {
mCoordinatesLatLng.remove(l);
}
mLocation = location;
MarkerDrawerManager.INSTANCE.setLonLat(new Pair(location.getLongitude(), location.getLatitude()));
drawCarMarker(location);
if (isFirstLocation) {
displayCustomOverView();
isFirstLocation = false;
}
}
public static boolean isPointOnCarFront(Location carLocal, LatLng pointLocal) {
double carLon = carLocal.getLongitude();
double carLat = carLocal.getLatitude();
double poiLon = pointLocal.longitude;
double poiLat = pointLocal.latitude;
float carAngle = carLocal.getBearing();
// 计算车辆与点之间的夹角
int diffAngle = DrivingDirectionUtils.getDegreeOfCar2Poi(
carLon, carLat, poiLon, poiLat, (int) carAngle);
return diffAngle <= 90;
}
@Override
public void drawablePolyline() {
}
public LatLng CoordinateConverterFrom84(Context mContext, MogoLatLng mogoLatLng) {
CoordinateConverter mCoordinateConverter = new CoordinateConverter(mContext);
mCoordinateConverter.from(CoordinateConverter.CoordType.GPS);
mCoordinateConverter.coord(new LatLng(mogoLatLng.lat, mogoLatLng.lon));
return mCoordinateConverter.convert();
}
public List<LatLng> CoordinateConverterFrom84ForList(Context mContext, List<MogoLatLng> mogoLatLngList) {
List<LatLng> list = new ArrayList<>();
for (MogoLatLng m : mogoLatLngList) {
LatLng mogoLatLng = CoordinateConverterFrom84(mContext, m);
list.add(mogoLatLng);
}
return list;
}
@Override
public void clearPolyline() {
if (mPolyline != null) {
@@ -412,6 +459,12 @@ public class AMapCustomView
}
}
public void clearCustomPolyline() {
if (mCustomPolyline != null) {
mCustomPolyline.remove();
}
}
public void resetPolyLine() {
mCoordinatesLatLng.clear();
if (mPolyline != null) {
@@ -420,34 +473,34 @@ public class AMapCustomView
}
public void onCreateView(Bundle savedInstanceState) {
if (mAMapNaviView != null) {
mAMapNaviView.onCreate(savedInstanceState);
if (mAMapView != null) {
mAMapView.onCreate(savedInstanceState);
}
}
public void onResume() {
if (mAMapNaviView != null) {
mAMapNaviView.onResume();
if (mAMapView != null) {
mAMapView.onResume();
}
}
public void onPause() {
if (mAMapNaviView != null) {
mAMapNaviView.onPause();
if (mAMapView != null) {
mAMapView.onPause();
}
}
public void onDestroy() {
if (mAMapNaviView != null) {
mAMapNaviView.onDestroy();
if (mAMapView != null) {
mAMapView.onDestroy();
}
//since 1.6.0 不再在naviview destroy的时候自动执行AMapNavi.stopNavi();请自行执行
if (mAMapNavi != null) {
mAMapNavi.stopNavi();
mAMapNavi.destroy();
}
if (mAMapNaviView != null) {
mAMapNaviView.onDestroy();
// //since 1.6.0 不再在naviview destroy的时候自动执行AMapNavi.stopNavi();请自行执行
// if (mAMapNavi != null) {
// mAMapNavi.stopNavi();
// mAMapNavi.destroy();
// }
if (mAMapView != null) {
mAMapView.onDestroy();
}
}
@@ -542,11 +595,6 @@ public class AMapCustomView
Log.d(TAG, "onNaviInfoUpdate");
}
@Override
public void onNaviInfoUpdated(AMapNaviInfo aMapNaviInfo) {
Log.d(TAG, "onNaviInfoUpdated");
}
@Override
public void updateCameraInfo(AMapNaviCameraInfo[] aMapNaviCameraInfos) {
Log.d(TAG, "updateCameraInfo");
@@ -612,11 +660,6 @@ public class AMapCustomView
}
@Override
public void OnUpdateTrafficFacility(TrafficFacilityInfo trafficFacilityInfo) {
}
@Override
public void updateAimlessModeStatistics(AimLessModeStat aimLessModeStat) {
@@ -636,16 +679,10 @@ public class AMapCustomView
@Override
public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) {
Log.d(TAG, "onCalculateRouteSuccess aMapCalcRouteResult" + aMapCalcRouteResult.toString());
//提测修改为EMULATOR
mAMapNavi.startNavi(NaviType.GPS);
UiThreadHandler.postDelayed(() -> {
mAMapNaviView.displayOverview();
}, 2000);
//停止导航测试代码
// mAMapNavi.startNavi(NaviType.GPS);
// UiThreadHandler.postDelayed(() -> {
// mAMapNavi.stopNavi();
// Log.d(TAG, "stop------------");
// }, 20000);
// mAMapView.displayOverview();
// }, 500);
}
@Override
@@ -658,6 +695,11 @@ public class AMapCustomView
Log.d(TAG, "onNaviRouteNotify");
}
@Override
public void onGpsSignalWeak(boolean b) {
}
@Override
public void onNaviSetting() {
@@ -727,6 +769,10 @@ public class AMapCustomView
}
/**
* 绘制新基建Markers(比如:摄像头)
* @param globalPathResp
*/
private void drawInfrastructureMarkers(MessagePad.GlobalPathResp globalPathResp) {
if (globalPathResp != null) {
if (!pathMap.isEmpty()) {
@@ -734,7 +780,11 @@ public class AMapCustomView
}
String geoHash;
ArrayList<Infrastructure> infList;
StringBuilder sb1 = new StringBuilder();
for (MessagePad.Location location : globalPathResp.getWayPointsList()) {
LonLatPoint p = new LonLatPoint(location.getLongitude(), location.getLatitude());
p = MapTools.INSTANCE.switchLonLatWGS84(p);
sb1.append(p.getLongitude()).append(",").append(p.getLatitude()).append("\n");
geoHash = GeoHash.withCharacterPrecision(location.getLatitude(), location.getLongitude(), 7).toBase32();
// 网格内的轨迹点只取一次
if (!pathMap.containsKey(geoHash)) {
@@ -745,6 +795,7 @@ public class AMapCustomView
}
}
}
String str1 = sb1.toString();
drawInfMarkers(pathMap);
}
}
@@ -782,7 +833,7 @@ public class AMapCustomView
});
}
private Bitmap getBitmap(int count) {
private Bitmap getBitmap(int count) {
MakerWithCount marker = new MakerWithCount(getContext());
marker.setCount(count);
@@ -793,4 +844,107 @@ public class AMapCustomView
marker.draw(new Canvas(bitmap));
return bitmap;
}
/**
* 进入自定义全览模式
*/
private void displayCustomOverView() {
ArrayList<LatLng> linePointsLatLng = MarkerDrawerManager.INSTANCE.getPlanningPoints();
MogoLocation location = mLocation;
if (linePointsLatLng.size() > 1){
//圈定地图显示范围
//存放经纬度
LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
for (int i = 0; i < linePointsLatLng.size(); i++) {
boundsBuilder.include(linePointsLatLng.get(i));
}
LatLng currentLatLng = new LatLng(location.getLatitude(), location.getLongitude());
boundsBuilder.include(currentLatLng);
//第二个参数为四周留空宽度
mAMap.moveCamera(CameraUpdateFactory.newLatLngBoundsRect(boundsBuilder.build(),50,50,50,50));
}else {
//设置希望展示的地图缩放级别
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(mCarMarker.getPosition()).tilt(0).bearing(location.getBearing()).zoom(zoomLevel).build();
mAMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
}
/**
* 绘制自车
* @param location
*/
private void drawCarMarker(MogoLocation location) {
if (location == null) return;
if (mCarMarker != null) {
LatLng currentLatLng = new LatLng(location.getLatitude(), location.getLongitude());
mCarMarker.setRotateAngle(360 - location.getBearing());
mCarMarker.setPosition(currentLatLng);
mCarMarker.setToTop();
}
}
/**
* 绘制起始点、终点
*/
private void drawStartAndEndMarker(List<LatLng> coordinates) {
if (mStartMarker != null) {
mStartMarker.setVisible(false);
}
if (mEndMarker != null) {
mEndMarker.setVisible(false);
}
if (coordinates.size() > 2) {
// 设置开始结束Marker位置
LatLng startLatLng = coordinates.get(0);
LatLng endLatLng = coordinates.get(coordinates.size() - 1);
mStartMarker.setPosition(startLatLng);
mEndMarker.setPosition(endLatLng);
mStartMarker.setVisible(true);
mEndMarker.setVisible(true);
}
}
/**
* 绘制轨迹线
* @param coordinates
* @param locIndex
*/
private void drawPolyline(List<LatLng> coordinates,int locIndex) {
if (textureList.size() > 0) {
textureList.clear();
}
if (texIndexList.size() > 0) {
texIndexList.clear();
}
for (int i = 0; i < coordinates.size(); i++){
if (i <= locIndex){
// 已走过的置灰
textureList.add(arrivedBitmap);
} else {
// 未走过的纹理
textureList.add(unArrivedBitmap);
}
texIndexList.add(i);
}
if (mCustomPolyline != null) {
mCustomPolyline.remove();
}
if (mAMap != null && coordinates.size() > 2) {
//设置线段纹理
PolylineOptions polylineOptions = new PolylineOptions();
polylineOptions.addAll(coordinates);
// polylineOptions.useGradient(true);
polylineOptions.width(12); //线段宽度
polylineOptions.isUseTexture();
polylineOptions.lineCapType(PolylineOptions.LineCapType.LineCapRound);
polylineOptions.setCustomTextureList(textureList);
polylineOptions.setCustomTextureIndex(texIndexList);
// 绘制线
mCustomPolyline = mAMap.addPolyline(polylineOptions);
}
}
}

View File

@@ -0,0 +1,169 @@
package com.mogo.eagle.core.function.smp
import android.content.Context
import android.util.Log
import com.amap.api.maps.CoordinateConverter
import com.amap.api.maps.model.LatLng
import com.mogo.cloud.commons.utils.CoordinateUtils
import io.reactivex.Observable
import io.reactivex.ObservableOnSubscribe
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import mogo.telematics.pad.MessagePad
import java.util.concurrent.TimeUnit
/**
* 自定义高德地图画线管理者
*/
object MarkerDrawerManager {
interface Callback {
fun onLocationChanged(planningPoints: List<LatLng>, locIndex: Int)
}
private val routeWipeDisposable by lazy {
CompositeDisposable()
}
// 自主画线的所有高德坐标系的轨迹点
val planningPoints by lazy {
ArrayList<LatLng>()
}
@Volatile
var lastArrivedIndex: Int = -1
@Volatile
var lonLat = Pair(0.0, 0.0)
var callback: Callback? = null
fun startLoopCalCarLocation() {
getLoopCalCarObservable().delay(1000L, TimeUnit.MILLISECONDS, true)
.subscribeOn(Schedulers.io())
.repeat()
.retry()
.observeOn(AndroidSchedulers.mainThread())
.subscribe().let {
routeWipeDisposable.add(it)
}
}
fun stopLoopCalCarLocation() {
if (!routeWipeDisposable.isDisposed) {
routeWipeDisposable.dispose()
}
}
private fun getLoopCalCarObservable(): Observable<Int> {
return Observable.create(ObservableOnSubscribe { emitter ->
if (emitter.isDisposed) return@ObservableOnSubscribe
synchronized(this) {
loopRouteAndWipe(planningPoints, lonLat.first, lonLat.second)
}
emitter.onComplete()
})
}
private fun loopRouteAndWipe(routePoints: List<LatLng>?, lon: Double, lat: Double) {
if (routePoints != null && routePoints.isNotEmpty()) {
val arrivedIndex: Int = getArrivedPointIndex(routePoints, lon, lat)
Log.d("cff", "thread is:${Thread.currentThread().name},arrivedIndex is:$arrivedIndex")
if (arrivedIndex != -1 && lastArrivedIndex != arrivedIndex) {
callback?.onLocationChanged(routePoints, arrivedIndex)
lastArrivedIndex = arrivedIndex
}
}
}
fun updateRoutePoints(routePoints: List<MessagePad.Location>?, context: Context) {
if (routePoints == null || routePoints.isEmpty()) return
val latLngModels = coordinateConverterWgsToGcjListCommon(context, routePoints)
synchronized(this) {
planningPoints.clear()
planningPoints.addAll(latLngModels)
}
// float remainingSumLength = calculateRemainingSumLength(mRoutePoints);
}
/**
* @param routePoints
* @param realLon
* @param realLat
* @return 返回已经到达点的index
*/
private fun getArrivedPointIndex(
routePoints: List<LatLng>,
realLon: Double,
realLat: Double
): Int {
var currentIndex = 0 //记录疑似点
if (routePoints.isNotEmpty()) {
//基础点
val baseLatLng = routePoints[0]
var baseDiffDis = CoordinateUtils.calculateLineDistance(
realLon, realLat, baseLatLng.longitude, baseLatLng.latitude
) // lon,lat, prelon, prelat
for (i in 1 until routePoints.size) {
val latLng = routePoints[i]
val diff = CoordinateUtils.calculateLineDistance(
realLon, realLat, latLng.longitude, latLng.latitude
)
if (baseDiffDis > diff) {
baseDiffDis = diff
currentIndex = i
}
}
return currentIndex
}
return currentIndex
}
/**
*
* @param points
* @return 剩余的总距离
*/
private fun calculateRemainingSumLength(points: List<LatLng>?): Float {
if (null == points || points.isEmpty()) return 0F
var sumLength = 0f
//计算全路径总距离
var i = 0
while (i + 1 < points.size) {
val preLat = points[i].latitude
val preLon = points[i].longitude
val laLat = points[i + 1].latitude
val laLon = points[i + 1].longitude
val length = CoordinateUtils.calculateLineDistance(laLon, laLat, preLon, preLat)
sumLength += length
i++
}
return sumLength
}
private fun coordinateConverterWgsToGcjListCommon(
mContext: Context,
models: List<MessagePad.Location>
): List<LatLng> {
//转成MogoLatLng集合
val list: MutableList<LatLng> = java.util.ArrayList()
for (m in models) {
val mogoLatLng = coordinateConverterWgsToGcj(mContext, m)
list.add(mogoLatLng)
}
return list
}
private fun coordinateConverterWgsToGcj(
mContext: Context,
mogoLatLng: MessagePad.Location
): LatLng {
val mCoordinateConverter =
CoordinateConverter(mContext)
mCoordinateConverter.from(CoordinateConverter.CoordType.GPS)
mCoordinateConverter.coord(LatLng(mogoLatLng.latitude, mogoLatLng.longitude))
return mCoordinateConverter.convert()
}
}

View File

@@ -1,6 +1,7 @@
package com.mogo.eagle.core.function.smp;
import android.content.Context;
import android.location.Location;
import android.os.Bundle;
import android.view.View;
@@ -19,7 +20,11 @@ import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningListen
import com.mogo.eagle.core.function.map.R;
import com.mogo.eagle.core.function.overview.InfStructureManager;
import com.mogo.eagle.core.data.map.Infrastructure;
import com.mogo.eagle.core.function.overview.ViewModelExtKt;
import com.mogo.eagle.core.function.overview.vm.OverViewModel;
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
import com.mogo.map.navi.IMogoCarLocationChangedListener2;
import com.mogo.module.common.MogoApisHandler;
import org.jetbrains.annotations.NotNull;
@@ -27,6 +32,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import kotlin.Pair;
import mogo.telematics.pad.MessagePad;
import mogo_msg.MogoReportMsg;
import system_master.SystemStatusInfo;

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 443 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 443 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

View File

@@ -17,8 +17,8 @@
android:layout_height="match_parent"
android:layout_centerInParent="true">
<com.amap.api.navi.AMapNaviView
android:id="@+id/aMapNaviView"
<com.amap.api.maps.TextureMapView
android:id="@+id/aMapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />