mapbox / mapbox/mapbox-maps-ios
How to restrict camera to circle bounds?
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 601
- Forks
- 196
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to migrate from 6.3 to 10.
I need to restrict camera moves inside circle with given center and radius.
In 6.3 I wrote:
func mapView(_ mapView: MGLMapView, shouldChangeFrom oldCamera: MGLMapCamera, to newCamera: MGLMapCamera) -> Bool {
guard let c = mapCenter else { // my property containing center coordinate
return true
}
let l1 = CLLocation(latitude: newCamera.centerCoordinate.latitude,
longitude: newCamera.centerCoordinate.longitude)
let l2 = CLLocation(latitude: c.latitude,
longitude: c.longitude)
let meters = l1.distance(from: l2)
if meters > MAX_DISTANCE_METERS {
return false
}
boundingView.cutoutCenter = mapView.convert(c, toPointTo: boundingView) //set view with transparent circle property
return true
}
See video how it looks: https://disk.yandex.ru/i/7pVgwGnf48myKg
I need to do the same in 10 version.
CameraBoundsOptions allows me restrict camera to rectangle, but I need cirle. Using rectange close to circle is not satisfactory solution.
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
Start by reading the migration context from Mapbox Maps iOS 6.3 to 10 and the CameraBoundsOptions API. Compare its rectangular restriction with the earlier shouldChangeFrom camera delegate shown in the issue, then determine whether circular bounds are supported. Done means camera movement is restricted to the specified center and radius rather than an enclosing rectangle.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, swift
- Domain
- mobile
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100