Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 18d98b3

Browse files
committed
[ios] Update changes in MapObserver::onDidFailLoadingMap
1 parent 75e9e1b commit 18d98b3

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

platform/ios/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
5555
* 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))
5656
* Added support for predicates in rendered feature querying [8256](https://github.com/mapbox/mapbox-gl-native/pull/8246)
5757
* Added a nightly build of the dynamic framework. ([#8337](https://github.com/mapbox/mapbox-gl-native/pull/8337))
58+
* Improved the error message when the map failed to load [8418](https://github.com/mapbox/mapbox-gl-native/pull/8418)
5859

5960
## 3.4.2 - February 21, 2017
6061

platform/ios/src/MGLMapView.mm

+38-18
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <mbgl/style/layers/custom_layer.hpp>
2323
#include <mbgl/map/backend.hpp>
2424
#include <mbgl/math/wrap.hpp>
25+
#include <mbgl/util/exception.hpp>
2526
#include <mbgl/util/geo.hpp>
2627
#include <mbgl/util/constants.hpp>
2728
#include <mbgl/util/image.hpp>
@@ -30,6 +31,7 @@
3031
#include <mbgl/util/chrono.hpp>
3132
#include <mbgl/util/run_loop.hpp>
3233
#include <mbgl/util/shared_thread_pool.hpp>
34+
#include <mbgl/util/string.hpp>
3335

3436
#import "Mapbox.h"
3537
#import "MGLFeature_Private.h"
@@ -4794,7 +4796,7 @@ - (void)cameraDidChangeAnimated:(BOOL)animated {
47944796
}
47954797
}
47964798

4797-
- (void)willStartLoadingMap {
4799+
- (void)mapViewWillStartLoadingMap {
47984800
if (!_mbglMap) {
47994801
return;
48004802
}
@@ -4805,7 +4807,7 @@ - (void)willStartLoadingMap {
48054807
}
48064808
}
48074809

4808-
- (void)didFinishLoadingMap {
4810+
- (void)mapViewDidFinishLoadingMap {
48094811
if (!_mbglMap) {
48104812
return;
48114813
}
@@ -4820,19 +4822,18 @@ - (void)didFinishLoadingMap {
48204822
}
48214823
}
48224824

4823-
- (void)didFailLoadingMap {
4825+
- (void)mapViewDidFailLoadingMapWithError:(NSError *)error {
48244826
if (!_mbglMap) {
48254827
return;
48264828
}
48274829

48284830
if ([self.delegate respondsToSelector:@selector(mapViewDidFailLoadingMap:withError:)])
48294831
{
4830-
NSError *error = [NSError errorWithDomain:MGLErrorDomain code:0 userInfo:nil];
48314832
[self.delegate mapViewDidFailLoadingMap:self withError:error];
48324833
}
48334834
}
48344835

4835-
- (void)willStartRenderingFrame {
4836+
- (void)mapViewWillStartRenderingFrame {
48364837
if (!_mbglMap) {
48374838
return;
48384839
}
@@ -4843,7 +4844,7 @@ - (void)willStartRenderingFrame {
48434844
}
48444845
}
48454846

4846-
- (void)didFinishRenderingFrameFullyRendered:(BOOL)fullyRendered {
4847+
- (void)mapViewDidFinishRenderingFrameFullyRendered:(BOOL)fullyRendered {
48474848
if (!_mbglMap) {
48484849
return;
48494850
}
@@ -4861,7 +4862,7 @@ - (void)didFinishRenderingFrameFullyRendered:(BOOL)fullyRendered {
48614862
}
48624863
}
48634864

4864-
- (void)willStartRenderingMap {
4865+
- (void)mapViewWillStartRenderingMap {
48654866
if (!_mbglMap) {
48664867
return;
48674868
}
@@ -4872,7 +4873,7 @@ - (void)willStartRenderingMap {
48724873
}
48734874
}
48744875

4875-
- (void)didFinishRenderingMapFullyRendered:(BOOL)fullyRendered {
4876+
- (void)mapViewDidFinishRenderingMapFullyRendered:(BOOL)fullyRendered {
48764877
if (!_mbglMap) {
48774878
return;
48784879
}
@@ -5375,33 +5376,52 @@ void onCameraDidChange(mbgl::MapObserver::CameraChangeMode mode) override {
53755376
}
53765377

53775378
void onWillStartLoadingMap() override {
5378-
[nativeView willStartLoadingMap];
5379+
[nativeView mapViewWillStartLoadingMap];
53795380
}
53805381

53815382
void onDidFinishLoadingMap() override {
5382-
[nativeView didFinishLoadingMap];
5383-
}
5384-
5385-
void onDidFailLoadingMap() override {
5386-
[nativeView didFailLoadingMap];
5383+
[nativeView mapViewDidFinishLoadingMap];
5384+
}
5385+
5386+
void onDidFailLoadingMap(std::exception_ptr exception) override {
5387+
NSString *description;
5388+
MGLErrorCode code;
5389+
try {
5390+
std::rethrow_exception(exception);
5391+
} catch (const mbgl::util::StyleParseException&) {
5392+
code = MGLErrorCodeParseStyleFailed;
5393+
description = NSLocalizedStringWithDefaultValue(@"PARSE_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because the style is corrupted.", @"");
5394+
} catch (const mbgl::util::StyleLoadException&) {
5395+
code = MGLErrorCodeLoadStyleFailed;
5396+
description = NSLocalizedStringWithDefaultValue(@"PARSE_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because the style can't be loaded.", @"");
5397+
} catch (const mbgl::util::NotFoundException&) {
5398+
code = MGLErrorCodeNotFound;
5399+
description = NSLocalizedStringWithDefaultValue(@"LOAD_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because the style can’t be found or is incompatible.", @"");
5400+
} catch (...) {
5401+
code = MGLErrorCodeUnknown;
5402+
description = NSLocalizedStringWithDefaultValue(@"LOAD_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because an unknown error occurred.", @"");
5403+
}
5404+
NSDictionary *userInfo = @{NSLocalizedDescriptionKey:description, NSLocalizedFailureReasonErrorKey:@(mbgl::util::toString(exception).c_str())};
5405+
NSError *error = [NSError errorWithDomain:MGLErrorDomain code:code userInfo:userInfo];
5406+
[nativeView mapViewDidFailLoadingMapWithError:error];
53875407
}
53885408

53895409
void onWillStartRenderingFrame() override {
5390-
[nativeView willStartRenderingFrame];
5410+
[nativeView mapViewWillStartRenderingFrame];
53915411
}
53925412

53935413
void onDidFinishRenderingFrame(mbgl::MapObserver::RenderMode mode) override {
53945414
bool fullyRendered = mode == mbgl::MapObserver::RenderMode::Full;
5395-
[nativeView didFinishRenderingFrameFullyRendered:fullyRendered];
5415+
[nativeView mapViewDidFinishRenderingFrameFullyRendered:fullyRendered];
53965416
}
53975417

53985418
void onWillStartRenderingMap() override {
5399-
[nativeView willStartRenderingMap];
5419+
[nativeView mapViewWillStartRenderingMap];
54005420
}
54015421

54025422
void onDidFinishRenderingMap(mbgl::MapObserver::RenderMode mode) override {
54035423
bool fullyRendered = mode == mbgl::MapObserver::RenderMode::Full;
5404-
[nativeView didFinishRenderingMapFullyRendered:fullyRendered];
5424+
[nativeView mapViewDidFinishRenderingMapFullyRendered:fullyRendered];
54055425
}
54065426

54075427
void onDidFinishLoadingStyle() override {

0 commit comments

Comments
 (0)