public class MapView
extends FrameLayout
implements com.mapbox.mapboxsdk.maps.NativeMapView.ViewCallback
A MapView provides an embeddable map interface.
You use this class to display map information and to manipulate the map contents from your application.
You can center the map on a given coordinate, specify the size of the area you want to display,
and style the features of the map to fit your application's use case.
Use of MapView requires a Mapbox API access token.
Obtain an access token on the Mapbox account page.
| Modifier and Type | Class and Description |
|---|---|
static interface |
MapView.OnCameraDidChangeListener
Interface definition for a callback to be invoked when the map region did change.
|
static interface |
MapView.OnCameraIsChangingListener
Interface definition for a callback to be invoked when the camera is changing.
|
static interface |
MapView.OnCameraWillChangeListener
Interface definition for a callback to be invoked when the camera will change.
|
static interface |
MapView.OnCanRemoveUnusedStyleImageListener
Interface definition for a callback to be invoked with an unused image identifier.
|
static interface |
MapView.OnDidBecomeIdleListener
Interface definition for a callback to be invoked when the map has entered the idle state.
|
static interface |
MapView.OnDidFailLoadingMapListener
Interface definition for a callback to be invoked when the map is changing.
|
static interface |
MapView.OnDidFailLoadingTileListener
Interface definition for a callback to be invoked when the tile failed to load.
|
static interface |
MapView.OnDidFinishLoadingMapListener
Interface definition for a callback to be invoked when the map finished loading.
|
static interface |
MapView.OnDidFinishLoadingStyleListener
Interface definition for a callback to be invoked when the map has loaded the style.
|
static interface |
MapView.OnDidFinishRenderingFrameListener
Interface definition for a callback to be invoked when the map finished rendering a frame.
|
static interface |
MapView.OnDidFinishRenderingMapListener
Interface definition for a callback to be invoked when the map is changing.
|
static interface |
MapView.OnSourceChangedListener
Interface definition for a callback to be invoked when a map source has changed.
|
static interface |
MapView.OnStyleImageMissingListener
Interface definition for a callback to be invoked with the id of a missing icon.
|
static interface |
MapView.OnWillStartLoadingMapListener
Interface definition for a callback to be invoked when the map will start loading.
|
static interface |
MapView.OnWillStartRenderingFrameListener
Interface definition for a callback to be invoked when the map will start rendering a frame.
|
static interface |
MapView.OnWillStartRenderingMapListener
Interface definition for a callback to be invoked when the map will start rendering the map.
|
| Constructor and Description |
|---|
MapView(Context context) |
MapView(Context context,
AttributeSet attrs) |
MapView(Context context,
AttributeSet attrs,
int defStyleAttr) |
MapView(Context context,
MapboxMapOptions options) |
| Modifier and Type | Method and Description |
|---|---|
void |
addOnCameraDidChangeListener(MapView.OnCameraDidChangeListener listener)
Set a callback that's invoked when the camera region did change.
|
void |
addOnCameraIsChangingListener(MapView.OnCameraIsChangingListener listener)
Set a callback that's invoked when the camera is changing.
|
void |
addOnCameraWillChangeListener(MapView.OnCameraWillChangeListener listener)
Set a callback that's invoked when the camera region will change.
|
void |
addOnCanRemoveUnusedStyleImageListener(MapView.OnCanRemoveUnusedStyleImageListener listener)
Set a callback that's invoked when map needs to release unused image resources.
|
void |
addOnDidBecomeIdleListener(MapView.OnDidBecomeIdleListener listener)
Set a callback that's invoked when the map has entered the idle state.
|
void |
addOnDidFailLoadingMapListener(MapView.OnDidFailLoadingMapListener listener)
Set a callback that's invoked when the map failed to load.
|
void |
addOnDidFailLoadingTileListener(MapView.OnDidFailLoadingTileListener listener)
Set a callback that's invoked when the tile failed to load.
|
void |
addOnDidFinishLoadingMapListener(MapView.OnDidFinishLoadingMapListener listener)
Set a callback that's invoked when the map has finished loading.
|
void |
addOnDidFinishLoadingStyleListener(MapView.OnDidFinishLoadingStyleListener listener)
Set a callback that's invoked when the style has finished loading.
|
void |
addOnDidFinishRenderingFrameListener(MapView.OnDidFinishRenderingFrameListener listener)
Set a callback that's invoked when the map has finished rendering a frame.
|
void |
addOnDidFinishRenderingMapListener(MapView.OnDidFinishRenderingMapListener listener)
Set a callback that's invoked when the map has finished rendering.
|
void |
addOnSourceChangedListener(MapView.OnSourceChangedListener listener)
Set a callback that's invoked when a map source has changed.
|
void |
addOnStyleImageMissingListener(MapView.OnStyleImageMissingListener listener)
Set a callback that's invoked when the id of an icon is missing.
|
boolean |
addOnTouchListener(OnTouchListener listener)
Add an OnTouchListener which will be call when an event occurs
|
void |
addOnWillStartLoadingMapListener(MapView.OnWillStartLoadingMapListener listener)
Set a callback that's invoked when the map will start loading.
|
void |
addOnWillStartRenderingFrameListener(MapView.OnWillStartRenderingFrameListener listener)
Set a callback that's invoked when the map will start rendering a frame.
|
void |
addOnWillStartRenderingMapListener(MapView.OnWillStartRenderingMapListener listener)
Set a callback that's invoked when the map will start rendering.
|
void |
getMapAsync(OnMapReadyCallback callback)
Sets a callback object which will be triggered when the
MapboxMap instance is ready to be used. |
float |
getPixelRatio()
Returns the map pixel ratio, by default it returns the device pixel ratio.
|
View |
getRenderView()
Returns the View used for rendering OpenGL.
|
Bitmap |
getViewContent() |
protected ImageView |
initialiseAttributionView() |
protected CompassView |
initialiseCompassView() |
protected ImageView |
initialiseLogoView() |
protected void |
initialize(Context context,
MapboxMapOptions options) |
boolean |
isDestroyed()
Returns if the map has been destroyed.
|
void |
onCreate(Bundle savedInstanceState)
You must call this method from the parent's Activity#onCreate(Bundle)} or
Fragment#onViewCreated(View, Bundle).
|
void |
onDestroy()
You must call this method from the parent's Activity#onDestroy() or Fragment#onDestroyView().
|
boolean |
onGenericMotionEvent(MotionEvent event) |
boolean |
onKeyDown(int keyCode,
KeyEvent event) |
boolean |
onKeyLongPress(int keyCode,
KeyEvent event) |
boolean |
onKeyUp(int keyCode,
KeyEvent event) |
void |
onLowMemory()
You must call this method from the parent's Activity#onLowMemory() or Fragment#onLowMemory().
|
void |
onPause()
You must call this method from the parent's Activity#onPause() or Fragment#onPause().
|
void |
onResume()
You must call this method from the parent's Activity#onResume() or Fragment#onResume().
|
void |
onSaveInstanceState(Bundle outState)
You must call this method from the parent's Activity#onSaveInstanceState(Bundle)
or Fragment#onSaveInstanceState(Bundle).
|
protected void |
onSizeChanged(int width,
int height,
int oldw,
int oldh) |
void |
onStart()
You must call this method from the parent's Activity#onStart() or Fragment#onStart()
|
void |
onStop()
You must call this method from the parent's Activity#onStop() or Fragment#onStop().
|
boolean |
onTouchEvent(MotionEvent event) |
boolean |
onTrackballEvent(MotionEvent event) |
void |
queueEvent(java.lang.Runnable runnable)
Queue a runnable to be executed on the map renderer thread.
|
void |
removeOnCameraDidChangeListener(MapView.OnCameraDidChangeListener listener)
Set a callback that's invoked when the camera region did change.
|
void |
removeOnCameraIsChangingListener(MapView.OnCameraIsChangingListener listener)
Remove a callback that's invoked when the camera is changing.
|
void |
removeOnCameraWillChangeListener(MapView.OnCameraWillChangeListener listener)
Remove a callback that's invoked when the camera region will change.
|
void |
removeOnCanRemoveUnusedStyleImageListener(MapView.OnCanRemoveUnusedStyleImageListener listener)
Removes a callback that's invoked when map needs to release unused image resources.
|
void |
removeOnDidBecomeIdleListener(MapView.OnDidBecomeIdleListener listener)
Remove a callback that's invoked when the map has entered the idle state.
|
void |
removeOnDidFailLoadingMapListener(MapView.OnDidFailLoadingMapListener listener)
Set a callback that's invoked when the map failed to load.
|
void |
removeOnDidFailLoadingTileListener(MapView.OnDidFailLoadingTileListener listener)
Set a callback that's invoked when the tile failed to load.
|
void |
removeOnDidFinishLoadingMapListener(MapView.OnDidFinishLoadingMapListener listener)
Set a callback that's invoked when the map has finished loading.
|
void |
removeOnDidFinishLoadingStyleListener(MapView.OnDidFinishLoadingStyleListener listener)
Set a callback that's invoked when the style has finished loading.
|
void |
removeOnDidFinishRenderingFrameListener(MapView.OnDidFinishRenderingFrameListener listener)
Set a callback that's invoked when the map has finished rendering a frame.
|
void |
removeOnDidFinishRenderingMapListener(MapView.OnDidFinishRenderingMapListener listener)
Remove a callback that's invoked when the map has finished rendering.
|
void |
removeOnSourceChangedListener(MapView.OnSourceChangedListener listener)
Set a callback that's invoked when a map source has changed.
|
void |
removeOnStyleImageMissingListener(MapView.OnStyleImageMissingListener listener)
Set a callback that's invoked when a map source has changed.
|
boolean |
removeOnTouchListener(OnTouchListener listener)
Remove an OnTouchListener previously registered
|
void |
removeOnWillStartLoadingMapListener(MapView.OnWillStartLoadingMapListener listener)
Set a callback that's invoked when the map will start loading.
|
void |
removeOnWillStartRenderingFrameListener(MapView.OnWillStartRenderingFrameListener listener)
Set a callback that's invoked when the map will start rendering a frame.
|
void |
removeOnWillStartRenderingMapListener(MapView.OnWillStartRenderingMapListener listener)
Set a callback that's invoked when the map will start rendering.
|
static void |
setMapStrictModeEnabled(boolean strictModeEnabled)
Sets the strict mode that will throw the
MapStrictModeException
whenever the map would fail silently otherwise. |
void |
setMaximumFps(int maximumFps)
The maximum frame rate at which the map view is rendered,
but it can't excess the ability of device hardware.
|
@UiThread
public MapView(@NonNull
Context context)
@UiThread
public MapView(@NonNull
Context context,
@Nullable
AttributeSet attrs)
@UiThread
public MapView(@NonNull
Context context,
@Nullable
AttributeSet attrs,
int defStyleAttr)
@UiThread
public MapView(@NonNull
Context context,
@Nullable
MapboxMapOptions options)
@CallSuper
@UiThread
protected void initialize(@NonNull
Context context,
@NonNull
MapboxMapOptions options)
protected CompassView initialiseCompassView()
protected ImageView initialiseAttributionView()
protected ImageView initialiseLogoView()
@UiThread
public void onCreate(@Nullable
Bundle savedInstanceState)
You must call this method from the parent's Activity#onCreate(Bundle)} or Fragment#onViewCreated(View, Bundle).
You must set a valid access token withMapbox.getInstance(Context, String)
before you call this method or an exception will be thrown.savedInstanceState - Pass in the parent's savedInstanceState.Mapbox.getInstance(Context, String)@UiThread
public void onSaveInstanceState(@NonNull
Bundle outState)
outState - Pass in the parent's outState.@UiThread public void onStart()
@UiThread public void onResume()
@UiThread public void onPause()
@UiThread public void onStop()
@UiThread public void onDestroy()
public void queueEvent(@NonNull
java.lang.Runnable runnable)
runnable - the runnable to queuepublic void setMaximumFps(int maximumFps)
maximumFps - Can be set to arbitrary integer values.@UiThread public boolean isDestroyed()
This method can be used to determine if the result of an asynchronous operation should be set.
@NonNull @UiThread public View getRenderView()
The type of the returned view is either a GLSurfaceView or a TextureView.
public boolean addOnTouchListener(OnTouchListener listener)
listener - listener to be called when touch event occurspublic boolean removeOnTouchListener(OnTouchListener listener)
listener - listener to be called when touch event occurspublic boolean onTouchEvent(MotionEvent event)
public boolean onKeyDown(int keyCode,
@NonNull
KeyEvent event)
public boolean onKeyLongPress(int keyCode,
KeyEvent event)
public boolean onKeyUp(int keyCode,
@NonNull
KeyEvent event)
public boolean onTrackballEvent(@NonNull
MotionEvent event)
public boolean onGenericMotionEvent(@NonNull
MotionEvent event)
@UiThread public void onLowMemory()
protected void onSizeChanged(int width,
int height,
int oldw,
int oldh)
public float getPixelRatio()
MapboxMapOptions.pixelRatio(float).@Nullable public Bitmap getViewContent()
getViewContent in interface com.mapbox.mapboxsdk.maps.NativeMapView.ViewCallbackpublic void addOnCameraWillChangeListener(@NonNull
MapView.OnCameraWillChangeListener listener)
listener - The callback that's invoked when the camera region will changepublic void removeOnCameraWillChangeListener(@NonNull
MapView.OnCameraWillChangeListener listener)
listener - The callback that's invoked when the camera region will changepublic void addOnCameraIsChangingListener(@NonNull
MapView.OnCameraIsChangingListener listener)
listener - The callback that's invoked when the camera is changingpublic void removeOnCameraIsChangingListener(@NonNull
MapView.OnCameraIsChangingListener listener)
listener - The callback that's invoked when the camera is changingpublic void addOnCameraDidChangeListener(@NonNull
MapView.OnCameraDidChangeListener listener)
listener - The callback that's invoked when the camera region did changepublic void removeOnCameraDidChangeListener(@NonNull
MapView.OnCameraDidChangeListener listener)
listener - The callback that's invoked when the camera region did changepublic void addOnWillStartLoadingMapListener(@NonNull
MapView.OnWillStartLoadingMapListener listener)
listener - The callback that's invoked when the map will start loadingpublic void removeOnWillStartLoadingMapListener(@NonNull
MapView.OnWillStartLoadingMapListener listener)
listener - The callback that's invoked when the map will start loadingpublic void addOnDidFinishLoadingMapListener(@NonNull
MapView.OnDidFinishLoadingMapListener listener)
listener - The callback that's invoked when the map has finished loadingpublic void removeOnDidFinishLoadingMapListener(@NonNull
MapView.OnDidFinishLoadingMapListener listener)
listener - The callback that's invoked when the map has finished loadingpublic void addOnDidFailLoadingMapListener(@NonNull
MapView.OnDidFailLoadingMapListener listener)
listener - The callback that's invoked when the map failed to loadpublic void removeOnDidFailLoadingMapListener(@NonNull
MapView.OnDidFailLoadingMapListener listener)
listener - The callback that's invoked when the map failed to loadpublic void addOnDidFailLoadingTileListener(@NonNull
MapView.OnDidFailLoadingTileListener listener)
listener - The callback that's invoked when the tile failed to loadpublic void removeOnDidFailLoadingTileListener(@NonNull
MapView.OnDidFailLoadingTileListener listener)
listener - The callback that's invoked when the tile failed to loadpublic void addOnWillStartRenderingFrameListener(@NonNull
MapView.OnWillStartRenderingFrameListener listener)
listener - The callback that's invoked when the camera will start rendering a framepublic void removeOnWillStartRenderingFrameListener(@NonNull
MapView.OnWillStartRenderingFrameListener listener)
listener - The callback that's invoked when the camera will start rendering a framepublic void addOnDidFinishRenderingFrameListener(@NonNull
MapView.OnDidFinishRenderingFrameListener listener)
listener - The callback that's invoked when the map has finished rendering a framepublic void removeOnDidFinishRenderingFrameListener(@NonNull
MapView.OnDidFinishRenderingFrameListener listener)
listener - The callback that's invoked when the map has finished rendering a framepublic void addOnWillStartRenderingMapListener(@NonNull
MapView.OnWillStartRenderingMapListener listener)
listener - The callback that's invoked when the map will start renderingpublic void removeOnWillStartRenderingMapListener(@NonNull
MapView.OnWillStartRenderingMapListener listener)
listener - The callback that's invoked when the map will start renderingpublic void addOnDidFinishRenderingMapListener(@NonNull
MapView.OnDidFinishRenderingMapListener listener)
listener - The callback that's invoked when the map has finished renderingpublic void removeOnDidFinishRenderingMapListener(MapView.OnDidFinishRenderingMapListener listener)
listener - The callback that's invoked when the map has has finished rendering.public void addOnDidBecomeIdleListener(@NonNull
MapView.OnDidBecomeIdleListener listener)
listener - The callback that's invoked when the map has entered the idle state.public void removeOnDidBecomeIdleListener(@NonNull
MapView.OnDidBecomeIdleListener listener)
listener - The callback that's invoked when the map has entered the idle state.public void addOnDidFinishLoadingStyleListener(@NonNull
MapView.OnDidFinishLoadingStyleListener listener)
listener - The callback that's invoked when the style has finished loadingpublic void removeOnDidFinishLoadingStyleListener(@NonNull
MapView.OnDidFinishLoadingStyleListener listener)
listener - The callback that's invoked when the style has finished loadingpublic void addOnSourceChangedListener(@NonNull
MapView.OnSourceChangedListener listener)
listener - The callback that's invoked when the source has changedpublic void removeOnSourceChangedListener(@NonNull
MapView.OnSourceChangedListener listener)
listener - The callback that's invoked when the source has changedpublic void addOnStyleImageMissingListener(@NonNull
MapView.OnStyleImageMissingListener listener)
listener - The callback that's invoked when the id of an icon is missingpublic void removeOnStyleImageMissingListener(@NonNull
MapView.OnStyleImageMissingListener listener)
listener - The callback that's invoked when the source has changedpublic void addOnCanRemoveUnusedStyleImageListener(@NonNull
MapView.OnCanRemoveUnusedStyleImageListener listener)
A callback will be called only for unused images that were provided by the client via
MapView.OnStyleImageMissingListener.onStyleImageMissing(String) listener interface.
By default, platform will remove unused images from the style. By adding listener, default behavior can be overridden and client can control whether to release unused resources.
listener - The callback that's invoked when map needs to release unused image resourcespublic void removeOnCanRemoveUnusedStyleImageListener(@NonNull
MapView.OnCanRemoveUnusedStyleImageListener listener)
When all listeners are removed, platform will fallback to default behavior, which is to remove unused images from the style.
listener - The callback that's invoked when map needs to release unused image resources@UiThread
public void getMapAsync(@NonNull
OnMapReadyCallback callback)
MapboxMap instance is ready to be used.callback - The callback object that will be triggered when the map is ready to be used.public static void setMapStrictModeEnabled(boolean strictModeEnabled)
MapStrictModeException
whenever the map would fail silently otherwise.strictModeEnabled - true to enable the strict mode, false otherwise