diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-03-15 16:08:12 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-03-17 11:25:48 +0200 |
commit | df0dfa162b4196f22af1742e1f898ec1fd63a88e (patch) | |
tree | 0de4c99bc4aade48efc82b74b4a6dd73fa886541 | |
parent | e7c1ba2edf8bdb8fbe8ffe0c15908b6beac517ce (diff) | |
download | qtlocation-mapboxgl-df0dfa162b4196f22af1742e1f898ec1fd63a88e.tar.gz |
[macos] Update changes in MapObserver::onDidFailLoadingMap
-rw-r--r-- | platform/darwin/src/MGLTypes.h | 4 | ||||
-rw-r--r-- | platform/macos/CHANGELOG.md | 1 | ||||
-rw-r--r-- | 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 8cd2cacaa6..e4573c285e 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 83b0b7475d..5235d6180e 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 127fe79325..5a5073e22d 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -35,8 +35,10 @@ #import <mbgl/math/wrap.hpp> #import <mbgl/util/constants.hpp> #import <mbgl/util/chrono.hpp> +#import <mbgl/util/exception.hpp> #import <mbgl/util/run_loop.hpp> #import <mbgl/util/shared_thread_pool.hpp> +#import <mbgl/util/string.hpp> #import <map> #import <unordered_map> @@ -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 { |