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

Commit

Permalink
[ios, macos] Fix visible coordinates when boundaries cross internatio…
Browse files Browse the repository at this point in the history
…nal dateline.
  • Loading branch information
fabian-guerra committed Oct 10, 2017
1 parent 5e08ce0 commit 3997c68
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2784,6 +2784,11 @@ - (void)_setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count
{
latLngs.push_back({coordinates[i].latitude, coordinates[i].longitude});
}

if (count == 4 && coordinates[1].longitude > 0 && coordinates[3].longitude < 0) {
latLngs = [self normalizeCoordinatesForAntimeridianSW:coordinates[1] ne:coordinates[3]];

}

mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngs(latLngs, padding);
if (direction >= 0)
Expand Down Expand Up @@ -2824,6 +2829,19 @@ - (void)_setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count
[self didChangeValueForKey:@"visibleCoordinateBounds"];
}

- (std::vector<mbgl::LatLng>)normalizeCoordinatesForAntimeridianSW:(CLLocationCoordinate2D)sw ne:(CLLocationCoordinate2D)ne
{
CLLocationDegrees longitude = (180 + (180 - fabs(sw.longitude))) * -1;
sw = CLLocationCoordinate2DMake(sw.latitude, longitude);

std::vector<mbgl::LatLng> latLngs = { {ne.latitude, sw.longitude},
{sw.latitude, sw.longitude},
{sw.latitude, ne.longitude},
{ne.latitude, ne.longitude} };

return latLngs;
}

+ (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingDirection
{
return [NSSet setWithObject:@"camera"];
Expand Down
7 changes: 7 additions & 0 deletions platform/macos/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,13 @@ - (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(NSEd

mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets);
padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets);

if (bounds.sw.longitude > 0 && bounds.ne.longitude < 0) {
CLLocationDegrees longitude = (180 + (180 - fabs(bounds.sw.longitude))) * -1;
bounds.sw = CLLocationCoordinate2DMake(bounds.sw.latitude, longitude);

}

mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), padding);
mbgl::AnimationOptions animationOptions;
if (animated) {
Expand Down

0 comments on commit 3997c68

Please sign in to comment.