From df0dfa162b4196f22af1742e1f898ec1fd63a88e Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Wed, 15 Mar 2017 16:08:12 +0200 Subject: [PATCH] [macos] Update changes in MapObserver::onDidFailLoadingMap --- platform/darwin/src/MGLTypes.h | 4 ++++ platform/macos/CHANGELOG.md | 1 + platform/macos/src/MGLMapView.mm | 32 ++++++++++++++++++++++++++------ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/platform/darwin/src/MGLTypes.h b/platform/darwin/src/MGLTypes.h index 8cd2cacaa..e4573c285 100644 --- a/platform/darwin/src/MGLTypes.h +++ b/platform/darwin/src/MGLTypes.h @@ -42,6 +42,10 @@ typedef NS_ENUM(NSInteger, MGLErrorCode) { MGLErrorCodeBadServerResponse = 2, /** An attempt to establish a connection failed. */ MGLErrorCodeConnectionFailed = 3, + /** A style parse error occurred while attempting to load the map. */ + MGLErrorCodeParseStyleFailed = 4, + /** An attempt to load the style failed. */ + MGLErrorCodeLoadStyleFailed = 5, }; /** diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 83b0b7475..5235d6180 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -49,6 +49,7 @@ * Fixed flickering that occurred when panning past the antimeridian. ([#7574](https://github.com/mapbox/mapbox-gl-native/pull/7574)) * Added a `MGLDistanceFormatter` class for formatting geographic distances. ([#7888](https://github.com/mapbox/mapbox-gl-native/pull/7888)) * Added support for predicates in rendered feature querying [8256](https://github.com/mapbox/mapbox-gl-native/pull/8246) +* Improved the error message when the map fails to load. [8418](https://github.com/mapbox/mapbox-gl-native/pull/8418) ## 0.3.1 - February 21, 2017 diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 127fe7932..5a5073e22 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -35,8 +35,10 @@ #import #import #import +#import #import #import +#import #import #import @@ -889,18 +891,17 @@ public: } } -- (void)mapViewDidFailLoadingMap { +- (void)mapViewDidFailLoadingMapWithError:(NSError *)error { if (!_mbglMap) { return; } if ([self.delegate respondsToSelector:@selector(mapViewDidFailLoadingMap:withError:)]) { - NSError *error = [NSError errorWithDomain:MGLErrorDomain code:0 userInfo:nil]; [self.delegate mapViewDidFailLoadingMap:self withError:error]; } } -- (void)MapViewWillStartRenderingFrame { +- (void)mapViewWillStartRenderingFrame { if (!_mbglMap) { return; } @@ -2794,12 +2795,31 @@ public: [nativeView mapViewDidFinishLoadingMap]; } - void onDidFailLoadingMap() override { - [nativeView mapViewDidFailLoadingMap]; + void onDidFailLoadingMap(std::exception_ptr exception) override { + NSString *description; + MGLErrorCode code; + try { + std::rethrow_exception(exception); + } catch (const mbgl::util::StyleParseException&) { + code = MGLErrorCodeParseStyleFailed; + description = NSLocalizedStringWithDefaultValue(@"PARSE_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because the style is corrupted.", @""); + } catch (const mbgl::util::StyleLoadException&) { + code = MGLErrorCodeLoadStyleFailed; + description = NSLocalizedStringWithDefaultValue(@"PARSE_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because the style can't be loaded.", @""); + } catch (const mbgl::util::NotFoundException&) { + code = MGLErrorCodeNotFound; + description = NSLocalizedStringWithDefaultValue(@"LOAD_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because the style can’t be found or is incompatible.", @""); + } catch (...) { + code = MGLErrorCodeUnknown; + description = NSLocalizedStringWithDefaultValue(@"LOAD_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because an unknown error occurred.", @""); + } + NSDictionary *userInfo = @{NSLocalizedDescriptionKey:description, NSLocalizedFailureReasonErrorKey:@(mbgl::util::toString(exception).c_str())}; + NSError *error = [NSError errorWithDomain:MGLErrorDomain code:code userInfo:userInfo]; + [nativeView mapViewDidFailLoadingMapWithError:error]; } void onWillStartRenderingFrame() override { - [nativeView MapViewWillStartRenderingFrame]; + [nativeView mapViewWillStartRenderingFrame]; } void onDidFinishRenderingFrame(mbgl::MapObserver::RenderMode mode) override {