mapbox / mapbox/mapbox-maps-ios
Part of view annotation is displayed outside superview
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 601
- Forks
- 196
- PR merge metrics
- No merged PRs in 30d
Description
## Environment
- Xcode version: 14.1
- iOS version: any
- Devices affected: any
- Maps SDK Version: 10.9.1
## Observed behavior and steps to reproduce
Part of a view annotation is displayed outside its superview because mapView.clipsToBounds is set to false.
Code snippet:
```
import UIKit
import MapboxMaps
/**
NOTE: This view controller should be used as a scratchpad
while you develop new features. Changes to this file
should not be committed.
*/
final class DebugViewController: UIViewController {
var mapView: MapView!
override func viewDidLoad() {
super.viewDidLoad()
mapView = MapView(frame: self.view.bounds)
mapView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(self.mapView)
NSLayoutConstraint.activate([
self.mapView.heightAnchor.constraint(equalToConstant: 300),
self.mapView.widthAnchor.constraint(equalToConstant: 300),
self.mapView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
self.mapView.centerYAnchor.constraint(equalTo: self.view.centerYAnchor),
])
self.addViewAnnotation(at: self.mapView.mapboxMap.coordinate(for: self.mapView.center))
}
private func addViewAnnotation(at coordinate: CLLocationCoordinate2D) {
let options = ViewAnnotationOptions(
geometry: Point(coordinate),
allowOverlap: true,
anchor: .bottom
)
let annotationView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
annotationView.backgroundColor = UIColor.blue
try? mapView.viewAnnotations.add(annotationView, options: options)
}
}
```

## Expected behavior
I expect to confine a view annotation to the bounds of its superview by default.
## Notes / preliminary analysis
I think it more natural to set mapView.clipsToBounds to true by default.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the behavior with the provided DebugViewController and inspect MapView's default clipping configuration and view-annotation handling. Confirm the default keeps annotations within the map view's bounds, then verify the provided 300-by-300 example no longer displays the annotation outside its superview.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, swift
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100