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.OnMapChangedListener
Interface definition for a callback to be invoked when the displayed map view changes.
|
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 |
addOnMapChangedListener(MapView.OnMapChangedListener listener)
Add a callback that's invoked when the displayed map view changes.
|
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 |
removeOnMapChangedListener(MapView.OnMapChangedListener listener)
Remove a callback added with
addOnMapChangedListener(OnMapChangedListener) |
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 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)
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.