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.MapChange
Definition of a map change event.
|
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.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.OnMapChangedListener
Deprecated.
use specific map change callbacks instead
|
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.
|
Modifier and Type | Field and Description |
---|---|
static int |
DID_FAIL_LOADING_MAP
This event is triggered when the map has failed to load a new map style.
|
static int |
DID_FINISH_LOADING_MAP
This is triggered when the map has successfully loaded a new map style.
|
static int |
DID_FINISH_LOADING_STYLE
This
MapView.MapChange is triggered when a style has finished loading. |
static int |
DID_FINISH_RENDERING_FRAME
This event is triggered when the map finished rendering a frame.
|
static int |
DID_FINISH_RENDERING_FRAME_FULLY_RENDERED
This event is triggered when the map finished rendering the frame fully.
|
static int |
DID_FINISH_RENDERING_MAP
This event is triggered when the map finished rendering the map.
|
static int |
DID_FINISH_RENDERING_MAP_FULLY_RENDERED
This event is triggered when the map is fully rendered.
|
static int |
REGION_DID_CHANGE
This event is triggered whenever the currently displayed map region finished changing
without an animation.
|
static int |
REGION_DID_CHANGE_ANIMATED
This event is triggered whenever the currently displayed map region finished changing
with an animation.
|
static int |
REGION_IS_CHANGING
This event is triggered whenever the currently displayed map region is changing.
|
static int |
REGION_WILL_CHANGE
This event is triggered whenever the currently displayed map region is about to changing
without an animation.
|
static int |
REGION_WILL_CHANGE_ANIMATED
This event is triggered whenever the currently displayed map region is about to changing
with an animation.
|
static int |
SOURCE_DID_CHANGE
This
MapView.MapChange is triggered when a source changes. |
static int |
WILL_START_LOADING_MAP
This event is triggered when the map is about to start loading a new map style.
|
static int |
WILL_START_RENDERING_FRAME
This event is triggered when the map will start rendering a frame.
|
static int |
WILL_START_RENDERING_MAP
This event is triggered 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 |
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 |
addOnMapChangedListener(MapView.OnMapChangedListener listener)
Deprecated.
use specific map change callbacks instead
|
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().
|
protected void |
onDetachedFromWindow() |
boolean |
onGenericMotionEvent(MotionEvent event) |
boolean |
onHoverEvent(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) |
protected void |
onVisibilityChanged(View changedView,
int visibility) |
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 |
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 |
removeOnMapChangedListener(MapView.OnMapChangedListener listener)
Deprecated.
use specific map change callbacks instead
|
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 |
setOfflineRegionDefinition(OfflineRegionDefinition definition)
Loads a new style from the specified offline region definition and moves the map camera to that region.
|
void |
setStyleUrl(String url)
Loads a new map style from the specified URL.
|
public static final int REGION_WILL_CHANGE
Register to MapView.MapChange
events with addOnMapChangedListener(OnMapChangedListener)
.
public static final int REGION_WILL_CHANGE_ANIMATED
Register to MapView.MapChange
events with addOnMapChangedListener(OnMapChangedListener)
public static final int REGION_IS_CHANGING
Register to MapView.MapChange
events with addOnMapChangedListener(OnMapChangedListener)
.
public static final int REGION_DID_CHANGE
Register to MapView.MapChange
events with addOnMapChangedListener(OnMapChangedListener)
.
public static final int REGION_DID_CHANGE_ANIMATED
Register to MapView.MapChange
events with addOnMapChangedListener(OnMapChangedListener)
.
public static final int WILL_START_LOADING_MAP
Register to MapView.MapChange
events with addOnMapChangedListener(OnMapChangedListener)
.
public static final int DID_FINISH_LOADING_MAP
Register to MapView.MapChange
events with addOnMapChangedListener(OnMapChangedListener)
.
public static final int DID_FAIL_LOADING_MAP
Register to MapView.MapChange
events with addOnMapChangedListener(OnMapChangedListener)
.
public static final int WILL_START_RENDERING_FRAME
Register to MapView.MapChange
events with addOnMapChangedListener(OnMapChangedListener)
.
public static final int DID_FINISH_RENDERING_FRAME
Register to MapView.MapChange
events with addOnMapChangedListener(OnMapChangedListener)
.
public static final int DID_FINISH_RENDERING_FRAME_FULLY_RENDERED
Register to MapView.MapChange
events with addOnMapChangedListener(OnMapChangedListener)
.
public static final int WILL_START_RENDERING_MAP
Register to MapView.MapChange
events with addOnMapChangedListener(OnMapChangedListener)
.
public static final int DID_FINISH_RENDERING_MAP
Register to MapView.MapChange
events with addOnMapChangedListener(OnMapChangedListener)
.
public static final int DID_FINISH_RENDERING_MAP_FULLY_RENDERED
Register to MapView.MapChange
events with addOnMapChangedListener(OnMapChangedListener)
.
public static final int DID_FINISH_LOADING_STYLE
MapView.MapChange
is triggered when a style has finished loading.
Register to MapView.MapChange
events with addOnMapChangedListener(OnMapChangedListener)
.
public static final int SOURCE_DID_CHANGE
MapView.MapChange
is triggered when a source changes.
Register to MapView.MapChange
events with addOnMapChangedListener(OnMapChangedListener)
.
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 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 boolean onHoverEvent(MotionEvent event)
public void onLowMemory()
public void setStyleUrl(String url)
Loads a new map style from the specified URL.
url
can take the following forms:
Style.*
: load one of the bundled styles in Style
.mapbox://styles/<user>/<style>
:
retrieves the style from a Mapbox account.
user
is your username. style
is the ID of your custom
style created in Mapbox Studio.http://...
or https://...
:
retrieves the style over the Internet from any web server.asset://...
:
reads the style from the APK assets/
directory.
This is used to load a style bundled with your app.null
: loads the default Style.MAPBOX_STREETS
style.
This method is asynchronous and will return immediately before the style finishes loading.
If you wish to wait for the map to finish loading listen for the DID_FINISH_LOADING_MAP
event.
DID_FAIL_LOADING_MAP
event will be sent.url
- The URL of the map styleStyle
public void setOfflineRegionDefinition(OfflineRegionDefinition definition)
definition
- the offline region definitionOfflineRegionDefinition
protected void onSizeChanged(int width, int height, int oldw, int oldh)
protected void onDetachedFromWindow()
protected void onVisibilityChanged(View changedView, int visibility)
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 finished renderingpublic 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 changed@Deprecated public void addOnMapChangedListener(MapView.OnMapChangedListener listener)
Add a callback that's invoked when the displayed map view changes.
To remove the callback, useremoveOnMapChangedListener(OnMapChangedListener)
.listener
- The callback that's invoked on every frame rendered to the map view.removeOnMapChangedListener(OnMapChangedListener)
@Deprecated public void removeOnMapChangedListener(MapView.OnMapChangedListener listener)
addOnMapChangedListener(OnMapChangedListener)
listener
- The previously added callback to remove.addOnMapChangedListener(OnMapChangedListener)
public 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–2018 Mapbox. All rights reserved.