From b554edf38ebb86e53fd67447ba2d492034e966f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Wed, 7 Jul 2021 11:16:47 +0800 Subject: [PATCH] Reversion small map style --- .../com/mogo/commons/AbsMogoApplication.java | 7 +- .../small/map/SmallMapDirectionView.java | 221 ++++++++---------- .../main/res/layout/module_small_map_view.xml | 3 +- .../res/values-xhdpi-2560x1440/dimens.xml | 2 +- .../src/main/res/values-xhdpi/dimens.xml | 2 +- 5 files changed, 109 insertions(+), 126 deletions(-) diff --git a/foudations/mogo-commons/src/main/java/com/mogo/commons/AbsMogoApplication.java b/foudations/mogo-commons/src/main/java/com/mogo/commons/AbsMogoApplication.java index 02a95ed614..e213d2afce 100644 --- a/foudations/mogo-commons/src/main/java/com/mogo/commons/AbsMogoApplication.java +++ b/foudations/mogo-commons/src/main/java/com/mogo/commons/AbsMogoApplication.java @@ -13,6 +13,7 @@ import android.widget.TextView; import com.alibaba.android.arouter.launcher.ARouter; import com.amap.api.maps.TextureMapView; +import com.amap.api.navi.AMapNaviView; import com.mogo.commons.analytics.AnalyticsUtils; import com.mogo.commons.debug.DebugConfig; import com.mogo.commons.device.Devices; @@ -61,16 +62,16 @@ public abstract class AbsMogoApplication extends Application { return sApp; } - public static TextureMapView aMapNaviView; + public static AMapNaviView aMapNaviView; - public static TextureMapView getMapNaviView() { + public static AMapNaviView getMapNaviView() { return aMapNaviView; } @Override public void onCreate() { super.onCreate(); - aMapNaviView = new TextureMapView(this); + aMapNaviView = new AMapNaviView(this); aMapNaviView.onCreate(null); // 在设置皮肤布局填充器之前进行克隆一个出来 mLayoutInflaterNoSkin = LayoutInflater.from(new ContextThemeWrapper(this, R.style.Theme_AppCompat)).cloneInContext(new ContextThemeWrapper(this, R.style.Theme_AppCompat)); diff --git a/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmallMapDirectionView.java b/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmallMapDirectionView.java index 4e2757fc78..4732079e66 100644 --- a/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmallMapDirectionView.java +++ b/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmallMapDirectionView.java @@ -1,31 +1,25 @@ package com.mogo.module.small.map; import android.content.Context; -import android.graphics.Color; +import android.graphics.BitmapFactory; import android.location.Location; import android.util.AttributeSet; -import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; +import android.view.View; import android.widget.RelativeLayout; import androidx.annotation.Nullable; -import com.alibaba.android.arouter.thread.CancelableCountDownLatch; import com.amap.api.maps.AMap; import com.amap.api.maps.CameraUpdate; import com.amap.api.maps.CameraUpdateFactory; -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.mogo.cloud.commons.utils.CoordinateUtils; +import com.amap.api.navi.AMapNavi; +import com.amap.api.navi.AMapNaviView; +import com.amap.api.navi.AMapNaviViewOptions; import com.mogo.commons.AbsMogoApplication; import com.mogo.commons.debug.DebugConfig; import com.mogo.map.MogoLatLng; @@ -36,11 +30,8 @@ import com.mogo.module.small.map.utils.MapAssetStyleUtils; import com.mogo.module.small.map.view.ISmallMapDirectionView; import com.mogo.utils.logger.Logger; -import java.util.ArrayList; import java.util.List; -import ch.hsr.geohash.GeoHash; - /** * 小地图的方向View * @@ -55,17 +46,10 @@ public class SmallMapDirectionView public static final String MODULE_NAME = "SmallMap"; private RoundLayout rlSmallMapBorder; - private TextureMapView mAMapNaviView; + private AMapNaviView mAMapNaviView; private AMap mAMap; - private Marker mCarMarker; - private Marker mStartMarker; - private Marker mEndMarker; - - private int zoomLevel = 13; - private List mCoordinatesLatLng = new ArrayList<>(); - private List mCoordinatesLatLngCurrent = new ArrayList<>(); - private Polyline mPolyline; - private CameraUpdate mCameraUpdate; + private AMapNavi mAMapNavi; + private int zoomLevel = 15; public SmallMapDirectionView(Context context) { this(context, null); @@ -122,7 +106,10 @@ public class SmallMapDirectionView } private void initAMapView() { - mCameraUpdate = CameraUpdateFactory.zoomTo(zoomLevel); + // 车头朝上 + mAMapNaviView.setNaviMode(AMapNaviView.CAR_UP_MODE); + // 设置电子眼所在路线的可见性 + mAMapNaviView.setRouteOverlayVisible(false); mAMap = mAMapNaviView.getMap(); // 关闭地图文字标注 mAMap.showMapText(false); @@ -130,15 +117,26 @@ public class SmallMapDirectionView mAMap.setMapType(AMap.MAP_TYPE_NIGHT); // 关闭显示实时路况图层,aMap是地图控制器对象。 mAMap.setTrafficEnabled(false); + mAMap.setOnCameraChangeListener(new AMap.OnCameraChangeListener() { + @Override + public void onCameraChange(CameraPosition cameraPosition) { + if (cameraPosition != null) { + //Log.w("onCameraChange", "cameraPosition=" + cameraPosition.bearing); + //changeAngle((int) cameraPosition.bearing); + } + } + + @Override + public void onCameraChangeFinish(CameraPosition cameraPosition) { + + } + }); + + mAMapNavi = AMapNavi.getInstance(getContext()); + //使用外部GPS数据 + mAMapNavi.setIsUseExtraGPSData(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))); new Thread(() -> { try { @@ -154,7 +152,8 @@ public class SmallMapDirectionView ); //设置希望展示的地图缩放级别 - mAMap.moveCamera(mCameraUpdate); + CameraUpdate cameraUpdate = CameraUpdateFactory.zoomTo(zoomLevel); + mAMap.moveCamera(cameraUpdate); }).start(); // 设置地图的样式 @@ -164,6 +163,70 @@ public class SmallMapDirectionView uiSettings.setMyLocationButtonEnabled(false); // 显示默认的定位按钮 uiSettings.setLogoBottomMargin(-150); //设置Logo下边界距离屏幕底部的边距,设置为负值即可 + // 导航地图 + AMapNaviViewOptions options = mAMapNaviView.getViewOptions(); + //设置导航界面UI是否显示。 + if (options != null) { + // 设置是否开启自动黑夜模式切换,默认为false,不自动切换 + options.setAutoNaviViewNightMode(false); + // 设置6秒后是否自动锁车 + options.setAutoLockCar(true); + // 设置路线上的摄像头气泡是否显示 + options.setCameraBubbleShow(false); + // 设置路线相关的配置属性,如:路线的路况颜色,路线上是否显示摄像头气泡等。 + // options.setRouteOverlayOptions( MapStyleUtils.getRouteOverlayOptions() ); + // 设置自车的图片对象 + options.setCarBitmap(BitmapFactory.decodeResource(getContext().getResources(), + R.drawable.module_small_map_view_my_location_logo)); + // 设置罗盘位图对象 + options.setFourCornersBitmap(BitmapFactory.decodeResource(getContext().getResources(), + R.drawable.icon_module_small_map_four_corners)); + // 设置指南针图标否在导航界面显示,默认显示。true,显示;false,隐藏。 + options.setCompassEnabled(false); + //设置路况光柱条是否显示(只适用于驾车导航,需要联网)。 + options.setTrafficBarEnabled(false); + // 设置[实时交通图层开关按钮]是否显示(只适用于驾车导航,需要联网)。 + options.setTrafficLayerEnabled(false); + // 设置导航界面是否显示路线全览按钮。 + options.setRouteListButtonShow(false); + // 设置屏幕是否常亮,默认开启 + options.setScreenAlwaysBright(false); + // 设置交通播报是否打开(只适用于驾车导航,需要联网)。 + options.setTrafficInfoUpdateEnabled(false); + // 设置摄像头播报是否打开(只适用于驾车导航)。 + options.setCameraInfoUpdateEnabled(false); + // 设置菜单按钮是否在导航界面显示。 + options.setSettingMenuEnabled(false); + // 设置是否绘制显示交通路况的线路(彩虹线),拥堵-红色,畅通-绿色,缓慢-黄色,未知-蓝色。默认不绘制彩虹线。 + options.setTrafficLine(false); + // 设置是否绘制牵引线(当前位置到目的地的指引线)。默认不绘制牵引线。 + options.setLeaderLineEnabled(-1); + // 设置导航界面UI是否显示。 + options.setLayoutVisible(false); + // 设置是否自动画路 + options.setAutoDrawRoute(false); + // 设置是否显示路口放大图(实景图) + options.setRealCrossDisplayShow(false); + // 设置是否显示路口放大图(路口模型图) + options.setModeCrossDisplayShow(false); + // 设置是否显示道路信息view + options.setLaneInfoShow(false); + // 设置是否自动改变缩放等级 + options.setAutoChangeZoom(false); + // 设置是否自动全览模式,即在算路成功后自动进入全览模式 + options.setAutoDisplayOverview(false); + // 设置路线转向箭头隐藏和显示 + options.setNaviArrowVisible(false); + // 通过路线是否自动置灰,仅支持驾车导航 + options.setAfterRouteAutoGray(false); + options.setZoom(((int) 10)); + //options.setPointToCenter(0.7D, 0.5D); + // 2D模式 + options.setTilt(0); + // 黑夜模式 + options.setNaviNight(true); + mAMapNaviView.setViewOptions(options); + } } @@ -175,44 +238,8 @@ public class SmallMapDirectionView @Override public void onCarLocationChanged2(Location latLng) { Logger.d(MODULE_NAME, "onCarLocationChanged2 latLng:" + latLng); - LatLng currentLatLng = new LatLng(latLng.getLatitude(), latLng.getLongitude()); - - if (mCarMarker != null) { - mCarMarker.setRotateAngle(360 - latLng.getBearing()); - mCarMarker.setPosition(currentLatLng); - mCarMarker.setToTop(); - } - - - if (mCoordinatesLatLng.size() > 1) { - mCoordinatesLatLngCurrent.clear(); - for (LatLng lng : mCoordinatesLatLng) { - MogoLatLng mogoLatLng = new MogoLatLng(lng.latitude, lng.longitude); - mCoordinatesLatLngCurrent.add(mogoLatLng); - } - - // 结束位置 - 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); -// Log.d(MODULE_NAME, "currentGeoHash=" + currentGeoHash); -// Log.d(MODULE_NAME, "endGeoHash=" + endGeoHash); - - float calculateDistance = CoordinateUtils.calculateLineDistance( - endLatLng.latitude, endLatLng.longitude, - currentLatLng.latitude, currentLatLng.longitude - ); - - Log.d(MODULE_NAME, "calculateDistance=" + calculateDistance); - if (calculateDistance <= 20) { - clearPolyline(); - } else { - drawablePolyline(mCoordinatesLatLngCurrent); - } - } else { - //设置希望展示的地图缩放级别 - mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, zoomLevel)); + if (mAMapNavi != null) { + mAMapNavi.setExtraGPSData(2, latLng); } } @@ -223,57 +250,11 @@ public class SmallMapDirectionView @Override public void drawablePolyline(List coordinates) { - clearPolyline(); - mCoordinatesLatLng.clear(); - for (MogoLatLng coordinate : coordinates) { - 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.setVisible(true); - mEndMarker.setVisible(true); - - //存放所有点的经纬度 - LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder(); - - for (int i = 0; i < mCoordinatesLatLng.size(); i++) { - //把所有点都include进去(LatLng类型) - boundsBuilder.include(mCoordinatesLatLng.get(i)); - } - //第二个参数为四周留空宽度 - mAMap.animateCamera(CameraUpdateFactory.newLatLngBoundsRect(boundsBuilder.build(), 65, 65, 65, 65)); - - // 绘制线 - mPolyline = mAMap.addPolyline( - new PolylineOptions() - .addAll(mCoordinatesLatLng) - .color(Color.argb(255, 31, 127, 255)) - .width(5)); - - } else { - //设置希望展示的地图缩放级别 - mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mCoordinatesLatLng.get(0), zoomLevel)); - } - } } @Override public void clearPolyline() { - mCoordinatesLatLng.clear(); - if (mPolyline != null) { - mPolyline.remove(); - } - if (mStartMarker != null) { - mStartMarker.setVisible(false); - } - if (mEndMarker != null) { - mEndMarker.setVisible(false); - } - } + } } diff --git a/modules/mogo-module-smp/src/main/res/layout/module_small_map_view.xml b/modules/mogo-module-smp/src/main/res/layout/module_small_map_view.xml index 8ad5786c81..a01b5d6828 100644 --- a/modules/mogo-module-smp/src/main/res/layout/module_small_map_view.xml +++ b/modules/mogo-module-smp/src/main/res/layout/module_small_map_view.xml @@ -10,7 +10,8 @@ android:layout_width="@dimen/module_small_map_view_border_width" android:layout_height="@dimen/module_small_map_view_border_width" android:layout_centerInParent="true" - android:background="@drawable/module_small_map_view_border_north" /> + android:layout_margin="@dimen/module_small_map_padding" + android:background="@drawable/module_small_map_view_border" /> 40px - 550px + 400px 360px \ No newline at end of file diff --git a/modules/mogo-module-smp/src/main/res/values-xhdpi/dimens.xml b/modules/mogo-module-smp/src/main/res/values-xhdpi/dimens.xml index 3620ac47d1..69b891aa2c 100644 --- a/modules/mogo-module-smp/src/main/res/values-xhdpi/dimens.xml +++ b/modules/mogo-module-smp/src/main/res/values-xhdpi/dimens.xml @@ -1,7 +1,7 @@ 30px - 450px + 288px 260px \ No newline at end of file