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.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.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.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 |
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 |
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 |
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. |
Bitmap |
getViewContent() |
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 |
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 |
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 |
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 |
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.
|
public MapView(Context context)
public MapView(Context context, AttributeSet attrs)
public MapView(Context context, AttributeSet attrs, int defStyleAttr)
public MapView(Context context, MapboxMapOptions options)
protected void initialize(Context context, MapboxMapOptions options)
public void onCreate(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)
public void onSaveInstanceState(Bundle outState)
outState
- Pass in the parent's outState.public void onStart()
public void onResume()
public void onPause()
public void onStop()
public void onDestroy()
public void setMaximumFps(int maximumFps)
maximumFps
- Can be set to arbitrary integer values.public boolean isDestroyed()
This method can be used to determine if the result of an asynchronous operation should be set.
public boolean onTouchEvent(MotionEvent event)
public boolean onKeyDown(int keyCode, KeyEvent event)
public boolean onKeyLongPress(int keyCode, KeyEvent event)
public boolean onKeyUp(int keyCode, KeyEvent event)
public boolean onTrackballEvent(MotionEvent event)
public boolean onGenericMotionEvent(MotionEvent event)
public void onLowMemory()
protected void onSizeChanged(int width, int height, int oldw, int oldh)
public Bitmap getViewContent()
getViewContent
in interface com.mapbox.mapboxsdk.maps.NativeMapView.ViewCallback
public void addOnCameraWillChangeListener(MapView.OnCameraWillChangeListener listener)
listener
- The callback that's invoked when the camera region will changepublic void removeOnCameraWillChangeListener(MapView.OnCameraWillChangeListener listener)
listener
- The callback that's invoked when the camera region will changepublic void addOnCameraIsChangingListener(MapView.OnCameraIsChangingListener listener)
listener
- The callback that's invoked when the camera is changingpublic void removeOnCameraIsChangingListener(MapView.OnCameraIsChangingListener listener)
listener
- The callback that's invoked when the camera is changingpublic void addOnCameraDidChangeListener(MapView.OnCameraDidChangeListener listener)
listener
- The callback that's invoked when the camera region did changepublic void removeOnCameraDidChangeListener(MapView.OnCameraDidChangeListener listener)
listener
- The callback that's invoked when the camera region did changepublic void addOnWillStartLoadingMapListener(MapView.OnWillStartLoadingMapListener listener)
listener
- The callback that's invoked when the map will start loadingpublic void removeOnWillStartLoadingMapListener(MapView.OnWillStartLoadingMapListener listener)
listener
- The callback that's invoked when the map will start loadingpublic void addOnDidFinishLoadingMapListener(MapView.OnDidFinishLoadingMapListener listener)
listener
- The callback that's invoked when the map has finished loadingpublic void removeOnDidFinishLoadingMapListener(MapView.OnDidFinishLoadingMapListener listener)
listener
- The callback that's invoked when the map has finished loadingpublic void addOnDidFailLoadingMapListener(MapView.OnDidFailLoadingMapListener listener)
listener
- The callback that's invoked when the map failed to loadpublic void removeOnDidFailLoadingMapListener(MapView.OnDidFailLoadingMapListener listener)
listener
- The callback that's invoked when the map failed to loadpublic void addOnWillStartRenderingFrameListener(MapView.OnWillStartRenderingFrameListener listener)
listener
- The callback that's invoked when the camera will start rendering a framepublic void removeOnWillStartRenderingFrameListener(MapView.OnWillStartRenderingFrameListener listener)
listener
- The callback that's invoked when the camera will start rendering a framepublic void addOnDidFinishRenderingFrameListener(MapView.OnDidFinishRenderingFrameListener listener)
listener
- The callback that's invoked when the map has finished rendering a framepublic void removeOnDidFinishRenderingFrameListener(MapView.OnDidFinishRenderingFrameListener listener)
listener
- The callback that's invoked when the map has finished rendering a framepublic void addOnWillStartRenderingMapListener(MapView.OnWillStartRenderingMapListener listener)
listener
- The callback that's invoked when the map will start renderingpublic void removeOnWillStartRenderingMapListener(MapView.OnWillStartRenderingMapListener listener)
listener
- The callback that's invoked when the map will start renderingpublic void addOnDidFinishRenderingMapListener(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(MapView.OnDidBecomeIdleListener listener)
listener
- The callback that's invoked when the map has entered the idle state.public void removeOnDidBecomeIdleListener(MapView.OnDidBecomeIdleListener listener)
listener
- The callback that's invoked when the map has entered the idle state.public void addOnDidFinishLoadingStyleListener(MapView.OnDidFinishLoadingStyleListener listener)
listener
- The callback that's invoked when the style has finished loadingpublic void removeOnDidFinishLoadingStyleListener(MapView.OnDidFinishLoadingStyleListener listener)
listener
- The callback that's invoked when the style has finished loadingpublic void addOnSourceChangedListener(MapView.OnSourceChangedListener listener)
listener
- The callback that's invoked when the source has changedpublic void removeOnSourceChangedListener(MapView.OnSourceChangedListener listener)
listener
- The callback that's invoked when the source has changedpublic void getMapAsync(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© 2015–2019 Mapbox. All rights reserved.