diff --git a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/CarOverlay.java b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/CarOverlay.java new file mode 100644 index 0000000000..ac995a7013 --- /dev/null +++ b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/CarOverlay.java @@ -0,0 +1,290 @@ +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.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 + *

+ * 创建时间:2018/3/1 + * 项目名称:AndroidNavigationSDK + * + * @author guibao.ggb + * @email guibao.ggb@alibaba-inc.com + *

+ * 类说明:自车位置管理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 TextureMapView 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, TextureMapView 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(); + } + } + +} diff --git a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/NaviUtil.java b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/NaviUtil.java new file mode 100644 index 0000000000..f009ec97c1 --- /dev/null +++ b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/NaviUtil.java @@ -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 + *

+ * 创建时间:2018/4/19 + * 项目名称:NaviDemo + * + * @author guibao.ggb + * @email guibao.ggb@alibaba-inc.com + *

+ * 类说明: + */ +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) + "公里"; + } +} diff --git a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/SmallMapDirectionView.java b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/SmallMapDirectionView.java index 5e0d974a80..c5e962f0e3 100644 --- a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/SmallMapDirectionView.java +++ b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/SmallMapDirectionView.java @@ -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,8 +39,24 @@ 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.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; @@ -63,7 +80,7 @@ import java.util.List; */ public class SmallMapDirectionView extends RelativeLayout - implements IMoGoMapLocationListener, ISmallMapDirectionView,ParallelRoadListener{ + implements IMoGoMapLocationListener, ISmallMapDirectionView, AMapNaviListener { //小地图名称 public static final String TAG = "SmallMapDirectionView"; @@ -72,11 +89,11 @@ public class SmallMapDirectionView private AMapNaviView mAMapNaviView; protected AMapNavi mAMapNavi; private AMap mAMap; - // private Marker mCarMarker; -// private Marker mStartMarker; + private Marker mCarMarker; + // private Marker mStartMarker; // private Marker mEndMarker; - protected NaviLatLng mEndLatlng = new NaviLatLng(40.032969, 116.313151); - protected NaviLatLng mStartLatlng = new NaviLatLng(40.106731, 116.248692); + protected NaviLatLng mEndLatlng = new NaviLatLng(26.817455, 112.579649); + protected NaviLatLng mStartLatlng = new NaviLatLng(26.818968, 112.571216); protected final List sList = new ArrayList(); protected final List eList = new ArrayList(); @@ -88,6 +105,12 @@ public class SmallMapDirectionView private Polyline mPolyline; private CameraUpdate mCameraUpdate; private Context mContext; + private float tilt = 20f; + private TextView overLayerView; + //自车位置,待定是否使用该类实现 + private CarOverlay carOverlay; + //路线Overlay + private RouteOverLay routeOverLay; public SmallMapDirectionView(Context context) { this(context, null); @@ -110,27 +133,31 @@ 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)); + //测试代码:路线指定路径 + 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)); 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.addAMapNaviListener(this); // rlSmallMapBorder = findViewById(R.id.rlSmallMapBorder); // rlSmallMapBorder.addView(mAMapNaviView); - - initAMapView(); + initAMapView(context); // 注册定位监听 CallerMapLocationListenerManager.INSTANCE.addListener(TAG, this); + //设置全览模式 + overLayerView.setOnClickListener(v -> { + mAMapNaviView.displayOverview(); + }); } @Override @@ -140,7 +167,10 @@ public class SmallMapDirectionView CallerMapLocationListenerManager.INSTANCE.removeListener(TAG); } - private void initAMapView() { + /** + * + */ + private void initAMapView(Context context) { mCameraUpdate = CameraUpdateFactory.zoomTo(zoomLevel); mAMap = mAMapNaviView.getMap(); // 地图文字标注 @@ -156,10 +186,10 @@ public class SmallMapDirectionView // 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())); +// CustomMapStyleOptions customMapStyleOptions = new CustomMapStyleOptions() +// .setEnable(true) +// .setStyleData(MapAssetStyleUtils.getAssetsStyle(getContext())) +// .setStyleExtraData(MapAssetStyleUtils.getAssetsExtraStyle(getContext())); AMapNaviViewOptions options = mAMapNaviView.getViewOptions(); //不显示导航界面 @@ -174,20 +204,16 @@ public class SmallMapDirectionView options.setCompassEnabled(false); //关闭自动绘制路线,自行绘制路线 options.setAutoDrawRoute(false); - //自定义样式 - RouteOverlayOptions routeOverlayOptions = new RouteOverlayOptions(); //自车车标 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.setStartPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.module_small_map_view_dir_start)); + 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.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.setRouteOverlayOptions(routeOverlayOptions); +// options.setEndPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.module_small_map_view_dir_end)); mAMapNaviView.setViewOptions(options); + // 设置自定义样式 - mAMap.setCustomMapStyle(customMapStyleOptions); +// mAMap.setCustomMapStyle(customMapStyleOptions); //设置希望展示的地图缩放级别 mAMap.moveCamera(mCameraUpdate); @@ -215,9 +241,6 @@ public class SmallMapDirectionView // 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); } @@ -249,7 +274,6 @@ public class SmallMapDirectionView // } CameraPosition cameraPosition; - float tilt = 20f; if (mCoordinatesLatLng.size() > 1) { // mCoordinatesLatLngCurrent.clear(); // for (LatLng lng : mCoordinatesLatLng) { @@ -284,7 +308,13 @@ 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"); + carOverlay.draw(mAMapNaviView.getMap(), new LatLng(mStartLatlng.getLatitude(), mStartLatlng.getLongitude()), location.getBearing()); + } + } private void removeLocation(Location latLng) { @@ -420,6 +450,23 @@ public class SmallMapDirectionView if (mAMapNaviView != null) { mAMapNaviView.onDestroy(); } + //since 1.6.0 不再在naviview destroy的时候自动执行AMapNavi.stopNavi();请自行执行 + if (mAMapNavi != null) { + mAMapNavi.stopNavi(); + mAMapNavi.destroy(); + } + if (carOverlay != null) { + carOverlay.destroy(); + } + + if (routeOverLay != null) { + routeOverLay.removeFromMap(); + routeOverLay.destroy(); + } + + if (mAMapNaviView != null) { + mAMapNaviView.onDestroy(); + } } public void convert(List coordinates) { @@ -430,9 +477,231 @@ public class SmallMapDirectionView } @Override - public void notifyParallelRoad(AMapNaviParallelRoadStatus aMapNaviParallelRoadStatus) { + 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_green));//通畅路段 + routeOverlayOptions.setSlowTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_slow));//缓慢路段 + routeOverlayOptions.setJamTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_bad));//拥堵路段 + routeOverlayOptions.setVeryJamTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_grayred));//超级拥堵路段 + 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); + } + } + } } + @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, "onLocationChange"); + } + + @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()); + } + + @Override + public void onCalculateRouteFailure(AMapCalcRouteResult aMapCalcRouteResult) { + Log.d(TAG, "onCalculateRouteFailure"); + } + + @Override + public void onNaviRouteNotify(AMapNaviRouteNotifyData aMapNaviRouteNotifyData) { + Log.d(TAG, "onNaviRouteNotify"); + } } diff --git a/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/custtexture_bad.png b/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/custtexture_bad.png new file mode 100644 index 0000000000..d5d1e9d950 Binary files /dev/null and b/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/custtexture_bad.png differ diff --git a/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/custtexture_grayred.png b/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/custtexture_grayred.png new file mode 100644 index 0000000000..dbc7b4bd2b Binary files /dev/null and b/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/custtexture_grayred.png differ diff --git a/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/custtexture_green.png b/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/custtexture_green.png new file mode 100644 index 0000000000..373b3bdf0b Binary files /dev/null and b/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/custtexture_green.png differ diff --git a/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/custtexture_slow.png b/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/custtexture_slow.png new file mode 100644 index 0000000000..cb65fd1e5d Binary files /dev/null and b/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/custtexture_slow.png differ diff --git a/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/module_small_map_view_border_north.png b/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/module_small_map_view_border_north.png new file mode 100644 index 0000000000..1c4bf333ca Binary files /dev/null and b/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/module_small_map_view_border_north.png differ diff --git a/core/function-impl/mogo-core-function-map/src/main/res/layout/module_small_map_view.xml b/core/function-impl/mogo-core-function-map/src/main/res/layout/module_small_map_view.xml index a14430dd88..ac5ed7b135 100644 --- a/core/function-impl/mogo-core-function-map/src/main/res/layout/module_small_map_view.xml +++ b/core/function-impl/mogo-core-function-map/src/main/res/layout/module_small_map_view.xml @@ -27,6 +27,17 @@ android:id="@+id/aMapNaviView" android:layout_width="match_parent" android:layout_height="match_parent" /> + + + \ No newline at end of file