-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Conversation
In light of #1781, maybe it doesn’t make sense for MGLMapView to handle this itself. What does MKMapView do with top and bottom bars? |
I'd like to move the core native API towards gl-js's |
Done in ed99904. That was pretty easy, actually, because I was relying on mbgl::Map instead of the view for all the calculations. That change also neatly avoids an erroneous call to |
This works well so far. I'll test again once the layout guides adjustments are in, that's the biggest difference between MapKit/Google and us right now. |
Note that fitting to bounds forcefully resets the direction back to north, without animation. Also, in 31d2918, I adapted the fit to bounds method to account for top and bottom bars, but it appears that MapKit does not. So I’m probably going to roll back that change. It’s easy enough to handle manually in client code. |
If you try to fit an MKMapView to any empty rect, MKMapView zooms way into the top-left corner of the map (in the Arctic Sea, above the Bering Strait). With this PR, however, MGLMapView centers on the empty coordinate bounds (which may originate anywhere) – I think that’s better behavior. |
The fit to bounds method now respects the current rotation. That turned out to require a lot less trig than I feared. 😃 |
The new implementation is now public and takes advantage of MGLCoordinateBounds. It is re-ported from `Camera.prototype.fitBounds()` in mapbox/mapbox-gl-js to ensure correct behavior. A new function, MGLCoordinateBoundsMake(), makes it easier to create an MGLCoordinateBounds for use with this method.
Each side of the bounding box is specified independently, allowing more flexibility than the offset + padding construct supported in mapbox/mapbox-gl-js’ Camera.
Added a bunch of functions to work with MGLCoordinateBounds in a separate header analogous to MKGeometry.h. Added resolution-independent tests for common fit to bounds scenarios.
Also fit to the rotated bounds. A little more verbose than necessary due to <http://stackoverflow.com/a/2357688/4585461>. ref mapbox/mapbox-gl-js#1338
bb7e60f
to
bcbb56c
Compare
Followup to #1783: Implemented the non-animated version of fit to bounds and makes it a KVO-compliant property.
This PR reimplements “fit to bounds” functionality to take advantage of MGLCoordinateBounds and additionally exposes the method publicly. I started by re-porting
Camera.prototype.fitBounds()
in mapbox/mapbox-gl-js to ensure correct baseline behavior. Then I wrote some logic for edge insets and rotation. Along for the ride, I added a bunch of public utility functions related to MGLCoordinateBounds.Adjust the viewport to account for top and bottom layout guidesedgePadding
parameter for parity with MapKit and mapbox-gl-js (to fix Expose MGLMapView's zoomToSouthWestCoordinate:northEastCoordinate:animated: method in public header #1775)@friedbunny @incanus, can you try out this implementation and see if there are any other edge cases that MapKit and Google Maps handle differently?