summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-06-26 14:27:44 -0700
committerMinh Nguyễn <mxn@1ec5.org>2015-06-26 21:46:15 -0700
commitac2ad993a594e309362787e0697ff1727b799e8e (patch)
tree8347096c4f0c0de64bfadb514387b44d27427f66 /platform
parent7b22caddd0bb58677cc29a29c005bec621368d4b (diff)
downloadqtlocation-mapboxgl-ac2ad993a594e309362787e0697ff1727b799e8e.tar.gz
Fit to coordinates
Whoever determined the boundaries of the District of Columbia did not have fit-to-bounds implementations in mind. With this change, shapes that are not unrotated rectangles fit much, much better.
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/MGLMapView.mm22
1 files changed, 21 insertions, 1 deletions
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index 50debf336b..07822dd03e 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -1524,12 +1524,32 @@ mbgl::LatLngBounds MGLLatLngBoundsFromCoordinateBounds(MGLCoordinateBounds coord
- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated
{
+ CLLocationCoordinate2D coordinates[] = {
+ {bounds.ne.latitude, bounds.sw.longitude},
+ bounds.sw,
+ {bounds.sw.latitude, bounds.ne.longitude},
+ bounds.ne,
+ };
+ [self setVisibleCoordinates:coordinates
+ count:sizeof(coordinates) / sizeof(coordinates[0])
+ edgePadding:insets
+ animated:animated];
+}
+
+- (void)setVisibleCoordinates:(CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated
+{
// NOTE: does not disrupt tracking mode
CGFloat duration = animated ? MGLAnimationDuration : 0;
[self willChangeValueForKey:@"visibleCoordinateBounds"];
mbgl::EdgeInsets mbglInsets = {insets.top, insets.left, insets.bottom, insets.right};
- _mbglMap->fitBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), mbglInsets, secondsAsDuration(duration));
+ mbgl::AnnotationSegment segment;
+ segment.reserve(count);
+ for (NSUInteger i = 0; i < count; i++)
+ {
+ segment.push_back({coordinates[i].latitude, coordinates[i].longitude});
+ }
+ _mbglMap->fitBounds(segment, mbglInsets, secondsAsDuration(duration));
[self didChangeValueForKey:@"visibleCoordinateBounds"];
[self unrotateIfNeededAnimated:animated];