Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
private val mCameraChangeTracker = CameraChangeTracker()
private var mPreferredFrameRate: Int? = null
private var mMaxPitch: Double? = null
private var mMinPitch: Double? = null
private lateinit var mMap: MapboxMap

private lateinit var mMapView: MapView
Expand Down Expand Up @@ -512,7 +513,8 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
LOGO(RNMBXMapView::applyLogo),
SCALEBAR(RNMBXMapView::applyScaleBar),
COMPASS(RNMBXMapView::applyCompass),
MAX_PITCH(RNMBXMapView::applyMaxPitch),;
MAX_PITCH(RNMBXMapView::applyMaxPitch),
MIN_PITCH(RNMBXMapView::applyMinPitch),;

override fun apply(mapView: RNMBXMapView) {
_apply(mapView)
Expand Down Expand Up @@ -603,6 +605,28 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
mMap.setBounds(builder.build())
}

fun setReactMinPitch(minPitch: Double?) {
mMinPitch = minPitch
changes.add(Property.MIN_PITCH)
}

private fun applyMinPitch() {
val minPitch = mMinPitch ?: return
if (!this::mMap.isInitialized) {
return
}

val currentBounds = mMap.getBounds()
val builder = CameraBoundsOptions.Builder()
.bounds(currentBounds.bounds)
.maxZoom(currentBounds.maxZoom)
.minZoom(currentBounds.minZoom)
.minPitch(minPitch)
.maxPitch(currentBounds.maxPitch)

mMap.setBounds(builder.build())
}

fun setReactStyleURL(styleURL: String) {
mStyleURL = styleURL
changes.add(Property.STYLE_URL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ open class RNMBXMapViewManager(context: ReactApplicationContext, val viewTagReso
map.setReactMaxPitch(if (maxPitch.type == ReadableType.Null) null else maxPitch.asDouble())
}

@ReactProp(name = "minPitch")
override fun setMinPitch(map: RNMBXMapView, minPitch: Dynamic) {
// Allow clearing the limit by passing null from JS
map.setReactMinPitch(if (minPitch.type == ReadableType.Null) null else minPitch.asDouble())
}

@ReactProp(name = "rotateEnabled")
override fun setRotateEnabled(map: RNMBXMapView, rotateEnabled: Dynamic) {
map.withMapView {
Expand Down
9 changes: 9 additions & 0 deletions docs/MapView.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ Maximum allowed pitch in degrees. Mirrors the Mapbox map option `maxPitch`.



### minPitch

```tsx
number
```
Minimum allowed pitch in degrees. Mirrors the Mapbox map option `minPitch`.



### rotateEnabled

```tsx
Expand Down
7 changes: 7 additions & 0 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5237,6 +5237,13 @@
"default": "none",
"description": "Maximum allowed pitch in degrees. Mirrors the Mapbox map option `maxPitch`."
},
{
"name": "minPitch",
"required": false,
"type": "number",
"default": "none",
"description": "Minimum allowed pitch in degrees. Mirrors the Mapbox map option `minPitch`."
},
{
"name": "rotateEnabled",
"required": false,
Expand Down
27 changes: 27 additions & 0 deletions ios/RNMBX/RNMBXMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ open class RNMBXMapView: UIView, RCTInvalidating {
case rotateEnabled
case pitchEnabled
case maxPitch
case minPitch
case onMapChange
case styleURL
case gestureSettings
Expand Down Expand Up @@ -462,6 +463,8 @@ open class RNMBXMapView: UIView, RCTInvalidating {
map.applyPitchEnabled()
case .maxPitch:
map.applyMaxPitch()
case .minPitch:
map.applyMinPitch()
case .gestureSettings:
map.applyGestureSettings()
case .preferredFramesPerSecond:
Expand Down Expand Up @@ -548,6 +551,30 @@ open class RNMBXMapView: UIView, RCTInvalidating {
}
}

var minPitch: Double? = nil

@objc public func setReactMinPitch(_ value: NSNumber?) {
minPitch = value?.doubleValue
changed(.minPitch)
}

func applyMinPitch() {
guard let minPitch = minPitch else { return }

withMapboxMap { mapboxMap in
logged("RNMBXMapView.applyMinPitch") {
let current = mapboxMap.cameraBounds
var options = CameraBoundsOptions()
options.bounds = current.bounds
options.maxZoom = current.maxZoom
options.minZoom = current.minZoom
options.minPitch = minPitch
options.maxPitch = current.maxPitch
try mapboxMap.setCameraBounds(with: options)
}
}
}

var locale: (layerIds: [String]?, locale: Locale)? = nil

@objc public func setReactLocalizeLabels(_ value: NSDictionary?) {
Expand Down
5 changes: 5 additions & 0 deletions src/components/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ type Props = ViewProps & {
*/
maxPitch?: number;

/**
* Minimum allowed pitch in degrees. Mirrors the Mapbox map option `minPitch`.
*/
minPitch?: number;

/**
* Enable/Disable rotation on map
*/
Expand Down
1 change: 1 addition & 0 deletions src/specs/RNMBXMapViewNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface NativeProps extends ViewProps {
rotateEnabled?: OptionalProp<boolean>;
pitchEnabled?: OptionalProp<boolean>;
maxPitch?: OptionalProp<Double>;
minPitch?: OptionalProp<Double>;

deselectAnnotationOnTap?: OptionalProp<boolean>;

Expand Down