diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2017-04-06 08:30:34 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-04-06 09:22:51 -0700 |
commit | 83824203143d85b40362317ba76313b34be782e4 (patch) | |
tree | 8291d7dea18b2fb03a5ad8513bc8f8f1251795f7 /platform/darwin/src/MGLMapCamera.mm | |
parent | ab6185fdc343448d3b6cbfc5e2bc91b5242fdf9f (diff) | |
download | qtlocation-mapboxgl-83824203143d85b40362317ba76313b34be782e4.tar.gz |
[ios, macos] Fail gracefully on invalid coordinates
Invalid coordinates no longer cause an exception to be raised immediately when used in conversion methods and model objects. Instead, the appropriate invalid values are used, consistent with MapKit. Exceptions are still raised when invalid model objects are used with the map.
Diffstat (limited to 'platform/darwin/src/MGLMapCamera.mm')
-rw-r--r-- | platform/darwin/src/MGLMapCamera.mm | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/platform/darwin/src/MGLMapCamera.mm b/platform/darwin/src/MGLMapCamera.mm index ecac2892b1..49c7e70900 100644 --- a/platform/darwin/src/MGLMapCamera.mm +++ b/platform/darwin/src/MGLMapCamera.mm @@ -24,17 +24,21 @@ BOOL MGLEqualFloatWithAccuracy(CGFloat left, CGFloat right, CGFloat accuracy) fromEyeCoordinate:(CLLocationCoordinate2D)eyeCoordinate eyeAltitude:(CLLocationDistance)eyeAltitude { - mbgl::LatLng centerLatLng = MGLLatLngFromLocationCoordinate2D(centerCoordinate); - mbgl::LatLng eyeLatLng = MGLLatLngFromLocationCoordinate2D(eyeCoordinate); - - mbgl::ProjectedMeters centerMeters = mbgl::Projection::projectedMetersForLatLng(centerLatLng); - mbgl::ProjectedMeters eyeMeters = mbgl::Projection::projectedMetersForLatLng(eyeLatLng); - CLLocationDirection heading = std::atan((centerMeters.northing - eyeMeters.northing) / - (centerMeters.easting - eyeMeters.easting)); - - double groundDistance = std::hypot(centerMeters.northing - eyeMeters.northing, - centerMeters.easting - eyeMeters.easting); - CGFloat pitch = std::atan(eyeAltitude / groundDistance); + CLLocationDirection heading = -1; + CGFloat pitch = -1; + if (CLLocationCoordinate2DIsValid(centerCoordinate) && CLLocationCoordinate2DIsValid(eyeCoordinate)) { + mbgl::LatLng centerLatLng = MGLLatLngFromLocationCoordinate2D(centerCoordinate); + mbgl::LatLng eyeLatLng = MGLLatLngFromLocationCoordinate2D(eyeCoordinate); + + mbgl::ProjectedMeters centerMeters = mbgl::Projection::projectedMetersForLatLng(centerLatLng); + mbgl::ProjectedMeters eyeMeters = mbgl::Projection::projectedMetersForLatLng(eyeLatLng); + heading = std::atan((centerMeters.northing - eyeMeters.northing) / + (centerMeters.easting - eyeMeters.easting)); + + double groundDistance = std::hypot(centerMeters.northing - eyeMeters.northing, + centerMeters.easting - eyeMeters.easting); + pitch = std::atan(eyeAltitude / groundDistance); + } return [[self alloc] initWithCenterCoordinate:centerCoordinate altitude:eyeAltitude |