From 247207e4213314548ad95e737b5eb2b185baad99 Mon Sep 17 00:00:00 2001 From: Petr Pokorny Date: Wed, 3 Feb 2021 10:53:17 +0100 Subject: [PATCH 1/2] [macos] Added open geo url support to the macos app. --- platform/ios/platform/macos/app/AppDelegate.m | 38 ++++++++++++++----- platform/ios/platform/macos/app/Info.plist | 10 +++++ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/platform/ios/platform/macos/app/AppDelegate.m b/platform/ios/platform/macos/app/AppDelegate.m index eda989d7f..ddb758276 100644 --- a/platform/ios/platform/macos/app/AppDelegate.m +++ b/platform/ios/platform/macos/app/AppDelegate.m @@ -157,18 +157,36 @@ NSString * const MGLLastMapDebugMaskDefaultsKey = @"MGLLastMapDebugMask"; #pragma mark Services - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent { + // geo:29.95,-90.066667,3000 + // geo:29.95,-90.066667?z=14 // mapboxgl://?center=29.95,-90.066667&zoom=14&bearing=45&pitch=30 - NSURL *url = [NSURL URLWithString:[event paramDescriptorForKeyword:keyDirectObject].stringValue]; + + NSURLComponents *components = [NSURLComponents componentsWithString:[event paramDescriptorForKeyword:keyDirectObject].stringValue]; + BOOL isGLURL = [components.scheme isEqualToString:@"mapboxgl"]; + BOOL isGeoURL = [components.scheme isEqualToString:@"geo"]; + + NSString *centerString; + NSMutableDictionary *params = [[NSMutableDictionary alloc] init]; - for (NSString *param in [url.query componentsSeparatedByString:@"&"]) { - NSArray *parts = [param componentsSeparatedByString:@"="]; - if (parts.count >= 2) { - params[parts[0]] = [parts[1] stringByRemovingPercentEncoding]; - } + for (NSURLQueryItem *queryItem in components.queryItems) { + params[queryItem.name] = queryItem.value; } + if (isGLURL) { + centerString = params[@"center"]; + } else if (isGeoURL) { + NSArray *parsedPath = [components.path componentsSeparatedByString:@";"]; + centerString = parsedPath.firstObject; + for (NSString *param in [parsedPath subarrayWithRange:NSMakeRange(1, parsedPath.count - 1)]) { + NSArray *parts = [param componentsSeparatedByString:@"="]; + if (parts.count >= 2) { + params[parts[0]] = parts[1]; + } + } + } + MGLMapCamera *camera = [MGLMapCamera camera]; - NSString *zoomLevelString = params[@"zoom"]; + NSString *zoomLevelString = params[@"zoom"] ?: params[@"z"]; self.pendingZoomLevel = zoomLevelString.length ? zoomLevelString.doubleValue : -1; NSString *directionString = params[@"bearing"]; @@ -176,13 +194,15 @@ NSString * const MGLLastMapDebugMaskDefaultsKey = @"MGLLastMapDebugMask"; camera.heading = directionString.doubleValue; } - NSString *centerString = params[@"center"]; if (centerString) { NSArray *coordinateValues = [centerString componentsSeparatedByString:@","]; - if (coordinateValues.count == 2) { + if (coordinateValues.count >= 2) { camera.centerCoordinate = CLLocationCoordinate2DMake([coordinateValues[0] doubleValue], [coordinateValues[1] doubleValue]); } + if (coordinateValues.count == 3) { + camera.altitude = [coordinateValues[2] doubleValue]; + } } NSString *pitchString = params[@"pitch"]; diff --git a/platform/ios/platform/macos/app/Info.plist b/platform/ios/platform/macos/app/Info.plist index 8a498ae40..28a2fcf15 100644 --- a/platform/ios/platform/macos/app/Info.plist +++ b/platform/ios/platform/macos/app/Info.plist @@ -43,6 +43,16 @@ mapboxgl + + CFBundleTypeRole + Viewer + CFBundleURLName + ${PRODUCT_NAME} + CFBundleURLSchemes + + geo + + CFBundleVersion 15256 From 276bae52e29bfb87fb343680a23bfd743fab41b5 Mon Sep 17 00:00:00 2001 From: Petr Pokorny Date: Wed, 3 Feb 2021 11:39:34 +0100 Subject: [PATCH 2/2] Update MGLMapSnapshotterTests.m Increasing test timeout --- platform/ios/platform/darwin/test/MGLMapSnapshotterTests.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/ios/platform/darwin/test/MGLMapSnapshotterTests.m b/platform/ios/platform/darwin/test/MGLMapSnapshotterTests.m index c885fd665..2433f2112 100644 --- a/platform/ios/platform/darwin/test/MGLMapSnapshotterTests.m +++ b/platform/ios/platform/darwin/test/MGLMapSnapshotterTests.m @@ -137,7 +137,7 @@ MGLImage *MGLImageFromCurrentContext() { } [completionExpectation fulfill]; }]; - [self waitForExpectations:@[self.styleLoadingExpectation, completionExpectation] timeout:5 enforceOrder:YES]; + [self waitForExpectations:@[self.styleLoadingExpectation, completionExpectation] timeout:10 enforceOrder:YES]; } - (void)testRuntimeStyling {