diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-03-15 16:08:29 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-03-17 11:25:48 +0200 |
commit | 6379cb0cd78a47697b90211df767750847369f8e (patch) | |
tree | 2b65b40c3540ed671c970283aad8cd2d7777ddd1 | |
parent | df0dfa162b4196f22af1742e1f898ec1fd63a88e (diff) | |
download | qtlocation-mapboxgl-6379cb0cd78a47697b90211df767750847369f8e.tar.gz |
[ios] Update changes in MapObserver::onDidFailLoadingMap
-rw-r--r-- | platform/ios/CHANGELOG.md | 1 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 56 |
2 files changed, 39 insertions, 18 deletions
diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index e59e02c87e..a2b5d9ed7b 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -55,6 +55,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Fixed an issue that was causing the system location indicator to stay on in background after telemetry was disabled. ([#7833](https://github.com/mapbox/mapbox-gl-native/pull/7833)) * Added support for predicates in rendered feature querying [8256](https://github.com/mapbox/mapbox-gl-native/pull/8246) * Added a nightly build of the dynamic framework. ([#8337](https://github.com/mapbox/mapbox-gl-native/pull/8337)) +* Improved the error message when the map fails to load. [8418](https://github.com/mapbox/mapbox-gl-native/pull/8418) ## 3.4.2 - February 21, 2017 diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 7aef71cdd6..6e45714441 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -22,6 +22,7 @@ #include <mbgl/style/layers/custom_layer.hpp> #include <mbgl/map/backend.hpp> #include <mbgl/math/wrap.hpp> +#include <mbgl/util/exception.hpp> #include <mbgl/util/geo.hpp> #include <mbgl/util/constants.hpp> #include <mbgl/util/image.hpp> @@ -30,6 +31,7 @@ #include <mbgl/util/chrono.hpp> #include <mbgl/util/run_loop.hpp> #include <mbgl/util/shared_thread_pool.hpp> +#include <mbgl/util/string.hpp> #import "Mapbox.h" #import "MGLFeature_Private.h" @@ -4794,7 +4796,7 @@ public: } } -- (void)willStartLoadingMap { +- (void)mapViewWillStartLoadingMap { if (!_mbglMap) { return; } @@ -4805,7 +4807,7 @@ public: } } -- (void)didFinishLoadingMap { +- (void)mapViewDidFinishLoadingMap { if (!_mbglMap) { return; } @@ -4820,19 +4822,18 @@ public: } } -- (void)didFailLoadingMap { +- (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)willStartRenderingFrame { +- (void)mapViewWillStartRenderingFrame { if (!_mbglMap) { return; } @@ -4843,7 +4844,7 @@ public: } } -- (void)didFinishRenderingFrameFullyRendered:(BOOL)fullyRendered { +- (void)mapViewDidFinishRenderingFrameFullyRendered:(BOOL)fullyRendered { if (!_mbglMap) { return; } @@ -4861,7 +4862,7 @@ public: } } -- (void)willStartRenderingMap { +- (void)mapViewWillStartRenderingMap { if (!_mbglMap) { return; } @@ -4872,7 +4873,7 @@ public: } } -- (void)didFinishRenderingMapFullyRendered:(BOOL)fullyRendered { +- (void)mapViewDidFinishRenderingMapFullyRendered:(BOOL)fullyRendered { if (!_mbglMap) { return; } @@ -5375,33 +5376,52 @@ public: } void onWillStartLoadingMap() override { - [nativeView willStartLoadingMap]; + [nativeView mapViewWillStartLoadingMap]; } void onDidFinishLoadingMap() override { - [nativeView didFinishLoadingMap]; - } - - void onDidFailLoadingMap() override { - [nativeView didFailLoadingMap]; + [nativeView mapViewDidFinishLoadingMap]; + } + + 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 willStartRenderingFrame]; + [nativeView mapViewWillStartRenderingFrame]; } void onDidFinishRenderingFrame(mbgl::MapObserver::RenderMode mode) override { bool fullyRendered = mode == mbgl::MapObserver::RenderMode::Full; - [nativeView didFinishRenderingFrameFullyRendered:fullyRendered]; + [nativeView mapViewDidFinishRenderingFrameFullyRendered:fullyRendered]; } void onWillStartRenderingMap() override { - [nativeView willStartRenderingMap]; + [nativeView mapViewWillStartRenderingMap]; } void onDidFinishRenderingMap(mbgl::MapObserver::RenderMode mode) override { bool fullyRendered = mode == mbgl::MapObserver::RenderMode::Full; - [nativeView didFinishRenderingMapFullyRendered:fullyRendered]; + [nativeView mapViewDidFinishRenderingMapFullyRendered:fullyRendered]; } void onDidFinishLoadingStyle() override { |