Merge branch 'local_282_navi' into feat_overview_mode_282
This commit is contained in:
@@ -776,7 +776,7 @@ class DebugSettingView @JvmOverloads constructor(
|
||||
SharedPrefsMgr.getInstance(context)
|
||||
.getString(MoGoConfig.AUTOPILOT_IP, FunctionBuildConfig.adasConnectIP)
|
||||
|
||||
etAutopilotIP.setText("172.30.10.10:41102")
|
||||
etAutopilotIP.setText("192.168.1.102")
|
||||
etAutopilotIP.text?.let { etAutopilotIP.setSelection(it.length) }
|
||||
//设置工控机IP
|
||||
btnSetAutopilotIP.setOnClickListener {
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
package com.mogo.eagle.core.function.smp;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.CameraUpdateFactory;
|
||||
import com.amap.api.maps.TextureMapView;
|
||||
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.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;
|
||||
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 包名: com.amap.api.navi.core
|
||||
* <p>
|
||||
* 创建时间:2018/3/1
|
||||
* 项目名称:AndroidNavigationSDK
|
||||
*
|
||||
* @author guibao.ggb
|
||||
* @email guibao.ggb@alibaba-inc.com
|
||||
* <p>
|
||||
* 类说明:自车位置管理Overlay类
|
||||
*/
|
||||
public class CarOverlay {
|
||||
|
||||
protected static final int CAR_MOVE_ANIMATION_PERIOD = 50;
|
||||
protected int carMoveAnimationFrameNum = 2;
|
||||
protected boolean mIsLock = true;
|
||||
protected IPoint mapAnchorBackup = null;
|
||||
protected double dXOffStep;
|
||||
protected double dYOffStep;
|
||||
protected float dAngleOffStep;
|
||||
protected int currentFrameIndex;
|
||||
protected float angleStart = 0;
|
||||
protected boolean isMoveStarted = false;
|
||||
protected float newAngle = 0;
|
||||
protected BitmapDescriptor carDescriptor = null;
|
||||
protected BitmapDescriptor fourCornersDescriptor = null;
|
||||
protected Marker carMarker;
|
||||
protected Marker directionMarker;
|
||||
protected AMap mAmap = null;
|
||||
protected AMapNaviView mapView;
|
||||
protected boolean isDirectionVisible = true;
|
||||
protected LatLng endLatLng = null;
|
||||
protected Polyline leaderLine = null;
|
||||
protected final int DISTANCE_OFFSET = 150;// 默认 500 偏差
|
||||
|
||||
// API 默认 1800 UI 默认 360
|
||||
protected int angleModValue = 1800;
|
||||
|
||||
|
||||
private ScheduledExecutorService executorService;
|
||||
|
||||
public CarOverlay(Context context, AMapNaviView mapView) {
|
||||
this.mapView = mapView;
|
||||
|
||||
fourCornersDescriptor = BitmapDescriptorFactory.fromBitmap(BitmapFactory
|
||||
.decodeResource(context.getResources(),
|
||||
R.drawable.module_small_map_navi_direction));
|
||||
|
||||
carDescriptor = BitmapDescriptorFactory.fromBitmap(BitmapFactory
|
||||
.decodeResource(context.getResources(),
|
||||
R.drawable.module_small_map_view_my_location_logo));
|
||||
angleModValue = 1800;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置自车状态
|
||||
*
|
||||
* @param lock true 锁车 false 非锁车
|
||||
*/
|
||||
public void setLock(boolean lock) {
|
||||
mIsLock = lock;
|
||||
if (carMarker == null) {
|
||||
return;
|
||||
}
|
||||
if (mAmap == null) {
|
||||
return;
|
||||
}
|
||||
if (directionMarker == null) {
|
||||
return;
|
||||
}
|
||||
carMarker.setFlat(true);
|
||||
directionMarker.setGeoPoint(carMarker.getGeoPoint());
|
||||
carMarker.setGeoPoint(carMarker.getGeoPoint());
|
||||
carMarker.setRotateAngle(carMarker.getRotateAngle());
|
||||
if (mIsLock) {
|
||||
CameraPosition cameraPosition = new CameraPosition.Builder().target(carMarker.getPosition()).bearing(newAngle).tilt(0).zoom(16).build();
|
||||
mAmap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
if (carMarker != null) {
|
||||
carMarker.remove();
|
||||
}
|
||||
if (directionMarker != null) {
|
||||
directionMarker.remove();
|
||||
}
|
||||
if (leaderLine != null) {
|
||||
leaderLine.remove();
|
||||
}
|
||||
leaderLine = null;
|
||||
carMarker = null;
|
||||
directionMarker = null;
|
||||
|
||||
if (executorService != null) {
|
||||
if (!executorService.isShutdown()) {
|
||||
executorService.shutdown();
|
||||
}
|
||||
isMoveStarted = false;
|
||||
|
||||
executorService = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制自车
|
||||
*
|
||||
* @param aMap
|
||||
* @param mLatLng
|
||||
* @param bearing
|
||||
*/
|
||||
public void draw(AMap aMap, LatLng mLatLng, float bearing) {
|
||||
if (aMap == null || mLatLng == null || carDescriptor == null) {
|
||||
return;
|
||||
}
|
||||
mAmap = aMap;
|
||||
try {
|
||||
if (carMarker == null) {
|
||||
carMarker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f).setFlat(true).icon(carDescriptor).position(mLatLng));
|
||||
}
|
||||
|
||||
if (directionMarker == null) {
|
||||
directionMarker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f).setFlat(true).icon(fourCornersDescriptor).position(mLatLng));
|
||||
if (isDirectionVisible) {
|
||||
directionMarker.setVisible(true);
|
||||
} else {
|
||||
directionMarker.setVisible(false);
|
||||
}
|
||||
}
|
||||
carMarker.setVisible(true);
|
||||
newAngle = bearing;
|
||||
IPoint resultGeoPnt = IPoint.obtain();
|
||||
resultGeoPnt = NaviUtil.lonlat2Geo(mLatLng.latitude, mLatLng.longitude, 20);
|
||||
updateCarPosition(resultGeoPnt);
|
||||
resultGeoPnt.recycle();
|
||||
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateCarPosition(IPoint p) {
|
||||
carMarker.setGeoPoint(p);
|
||||
carMarker.setFlat(true);
|
||||
carMarker.setRotateAngle(360 - newAngle);
|
||||
if (directionMarker != null) {
|
||||
directionMarker.setGeoPoint(p);
|
||||
}
|
||||
|
||||
if (mIsLock) {
|
||||
CameraPosition cameraPosition = new CameraPosition.Builder().target(carMarker.getPosition()).bearing(newAngle).tilt(0).zoom(16).build();
|
||||
mAmap.moveCamera(CameraUpdateFactory.changeBearingGeoCenter(newAngle, p));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setEndPoi(LatLng latlng) {
|
||||
endLatLng = latlng;
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放自车资源
|
||||
*/
|
||||
public void destroy() {
|
||||
if (carMarker != null) {
|
||||
carMarker.remove();
|
||||
carMarker = null;
|
||||
}
|
||||
if (directionMarker != null) {
|
||||
directionMarker.remove();
|
||||
directionMarker = null;
|
||||
}
|
||||
carDescriptor = null;
|
||||
|
||||
if (executorService != null && !executorService.isShutdown()) {
|
||||
executorService.shutdown();
|
||||
isMoveStarted = false;
|
||||
|
||||
executorService = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateCarSmoothMoveOffset(IPoint newCenter, float newAngle) {
|
||||
if (carMarker == null) {
|
||||
return;
|
||||
}
|
||||
IPoint currentAnchorGeoPoint = carMarker.getGeoPoint();
|
||||
if (currentAnchorGeoPoint == null || currentAnchorGeoPoint.x == 0 || currentAnchorGeoPoint.y == 0) {
|
||||
currentAnchorGeoPoint = newCenter;
|
||||
}
|
||||
currentFrameIndex = 0;
|
||||
mapAnchorBackup = currentAnchorGeoPoint;
|
||||
dXOffStep = (newCenter.x - currentAnchorGeoPoint.x) / carMoveAnimationFrameNum;
|
||||
dYOffStep = (newCenter.y - currentAnchorGeoPoint.y) / carMoveAnimationFrameNum;
|
||||
// 获取当前的旋转角度
|
||||
angleStart = carMarker.getRotateAngle();
|
||||
boolean isFirst = false;
|
||||
|
||||
if (Float.compare(angleStart, newAngle) == 0) {
|
||||
isFirst = true;
|
||||
} else {
|
||||
angleStart = 360 - angleStart;
|
||||
}
|
||||
// 校正旋转角度问题
|
||||
float dAngleDelta = newAngle - angleStart;
|
||||
if (isFirst) {
|
||||
dAngleDelta = 0;
|
||||
}
|
||||
if (dAngleDelta > 180) {
|
||||
dAngleDelta = dAngleDelta - 360;
|
||||
}
|
||||
else if (dAngleDelta < -180) {
|
||||
dAngleDelta = dAngleDelta + 360;
|
||||
}
|
||||
dAngleOffStep = dAngleDelta / carMoveAnimationFrameNum;
|
||||
isMoveStarted = true;
|
||||
}
|
||||
|
||||
// protected void startSmoothMoveTimer() {
|
||||
// if (executorService == null) {
|
||||
// executorService = new ScheduledThreadPoolExecutor(1, new BasicThreadFactory.Builder().namingPattern("caroverlay-schedule-pool-%d").daemon(true).build());
|
||||
//
|
||||
// executorService.scheduleAtFixedRate(new Runnable() {
|
||||
// long currentSeconds;
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try{
|
||||
// currentSeconds = System.currentTimeMillis();
|
||||
// mapSmoothMoveTimerTick();
|
||||
// } catch(Throwable e){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }, 0, CAR_MOVE_ANIMATION_PERIOD, TimeUnit.MILLISECONDS);
|
||||
// }
|
||||
// }
|
||||
|
||||
private void mapSmoothMoveTimerTick() {
|
||||
if (!isMoveStarted) {
|
||||
return;
|
||||
}
|
||||
if (carMarker == null) {
|
||||
return;
|
||||
}
|
||||
if (mAmap == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
IPoint p = carMarker.getGeoPoint();
|
||||
double newX = 0, newY = 0;
|
||||
if (currentFrameIndex++ < carMoveAnimationFrameNum) {
|
||||
newX = mapAnchorBackup.x + dXOffStep * currentFrameIndex;
|
||||
newY = mapAnchorBackup.y + dYOffStep * currentFrameIndex;
|
||||
newAngle = angleStart + dAngleOffStep * currentFrameIndex;
|
||||
newAngle %= angleModValue;
|
||||
if (newX != 0 || newY != 0) {
|
||||
p = new IPoint((int)newX, (int)newY);
|
||||
}
|
||||
updateCarPosition(p);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.mogo.eagle.core.function.smp;
|
||||
|
||||
import com.amap.api.maps.AMapUtils;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.navi.model.NaviLatLng;
|
||||
import com.autonavi.amap.mapcore.IPoint;
|
||||
import com.autonavi.amap.mapcore.MapProjection;
|
||||
|
||||
/**
|
||||
* 包名: com.amap.navi.demo.util
|
||||
* <p>
|
||||
* 创建时间:2018/4/19
|
||||
* 项目名称:NaviDemo
|
||||
*
|
||||
* @author guibao.ggb
|
||||
* @email guibao.ggb@alibaba-inc.com
|
||||
* <p>
|
||||
* 类说明:
|
||||
*/
|
||||
public class NaviUtil {
|
||||
|
||||
public static float calculateDistance(NaviLatLng start, NaviLatLng end) {
|
||||
double x1 = start.getLongitude();
|
||||
double y1 = start.getLatitude();
|
||||
double x2 = end.getLongitude();
|
||||
double y2 = end.getLatitude();
|
||||
return AMapUtils.calculateLineDistance(new LatLng(y1, x1), new LatLng(y2, x2));
|
||||
}
|
||||
|
||||
|
||||
public static NaviLatLng getPointForDis(NaviLatLng sPt, NaviLatLng ePt, double dis) {
|
||||
double lSegLength = calculateDistance(sPt, ePt);
|
||||
NaviLatLng pt = new NaviLatLng();
|
||||
double preResult = dis / lSegLength;
|
||||
pt.setLatitude(((ePt.getLatitude() - sPt.getLatitude()) * preResult + sPt.getLatitude()));
|
||||
pt.setLongitude(((ePt.getLongitude() - sPt.getLongitude()) * preResult + sPt.getLongitude()));
|
||||
return pt;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据经纬度计算需要偏转的角度
|
||||
*
|
||||
* @param startPoi
|
||||
* @param secondPoi
|
||||
* @return
|
||||
*/
|
||||
public static float getRotate(NaviLatLng startPoi, NaviLatLng secondPoi) {
|
||||
float rotate = 0;
|
||||
try {
|
||||
IPoint point1 = new IPoint();
|
||||
IPoint point2 = new IPoint();
|
||||
MapProjection.lonlat2Geo(startPoi.getLongitude(), startPoi.getLatitude(), point1);
|
||||
MapProjection.lonlat2Geo(secondPoi.getLongitude(), secondPoi.getLatitude(), point2);
|
||||
double x1 = point1.x;
|
||||
double x2 = point2.x;
|
||||
double y1 = point1.y;
|
||||
double y2 = point2.y;
|
||||
rotate = (float) (Math.atan2(y2 - y1, x2 - x1) / Math.PI * 180);
|
||||
rotate = rotate + 90;
|
||||
return rotate;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return rotate;
|
||||
}
|
||||
|
||||
|
||||
public static final int MAXZOOMLEVEL = 20;
|
||||
public static final int PIXELSPERTILE = 256;
|
||||
public static final double MINLATITUDE = -85.0511287798;
|
||||
public static final double MAXLATITUDE = 85.0511287798;
|
||||
public static final double MINLONGITUDE = -180;
|
||||
public static final double MAXLONGITUDE = 180;
|
||||
public static final int EARTHRADIUSINMETERS = 6378137;
|
||||
public static final int TILESPLITLEVEL = 0;
|
||||
|
||||
|
||||
public static final double EarthCircumferenceInMeters = 2 * Math.PI
|
||||
* EARTHRADIUSINMETERS;
|
||||
|
||||
|
||||
public static double clip(double n, double minValue, double maxValue) {
|
||||
return Math.min(Math.max(n, minValue), maxValue);
|
||||
}
|
||||
|
||||
public static IPoint lonlat2Geo(double latitude, double longitude,
|
||||
int levelOfDetail) {
|
||||
IPoint rPnt = new IPoint();
|
||||
latitude = clip(latitude, MINLATITUDE, MAXLATITUDE) * Math.PI / 180;
|
||||
longitude = clip(longitude, MINLONGITUDE, MAXLONGITUDE) * Math.PI / 180;
|
||||
double sinLatitude = Math.sin(latitude);
|
||||
double xMeters = EARTHRADIUSINMETERS * longitude;
|
||||
double lLog = Math.log((1 + sinLatitude) / (1 - sinLatitude));
|
||||
double yMeters = EARTHRADIUSINMETERS / 2 * lLog;
|
||||
long numPixels = (long) PIXELSPERTILE << levelOfDetail;
|
||||
double metersPerPixel = EarthCircumferenceInMeters / numPixels;
|
||||
rPnt.x = (int) clip((EarthCircumferenceInMeters / 2 + xMeters)
|
||||
/ metersPerPixel + 0.5, 0, numPixels - 1);
|
||||
long tmp = (long) (EarthCircumferenceInMeters / 2 - yMeters);
|
||||
rPnt.y = (int) clip((double) tmp / metersPerPixel + 0.5, 0,
|
||||
numPixels - 1);
|
||||
return rPnt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String formatKM(int d) {
|
||||
if (d == 0) {
|
||||
return "0米";
|
||||
} else if (d < 100) {
|
||||
return d + "米";
|
||||
} else if ((100 <= d) && (d < 1000)) {
|
||||
return d + "米";
|
||||
} else if ((1000 <= d) && (d < 10000)) {
|
||||
return (d / 10) * 10 / 1000.0D + "公里";
|
||||
} else if ((10000 <= d) && (d < 100000)) {
|
||||
return (d / 100) * 100 / 1000.0D + "公里";
|
||||
}
|
||||
return (d / 1000) + "公里";
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
@@ -38,11 +39,29 @@ import com.amap.api.navi.AMapNaviViewListener;
|
||||
import com.amap.api.navi.AMapNaviViewOptions;
|
||||
import com.amap.api.navi.ParallelRoadListener;
|
||||
import com.amap.api.navi.enums.AMapNaviParallelRoadStatus;
|
||||
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.AMapNaviPath;
|
||||
import com.amap.api.navi.model.AMapNaviRouteNotifyData;
|
||||
import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
|
||||
import com.amap.api.navi.model.AMapServiceAreaInfo;
|
||||
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.amap.api.navi.view.RouteOverLay;
|
||||
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;
|
||||
@@ -52,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,ParallelRoadListener{
|
||||
implements IMoGoMapLocationListener, ISmallMapDirectionView, AMapNaviListener, AMapNaviViewListener, IMoGoAutopilotPlanningListener {
|
||||
|
||||
//小地图名称
|
||||
public static final String TAG = "SmallMapDirectionView";
|
||||
@@ -73,10 +96,15 @@ public class SmallMapDirectionView
|
||||
protected AMapNavi mAMapNavi;
|
||||
private AMap mAMap;
|
||||
// private Marker mCarMarker;
|
||||
// private Marker mStartMarker;
|
||||
// private Marker mStartMarker;
|
||||
// private Marker mEndMarker;
|
||||
protected NaviLatLng mEndLatlng = new NaviLatLng(40.032969, 116.313151);
|
||||
protected NaviLatLng mStartLatlng = new NaviLatLng(40.106731, 116.248692);
|
||||
//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>();
|
||||
|
||||
@@ -88,6 +116,8 @@ public class SmallMapDirectionView
|
||||
private Polyline mPolyline;
|
||||
private CameraUpdate mCameraUpdate;
|
||||
private Context mContext;
|
||||
private float tilt = 20f;
|
||||
private TextView overLayerView;
|
||||
|
||||
public SmallMapDirectionView(Context context) {
|
||||
this(context, null);
|
||||
@@ -110,27 +140,42 @@ public class SmallMapDirectionView
|
||||
mContext = context;
|
||||
sList.add(mStartLatlng);
|
||||
eList.add(mEndLatlng);
|
||||
mWayPointList.add(new NaviLatLng(40.048674, 116.308173));
|
||||
mWayPointList.add(new NaviLatLng(40.056558, 116.303023));
|
||||
mWayPointList.add(new NaviLatLng(40.069039, 116.2965));
|
||||
mWayPointList.add(new NaviLatLng(40.084144, 116.28311));
|
||||
mWayPointList.add(new NaviLatLng(40.089529, 116.275042));
|
||||
mWayPointList.add(new NaviLatLng(40.099115, 116.258391));
|
||||
//测试代码:路线指定路径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.addAMapNaviListener((AMapNaviListener) this);
|
||||
mAMapNavi.addParallelRoadListener(this);
|
||||
mAMapNavi.setUseInnerVoice(true, true);
|
||||
// mAMapNavi.setUseInnerVoice(true, true);
|
||||
mAMapNavi.addAMapNaviListener(this);
|
||||
mAMapNaviView.setAMapNaviViewListener(this);
|
||||
// rlSmallMapBorder = findViewById(R.id.rlSmallMapBorder);
|
||||
// rlSmallMapBorder.addView(mAMapNaviView);
|
||||
|
||||
initAMapView();
|
||||
|
||||
initAMapView(context);
|
||||
// 注册定位监听
|
||||
CallerMapLocationListenerManager.INSTANCE.addListener(TAG, this);
|
||||
//设置全览模式
|
||||
overLayerView.setOnClickListener(v -> {
|
||||
mAMapNaviView.displayOverview();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,55 +185,46 @@ public class SmallMapDirectionView
|
||||
CallerMapLocationListenerManager.INSTANCE.removeListener(TAG);
|
||||
}
|
||||
|
||||
private void initAMapView() {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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);
|
||||
//打开走过的路段自定义
|
||||
options.setAfterRouteAutoGray(true);
|
||||
//黑夜模式
|
||||
options.setNaviNight(true);
|
||||
//导航全程光柱
|
||||
options.setTrafficBarEnabled(false);
|
||||
//指南针
|
||||
options.setCompassEnabled(false);
|
||||
//关闭自动绘制路线,自行绘制路线
|
||||
options.setAutoDrawRoute(false);
|
||||
//自定义样式
|
||||
RouteOverlayOptions routeOverlayOptions = new RouteOverlayOptions();
|
||||
//只做一次算路
|
||||
// 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_navi_direction));
|
||||
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));
|
||||
//驶过路段擦除
|
||||
routeOverlayOptions.setPassRoute(BitmapFactory.decodeResource(getResources(), R.drawable.module_small_map_view_dir_pass_route));
|
||||
//与走过的路线
|
||||
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));//走过的路段
|
||||
options.setRouteOverlayOptions(routeOverlayOptions);
|
||||
mAMapNaviView.setViewOptions(options);
|
||||
// 设置自定义样式
|
||||
mAMap.setCustomMapStyle(customMapStyleOptions);
|
||||
|
||||
mAMap = mAMapNaviView.getMap();
|
||||
// 地图文字标注
|
||||
mAMap.showMapText(true);
|
||||
// 显示实时路况图层,aMap是地图控制器对象。
|
||||
mAMap.setTrafficEnabled(true);
|
||||
//设置希望展示的地图缩放级别
|
||||
mAMap.moveCamera(mCameraUpdate);
|
||||
//设置地图的样式
|
||||
@@ -205,19 +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);
|
||||
// });
|
||||
//设置全览模式
|
||||
mAMapNaviView.displayOverview();
|
||||
|
||||
int strategy = 0;
|
||||
try {
|
||||
//再次强调,最后一个参数为true时代表多路径,否则代表单路径
|
||||
@@ -225,6 +248,8 @@ public class SmallMapDirectionView
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.d(TAG, "calculateDriveRoute:" + sList.toString() + "," + eList.toString() + "," + mWayPointList.toString());
|
||||
//指定路径绘制导航路线
|
||||
mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy);
|
||||
}
|
||||
|
||||
@@ -237,6 +262,7 @@ public class SmallMapDirectionView
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(@org.jetbrains.annotations.Nullable MogoLocation location, int from) {
|
||||
// Log.d(TAG, "onLocationChanged location:" + location.toString());
|
||||
if (location == null) {
|
||||
return;
|
||||
}
|
||||
@@ -249,7 +275,6 @@ public class SmallMapDirectionView
|
||||
// }
|
||||
|
||||
CameraPosition cameraPosition;
|
||||
float tilt = 20f;
|
||||
if (mCoordinatesLatLng.size() > 1) {
|
||||
// mCoordinatesLatLngCurrent.clear();
|
||||
// for (LatLng lng : mCoordinatesLatLng) {
|
||||
@@ -284,7 +309,14 @@ public class SmallMapDirectionView
|
||||
cameraPosition = new CameraPosition.Builder().target(currentLatLng).tilt(tilt).bearing(location.getBearing()).zoom(zoomLevel).build();
|
||||
// mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, zoomLevel));
|
||||
}
|
||||
mAMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
|
||||
// mAMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
|
||||
|
||||
// if (carOverlay != null) {
|
||||
// Log.d(TAG, "carOverlay != null");
|
||||
// LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
|
||||
// carOverlay.draw(mAMapNaviView.getMap(), latLng, location.getBearing());
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
private void removeLocation(Location latLng) {
|
||||
@@ -420,6 +452,14 @@ public class SmallMapDirectionView
|
||||
if (mAMapNaviView != null) {
|
||||
mAMapNaviView.onDestroy();
|
||||
}
|
||||
//since 1.6.0 不再在naviview destroy的时候自动执行AMapNavi.stopNavi();请自行执行
|
||||
if (mAMapNavi != null) {
|
||||
mAMapNavi.stopNavi();
|
||||
mAMapNavi.destroy();
|
||||
}
|
||||
if (mAMapNaviView != null) {
|
||||
mAMapNaviView.onDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
public void convert(List<MogoLatLng> coordinates) {
|
||||
@@ -429,10 +469,264 @@ public class SmallMapDirectionView
|
||||
mCoordinatesLatLng.addAll(latLngs);
|
||||
}
|
||||
|
||||
//多路径算路成功回调
|
||||
@Override
|
||||
public void notifyParallelRoad(AMapNaviParallelRoadStatus aMapNaviParallelRoadStatus) {
|
||||
|
||||
public void onCalculateRouteSuccess(int[] ints) {
|
||||
Log.d(TAG, "onCalculateRouteSuccess int");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onInitNaviFailure() {
|
||||
Log.d(TAG, "onInitNaviFailure");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitNaviSuccess() {
|
||||
Log.d(TAG, "onInitNaviSuccess");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartNavi(int i) {
|
||||
Log.d(TAG, "onStartNavi");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrafficStatusUpdate() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChange(AMapNaviLocation aMapNaviLocation) {
|
||||
Log.d(TAG, "高德地图经纬度:" + aMapNaviLocation.getCoord().getLongitude() + "," + aMapNaviLocation.getCoord().getLatitude());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetNavigationText(int i, String s) {
|
||||
Log.d(TAG, "onGetNavigationText int");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetNavigationText(String s) {
|
||||
Log.d(TAG, "onGetNavigationText ss");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEndEmulatorNavi() {
|
||||
Log.d(TAG, "onEndEmulatorNavi");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onArriveDestination() {
|
||||
Log.d(TAG, "onArriveDestination");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculateRouteFailure(int i) {
|
||||
Log.d(TAG, "onCalculateRouteFailure");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReCalculateRouteForYaw() {
|
||||
Log.d(TAG, "onReCalculateRouteForYaw");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReCalculateRouteForTrafficJam() {
|
||||
Log.d(TAG, "onReCalculateRouteForTrafficJam");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onArrivedWayPoint(int i) {
|
||||
Log.d(TAG, "onArrivedWayPoint");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGpsOpenStatus(boolean b) {
|
||||
Log.d(TAG, "onGpsOpenStatus");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviInfoUpdate(NaviInfo naviInfo) {
|
||||
Log.d(TAG, "onNaviInfoUpdate");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviInfoUpdated(AMapNaviInfo aMapNaviInfo) {
|
||||
Log.d(TAG, "onNaviInfoUpdated");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCameraInfo(AMapNaviCameraInfo[] aMapNaviCameraInfos) {
|
||||
Log.d(TAG, "updateCameraInfo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateIntervalCameraInfo(AMapNaviCameraInfo aMapNaviCameraInfo, AMapNaviCameraInfo aMapNaviCameraInfo1, int i) {
|
||||
Log.d(TAG, "updateIntervalCameraInfo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceAreaUpdate(AMapServiceAreaInfo[] aMapServiceAreaInfos) {
|
||||
Log.d(TAG, "onServiceAreaUpdate");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showCross(AMapNaviCross aMapNaviCross) {
|
||||
Log.d(TAG, "showCross");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideCross() {
|
||||
Log.d(TAG, "hideCross");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showModeCross(AMapModelCross aMapModelCross) {
|
||||
Log.d(TAG, "showModeCross");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideModeCross() {
|
||||
Log.d(TAG, "hideModeCross");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showLaneInfo(AMapLaneInfo[] aMapLaneInfos, byte[] bytes, byte[] bytes1) {
|
||||
Log.d(TAG, "showLaneInfo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showLaneInfo(AMapLaneInfo aMapLaneInfo) {
|
||||
Log.d(TAG, "showLaneInfo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideLaneInfo() {
|
||||
Log.d(TAG, "hideLaneInfo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyParallelRoad(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void OnUpdateTrafficFacility(TrafficFacilityInfo trafficFacilityInfo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAimlessModeStatistics(AimLessModeStat aimLessModeStat) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo aimLessModeCongestionInfo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayRing(int i) {
|
||||
|
||||
}
|
||||
|
||||
//算路详情
|
||||
@Override
|
||||
public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) {
|
||||
Log.d(TAG, "onCalculateRouteSuccess aMapCalcRouteResult" + aMapCalcRouteResult.toString());
|
||||
mAMapNavi.startNavi(NaviType.GPS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculateRouteFailure(AMapCalcRouteResult aMapCalcRouteResult) {
|
||||
Log.d(TAG, "onCalculateRouteFailure");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviRouteNotify(AMapNaviRouteNotifyData aMapNaviRouteNotifyData) {
|
||||
Log.d(TAG, "onNaviRouteNotify");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviSetting() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviCancel() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNaviBackClick() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviMapMode(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviTurnClick() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNextRoadClick() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanViewButtonClick() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLockMap(boolean b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviViewLoaded() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapTypeChanged(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 162 B |
Binary file not shown.
|
After Width: | Height: | Size: 396 B |
Binary file not shown.
|
After Width: | Height: | Size: 179 B |
Binary file not shown.
|
After Width: | Height: | Size: 139 B |
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
@@ -27,6 +27,17 @@
|
||||
android:id="@+id/aMapNaviView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/overLayer"
|
||||
android:layout_width="@dimen/dp_80"
|
||||
android:layout_height="@dimen/dp_80"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:background="@color/blue"
|
||||
android:text="全览模式"
|
||||
android:textColor="@drawable/white"
|
||||
android:textSize="@dimen/dp_34" />
|
||||
</com.mogo.eagle.core.widget.RoundLayout>
|
||||
|
||||
<ImageView
|
||||
@@ -37,4 +48,5 @@
|
||||
android:src="@drawable/module_small_map_view_border_north"
|
||||
android:visibility="gone" />
|
||||
|
||||
|
||||
</merge>
|
||||
Reference in New Issue
Block a user