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

Commit b271b4b

Browse files
committed
[macos] Update changes in MapObserver::onDidFailLoadingMap
1 parent ae45a13 commit b271b4b

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

platform/darwin/src/MGLTypes.h

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ typedef NS_ENUM(NSInteger, MGLErrorCode) {
4242
MGLErrorCodeBadServerResponse = 2,
4343
/** An attempt to establish a connection failed. */
4444
MGLErrorCodeConnectionFailed = 3,
45+
/** A style parse error occurred while attempting to load the map. */
46+
MGLErrorCodeParseStyleFailed = 4,
47+
/** An attempt to load the style failed. */
48+
MGLErrorCodeLoadStyleFailed = 5,
4549
};
4650

4751
/**

platform/macos/src/MGLMapView.mm

+22-6
Original file line numberDiff line numberDiff line change
@@ -889,18 +889,17 @@ - (void)mapViewDidFinishLoadingMap {
889889
}
890890
}
891891

892-
- (void)mapViewDidFailLoadingMap {
892+
- (void)mapViewDidFailLoadingMapWithError:(NSError *)error {
893893
if (!_mbglMap) {
894894
return;
895895
}
896896

897897
if ([self.delegate respondsToSelector:@selector(mapViewDidFailLoadingMap:withError:)]) {
898-
NSError *error = [NSError errorWithDomain:MGLErrorDomain code:0 userInfo:nil];
899898
[self.delegate mapViewDidFailLoadingMap:self withError:error];
900899
}
901900
}
902901

903-
- (void)MapViewWillStartRenderingFrame {
902+
- (void)mapViewWillStartRenderingFrame {
904903
if (!_mbglMap) {
905904
return;
906905
}
@@ -2794,12 +2793,29 @@ void onDidFinishLoadingMap() override {
27942793
[nativeView mapViewDidFinishLoadingMap];
27952794
}
27962795

2797-
void onDidFailLoadingMap() override {
2798-
[nativeView mapViewDidFailLoadingMap];
2796+
void onDidFailLoadingMap(mbgl::MapObserver::ErrorType type, const std::string& message) override {
2797+
NSError *error;
2798+
NSString *errorDescription = @(message.c_str());
2799+
MGLErrorCode errorCode;
2800+
switch (type) {
2801+
case mbgl::MapObserver::ErrorType::ParseStyle:
2802+
errorCode = MGLErrorCodeParseStyleFailed;
2803+
break;
2804+
case mbgl::MapObserver::ErrorType::NotFound:
2805+
errorCode = MGLErrorCodeNotFound;
2806+
break;
2807+
case mbgl::MapObserver::ErrorType::LoadingStyle:
2808+
errorCode = MGLErrorCodeLoadStyleFailed;
2809+
break;
2810+
}
2811+
error = [NSError errorWithDomain:MGLErrorDomain code:errorCode userInfo:errorDescription ? @{
2812+
NSLocalizedDescriptionKey: errorDescription,
2813+
} : nil];
2814+
[nativeView mapViewDidFailLoadingMapWithError:error];
27992815
}
28002816

28012817
void onWillStartRenderingFrame() override {
2802-
[nativeView MapViewWillStartRenderingFrame];
2818+
[nativeView mapViewWillStartRenderingFrame];
28032819
}
28042820

28052821
void onDidFinishRenderingFrame(mbgl::MapObserver::RenderMode mode) override {

0 commit comments

Comments
 (0)