高德导航路径规划,路算能力配合自动驾驶状态,模拟数据添加验证,GPS类型下实现路径擦除能力
This commit is contained in:
@@ -13,6 +13,7 @@ import com.amap.api.maps.model.LatLng;
|
||||
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.AMapNaviView;
|
||||
import com.autonavi.amap.mapcore.IPoint;
|
||||
import com.mogo.eagle.core.function.map.R;
|
||||
|
||||
@@ -49,7 +50,7 @@ public class CarOverlay {
|
||||
protected Marker carMarker;
|
||||
protected Marker directionMarker;
|
||||
protected AMap mAmap = null;
|
||||
protected TextureMapView mapView;
|
||||
protected AMapNaviView mapView;
|
||||
protected boolean isDirectionVisible = true;
|
||||
protected LatLng endLatLng = null;
|
||||
protected Polyline leaderLine = null;
|
||||
@@ -61,7 +62,7 @@ public class CarOverlay {
|
||||
|
||||
private ScheduledExecutorService executorService;
|
||||
|
||||
public CarOverlay(Context context, TextureMapView mapView) {
|
||||
public CarOverlay(Context context, AMapNaviView mapView) {
|
||||
this.mapView = mapView;
|
||||
|
||||
fourCornersDescriptor = BitmapDescriptorFactory.fromBitmap(BitmapFactory
|
||||
|
||||
@@ -61,6 +61,7 @@ import com.autonavi.tbt.TrafficFacilityInfo;
|
||||
import com.mogo.cloud.commons.utils.CoordinateUtils;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.eagle.core.data.map.MogoLocation;
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotPlanningListener;
|
||||
import com.mogo.eagle.core.function.api.map.listener.IMoGoMapLocationListener;
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
|
||||
import com.mogo.eagle.core.function.call.map.CallerMapLocationListenerManager;
|
||||
@@ -70,18 +71,22 @@ import com.mogo.eagle.core.function.smp.view.ISmallMapDirectionView;
|
||||
import com.mogo.eagle.core.widget.RoundLayout;
|
||||
import com.mogo.module.common.utils.DrivingDirectionUtils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
/**
|
||||
* 小地图的方向View
|
||||
*
|
||||
* 监听自动驾驶路径结束,结束高德地图导航
|
||||
* @author donghongyu
|
||||
* @date 12/14/20 4:40 PM
|
||||
*/
|
||||
public class SmallMapDirectionView
|
||||
extends RelativeLayout
|
||||
implements IMoGoMapLocationListener, ISmallMapDirectionView, AMapNaviListener, AMapNaviViewListener {
|
||||
implements IMoGoMapLocationListener, ISmallMapDirectionView, AMapNaviListener, AMapNaviViewListener, IMoGoAutopilotPlanningListener {
|
||||
|
||||
//小地图名称
|
||||
public static final String TAG = "SmallMapDirectionView";
|
||||
@@ -90,11 +95,16 @@ public class SmallMapDirectionView
|
||||
private AMapNaviView mAMapNaviView;
|
||||
protected AMapNavi mAMapNavi;
|
||||
private AMap mAMap;
|
||||
private Marker mCarMarker;
|
||||
// private Marker mCarMarker;
|
||||
// private Marker mStartMarker;
|
||||
// private Marker mEndMarker;
|
||||
protected NaviLatLng mEndLatlng = new NaviLatLng(26.817455, 112.579649);
|
||||
protected NaviLatLng mStartLatlng = new NaviLatLng(26.818968, 112.571216);
|
||||
//328路线测试数据
|
||||
protected NaviLatLng mStartLatlng = new NaviLatLng(39.969111, 116.411903);
|
||||
protected NaviLatLng mEndLatlng = new NaviLatLng(40.037209, 116.314358);
|
||||
|
||||
//顺义国展测试数据
|
||||
// protected NaviLatLng mStartLatlng = new NaviLatLng(40.09383,116.51899);
|
||||
// protected NaviLatLng mEndLatlng = new NaviLatLng(40.09964,116.54570);
|
||||
protected final List<NaviLatLng> sList = new ArrayList<NaviLatLng>();
|
||||
protected final List<NaviLatLng> eList = new ArrayList<NaviLatLng>();
|
||||
|
||||
@@ -108,10 +118,6 @@ public class SmallMapDirectionView
|
||||
private Context mContext;
|
||||
private float tilt = 20f;
|
||||
private TextView overLayerView;
|
||||
//自车位置,待定是否使用该类实现
|
||||
private CarOverlay carOverlay;
|
||||
//路线Overlay
|
||||
private RouteOverLay routeOverLay;
|
||||
|
||||
public SmallMapDirectionView(Context context) {
|
||||
this(context, null);
|
||||
@@ -134,26 +140,36 @@ public class SmallMapDirectionView
|
||||
mContext = context;
|
||||
sList.add(mStartLatlng);
|
||||
eList.add(mEndLatlng);
|
||||
//测试代码:路线指定路径
|
||||
mWayPointList.add(new NaviLatLng(26.81930638, 112.57276816));
|
||||
mWayPointList.add(new NaviLatLng(26.81930735, 112.57277308));
|
||||
mWayPointList.add(new NaviLatLng(26.81930829, 112.57277782));
|
||||
mWayPointList.add(new NaviLatLng(26.81930947, 112.57278384));
|
||||
mWayPointList.add(new NaviLatLng(26.81931044, 112.57278879));
|
||||
mWayPointList.add(new NaviLatLng(26.81931096, 112.57279149));
|
||||
//测试代码:路线指定路径328线路
|
||||
mWayPointList.add(new NaviLatLng(39.968847, 116.406952));
|
||||
mWayPointList.add(new NaviLatLng(39.969058, 116.407346));
|
||||
mWayPointList.add(new NaviLatLng(39.968955, 116.401767));
|
||||
mWayPointList.add(new NaviLatLng(39.968626, 116.394938));
|
||||
mWayPointList.add(new NaviLatLng(39.968433, 116.388725));
|
||||
mWayPointList.add(new NaviLatLng(39.968542, 116.383775));
|
||||
mWayPointList.add(new NaviLatLng(40.037808, 116.342539));
|
||||
mWayPointList.add(new NaviLatLng(40.037239, 116.337172));
|
||||
mWayPointList.add(new NaviLatLng(40.035897, 116.329582));
|
||||
mWayPointList.add(new NaviLatLng(40.036396, 116.322166));
|
||||
|
||||
//顺义国展路线
|
||||
// mWayPointList.add(new NaviLatLng(40.097621,116.526495));
|
||||
// mWayPointList.add(new NaviLatLng(40.097982,116.529135));
|
||||
// mWayPointList.add(new NaviLatLng(40.098434,116.531903));
|
||||
// mWayPointList.add(new NaviLatLng(40.098828,116.534563));
|
||||
// mWayPointList.add(new NaviLatLng(40.099377,116.538651));
|
||||
// mWayPointList.add(new NaviLatLng(40.099927,116.54173));
|
||||
|
||||
View smpView = LayoutInflater.from(context).inflate(R.layout.module_small_map_view, this);
|
||||
mAMapNaviView = smpView.findViewById(R.id.aMapNaviView);
|
||||
overLayerView = findViewById(R.id.overLayer);
|
||||
mAMapNavi = AMapNavi.getInstance(context);
|
||||
// mAMapNavi.setUseInnerVoice(true, true);
|
||||
|
||||
mAMapNavi.addAMapNaviListener(this);
|
||||
mAMapNaviView.setAMapNaviViewListener(this);
|
||||
// rlSmallMapBorder = findViewById(R.id.rlSmallMapBorder);
|
||||
// rlSmallMapBorder.addView(mAMapNaviView);
|
||||
initAMapView(context);
|
||||
|
||||
// 注册定位监听
|
||||
CallerMapLocationListenerManager.INSTANCE.addListener(TAG, this);
|
||||
//设置全览模式
|
||||
@@ -174,26 +190,9 @@ public class SmallMapDirectionView
|
||||
*/
|
||||
private void initAMapView(Context context) {
|
||||
mCameraUpdate = CameraUpdateFactory.zoomTo(zoomLevel);
|
||||
mAMap = mAMapNaviView.getMap();
|
||||
// 地图文字标注
|
||||
mAMap.showMapText(true);
|
||||
// 显示实时路况图层,aMap是地图控制器对象。
|
||||
mAMap.setTrafficEnabled(true);
|
||||
// 设置 锚点 图标
|
||||
// mCarMarker = mAMap.addMarker(new MarkerOptions()
|
||||
// .icon(BitmapDescriptorFactory.fromResource(R.drawable.module_small_map_view_my_location_logo))
|
||||
// .anchor(0.5f, 0.5f));
|
||||
// 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)));
|
||||
// 加载自定义样式
|
||||
// CustomMapStyleOptions customMapStyleOptions = new CustomMapStyleOptions()
|
||||
// .setEnable(true)
|
||||
// .setStyleData(MapAssetStyleUtils.getAssetsStyle(getContext()))
|
||||
// .setStyleExtraData(MapAssetStyleUtils.getAssetsExtraStyle(getContext()));
|
||||
|
||||
AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
|
||||
//关闭自动绘制路线,自行绘制路线
|
||||
// options.setAutoDrawRoute(false);
|
||||
//不显示导航界面
|
||||
options.setLayoutVisible(false);
|
||||
//黑夜模式
|
||||
@@ -202,29 +201,30 @@ public class SmallMapDirectionView
|
||||
options.setTrafficBarEnabled(false);
|
||||
//指南针
|
||||
options.setCompassEnabled(false);
|
||||
//关闭自动绘制路线,自行绘制路线
|
||||
options.setAutoDrawRoute(false);
|
||||
//只做一次算路
|
||||
// options.setO
|
||||
options.setTilt((int) tilt);
|
||||
//自车车标
|
||||
options.setCarBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.module_small_map_view_my_location_logo));
|
||||
options.setFourCornersBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.module_small_map_view_border_north));
|
||||
options.setStartPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.module_small_map_view_dir_start));
|
||||
// options.setWayPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.navi_way));
|
||||
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.setSmoothTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.module_small_map_view_dir_pass_route));
|
||||
routeOverlayOptions.setPassRoute(BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_slow));//走过的路段
|
||||
|
||||
//打开走过的路段自定义
|
||||
if (routeOverlayOptions != null) {
|
||||
Log.d(TAG, "routeOverlayOptions != null");
|
||||
}
|
||||
options.setRouteOverlayOptions(routeOverlayOptions);
|
||||
mAMapNaviView.setViewOptions(options);
|
||||
// 设置自定义样式
|
||||
// mAMap.setCustomMapStyle(customMapStyleOptions);
|
||||
|
||||
mAMap = mAMapNaviView.getMap();
|
||||
// 地图文字标注
|
||||
mAMap.showMapText(true);
|
||||
// 显示实时路况图层,aMap是地图控制器对象。
|
||||
mAMap.setTrafficEnabled(true);
|
||||
//设置希望展示的地图缩放级别
|
||||
mAMap.moveCamera(mCameraUpdate);
|
||||
//设置地图的样式
|
||||
@@ -241,16 +241,6 @@ public class SmallMapDirectionView
|
||||
uiSettings.setMyLocationButtonEnabled(false);
|
||||
//设置Logo下边界距离屏幕底部的边距,设置为负值即可
|
||||
uiSettings.setLogoBottomMargin(-150);
|
||||
// mAMap.setOnMapLoadedListener(() -> {
|
||||
// // 加载自定义样式
|
||||
// CustomMapStyleOptions customMapStyleOptions1 = new CustomMapStyleOptions()
|
||||
// .setEnable(true)
|
||||
// .setStyleData(MapAssetStyleUtils.getAssetsStyle(getContext()))
|
||||
// .setStyleExtraData(MapAssetStyleUtils.getAssetsExtraStyle(getContext()));
|
||||
// // 设置自定义样式
|
||||
// mAMap.setCustomMapStyle(customMapStyleOptions1);
|
||||
// mAMapNaviView.getMap().setPointToCenter(mAMapNaviView.getWidth() / 2, mAMapNaviView.getHeight() / 2);
|
||||
// });
|
||||
int strategy = 0;
|
||||
try {
|
||||
//再次强调,最后一个参数为true时代表多路径,否则代表单路径
|
||||
@@ -272,7 +262,7 @@ public class SmallMapDirectionView
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(@org.jetbrains.annotations.Nullable MogoLocation location, int from) {
|
||||
Log.d(TAG, "onLocationChanged location:" + location.toString());
|
||||
// Log.d(TAG, "onLocationChanged location:" + location.toString());
|
||||
if (location == null) {
|
||||
return;
|
||||
}
|
||||
@@ -321,10 +311,11 @@ public class SmallMapDirectionView
|
||||
}
|
||||
// mAMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
|
||||
|
||||
if (carOverlay != null) {
|
||||
Log.d(TAG, "carOverlay != null");
|
||||
carOverlay.draw(mAMapNaviView.getMap(), new LatLng(mStartLatlng.getLatitude(), mStartLatlng.getLongitude()), location.getBearing());
|
||||
}
|
||||
// if (carOverlay != null) {
|
||||
// Log.d(TAG, "carOverlay != null");
|
||||
// LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
|
||||
// carOverlay.draw(mAMapNaviView.getMap(), latLng, location.getBearing());
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -466,15 +457,6 @@ public class SmallMapDirectionView
|
||||
mAMapNavi.stopNavi();
|
||||
mAMapNavi.destroy();
|
||||
}
|
||||
if (carOverlay != null) {
|
||||
carOverlay.destroy();
|
||||
}
|
||||
|
||||
if (routeOverLay != null) {
|
||||
routeOverLay.removeFromMap();
|
||||
routeOverLay.destroy();
|
||||
}
|
||||
|
||||
if (mAMapNaviView != null) {
|
||||
mAMapNaviView.onDestroy();
|
||||
}
|
||||
@@ -491,44 +473,6 @@ public class SmallMapDirectionView
|
||||
@Override
|
||||
public void onCalculateRouteSuccess(int[] ints) {
|
||||
Log.d(TAG, "onCalculateRouteSuccess int");
|
||||
AMapNaviPath naviPath = mAMapNavi.getNaviPath();
|
||||
if (naviPath != null) {
|
||||
Log.d(TAG, "naviPath != null");
|
||||
if (routeOverLay == null) {
|
||||
Log.d(TAG, "routeOverLay == null");
|
||||
// 初始化路线参数
|
||||
// routeOverLay = new RouteOverLay(mAMapNaviView.getMap(), naviPath, mContext);
|
||||
// routeOverLay.setWayPointBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.icon_module_small_map_four_corners));
|
||||
// routeOverLay.setEndPointBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.module_small_map_view_dir_end));
|
||||
// routeOverLay.setStartPointBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.module_small_map_view_dir_start));
|
||||
|
||||
//自定义样式
|
||||
// RouteOverlayOptions routeOverlayOptions = new RouteOverlayOptions();
|
||||
//驶过路段擦除
|
||||
// routeOverlayOptions.setPassRoute(BitmapFactory.decodeResource(getResources(), R.drawable.module_small_map_view_dir_pass_route));
|
||||
// routeOverlayOptions.setSmoothTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_slow));//通畅路段
|
||||
// routeOverLay.setRouteOverlayOptions(routeOverlayOptions);
|
||||
}
|
||||
// if (routeOverLay != null) {
|
||||
// Log.d(TAG, "routeOverLay != null");
|
||||
// routeOverLay.setAMapNaviPath(naviPath);
|
||||
// routeOverLay.addToMap();
|
||||
// }
|
||||
float bearing = NaviUtil.getRotate(mStartLatlng, naviPath.getCoordList().get(1));
|
||||
// if (mStartLatlng != null) {
|
||||
// Log.d(TAG, "mStartLatlng != null");
|
||||
// carOverlay.reset();
|
||||
// /**
|
||||
// * 绘制自车位置
|
||||
// */
|
||||
// carOverlay.draw(mAMapNaviView.getMap(), new LatLng(mStartLatlng.getLatitude(), mStartLatlng.getLongitude()), bearing);
|
||||
// if (naviPath.getEndPoint() != null) {
|
||||
// LatLng latlng = new LatLng(naviPath.getEndPoint().getLatitude(), naviPath.getEndPoint().getLongitude());
|
||||
// carOverlay.setEndPoi(latlng);
|
||||
// }
|
||||
// }
|
||||
// mAMapNavi.startNavi(NaviType.EMULATOR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -556,7 +500,8 @@ public class SmallMapDirectionView
|
||||
|
||||
@Override
|
||||
public void onLocationChange(AMapNaviLocation aMapNaviLocation) {
|
||||
Log.d(TAG, "高德地图:onLocationChange");
|
||||
Log.d(TAG, "高德地图经纬度:" + aMapNaviLocation.getCoord().getLongitude() + "," + aMapNaviLocation.getCoord().getLatitude());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -704,7 +649,7 @@ public class SmallMapDirectionView
|
||||
@Override
|
||||
public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) {
|
||||
Log.d(TAG, "onCalculateRouteSuccess aMapCalcRouteResult" + aMapCalcRouteResult.toString());
|
||||
mAMapNavi.startNavi(NaviType.EMULATOR);
|
||||
mAMapNavi.startNavi(NaviType.GPS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -771,4 +716,17 @@ public class SmallMapDirectionView
|
||||
public void onNaviViewShowMode(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutopilotTrajectory(@NotNull List<MessagePad.TrajectoryPoint> trajectoryInfos) {
|
||||
|
||||
}
|
||||
|
||||
//自动驾驶状态开启之后返回,真实路径需要确认返回时间
|
||||
//数据返回之后触发路算
|
||||
@Override
|
||||
public void onAutopilotRotting(@org.jetbrains.annotations.Nullable MessagePad.GlobalPathResp globalPathResp) {
|
||||
List list = globalPathResp.getWayPointsList();
|
||||
Log.d(TAG, "adas返回全路径:" + list.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user