Skip to content

地图视图与初始化 ​

MapView ​

com.sfmap.api.maps.MapView

基于 GLSurfaceView 的地图视图容器。使用必须按生命周期调用对应方法;通过 getMap() 获取 MapController。

构造 ​

方法说明
MapView(Context context)基本构造
MapView(Context context, AttributeSet attrs)XML 属性构造
MapView(Context context, AttributeSet attrs, int defStyleAttr)XML 属性 + 样式构造
MapView(Context context, MapOptions options)传入配置选项构造

生命周期(均为 final,必须在对应 Activity/Fragment 生命周期中调用) ​

方法
void onCreate(Bundle bundle)
void onStart()
void onResume()
void onPause()
void onStop()
void onDestroy()
void onLowMemory()
void onSaveInstanceState(Bundle outState)

其它 ​

方法说明
MapController getMap()返回 MapController(构造后同步返回非 null)
void setVisibility(int visibility)设置可见性

XML 自定义属性 ​

在布局中可直接配置:

xml
<com.sfmap.api.maps.MapView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:compassEnabled="true"
    app:zoomGesturesEnabled="true"
    app:rotateGesturesEnabled="false"
    app:scrollGesturesEnabled="true"
    app:tiltGesturesEnabled="true"
    app:zoomControlsEnabled="true"
    app:zOrderOnTop="false"
    app:textureMode="false"
    app:cameraTargetLat="22.5429"
    app:cameraTargetLng="113.9414"
    app:cameraZoom="12" />

TextureMapView ​

com.sfmap.api.maps.TextureMapView

与 MapView 功能一致,底层为 TextureView。可与其它 GLSurfaceView 共存不穿透,放入 ViewPager 无黑边。API 与 MapView 完全相同(构造、生命周期、getMap())。


SupportMapFragment ​

com.sfmap.api.maps.SupportMapFragment

基于 AndroidX Fragment 的地图容器(GLSurfaceView),自动处理 View 生命周期。

方法说明
SupportMapFragment()构造
static SupportMapFragment newInstance()默认选项
static SupportMapFragment newInstance(MapOptions options)传入 MapOptions
MapController getMap()返回 MapController

TextureMapFragment ​

com.sfmap.api.maps.TextureMapFragment

基于 android.app.Fragment(原生 Fragment)的 TextureView 地图容器。

方法说明
TextureMapFragment()构造
static TextureMapFragment newInstance()默认选项
static TextureMapFragment newInstance(MapOptions options)传入 MapOptions
MapController getMap()返回 MapController

TextureSupportMapFragment ​

com.sfmap.api.maps.TextureSupportMapFragment

基于 AndroidX Fragment 的 TextureView 地图容器。API 与 TextureMapFragment 一致。


MapsInitializer ​

com.sfmap.api.maps.MapsInitializer

在获取地图之前用于初始化地图 API 的工具类。

坐标系等配置需在 Activity 的 onCreate() 第一行(地图视图创建前)调用。

常量 ​

常量值说明
COOD_SYSTEM_9009130墨卡托投影坐标系(默认)
COOD_SYSTEM_43261WGS84 坐标系
DEFAULT_STYLE_URL—丰图地图默认样式 URL(矢量白天)
NIGHT_STYLE_URL—丰图地图黑夜样式 URL

字段 ​

字段说明
String sdcardDir地图存储目录

方法 ​

方法说明
int getCoodSystem()获取坐标系类型
void setCoodSystem(int coodSystem)设置坐标系类型(onCreate 第一行调用)
void setNetWorkEnable(boolean enable)设置是否联网获取地图数据(默认 true)
boolean getNetWorkEnable()获取联网开关
void setApiKey(String apiKey)设置访问 apiKey
String getVersion()返回 SDK 版本号

MapOptions ​

com.sfmap.api.maps.MapOptions(实现 Parcelable)

地图初始化配置选项,用于 MapView(Context, MapOptions) 或 SupportMapFragment.newInstance(MapOptions) 构造时传入。

常量 ​

常量值说明
POSITION_ZOOMCONTROLLER0缩放按钮位置
POSITION_COMPASS1指北针位置
POSITION_LOGO2logo 位置
POSITION_SCALE3比例尺位置
POSITION_LOCATION_BUTTON4定位按钮位置

链式方法(返回 MapOptions) ​

方法说明
compassEnabled(boolean enabled)指北针开关
rotateGesturesEnabled(boolean enabled)旋转手势
scrollGesturesEnabled(boolean enabled)平移手势
zoomControlsEnabled(boolean enabled)缩放按钮
zoomGesturesEnabled(boolean enabled)缩放手势
tiltGesturesEnabled(boolean enabled)倾斜手势
camera(CameraPosition camera)初始相机位置
zOrderOnTop(boolean zOrderOnTop)是否置顶
textureMode(boolean textureMode)是否 TextureView 模式

Getter ​

isCompassEnabled()、isRotateGesturesEnabled()、isScrollGesturesEnabled()、isZoomControlsEnabled()、isZoomGesturesEnabled()、isTiltGesturesEnabled()、getCamera()、isZOrderOnTop()、isTextureMode()

V3.2-202604301400