From 7757793225989ef9817093a842f4fe77561df968 Mon Sep 17 00:00:00 2001 From: wangcongtao Date: Fri, 25 Dec 2020 16:10:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E8=87=AA=E7=A0=94=E5=9C=B0?= =?UTF-8?q?=E5=9B=BEsdk=E7=89=88=E6=9C=AC=20=E6=B7=BB=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=87=E6=8D=A2=E5=9C=B0=E5=9B=BE=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=88=E9=A1=BA=E4=B9=89=E5=8C=BA=E5=9F=9F?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libraries/map-custom/build.gradle | 4 +- .../mogo/map/impl/custom/AMapViewWrapper.java | 21 +++- .../map/impl/custom/MapStyleController.java | 108 ++++++++++++++++++ 3 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 libraries/map-custom/src/main/java/com/mogo/map/impl/custom/MapStyleController.java diff --git a/libraries/map-custom/build.gradle b/libraries/map-custom/build.gradle index f514411412..377804e0b4 100644 --- a/libraries/map-custom/build.gradle +++ b/libraries/map-custom/build.gradle @@ -67,8 +67,8 @@ dependencies { implementation project(':foudations:mogo-commons') } -// implementation 'com.zhidaoauto.machine:map:1.0.0-vr-7.4.5' - implementation 'com.zhidaoauto.machine:map:1.0.0-vr-7.4.5-log-1' + implementation 'com.zhidaoauto.machine:map:1.0.0-vr-7.4.6' +// implementation 'com.zhidaoauto.machine:map:1.0.0-vr-7.4.5-log-1' } apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString() diff --git a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java index 6f2926e740..1a4e6f9297 100644 --- a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java +++ b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java @@ -62,7 +62,8 @@ public class AMapViewWrapper implements IMogoMapView, OnMapClickListener, OnMapTouchListener, OnMarkClickListener, - OnMapStyleListener { + OnMapStyleListener, + MapStyleController.IMapStyleAutoChangedListener { private static final String TAG = "AMapViewWrapper"; private final MapAutoView mMapView; @@ -684,6 +685,7 @@ public class AMapViewWrapper implements IMogoMapView, } NaviClient.getInstance( getContext() ).syncCarLocation( sysLocation ); + MapStyleController.getInstance().onLocationChanged( location, this ); } @Override @@ -797,4 +799,21 @@ public class AMapViewWrapper implements IMogoMapView, public void testGpsData() { GpsTester.getInstance().testGpsData(); } + + @Override + public void onStyleAutoChanged( boolean isVrMode ) { + if ( isVrMode ) { + if ( mCurrentUI != EnumMapUI.Type_VR ) { + changeZoom( 20 ); + changeMapMode( EnumMapUI.Type_VR ); + Logger.d( TAG, "自动切换为vr模式" ); + } + } else { + if ( mCurrentUI == EnumMapUI.Type_VR ) { + changeZoom( 16 ); + changeMapMode( EnumMapUI.Type_Night ); + Logger.d( TAG, "自动切换为2D模式" ); + } + } + } } diff --git a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/MapStyleController.java b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/MapStyleController.java new file mode 100644 index 0000000000..4a081d996f --- /dev/null +++ b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/MapStyleController.java @@ -0,0 +1,108 @@ +package com.mogo.map.impl.custom; + + +import com.zhidaoauto.map.sdk.open.location.MogoLocation; + +import java.util.ArrayList; +import java.util.List; + +public +/** + * @author congtaowang + * @since 2020/12/25 + * + * 地图样式控制 + */ +class MapStyleController { + + + private static volatile MapStyleController sInstance; + + private boolean mIsInVrMode = false; + + private List< VrAreaFilter > mVrAreaFilters = new ArrayList<>(); + + private MapStyleController() { + mVrAreaFilters.add( new ShunYiArea() ); + } + + public static MapStyleController getInstance() { + if ( sInstance == null ) { + synchronized ( MapStyleController.class ) { + if ( sInstance == null ) { + sInstance = new MapStyleController(); + } + } + } + return sInstance; + } + + public synchronized void release() { + sInstance = null; + } + + private Object readResolve() { + // 阻止反序列化,必须实现 Serializable 接口 + return sInstance; + } + + public void onLocationChanged( MogoLocation location, IMapStyleAutoChangedListener listener ) { + if ( location == null ) { + return; + } + + boolean isInVrMode = false; + for ( VrAreaFilter vrAreaFilter : mVrAreaFilters ) { + if ( vrAreaFilter == null ) { + continue; + } + isInVrMode |= vrAreaFilter.isVrArea( location ); + if ( isInVrMode ) { + break; + } + } + if ( isInVrMode ) { + if ( !mIsInVrMode ) { + // 第一次进入 vr 区域,自动变为 vr 模式 + mIsInVrMode = true; + if ( listener != null ) { + listener.onStyleAutoChanged( true ); + } + } + } else { + if ( mIsInVrMode ) { + // 驶出 vr 区域,自动变为 2d 模式 + mIsInVrMode = false; + if ( listener != null ) { + listener.onStyleAutoChanged( false ); + } + } + } + } + + public interface IMapStyleAutoChangedListener { + void onStyleAutoChanged( boolean isVrMode ); + } + + public interface VrAreaFilter { + boolean isVrArea( MogoLocation location ); + } + + public static class ShunYiArea implements VrAreaFilter { + + // 顺义一期高精地图范围(目前圈定了一个矩形区域,认为都是高精地图区域) + private final double leftBottomLat = 40.18728; + private final double leftBottomLon = 116.71194; + private final double rightTopLat = 40.20671; + private final double rightTopLon = 116.74804; + + @Override + public boolean isVrArea( MogoLocation location ) { + if ( location == null ) { + return false; + } + return location.getLat() > leftBottomLat && location.getLon() > leftBottomLon + && location.getLat() < rightTopLat && location.getLon() < rightTopLon; + } + } +}