MapBox Android学习笔记2关于地图的一些基础设置
上一篇Mapbox学习笔记中我们已经把基础地图加载出来了,现在就在地图上一些基础的设置,在mapboxMap中有一个UiSettings参数,通过UiSettings setting= mapboxMap.getUiSettings(),可以获得settings对象,我们看看UiSettings可以做那些事情呢?
查看API
我们只看一下set方法,这里set和get是对应的
设置指南针(地图指南针)
- 设置指南针是否可用
setCompassEnabled(boolean compassEnabled) - 设置指南针的位置的
setCompassGravity(int gravity ) - 当地图朝北时隐藏或淡化指南针
setCompassFadeFacingNorth(boolean compassFadeFacingNorth) - 设置指南针的图标
setCompassImage(@NonNull android.graphics.drawable.Drawable compass) - 设置指南针的margin
setCompassMargins(@Px int left, @Px int top, @Px int right,@Px int bottom)
设置LOGO
- 设置LOGO是否可用(默认地图左下角会显示mapbox的logo)
setLogoEnabled(boolean enable) - 设置logo的位置
setLogoGravity(int gravity) - 设置LOGO图标的margin
setLogoMargins(@Px int left, @Px int top, @Px int right,@Px int bottom)
设置Attribution(logo后面的小图标)
- 设置attri图标是否可用
setAttributionEnabled(boolean enabled) - 设置attr图标点击后弹出的内容
setAttributionDialogManager(@NonNull AttributionDialogManager attributionDialogManager) - 设置attr图标的位置
setAttributionGravity(int gravity) - 设置attr图标的颜色
setAttributionTintColor(int tintColor)
设置手势动作
-
设置旋转手势是否可用
setRotateGesturesEnabled(boolean rotateGesturesEnabled) -
设置倾斜角度手势是否可用
setTiltGesturesEnabled(boolean tiltGesturesEnabled) -
设置缩放手势是否可用
setZoomGesturesEnabled(boolean zoomGesturesEnabled) -
设置双指手势是否可用
setDoubleTapGesturesEnabled(boolean doubleTapGesturesEnabled) -
设置快速缩放手势是否可用
setQuickZoomGesturesEnabled(boolean quickZoomGesturesEnabled) -
设置标记点在点击地图时是否自动取消
setDeselectMarkersOnTap(boolean deselectMarkersOnTap) -
设置缩放手势速率,默认是1.0
setZoomRate(float zoomRate) -
设置是否可以水平滑动手势
setHorizontalScrollGesturesEnabled(boolean horizontalScrollGesturesEnabled) -
设置用户完成一个手势后是否执行缩放速度动画。
setScaleVelocityAnimationEnabled(boolean scaleVelocityAnimationEnabled) -
设置用户完成一个手势后是否执行旋转速度动画。
setRotateVelocityAnimationEnabled(boolean
rotateVelocityAnimationEnabled) -
设置用户完成一个手势后是否执行惯性速动画
setFlingVelocityAnimationEnabled(boolean flingVelocityAnimationEnabled) -
设置用户完成一个手势后是否执行所有速度动画(上面几种)
setAllVelocityAnimationsEnabled(boolean allVelocityAnimationsEnabled)// -
设置当检测到旋转时是否增加缩放阈值
setIncreaseScaleThresholdWhenRotating(boolean increaseScaleThresholdWhenRotating) -
设置所有的手势是否可用
setAllGesturesEnabled(boolean enabled) -
设置作为手势中心的焦点
setFocalPoint(@Nullable android.graphics.PointF focalPoint)
这里包含了基本的手势操作和logo,指南针,以及地图的attribution的设置
public static void UiSettingInit(UiSettings uiSettings) {
//设置所有手势可用
uiSettings.setAllGesturesEnabled(true);
//设置指南针可用
uiSettings.setCompassEnabled(true);
uiSettings.setCompassFadeFacingNorth(false);
//设置指南针位置
uiSettings.setCompassGravity(Gravity.BOTTOM | Gravity.END);
uiSettings.setCompassMargins(0, 0, 0, DensityUtil.dp2px(40));
//设置惯性手势动画可用
uiSettings.setFlingVelocityAnimationEnabled(true);
uiSettings.setAttributionEnabled(true);
//设置mapboxLogo不可用
uiSettings.setLogoEnabled(true);
uiSettings.setRotateGesturesEnabled(true);
uiSettings.setFlingVelocityAnimationEnabled(true);
uiSettings.setScrollGesturesEnabled(true);
}