mapbox / mapbox/mapbox-maps-ios

How to restrict camera to circle bounds?

Open
#905 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged feature :green_apple:
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.