更改了高德地图的自定义样式
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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);// 缩放手势
|
||||
|
||||
Reference in New Issue
Block a user