Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

#2329 Constrain map to user specified bounds #2341

Closed
wants to merge 3 commits into from
Closed

#2329 Constrain map to user specified bounds #2341

wants to merge 3 commits into from

Conversation

maciekish
Copy link
Contributor

This PR enables the user to constrain movement of the map to a specific area.

Example
Set the bounds to lock the map to Sweden:

[self.mapView setUserConstraintsSouthWest:CLLocationCoordinate2DMake(55.336944, 10.9575) andNorthEast:CLLocationCoordinate2DMake(69.06, 24.155833)];

Implemented in transform_state.cpp by looking at how the existing TransformState::constrain(double& scale_, double& y_) function works to prevent panning the map outside 90 degrees latitude.

The new function TransformState::userConstrain(double& scale_, double& x_, double& y_) will constrain scale, x and y. By implementing it at this level both panning, flicking, pinching, double tapping and tapping the map with two fingers will be correctly constrained to the given coordinates. It does however not take angle or pitch into account.

Requested by me in #2329, but since i don't like waiting i went ahead and did it myself. This is my first c++ code ever so please be gentle :) Any feedback is appreciated.

@maciekish
Copy link
Contributor Author

Here it is in action http://s.swic.name/d7z3

@maciekish
Copy link
Contributor Author

Updated with the latest changes from master

@friedbunny friedbunny mentioned this pull request Jan 21, 2016
@1ec5
Copy link
Contributor

1ec5 commented Feb 22, 2016

Thanks for this PR. We’re thinking about a different approach to constraining the viewport that relies on a delegate method, similar to the way UIScrollView works: #2457. The nice thing about that approach is that it’ll handle a “rubber band” effect without much effort on the part of the developer. It’ll also be possible to constrain to a non-rectangular region, which may be important if rotation or tilting is allowed.

@1ec5 1ec5 added the iOS Mapbox Maps SDK for iOS label Feb 22, 2016
@1ec5
Copy link
Contributor

1ec5 commented Mar 22, 2016

Closing for now; will revisit later if #2457 turns out to be inadequate.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants