Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double padding on camera when setting bounds #3354

Merged
merged 10 commits into from
Feb 13, 2024
38 changes: 8 additions & 30 deletions ios/RNMBX/RNMBXCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,12 @@ open class RNMBXCamera : RNMBXMapComponentBase {
logged("RNMBXCamera._updateMaxBounds._toCoordinateBounds") {
options.bounds = try self._toCoordinateBounds(maxBounds)
}
} else {
options.bounds = nil
}
if let minZoomLevel = self.minZoomLevel {
options.minZoom = minZoomLevel.CGFloat
}
if let maxZoomLevel = self.maxZoomLevel {
options.maxZoom = maxZoomLevel.CGFloat
}

options.minZoom = self.minZoomLevel?.CGFloat
options.maxZoom = self.maxZoomLevel?.CGFloat

naftalibeder marked this conversation as resolved.
Show resolved Hide resolved
logged("RNMBXCamera._updateMaxBounds") {
try map.mapboxMap.setCameraBounds(with: options)
}
Expand Down Expand Up @@ -377,13 +375,7 @@ open class RNMBXCamera : RNMBXMapComponentBase {
if let z = stop["zoom"] as? Double {
zoom = CGFloat(z)
}
if let _minNS = minZoomLevel, let _min = CGFloat(exactly: _minNS), let _zoom = zoom, _zoom < _min {
zoom = _min
}
if let _maxNS = maxZoomLevel, let _max = CGFloat(exactly: _maxNS), let _zoom = zoom, _zoom < _max {
zoom = _max
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clamping logic doesn't actually have an effect - the map automatically restricts according to the min/max zoom settings.


var pitch: CGFloat?
if let p = stop["pitch"] as? Double {
pitch = CGFloat(p)
Expand Down Expand Up @@ -455,21 +447,7 @@ open class RNMBXCamera : RNMBXMapComponentBase {
#else
let bounds = CoordinateBounds(southwest: sw, northeast: ne)
#endif

if padding.top + padding.bottom >= map.bounds.height {
Logger.log(level: .info, message: "RNMBXCamera.toUpdateItem: Vertical padding (top: \(round(padding.top)), bottom: \(round(padding.bottom)), total: \(round(padding.top + padding.bottom))) exceeds map height (\(round(map.bounds.height)))")
let overflowRatio = (padding.top + padding.bottom) / map.bounds.height
padding.top = (padding.top / overflowRatio) - 1
padding.bottom = (padding.bottom / overflowRatio) - 1
}

if padding.left + padding.right >= map.bounds.width {
Logger.log(level: .info, message: "RNMBXCamera.toUpdateItem: Horizontal padding (left: \(round(padding.left)), right: \(round(padding.right)), total: \(round(padding.left + padding.right))) exceeds map width (\(round(map.bounds.width)))")
let overflowRatio = (padding.left + padding.right) / map.bounds.width
padding.left = (padding.left / overflowRatio) - 1
padding.right = (padding.right / overflowRatio) - 1
}


camera = map.mapboxMap.camera(
for: bounds,
padding: padding,
Expand All @@ -482,7 +460,7 @@ open class RNMBXCamera : RNMBXMapComponentBase {
guard let camera = camera else {
return nil
}

var duration: TimeInterval?
if let d = stop["duration"] as? Double {
duration = toSeconds(d)
Expand Down
Loading