mapbox / mapbox/mapbox-maps-ios

Part of view annotation is displayed outside superview

Open
#1,780 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle:
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)
}
}
```

![206332284-a336ce50-8319-4721-8da1-31613ec7c3a3](https://user-images.githubusercontent.com/61189782/206332855-035a7110-ad76-4168-83c7-3ef4d12d1c59.png)

## 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.