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 @@ -184,7 +184,7 @@ class RNMBXCamera(private val mContext: Context, private val mManager: RNMBXCame
val map = mapView.getMapboxMap()
val currentBounds = map.getBounds()
val builder = CameraBoundsOptions.Builder()
builder.bounds(mMaxBounds?.toBounds())
builder.bounds(mMaxBounds?.toBounds() ?: CoordinateBounds.world()) // Passing null does not reset this value.
builder.minZoom(mMinZoomLevel ?: 0.0) // Passing null does not reset this value.
builder.maxZoom(mMaxZoomLevel ?: 25.0) // Passing null does not reset this value.
builder.minPitch(currentBounds.minPitch)
Expand Down
38 changes: 23 additions & 15 deletions example/src/examples/Camera/RestrictMapBounds.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import React, { useState } from 'react';
import { Text } from 'react-native';
import {
MapView,
Camera,
Expand All @@ -9,6 +10,7 @@ import {
import bboxPolygon from '@turf/bbox-polygon';

import sheet from '../../styles/sheet';
import Bubble from '../common/Bubble';

const boundsStyle = {
fillColor: 'rgba(255, 255, 255, 0.1)',
Expand All @@ -23,19 +25,25 @@ const bounds = {
const { ne, sw } = bounds;
const polygon = bboxPolygon([sw[0], sw[1], ne[0], ne[1]]);

const RestrictMapBounds = (props) => (
<>
<MapView style={sheet.matchParent} styleURL={StyleURL.SatelliteStreet}>
<Camera
maxBounds={bounds}
zoomLevel={7}
centerCoordinate={[-4.744276, 50.361239]}
/>
<ShapeSource id="bounds" shape={polygon}>
<FillLayer id="boundsFill" style={boundsStyle} />
</ShapeSource>
</MapView>
</>
);
const RestrictMapBounds = (props) => {
const [restrictBounds, setRestrictBounds] = useState(true);
return (
<>
<MapView style={sheet.matchParent} styleURL={StyleURL.SatelliteStreet}>
<Camera
maxBounds={restrictBounds ? bounds : null}
zoomLevel={7}
centerCoordinate={[-4.744276, 50.361239]}
/>
<ShapeSource id="bounds" shape={polygon}>
<FillLayer id="boundsFill" style={boundsStyle} />
</ShapeSource>
</MapView>
<Bubble onPress={() => setRestrictBounds(!restrictBounds)}>
<Text>{restrictBounds ? 'Remove bounds' : 'Restrict bounds'}</Text>
</Bubble>
</>
);
};

export default RestrictMapBounds;
7 changes: 6 additions & 1 deletion ios/RNMBX/RNMBXCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,12 @@ open class RNMBXCamera : RNMBXMapAndMapViewComponentBase {
options.bounds = try self._toCoordinateBounds(maxBounds)
}
} else {
options.bounds = nil
// Passing nil does not reset this value, so reset to the SDK default (infinite world bounds).
options.bounds = CoordinateBounds(
southwest: CLLocationCoordinate2D(latitude: -90, longitude: -180),
northeast: CLLocationCoordinate2D(latitude: 90, longitude: 180),
infiniteBounds: true
)
}
options.minZoom = self.minZoomLevel?.CGFloat
options.maxZoom = self.maxZoomLevel?.CGFloat
Expand Down