MapView.md

March 20, 2019 · View on GitHub

<MapboxGL.MapView />

MapView backed by Mapbox Native GL

props

PropTypeDefaultRequiredDescription
animatedboolfalsefalseAnimates changes between pitch and bearing
centerCoordinatearrayOfnonefalseInitial center coordinate on map [lng, lat]
visibleCoordinateBoundsarrayOfnonefalseInitial bounds on map [[lng, lat], [lng, lat]]
showUserLocationboolnonefalseShows the users location on the map
userTrackingModenumberMapboxGL.UserTrackingModes.NonefalseThe mode used to track the user location on the map
userLocationVerticalAlignmentnumbernonefalseThe vertical alignment of the user location within in map. This is only enabled while tracking the users location.
contentInsetunionnonefalseThe distance from the edges of the map view’s frame to the edges of the map view’s logical viewport.
headingnumber0falseInitial heading on map
pitchnumber0falseInitial pitch on map
styleanynonefalseStyle for wrapping React Native View
styleURLstringMapboxGL.StyleURL.StreetfalseStyle URL for map
zoomLevelnumber16falseInitial zoom level of map
minZoomLevelnumbernonefalseMin zoom level of map
maxZoomLevelnumbernonefalseMax zoom level of map
localizeLabelsboolfalsefalseAutomatically change the language of the map labels to the system’s preferred language,
this is not something that can be toggled on/off
zoomEnabledboolnonefalseEnable/Disable zoom on the map
scrollEnabledbooltruefalseEnable/Disable scroll on the map
pitchEnabledbooltruefalseEnable/Disable pitch on map
rotateEnabledbooltruefalseEnable/Disable rotation on map
attributionEnabledbooltruefalseThe Mapbox terms of service, which governs the use of Mapbox-hosted vector tiles and styles,
requires these copyright notices to accompany any map that features Mapbox-designed styles, OpenStreetMap data, or other Mapbox data such as satellite or terrain data.
If that applies to this map view, do not hide this view or remove any notices from it.

You are additionally required to provide users with the option to disable anonymous usage and location sharing (telemetry).
If this view is hidden, you must implement this setting elsewhere in your app. See our website for Android and iOS for implementation details.

Enable/Disable attribution on map. For iOS you need to add MGLMapboxMetricsEnabledSettingShownInApp=YES
to your Info.plist
logoEnabledbooltruefalseEnable/Disable the logo on the map.
compassEnabledboolnonefalseEnable/Disable the compass from appearing on the map
surfaceViewboolfalsefalse[Android only] Enable/Disable use of GLSurfaceView insted of TextureView.
onPressfuncnonefalseMap press listener, gets called when a user presses the map
onLongPressfuncnonefalseMap long press listener, gets called when a user long presses the map
onRegionWillChangefuncnonefalseThis event is triggered whenever the currently displayed map region is about to change.
onRegionIsChangingfuncnonefalseThis event is triggered whenever the currently displayed map region is changing.
onRegionDidChangefuncnonefalseThis event is triggered whenever the currently displayed map region finished changing
onUserLocationUpdatefuncnonefalseThis event is triggered whenever the location engine receives a location update
onWillStartLoadingMapfuncnonefalseThis event is triggered when the map is about to start loading a new map style.
onDidFinishLoadingMapfuncnonefalseThis is triggered when the map has successfully loaded a new map style.
onDidFailLoadingMapfuncnonefalseThis event is triggered when the map has failed to load a new map style.
onWillStartRenderingFramefuncnonefalseThis event is triggered when the map will start rendering a frame.
onDidFinishRenderingFramefuncnonefalseThis event is triggered when the map finished rendering a frame.
onDidFinishRenderingFrameFullyfuncnonefalseThis event is triggered when the map fully finished rendering a frame.
onWillStartRenderingMapfuncnonefalseThis event is triggered when the map will start rendering the map.
onDidFinishRenderingMapfuncnonefalseThis event is triggered when the map finished rendering the map.
onDidFinishRenderingMapFullyfuncnonefalseThis event is triggered when the map fully finished rendering the map.
onDidFinishLoadingStylefuncnonefalseThis event is triggered when a style has finished loading.
onUserTrackingModeChangefuncnonefalseThis event is triggered when the users tracking mode is changed.
regionWillChangeDebounceTimenumber10falseThe emitted frequency of regionwillchange events
regionDidChangeDebounceTimenumber500falseThe emitted frequency of regiondidchange events

methods

getPointInView(coordinate)

Converts a geographic coordinate to a point in the given view’s coordinate system.

