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/AMapCustomView.java similarity index 72% rename from core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/SmallMapDirectionView.java rename to core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/AMapCustomView.java index 7254e72cd5..07898d151c 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/AMapCustomView.java @@ -1,6 +1,8 @@ package com.mogo.eagle.core.function.smp; import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_MAP; +import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_V2X; +import static com.mogo.module.common.constants.DataTypes.TYPE_MARKER_CLOUD_STOP_LINE_DATA; import android.content.Context; import android.graphics.BitmapFactory; @@ -16,20 +18,16 @@ import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.Nullable; +import androidx.annotation.UiThread; 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.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.maps.model.PolylineOptions; import com.amap.api.navi.AMapNavi; @@ -37,8 +35,6 @@ 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.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; @@ -47,7 +43,6 @@ 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; @@ -56,19 +51,23 @@ 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.commons.AbsMogoApplication; +import com.mogo.eagle.core.data.config.FunctionBuildConfig; 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.AppIdentityModeUtils; import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger; import com.mogo.eagle.core.function.call.map.CallerMapLocationListenerManager; import com.mogo.eagle.core.function.map.R; -import com.mogo.eagle.core.utilcode.mogo.MapAssetStyleUtils; import com.mogo.eagle.core.function.smp.view.ISmallMapDirectionView; +import com.mogo.eagle.core.utilcode.util.UiThreadHandler; import com.mogo.eagle.core.widget.RoundLayout; +import com.mogo.map.MogoMarkerManager; +import com.mogo.map.marker.IMogoMarkerManager; import com.mogo.module.common.utils.DrivingDirectionUtils; import org.jetbrains.annotations.NotNull; @@ -85,50 +84,40 @@ import mogo.telematics.pad.MessagePad; * @author donghongyu * @date 12/14/20 4:40 PM */ -public class SmallMapDirectionView +public class AMapCustomView extends RelativeLayout implements IMoGoMapLocationListener, ISmallMapDirectionView, AMapNaviListener, AMapNaviViewListener, IMoGoAutopilotPlanningListener { - - //小地图名称 public static final String TAG = "SmallMapDirectionView"; - - private RoundLayout rlSmallMapBorder; private AMapNaviView mAMapNaviView; protected AMapNavi mAMapNavi; private AMap mAMap; - // private Marker mCarMarker; - // private Marker mStartMarker; -// private Marker mEndMarker; //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); +// mStartLatlng = new NaviLatLng(40.09383,116.51899); +// mEndLatlng = new NaviLatLng(40.09964,116.54570); protected final List sList = new ArrayList(); protected final List eList = new ArrayList(); - private int zoomLevel = 15; private final List mCoordinatesLatLng = new ArrayList<>(); private final List mCoordinatesLatLngCurrent = new ArrayList<>(); protected List mWayPointList = new ArrayList(); - private Polyline mPolyline; private CameraUpdate mCameraUpdate; private Context mContext; - private float tilt = 20f; + private float tilt = 40f; private TextView overLayerView; - public SmallMapDirectionView(Context context) { + public AMapCustomView(Context context) { this(context, null); } - public SmallMapDirectionView(Context context, @Nullable AttributeSet attrs) { + public AMapCustomView(Context context, @Nullable AttributeSet attrs) { this(context, attrs, 0); } - public SmallMapDirectionView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + public AMapCustomView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); try { initView(context); @@ -165,11 +154,8 @@ public class SmallMapDirectionView 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); @@ -186,9 +172,6 @@ public class SmallMapDirectionView CallerMapLocationListenerManager.INSTANCE.removeListener(TAG); } - /** - * - */ private void initAMapView(Context context) { mCameraUpdate = CameraUpdateFactory.zoomTo(zoomLevel); AMapNaviViewOptions options = mAMapNaviView.getViewOptions(); @@ -202,12 +185,10 @@ public class SmallMapDirectionView options.setTrafficBarEnabled(false); //指南针 options.setCompassEnabled(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.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)); @@ -216,7 +197,7 @@ public class SmallMapDirectionView //路线纹理自定义 RouteOverlayOptions routeOverlayOptions = new RouteOverlayOptions(); routeOverlayOptions.setTurnArrowIs3D(false); - routeOverlayOptions.setSmoothTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.module_small_map_view_dir_pass_route)); + routeOverlayOptions.setSmoothTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.amap_custom_smooth_route)); routeOverlayOptions.setPassRoute(BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_slow));//走过的路段 options.setRouteOverlayOptions(routeOverlayOptions); mAMapNaviView.setViewOptions(options); @@ -249,7 +230,6 @@ public class SmallMapDirectionView } catch (Exception e) { e.printStackTrace(); } - Log.d(TAG, "calculateDriveRoute:" + sList.toString() + "," + eList.toString() + "," + mWayPointList.toString()); //指定路径绘制导航路线 mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy); } @@ -263,60 +243,6 @@ 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; - } - LatLng currentLatLng = new LatLng(location.getLatitude(), location.getLongitude()); - //更新车辆位置 -// if (mCarMarker != null) { -// mCarMarker.setRotateAngle(location.getBearing()); -// mCarMarker.setPosition(currentLatLng); -// mCarMarker.setToTop(); -// } - - CameraPosition cameraPosition; - if (mCoordinatesLatLng.size() > 1) { -// mCoordinatesLatLngCurrent.clear(); -// for (LatLng lng : mCoordinatesLatLng) { -// MogoLatLng mogoLatLng = new MogoLatLng(lng.latitude, lng.longitude); -// mCoordinatesLatLngCurrent.add(mogoLatLng); -// } -// removeLoction(latLng); - - // 结束位置 - LatLng endLatLng = mCoordinatesLatLng.get(mCoordinatesLatLng.size() - 1); - // 与结束位置进行 GeoHash 0-12 -// GeoHash endGeoHash = GeoHash.withCharacterPrecision(endLatLng.latitude, endLatLng.longitude, 7); -// GeoHash currentGeoHash = GeoHash.withCharacterPrecision(currentLatLng.latitude, currentLatLng.longitude, 7); - - float calculateDistance = CoordinateUtils.calculateLineDistance( - endLatLng.latitude, endLatLng.longitude, - currentLatLng.latitude, currentLatLng.longitude - ); - - CallerLogger.INSTANCE.d(M_MAP + TAG, "calculateDistance=" + calculateDistance); - if (calculateDistance <= 5) { - clearPolyline(); - mCoordinatesLatLng.clear(); - } - //target:地图的中心位置(经度和纬度) - //tilt:倾斜角度的范围为【0.f-45.f】,0度时建筑物没有远近关系,随着角度增加,建筑物的远近效果比较明显,产生立体效果 - //bearing:旋转角度范围为:【0.f-360.f】,正北方向为0度,逆时针旋转值会增加 - //zoom:地图缩放级别范围为【4-20级】,值越大地图越详细,反之 - cameraPosition = new CameraPosition.Builder().target(currentLatLng).tilt(tilt).bearing(location.getBearing()).zoom(zoomLevel).build(); - } else { - //设置希望展示的地图缩放级别 - 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)); - -// if (carOverlay != null) { -// Log.d(TAG, "carOverlay != null"); -// LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); -// carOverlay.draw(mAMapNaviView.getMap(), latLng, location.getBearing()); -// } } @@ -345,46 +271,6 @@ public class SmallMapDirectionView @Override public void drawablePolyline() { - clearPolyline(); -// mCoordinatesLatLng.clear(); -// List latLngs = CoordinateConverterFrom84ForList(mContext,coordinates); -// mCoordinatesLatLng.addAll(latLngs); -// for (LatLng coordinate : mCoordinatesLatLng) { -// mCoordinatesLatLng.add(new LatLng(coordinate.getLat(), coordinate.getLon())); -// } - if (mAMap != null) { - if (mCoordinatesLatLng.size() > 2) { - // 设置开始结束Marker位置 -// mStartMarker.setPosition(mCoordinatesLatLng.get(0)); -// mEndMarker.setPosition(mCoordinatesLatLng.get(mCoordinatesLatLng.size() - 1)); -// mStartMarker.setToTop(); -// mStartMarker.setVisible(true); -// mEndMarker.setVisible(true); -// mEndMarker.setToTop(); - - - //存放所有点的经纬度 - LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder(); - - for (int i = 0; i < mCoordinatesLatLng.size(); i++) { - //把所有点都include进去(LatLng类型) - boundsBuilder.include(mCoordinatesLatLng.get(i)); - } - //第二个参数为四周留空宽度 - mAMap.animateCamera(CameraUpdateFactory.newLatLngBounds(boundsBuilder.build(), 30)); - // 绘制线 - mPolyline = mAMap.addPolyline( - new PolylineOptions() - .addAll(mCoordinatesLatLng) - .color(Color.argb(255, 31, 127, 255)) - .width(12)); - - } -// else { -// //设置希望展示的地图缩放级别 -// mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mCoordinatesLatLng.get(0), zoomLevel)); -// } - } } @@ -406,16 +292,9 @@ public class SmallMapDirectionView @Override public void clearPolyline() { -// mCoordinatesLatLng.clear(); if (mPolyline != null) { mPolyline.remove(); } -// if (mStartMarker != null) { -// mStartMarker.setVisible(false); -// } -// if (mEndMarker != null) { -// mEndMarker.setVisible(false); -// } } public void resetPolyLine() { @@ -423,12 +302,6 @@ public class SmallMapDirectionView if (mPolyline != null) { mPolyline.remove(); } -// if (mStartMarker != null) { -// mStartMarker.setVisible(false); -// } -// if (mEndMarker != null) { -// mEndMarker.setVisible(false); -// } } public void onCreateView(Bundle savedInstanceState) { @@ -464,10 +337,7 @@ public class SmallMapDirectionView } public void convert(List coordinates) { - mCoordinatesLatLng.clear(); - List latLngs = CoordinateConverterFrom84ForList(mContext, coordinates); - Log.d(TAG, "convert===============:" + latLngs.toString()); - mCoordinatesLatLng.addAll(latLngs); + } //多路径算路成功回调 @@ -650,7 +520,14 @@ public class SmallMapDirectionView @Override public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) { Log.d(TAG, "onCalculateRouteSuccess aMapCalcRouteResult" + aMapCalcRouteResult.toString()); - mAMapNavi.startNavi(NaviType.GPS); + mAMapNavi.startNavi(NaviType.EMULATOR); + mAMapNaviView.displayOverview(); + + //停止导航测试代码 +// UiThreadHandler.postDelayed(() -> { +// mAMapNavi.stopNavi(); +// Log.d(TAG, "stop------------"); +// }, 20000); } @Override @@ -731,7 +608,6 @@ public class SmallMapDirectionView @Override public void onAutopilotRotting(@org.jetbrains.annotations.Nullable MessagePad.GlobalPathResp globalPathResp) { List list = globalPathResp.getWayPointsList(); - Log.d(TAG, "adas返回全路径:" + list.toString()); int minCount = 2; if (list.size() >= minCount) { Location sLocation = (Location) list.get(0); @@ -753,7 +629,7 @@ public class SmallMapDirectionView } catch (Exception e) { e.printStackTrace(); } - Log.d(TAG, "calculateDriveRoute:" + sList.toString() + "," + eList.toString() + "," + mWayPointList.toString()); + Log.d(TAG, "calculateDriveRoute ADAS全局路径坐标:" + list.size() + "," + sList.toString() + "," + eList.toString() + "," + mWayPointList.toString()); //指定路径绘制导航路线 mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy); } diff --git a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/SmallMapFragment.java b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/SmallMapFragment.java index c0eda012a2..0e4e1d8aa9 100644 --- a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/SmallMapFragment.java +++ b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/smp/SmallMapFragment.java @@ -35,7 +35,7 @@ public class SmallMapFragment extends BaseFragment implements IMogoSmallMapProvider, IMoGoAutopilotPlanningListener, IMoGoAutopilotStatusListener { private final String TAG = "SmallMapFragment"; - protected SmallMapDirectionView mSmallMapDirectionView; + protected AMapCustomView mAMapCustomView; @Override public void onAttach(Context context) { @@ -60,33 +60,33 @@ public class SmallMapFragment extends BaseFragment @Override protected void initViews(Bundle savedInstanceState) { super.initViews(savedInstanceState); - mSmallMapDirectionView = mRootView.findViewById(R.id.smallMapDirectionView); - mSmallMapDirectionView.onCreateView(savedInstanceState); + mAMapCustomView = mRootView.findViewById(R.id.smallMapDirectionView); + mAMapCustomView.onCreateView(savedInstanceState); CallerAutopilotPlanningListenerManager.INSTANCE.addListener(TAG, this); } @Override public void showPanel() { - if (mSmallMapDirectionView != null) { - mSmallMapDirectionView.setVisibility(View.VISIBLE); + if (mAMapCustomView != null) { + mAMapCustomView.setVisibility(View.VISIBLE); } } @Override public void hidePanel() { - if (mSmallMapDirectionView != null) { - mSmallMapDirectionView.setVisibility(View.GONE); + if (mAMapCustomView != null) { + mAMapCustomView.setVisibility(View.GONE); } } @Override public void drawablePolyline(List coordinates) { - if (mSmallMapDirectionView != null) { - mSmallMapDirectionView.convert(coordinates); + if (mAMapCustomView != null) { + mAMapCustomView.convert(coordinates); UiThreadHandler.post(new Runnable() { @Override public void run() { - mSmallMapDirectionView.drawablePolyline(); + mAMapCustomView.drawablePolyline(); } }); } @@ -94,11 +94,11 @@ public class SmallMapFragment extends BaseFragment @Override public void clearPolyline() { - if (mSmallMapDirectionView != null) { + if (mAMapCustomView != null) { UiThreadHandler.post(new Runnable() { @Override public void run() { - mSmallMapDirectionView.clearPolyline(); + mAMapCustomView.clearPolyline(); } }); } @@ -107,16 +107,16 @@ public class SmallMapFragment extends BaseFragment @Override public void onResume() { super.onResume(); - if (mSmallMapDirectionView != null) { - mSmallMapDirectionView.onResume(); + if (mAMapCustomView != null) { + mAMapCustomView.onResume(); } } @Override public void onPause() { super.onPause(); - if (mSmallMapDirectionView != null) { - mSmallMapDirectionView.onPause(); + if (mAMapCustomView != null) { + mAMapCustomView.onPause(); } } @@ -124,8 +124,8 @@ public class SmallMapFragment extends BaseFragment @Override public void onDestroy() { super.onDestroy(); - if (mSmallMapDirectionView != null) { - mSmallMapDirectionView.onDestroy(); + if (mAMapCustomView != null) { + mAMapCustomView.onDestroy(); } CallerAutopilotPlanningListenerManager.INSTANCE.removeListener(TAG); } diff --git a/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/amap_custom_corner.png b/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/amap_custom_corner.png new file mode 100644 index 0000000000..9c81fd6895 Binary files /dev/null and b/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/amap_custom_corner.png differ diff --git a/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/amap_custom_smooth_route.png b/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/amap_custom_smooth_route.png new file mode 100644 index 0000000000..d706a68093 Binary files /dev/null and b/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi-2560x1440/amap_custom_smooth_route.png differ diff --git a/core/function-impl/mogo-core-function-map/src/main/res/layout/module_small_map_fragment.xml b/core/function-impl/mogo-core-function-map/src/main/res/layout/module_small_map_fragment.xml index 47b8763b7d..518457be06 100644 --- a/core/function-impl/mogo-core-function-map/src/main/res/layout/module_small_map_fragment.xml +++ b/core/function-impl/mogo-core-function-map/src/main/res/layout/module_small_map_fragment.xml @@ -4,7 +4,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - - - - - - - - +