From f6acddfc2112873efd342808bc18ace33bd5669a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Thu, 17 Dec 2020 16:29:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=BA=86=E9=AB=98=E5=BE=B7?= =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E7=9A=84=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/mogo-module-smp/build.gradle | 1 + .../small/map/SmallMapDirectionView.java | 59 +++++++++++++++---- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/modules/mogo-module-smp/build.gradle b/modules/mogo-module-smp/build.gradle index 888a054935..b4842f190f 100644 --- a/modules/mogo-module-smp/build.gradle +++ b/modules/mogo-module-smp/build.gradle @@ -40,6 +40,7 @@ dependencies { implementation rootProject.ext.dependencies.arouter implementation rootProject.ext.dependencies.amapnavi3dmap + implementation rootProject.ext.dependencies.amaplocation annotationProcessor rootProject.ext.dependencies.aroutercompiler if (Boolean.valueOf(RELEASE)) { 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 1eaedef6d3..529a290183 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 @@ -8,6 +8,8 @@ import android.widget.ImageView; import androidx.annotation.Nullable; +import com.amap.api.location.AMapLocationClient; +import com.amap.api.location.AMapLocationClientOption; import com.amap.api.maps.AMap; import com.amap.api.maps.CameraUpdate; import com.amap.api.maps.CameraUpdateFactory; @@ -20,8 +22,8 @@ import com.amap.api.maps.model.MyLocationStyle; import com.mogo.module.common.view.RoundLayout; import com.mogo.module.small.map.animation.DirectionRotateAnimation; +import java.io.IOException; import java.io.InputStream; -import java.net.URL; /** * 小地图的方向View @@ -37,6 +39,8 @@ public class SmallMapDirectionView extends RoundLayout { private UiSettings mUiSettings; private CameraUpdate mCameraUpdate; private MyLocationStyle myLocationStyle; + private AMapLocationClient mLocationClient; + private AMapLocationClientOption mLocationClientOption; private DirectionRotateAnimation mRotateAnimation; private int lastAngle = 0; @@ -63,28 +67,59 @@ public class SmallMapDirectionView extends RoundLayout { mTextureMapView.onCreate(null); mAMap = mTextureMapView.getMap(); - mAMap.setMapType(AMap.MAP_TYPE_NIGHT);//夜景地图,aMap是地图控制器对象。 - URL small_map_style = getClass().getResource("/assets/small_map_style.data"); - URL small_map_style_extra = getClass().getResource("/assets/small_map_style_extra.data"); + // 设置自定义地图样式 + try { + byte[] buffer1 = null; + byte[] buffer2 = null; + InputStream is1 = null; + InputStream is2 = null; + try { + is1 = context.getAssets().open("small_map_style.data"); + int lenght1 = is1.available(); + buffer1 = new byte[lenght1]; + is1.read(buffer1); + is2 = context.getAssets().open("small_map_style_extra.data"); + int lenght2 = is2.available(); + buffer2 = new byte[lenght2]; + is2.read(buffer2); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (is1 != null) + is1.close(); + if (is2 != null) + is2.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } - mAMap.setCustomMapStyle(new CustomMapStyleOptions() - .setEnable(true) - .setStyleDataPath(small_map_style.getPath()) - .setStyleExtraPath(small_map_style_extra.getPath()) - ); + CustomMapStyleOptions customMapStyleOptions = new CustomMapStyleOptions(); + customMapStyleOptions.setStyleData(buffer1); + customMapStyleOptions.setStyleExtraData(buffer2); + customMapStyleOptions.setEnable(true); + mAMap.setCustomMapStyle(customMapStyleOptions); + } catch (Exception e) { + e.printStackTrace(); + } - myLocationStyle = new MyLocationStyle();//初始化定位蓝点样式类myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);//连续定位、且将视角移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。(1秒1次定位)如果不设置myLocationType,默认也会执行此种模式。 - myLocationStyle.interval(2000); //设置连续定位模式下的定位间隔,只在连续定位模式下生效,单次定位模式下不会生效。单位为毫秒。 + // 设置当前位置的样式 + myLocationStyle = new MyLocationStyle();//初始化定位蓝点样式类 + myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);//连续定位、且将视角移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。(1秒1次定位)如果不设置myLocationType,默认也会执行此种模式。 + myLocationStyle.interval(1000); //设置连续定位模式下的定位间隔,只在连续定位模式下生效,单次定位模式下不会生效。单位为毫秒。 BitmapDescriptor location = BitmapDescriptorFactory.fromResource(R.drawable.module_small_map_view_my_location_logo); myLocationStyle.myLocationIcon(location); mAMap.setMyLocationStyle(myLocationStyle);//设置定位蓝点的Style mAMap.setMyLocationEnabled(true);// 设置为true表示启动显示定位蓝点,false表示隐藏定位蓝点并不进行定位,默认是false。 //设置希望展示的地图缩放级别 - mCameraUpdate = CameraUpdateFactory.zoomTo(12); + mCameraUpdate = CameraUpdateFactory.zoomTo(17); mAMap.moveCamera(mCameraUpdate); + + // 设置地图的样式 mUiSettings = mAMap.getUiSettings(); mUiSettings.setZoomControlsEnabled(false);// 地图缩放级别的交换按钮 // mUiSettings.setZoomGesturesEnabled(false);// 缩放手势