[ios, macos] Unwrap coordinate bounds
Updated coordinate bounds conversion methods to use the beyond-±180 method to indicate that the bounds extends beyond the antimeridian. Also copyedited conversion documentation.
This commit is contained in:
committed by
Minh Nguyễn
parent
25629c81a6
commit
0525fd1e4a
@@ -41,6 +41,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
|
||||
|
||||
### Other changes
|
||||
|
||||
* The `-[MGLMapView convertRect:toCoordinateBoundsFromView:]` method and the `MGLMapView.visibleCoordinateBounds` property’s getter now indicate that the coordinate bounds straddles the antimeridian by extending one side beyond ±180 degrees longitude. ([#11265](https://github.com/mapbox/mapbox-gl-native/pull/11265))
|
||||
* Feature querying results now account for the `MGLSymbolStyleLayer.circleStrokeWidth` property. ([#10897](https://github.com/mapbox/mapbox-gl-native/pull/10897))
|
||||
* Fixed an issue preventing labels from being transliterated when VoiceOver was enabled on iOS 10._x_ and below. ([#10881](https://github.com/mapbox/mapbox-gl-native/pull/10881))
|
||||
* Labels are now transliterated from more languages when VoiceOver is enabled. ([#10881](https://github.com/mapbox/mapbox-gl-native/pull/10881))
|
||||
|
||||
@@ -659,11 +659,10 @@ MGL_EXPORT IB_DESIGNABLE
|
||||
want to animate the change, call `-setVisibleCoordinateBounds:animated:`
|
||||
instead.
|
||||
|
||||
If a longitude is less than −180 degrees or greater than 180 degrees, the visible
|
||||
bounds straddles the antimeridian or international date line.
|
||||
|
||||
For example, a visible bounds that stretches from Tokyo to San Francisco would have
|
||||
coordinates of (35.68476, -220.24257) and (37.78428, -122.41310).
|
||||
If a longitude is less than −180 degrees or greater than 180 degrees, the
|
||||
visible bounds straddles the antimeridian or international date line. For
|
||||
example, if both Tokyo and San Francisco are visible, the visible bounds might
|
||||
extend from (35.68476, −220.24257) to (37.78428, −122.41310).
|
||||
*/
|
||||
@property (nonatomic) MGLCoordinateBounds visibleCoordinateBounds;
|
||||
|
||||
@@ -671,11 +670,10 @@ MGL_EXPORT IB_DESIGNABLE
|
||||
Changes the receiver’s viewport to fit the given coordinate bounds,
|
||||
optionally animating the change.
|
||||
|
||||
To make the visible bounds go across the antimeridian or international date line,
|
||||
specify some longitudes less than −180 degrees or greater than 180 degrees.
|
||||
|
||||
For example, a visible bounds that stretches from Tokyo to San Francisco would have
|
||||
coordinates of (35.68476, -220.24257) and (37.78428, -122.41310).
|
||||
To bring both sides of the antimeridian or international date line into view,
|
||||
specify some longitudes less than −180 degrees or greater than 180 degrees. For
|
||||
example, to show both Tokyo and San Francisco simultaneously, you could set the
|
||||
visible bounds to extend from (35.68476, −220.24257) to (37.78428, −122.41310).
|
||||
|
||||
@param bounds The bounds that the viewport will show in its entirety.
|
||||
@param animated Specify `YES` to animate the change by smoothly scrolling
|
||||
@@ -686,6 +684,11 @@ MGL_EXPORT IB_DESIGNABLE
|
||||
/**
|
||||
Changes the receiver’s viewport to fit the given coordinate bounds and
|
||||
optionally some additional padding on each side.
|
||||
|
||||
To bring both sides of the antimeridian or international date line into view,
|
||||
specify some longitudes less than −180 degrees or greater than 180 degrees. For
|
||||
example, to show both Tokyo and San Francisco simultaneously, you could set the
|
||||
visible bounds to extend from (35.68476, −220.24257) to (37.78428, −122.41310).
|
||||
|
||||
@param bounds The bounds that the viewport will show in its entirety.
|
||||
@param insets The minimum padding (in screen points) that will be visible
|
||||
@@ -698,6 +701,11 @@ MGL_EXPORT IB_DESIGNABLE
|
||||
/**
|
||||
Changes the receiver’s viewport to fit all of the given coordinates and
|
||||
optionally some additional padding on each side.
|
||||
|
||||
To bring both sides of the antimeridian or international date line into view,
|
||||
specify some longitudes less than −180 degrees or greater than 180 degrees. For
|
||||
example, to show both Tokyo and San Francisco simultaneously, you could set the
|
||||
visible coordinates to (35.68476, −220.24257) and (37.78428, −122.41310).
|
||||
|
||||
@param coordinates The coordinates that the viewport will show.
|
||||
@param count The number of coordinates. This number must not be greater than
|
||||
@@ -712,6 +720,11 @@ MGL_EXPORT IB_DESIGNABLE
|
||||
/**
|
||||
Changes the receiver’s viewport to fit all of the given coordinates and
|
||||
optionally some additional padding on each side.
|
||||
|
||||
To bring both sides of the antimeridian or international date line into view,
|
||||
specify some longitudes less than −180 degrees or greater than 180 degrees. For
|
||||
example, to show both Tokyo and San Francisco simultaneously, you could set the
|
||||
visible coordinates to (35.68476, −220.24257) and (37.78428, −122.41310).
|
||||
|
||||
@param coordinates The coordinates that the viewport will show.
|
||||
@param count The number of coordinates. This number must not be greater than
|
||||
@@ -994,6 +1007,9 @@ MGL_EXPORT IB_DESIGNABLE
|
||||
/**
|
||||
Converts a rectangle in the given view’s coordinate system to a geographic
|
||||
bounding box.
|
||||
|
||||
If a longitude is less than −180 degrees or greater than 180 degrees, the
|
||||
bounding box straddles the antimeridian or international date line.
|
||||
|
||||
@param rect The rectangle to convert.
|
||||
@param view The view in whose coordinate system the rectangle is expressed.
|
||||
|
||||
@@ -3423,36 +3423,24 @@ public:
|
||||
/// bounding box.
|
||||
- (mbgl::LatLngBounds)convertRect:(CGRect)rect toLatLngBoundsFromView:(nullable UIView *)view
|
||||
{
|
||||
mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty();
|
||||
bounds.extend([self convertPoint:rect.origin toLatLngFromView:view]);
|
||||
bounds.extend([self convertPoint:{ CGRectGetMaxX(rect), CGRectGetMinY(rect) } toLatLngFromView:view]);
|
||||
bounds.extend([self convertPoint:{ CGRectGetMaxX(rect), CGRectGetMaxY(rect) } toLatLngFromView:view]);
|
||||
bounds.extend([self convertPoint:{ CGRectGetMinX(rect), CGRectGetMaxY(rect) } toLatLngFromView:view]);
|
||||
|
||||
// The world is wrapping if a point just outside the bounds is also within
|
||||
// the rect.
|
||||
mbgl::LatLng outsideLatLng;
|
||||
if (bounds.west() > -180)
|
||||
{
|
||||
outsideLatLng = {
|
||||
(bounds.south() + bounds.north()) / 2,
|
||||
bounds.west() - 1,
|
||||
};
|
||||
}
|
||||
else if (bounds.east() < 180)
|
||||
{
|
||||
outsideLatLng = {
|
||||
(bounds.south() + bounds.north()) / 2,
|
||||
bounds.east() + 1,
|
||||
};
|
||||
}
|
||||
|
||||
// If the world is wrapping, extend the bounds to cover all longitudes.
|
||||
if (CGRectContainsPoint(rect, [self convertLatLng:outsideLatLng toPointToView:view]))
|
||||
{
|
||||
bounds.extend(mbgl::LatLng(bounds.south(), -180));
|
||||
bounds.extend(mbgl::LatLng(bounds.south(), 180));
|
||||
}
|
||||
auto bounds = mbgl::LatLngBounds::empty();
|
||||
auto topLeft = [self convertPoint:{ CGRectGetMinX(rect), CGRectGetMinY(rect) } toLatLngFromView:view];
|
||||
auto topRight = [self convertPoint:{ CGRectGetMaxX(rect), CGRectGetMinY(rect) } toLatLngFromView:view];
|
||||
auto bottomRight = [self convertPoint:{ CGRectGetMaxX(rect), CGRectGetMaxY(rect) } toLatLngFromView:view];
|
||||
auto bottomLeft = [self convertPoint:{ CGRectGetMinX(rect), CGRectGetMaxY(rect) } toLatLngFromView:view];
|
||||
|
||||
// If the bounds straddles the antimeridian, unwrap it so that one side
|
||||
// extends beyond ±180° longitude.
|
||||
auto center = [self convertPoint:{ CGRectGetMidX(rect), CGRectGetMidY(rect) } toLatLngFromView:view];
|
||||
topLeft.unwrapForShortestPath(center);
|
||||
topRight.unwrapForShortestPath(center);
|
||||
bottomRight.unwrapForShortestPath(center);
|
||||
bottomLeft.unwrapForShortestPath(center);
|
||||
|
||||
bounds.extend(topLeft);
|
||||
bounds.extend(topRight);
|
||||
bounds.extend(bottomRight);
|
||||
bounds.extend(bottomLeft);
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
### Other changes
|
||||
|
||||
* Added Danish and Hebrew localizations. ([#10967](https://github.com/mapbox/mapbox-gl-native/pull/10967), [#11136](https://github.com/mapbox/mapbox-gl-native/pull/11134))
|
||||
* The `-[MGLMapView convertRect:toCoordinateBoundsFromView:]` method and the `MGLMapView.visibleCoordinateBounds` property’s getter now indicate that the coordinate bounds straddles the antimeridian by extending one side beyond ±180 degrees longitude. ([#11265](https://github.com/mapbox/mapbox-gl-native/pull/11265))
|
||||
* Feature querying results now account for the `MGLSymbolStyleLayer.circleStrokeWidth` property. ([#10897](https://github.com/mapbox/mapbox-gl-native/pull/10897))
|
||||
* Removed methods, properties, and constants that had been deprecated as of v0.6.1. ([#11205](https://github.com/mapbox/mapbox-gl-native/pull/11205))
|
||||
|
||||
|
||||
@@ -397,11 +397,10 @@ MGL_EXPORT IB_DESIGNABLE
|
||||
want to animate the change, use the `-setVisibleCoordinateBounds:animated:`
|
||||
method instead.
|
||||
|
||||
If a longitude is less than −180 degrees or greater than 180 degrees, the visible
|
||||
bounds straddles the antimeridian or international date line.
|
||||
|
||||
For example, a visible bounds that stretches from Tokyo to San Francisco would have
|
||||
coordinates of (35.68476, -220.24257) and (37.78428, -122.41310).
|
||||
If a longitude is less than −180 degrees or greater than 180 degrees, the
|
||||
visible bounds straddles the antimeridian or international date line. For
|
||||
example, if both Tokyo and San Francisco are visible, the visible bounds might
|
||||
extend from (35.68476, −220.24257) to (37.78428, −122.41310).
|
||||
*/
|
||||
@property (nonatomic) MGLCoordinateBounds visibleCoordinateBounds;
|
||||
|
||||
@@ -409,11 +408,10 @@ MGL_EXPORT IB_DESIGNABLE
|
||||
Changes the receiver’s viewport to fit the given coordinate bounds, optionally
|
||||
animating the change.
|
||||
|
||||
To make the visible bounds go across the antimeridian or international date line,
|
||||
specify some longitudes less than −180 degrees or greater than 180 degrees.
|
||||
|
||||
For example, a visible bounds that stretches from Tokyo to San Francisco would have
|
||||
coordinates of (35.68476, -220.24257) and (37.78428, -122.41310).
|
||||
To bring both sides of the antimeridian or international date line into view,
|
||||
specify some longitudes less than −180 degrees or greater than 180 degrees. For
|
||||
example, to show both Tokyo and San Francisco simultaneously, you could set the
|
||||
visible bounds to extend from (35.68476, −220.24257) to (37.78428, −122.41310).
|
||||
|
||||
@param bounds The bounds that the viewport will show in its entirety.
|
||||
@param animated Specify `YES` to animate the change by smoothly scrolling and
|
||||
@@ -1060,6 +1058,9 @@ MGL_EXPORT IB_DESIGNABLE
|
||||
/**
|
||||
Converts a rectangle in the given view’s coordinate system to a geographic
|
||||
bounding box.
|
||||
|
||||
If a longitude is less than −180 degrees or greater than 180 degrees, the
|
||||
bounding box straddles the antimeridian or international date line.
|
||||
|
||||
@param rect The rectangle to convert.
|
||||
@param view The view in whose coordinate system the rectangle is expressed.
|
||||
|
||||
@@ -2717,32 +2717,24 @@ public:
|
||||
/// Converts a rectangle in the given view’s coordinate system to a geographic
|
||||
/// bounding box.
|
||||
- (mbgl::LatLngBounds)convertRect:(NSRect)rect toLatLngBoundsFromView:(nullable NSView *)view {
|
||||
mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty();
|
||||
bounds.extend([self convertPoint:rect.origin toLatLngFromView:view]);
|
||||
bounds.extend([self convertPoint:{ NSMaxX(rect), NSMinY(rect) } toLatLngFromView:view]);
|
||||
bounds.extend([self convertPoint:{ NSMaxX(rect), NSMaxY(rect) } toLatLngFromView:view]);
|
||||
bounds.extend([self convertPoint:{ NSMinX(rect), NSMaxY(rect) } toLatLngFromView:view]);
|
||||
|
||||
// The world is wrapping if a point just outside the bounds is also within
|
||||
// the rect.
|
||||
mbgl::LatLng outsideLatLng;
|
||||
if (bounds.west() > -180) {
|
||||
outsideLatLng = {
|
||||
(bounds.south() + bounds.north()) / 2,
|
||||
bounds.west() - 1,
|
||||
};
|
||||
} else if (bounds.northeast().longitude() < 180) {
|
||||
outsideLatLng = {
|
||||
(bounds.south() + bounds.north()) / 2,
|
||||
bounds.east() + 1,
|
||||
};
|
||||
}
|
||||
|
||||
// If the world is wrapping, extend the bounds to cover all longitudes.
|
||||
if (NSPointInRect([self convertLatLng:outsideLatLng toPointToView:view], rect)) {
|
||||
bounds.extend(mbgl::LatLng(bounds.south(), -180));
|
||||
bounds.extend(mbgl::LatLng(bounds.south(), 180));
|
||||
}
|
||||
auto bounds = mbgl::LatLngBounds::empty();
|
||||
auto bottomLeft = [self convertPoint:{ NSMinX(rect), NSMinY(rect) } toLatLngFromView:view];
|
||||
auto bottomRight = [self convertPoint:{ NSMaxX(rect), NSMinY(rect) } toLatLngFromView:view];
|
||||
auto topRight = [self convertPoint:{ NSMaxX(rect), NSMaxY(rect) } toLatLngFromView:view];
|
||||
auto topLeft = [self convertPoint:{ NSMinX(rect), NSMaxY(rect) } toLatLngFromView:view];
|
||||
|
||||
// If the bounds straddles the antimeridian, unwrap it so that one side
|
||||
// extends beyond ±180° longitude.
|
||||
auto center = [self convertPoint:{ NSMidX(rect), NSMidY(rect) } toLatLngFromView:view];
|
||||
bottomLeft.unwrapForShortestPath(center);
|
||||
bottomRight.unwrapForShortestPath(center);
|
||||
topRight.unwrapForShortestPath(center);
|
||||
topLeft.unwrapForShortestPath(center);
|
||||
|
||||
bounds.extend(bottomLeft);
|
||||
bounds.extend(bottomRight);
|
||||
bounds.extend(topRight);
|
||||
bounds.extend(topLeft);
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user