[ios, macos] Fix overlay bounds that span the antimeridian. (#11783)

* [ios, macos] Fix overlay bounds that span the antimeridian.

* [ios, macos] Update changelogs.

* [ios, macos] Make MGLLocationCoordinate2DIsValid private.

* [ios, macos] Update changelogs.
This commit is contained in:
Fabian Guerra Soto
2018-05-04 12:49:58 -04:00
committed by GitHub
parent 167a2321d9
commit 86a2e93294
7 changed files with 56 additions and 2 deletions

View File

@@ -71,6 +71,17 @@ NS_INLINE MGLCoordinateQuad MGLCoordinateQuadFromLatLngArray(std::array<mbgl::La
MGLLocationCoordinate2DFromLatLng(quad[1]) };
}
/**
YES if the coordinate is valid or NO if it is not.
Considers extended coordinates.
*/
NS_INLINE BOOL MGLLocationCoordinate2DIsValid(CLLocationCoordinate2D coordinate) {
return (coordinate.latitude <= 90.0 &&
coordinate.latitude >= -90.0 &&
coordinate.longitude <= 360.0 &&
coordinate.longitude >= -360.0);
}
#if TARGET_OS_IPHONE
NS_INLINE mbgl::EdgeInsets MGLEdgeInsetsFromNSEdgeInsets(UIEdgeInsets insets) {
return { insets.top, insets.left, insets.bottom, insets.right };

View File

@@ -163,7 +163,7 @@
if (!_bounds) {
mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty();
for (auto coordinate : _coordinates) {
if (!CLLocationCoordinate2DIsValid(coordinate)) {
if (!MGLLocationCoordinate2DIsValid(coordinate)) {
bounds = mbgl::LatLngBounds::empty();
break;
}

View File

@@ -30,6 +30,11 @@ NS_ASSUME_NONNULL_BEGIN
This property contains the smallest rectangle that completely encompasses the
overlay. Implementers of this protocol must set this area when implementing
their overlay class, and after setting it, you must not change it.
If this overlay spans the antimeridian, its bounds may extend west of −180 degrees
longitude or east of 180 degrees longitude. For example, an overlay covering the
Pacific Ocean from Tokyo to San Francisco might have a bounds extending
from (35.68476, −220.24257) to (37.78428, −122.41310).
*/
@property (nonatomic, readonly) MGLCoordinateBounds overlayBounds;

View File

@@ -54,7 +54,7 @@ NS_ASSUME_NONNULL_BEGIN
if (!_bounds) {
mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty();
for (auto coordinate : _coordinates) {
if (!CLLocationCoordinate2DIsValid(coordinate)) {
if (!MGLLocationCoordinate2DIsValid(coordinate)) {
bounds = mbgl::LatLngBounds::empty();
break;
}

View File

@@ -172,4 +172,40 @@
XCTAssertEqual(point.y, roundTrippedPoint.y);
XCTAssertEqual(point.zoomLevel, roundTrippedPoint.zoomLevel);
}
- (void)testMGLLocationCoordinate2DIsValid {
{
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(37.936, -71.516);
XCTAssertTrue(MGLLocationCoordinate2DIsValid(coordinate));
}
{
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(46.816368, 5.844469);
XCTAssertTrue(MGLLocationCoordinate2DIsValid(coordinate));
}
{
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(-21.512680, 23.334703);
XCTAssertTrue(MGLLocationCoordinate2DIsValid(coordinate));
}
{
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(-44.947936, -73.081313);
XCTAssertTrue(MGLLocationCoordinate2DIsValid(coordinate));
}
{
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(19.333630, 203.555405);
XCTAssertTrue(MGLLocationCoordinate2DIsValid(coordinate));
}
{
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(23.254696, -240.795323);
XCTAssertTrue(MGLLocationCoordinate2DIsValid(coordinate));
}
{
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(91, 361);
XCTAssertFalse(MGLLocationCoordinate2DIsValid(coordinate));
}
{
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(-91, -361);
XCTAssertFalse(MGLLocationCoordinate2DIsValid(coordinate));
}
}
@end

View File

@@ -20,6 +20,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Fixed an issue where `-[MGLMapView metersPerPixelAtLatitude:]` was removed, but not marked as unavailable. ([#11765](https://github.com/mapbox/mapbox-gl-native/pull/11765))
* Reduce per-frame render CPU time ([#11811](https://github.com/mapbox/mapbox-gl-native/issues/11811))
* Fixed a crash when removing an `MGLOfflinePack`. ([#6092](https://github.com/mapbox/mapbox-gl-native/issues/6092))
* Fixed an issue where an `MGLOverlay` object straddling the antimeridian had an empty `MGLOverlay.overlayBounds` value. ([#11783](https://github.com/mapbox/mapbox-gl-native/pull/11783))
## 4.0.0 - April 19, 2018

View File

@@ -10,6 +10,7 @@
* Fixed an issue where selecting an onscreen annotation could move the map unintentionally. ([#11731](https://github.com/mapbox/mapbox-gl-native/pull/11731))
* Fixed a crash when removing an `MGLOfflinePack`. ([#6092](https://github.com/mapbox/mapbox-gl-native/issues/6092))
* Fixed an issue where an `MGLOverlay` object straddling the antimeridian had an empty `MGLOverlay.overlayBounds` value. ([#11783](https://github.com/mapbox/mapbox-gl-native/pull/11783))
## 0.7.0 - April 19, 2018