arguments
NameTypeRequiredDescription
coordinateArrayYesA point expressed in the map view's coordinate system.
const pointInView = await this._map.getPointInView([-37.817070, 144.949901]);

getCoordinateFromView(point)

Converts a point in the given view’s coordinate system to a geographic coordinate.

arguments
NameTypeRequiredDescription
pointArrayYesA point expressed in the given view’s coordinate system.
const coordinate = await this._map.getCoordinateFromView([100, 100]);

getVisibleBounds()

The coordinate bounds(ne, sw) visible in the users’s viewport.

arguments
NameTypeRequiredDescription
const visibleBounds = await this._map.getVisibleBounds();

queryRenderedFeaturesAtPoint(coordinate[, filter][, layerIDs])

Returns an array of rendered map features that intersect with a given point.

arguments
NameTypeRequiredDescription
coordinateArrayYesA point expressed in the map view’s coordinate system.
filterArrayNoA set of strings that correspond to the names of layers defined in the current style. Only the features contained in these layers are included in the returned array.
layerIDsArrayNoA array of layer id's to filter the features by
this._map.queryRenderedFeaturesAtPoint([30, 40], ['==', 'type', 'Point'], ['id1', 'id2'])

queryRenderedFeaturesInRect(bbox[, filter][, layerIDs])

Returns an array of rendered map features that intersect with the given rectangle,
restricted to the given style layers and filtered by the given predicate.

arguments
NameTypeRequiredDescription
bboxArrayYesA rectangle expressed in the map view’s coordinate system.
filterArrayNoA set of strings that correspond to the names of layers defined in the current style. Only the features contained in these layers are included in the returned array.
layerIDsArrayNoA array of layer id's to filter the features by
this._map.queryRenderedFeaturesInRect([30, 40, 20, 10], ['==', 'type', 'Point'], ['id1', 'id2'])

fitBounds(northEastCoordinates, southWestCoordinates[, padding][, duration])

Map camera transitions to fit provided bounds

arguments
NameTypeRequiredDescription
northEastCoordinatesArrayYesNorth east coordinate of bound
southWestCoordinatesArrayYesSouth west coordinate of bound
paddingNumberNoCamera padding for bound
durationNumberNoDuration of camera animation
this.map.fitBounds([lng, lat], [lng, lat])
this.map.fitBounds([lng, lat], [lng, lat], 20, 1000) // padding for all sides
this.map.fitBounds([lng, lat], [lng, lat], [verticalPadding, horizontalPadding], 1000)
this.map.fitBounds([lng, lat], [lng, lat], [top, right, bottom, left], 1000)

flyTo(coordinates[, duration])

Map camera will fly to new coordinate

arguments
NameTypeRequiredDescription
coordinatesArrayYesCoordinates that map camera will jump too
durationNumberNoDuration of camera animation
this.map.flyTo([lng, lat])
this.map.flyTo([lng, lat], 12000)

moveTo(coordinates[, duration])

Map camera will move to new coordinate at the same zoom level

arguments
NameTypeRequiredDescription
coordinatesArrayYesCoordinates that map camera will move too
durationNumberNoDuration of camera animation
this.map.moveTo([lng, lat], 200) // eases camera to new location based on duration
this.map.moveTo([lng, lat]) // snaps camera to new location without any easing

zoomTo(zoomLevel[, duration])

Map camera will zoom to specified level

arguments
NameTypeRequiredDescription
zoomLevelNumberYesZoom level that the map camera will animate too
durationNumberNoDuration of camera animation
this.map.zoomTo(16)
this.map.zoomTo(16, 100)

setCamera(config)

Map camera will perform updates based on provided config. Advanced use only!

arguments
NameTypeRequiredDescription
configObjectYesCamera configuration
this.map.setCamera({
  centerCoordinate: [lng, lat],
  zoom: 16,
  duration: 2000,
})

this.map.setCamera({
  stops: [
    { pitch: 45, duration: 200 },
    { heading: 180, duration: 300 },
  ]
})

takeSnap(writeToDisk)

Takes snapshot of map with current tiles and returns a URI to the image

arguments
NameTypeRequiredDescription
writeToDiskBooleanYesIf true will create a temp file, otherwise it is in base64

getZoom()

Returns the current zoom of the map view.

arguments
NameTypeRequiredDescription
const zoom = await this._map.getZoom();

getCenter()

Returns the map's geographical centerpoint

arguments
NameTypeRequiredDescription
const center = await this._map.getCenter();

showAttribution()

Show the attribution and telemetry action sheet.
If you implement a custom attribution button, you should add this action to the button.

arguments
NameTypeRequiredDescription