diff options
author | Julian Rex <julian.rex@mapbox.com> | 2019-07-19 14:29:18 -0400 |
---|---|---|
committer | Julian Rex <julian.rex@mapbox.com> | 2019-08-23 16:22:07 -0400 |
commit | 93a4545092cf8f5b9dc1d4f06b97a577ca2db87b (patch) | |
tree | dcabeaa10d91e93883f2d5b9c316740b7013c0da | |
parent | 9f0d0e5ae09f57a3e8fa73249e861f2719d4f36d (diff) | |
download | qtlocation-mapboxgl-93a4545092cf8f5b9dc1d4f06b97a577ca2db87b.tar.gz |
[ios] Clean up iosapp / Add separate entry for road query.
-rw-r--r-- | platform/ios/app/MBXViewController.m | 116 | ||||
-rw-r--r-- | platform/ios/ios.xcodeproj/project.pbxproj | 6 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 9 |
3 files changed, 79 insertions, 52 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 78098bbbe5..3d873f94df 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -20,19 +20,6 @@ #import <os/log.h> #import <os/signpost.h> -os_log_t signpostlog; -os_signpost_id_t signpost; -BOOL queryForRoads = NO; - -@interface MGLStyle (qrf) -@property (nonatomic, readonly, copy) NSArray<MGLVectorStyleLayer *> *roadStyleLayers; -@end - -@interface MGLMapView () -- (void)setNeedsRerender; -@end - - static const CLLocationCoordinate2D WorldTourDestinations[] = { { .latitude = 38.8999418, .longitude = -77.033996 }, { .latitude = 37.7884307, .longitude = -122.3998631 }, @@ -78,6 +65,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsAnnotationsRows) { MBXSettingsAnnotationsTestShapes, MBXSettingsAnnotationsCustomCallout, MBXSettingsAnnotationsQueryAnnotations, + MBXSettingsAnnotationsQueryRoadsAroundDC, MBXSettingsAnnotationsCustomUserDot, MBXSettingsAnnotationsRemoveAnnotations, MBXSettingsAnnotationSelectRandomOffscreenPointAnnotation, @@ -229,10 +217,30 @@ CLLocationCoordinate2D randomWorldCoordinate() { @property (nonatomic) NSMutableArray<UIWindow *> *helperWindows; @property (nonatomic) NSMutableArray<UIView *> *contentInsetsOverlays; +@property (nonatomic) os_log_t log; +@property (nonatomic) os_signpost_id_t signpost; +@property (nonatomic) NSMutableArray<dispatch_block_t> *pendingIdleBlocks; + @end +#define OS_SIGNPOST_BEGIN(name) \ + if (@available(iOS 12.0, *)) { os_signpost_interval_begin(self.log, self.signpost, name); } + +#define OS_SIGNPOST_END(name) \ + if (@available(iOS 12.0, *)) { os_signpost_interval_end(self.log, self.signpost, name); } + +#define OS_SIGNPOST_EVENT(name, ...) \ + if (@available(iOS 12.0, *)) { os_signpost_event_emit(self.log, self.signpost, name, ##__VA_ARGS__); } + +// Expose properties for testing @interface MGLMapView (MBXViewController) @property (nonatomic) NSDictionary *annotationViewReuseQueueByIdentifier; +- (void)setNeedsRerender; +- (UIEdgeInsets)defaultEdgeInsetsForShowAnnotations; +@end + +@interface MGLStyle (MBXViewController) +@property (nonatomic, readonly, copy) NSArray<MGLVectorStyleLayer *> *roadStyleLayers; @end @implementation MBXViewController @@ -248,6 +256,12 @@ CLLocationCoordinate2D randomWorldCoordinate() { { [super viewDidLoad]; + self.pendingIdleBlocks = [NSMutableArray array]; + self.log = os_log_create("com.mapbox.iosapp", "MBXViewController"); + if (@available(iOS 12.0, *)) { + self.signpost = os_signpost_id_generate(self.log); + } + // Keep track of current map state and debug preferences, // saving and restoring when the application's state changes. self.currentState = [MBXStateManager sharedManager].currentState; @@ -403,6 +417,7 @@ CLLocationCoordinate2D randomWorldCoordinate() { @"Add Test Shapes", @"Add Point With Custom Callout", @"Query Annotations", + @"Query Roads around DC", [NSString stringWithFormat:@"%@ Custom User Dot", (_customUserLocationAnnnotationEnabled ? @"Disable" : @"Enable")], @"Remove Annotations", @"Select an offscreen point annotation", @@ -525,22 +540,22 @@ CLLocationCoordinate2D randomWorldCoordinate() { switch (indexPath.row) { case MBXSettingsAnnotations100Views: - [self parseFeaturesAddingCount:100 usingViews:YES]; + [self parseFeaturesAddingCount:100 usingViews:YES completionHandler:NULL]; break; case MBXSettingsAnnotations1000Views: - [self parseFeaturesAddingCount:1000 usingViews:YES]; + [self parseFeaturesAddingCount:1000 usingViews:YES completionHandler:NULL]; break; case MBXSettingsAnnotations10000Views: - [self parseFeaturesAddingCount:10000 usingViews:YES]; + [self parseFeaturesAddingCount:10000 usingViews:YES completionHandler:NULL]; break; case MBXSettingsAnnotations100Sprites: - [self parseFeaturesAddingCount:100 usingViews:NO]; + [self parseFeaturesAddingCount:100 usingViews:NO completionHandler:NULL]; break; case MBXSettingsAnnotations1000Sprites: - [self parseFeaturesAddingCount:1000 usingViews:NO]; + [self parseFeaturesAddingCount:1000 usingViews:NO completionHandler:NULL]; break; case MBXSettingsAnnotations10000Sprites: - [self parseFeaturesAddingCount:10000 usingViews:NO]; + [self parseFeaturesAddingCount:10000 usingViews:NO completionHandler:NULL]; break; case MBXSettingsAnnotationAnimation: [self animateAnnotationView]; @@ -554,6 +569,18 @@ CLLocationCoordinate2D randomWorldCoordinate() { case MBXSettingsAnnotationsQueryAnnotations: [self testQueryPointAnnotations]; break; + + case MBXSettingsAnnotationsQueryRoadsAroundDC: + { + __weak __typeof__(self) weakSelf = self; + [self parseFeaturesAddingCount:100 usingViews:YES completionHandler:^{ + [self.mapView setNeedsRerender]; + [self.pendingIdleBlocks addObject:^{ + [weakSelf queryRoads]; + }]; + }]; + } + break; case MBXSettingsAnnotationsCustomUserDot: [self toggleCustomUserDot]; break; @@ -810,7 +837,7 @@ CLLocationCoordinate2D randomWorldCoordinate() { #pragma mark - Debugging Actions -- (void)parseFeaturesAddingCount:(NSUInteger)featuresCount usingViews:(BOOL)useViews +- (void)parseFeaturesAddingCount:(NSUInteger)featuresCount usingViews:(BOOL)useViews completionHandler:(nullable dispatch_block_t)completion { [self.mapView removeAnnotations:self.mapView.annotations]; @@ -845,22 +872,11 @@ CLLocationCoordinate2D randomWorldCoordinate() { dispatch_async(dispatch_get_main_queue(), ^ { [self.mapView addAnnotations:annotations]; - - signpostlog = os_log_create("com.mapbox.iosapp", "qrf"); - signpost = os_signpost_id_generate(signpostlog); - - -// [self.mapView showAnnotations:annotations animated:YES]; - - os_signpost_interval_begin(signpostlog, signpost, "show-annotations"); - [self.mapView showAnnotations:annotations edgePadding:UIEdgeInsetsZero animated:YES completionHandler:^{ - os_signpost_interval_end(signpostlog, signpost, "show-annotations"); - - // Idle till after all tile parsing/rendering is done (don't want a busy CPU) - [self.mapView setNeedsRerender]; - queryForRoads = YES; - }]; - + UIEdgeInsets insets = [self.mapView defaultEdgeInsetsForShowAnnotations]; + [self.mapView showAnnotations:annotations + edgePadding:insets + animated:YES + completionHandler:completion]; }); } }); @@ -1744,6 +1760,21 @@ CLLocationCoordinate2D randomWorldCoordinate() { return backupImage; } +#pragma mark - Query Rendered Features + +- (void)queryRoads +{ + OS_SIGNPOST_BEGIN("query-roads"); + + NSArray *roadStyleLayerIdentifiers = [self.mapView.style.roadStyleLayers valueForKey:@"identifier"]; + NSArray *visibleRoadFeatures = [self.mapView visibleFeaturesInRect:self.mapView.bounds inStyleLayersWithIdentifiers:[NSSet setWithArray:roadStyleLayerIdentifiers]]; + + OS_SIGNPOST_END("query-roads"); + OS_SIGNPOST_EVENT("query-roads-count", "%lu", (unsigned long)visibleRoadFeatures.count); + + NSLog(@"Roads & labels feature count: %lu", (unsigned long)visibleRoadFeatures.count); +} + #pragma mark - Random World Tour - (void)addAnnotations:(NSInteger)numAnnotations aroundCoordinate:(CLLocationCoordinate2D)coordinate radius:(CLLocationDistance)radius { @@ -2029,14 +2060,11 @@ CLLocationCoordinate2D randomWorldCoordinate() { - (void)mapViewDidBecomeIdle:(MGLMapView *)mapView { - if (queryForRoads) - { - os_signpost_interval_begin(signpostlog, signpost, "query-roads"); - NSArray *roadStyleLayerIdentifiers = [self.mapView.style.roadStyleLayers valueForKey:@"identifier"]; - NSArray *visibleRoadFeatures = [self.mapView visibleFeaturesInRect:self.mapView.bounds inStyleLayersWithIdentifiers:[NSSet setWithArray:roadStyleLayerIdentifiers]]; - os_signpost_interval_end(signpostlog, signpost, "query-roads"); - os_signpost_event_emit(signpostlog, signpost, "query-roads-count", "%ld", visibleRoadFeatures.count); - queryForRoads = YES; + NSArray *blocks = [self.pendingIdleBlocks copy]; + [self.pendingIdleBlocks removeAllObjects]; + + for (dispatch_block_t block in blocks) { + block(); } } diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index fc437084b8..5a5cb00b49 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -3951,7 +3951,6 @@ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = NO; DEVELOPMENT_TEAM = GJZR2MEM28; INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGL; PRODUCT_NAME = "Mapbox GL"; @@ -3990,7 +3989,6 @@ ); INFOPLIST_FILE = framework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", @@ -4305,7 +4303,6 @@ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = NO; DEVELOPMENT_TEAM = GJZR2MEM28; INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGL; PRODUCT_NAME = "Mapbox GL"; @@ -4320,7 +4317,6 @@ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = NO; DEVELOPMENT_TEAM = GJZR2MEM28; INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGL; PRODUCT_NAME = "Mapbox GL"; @@ -4406,7 +4402,6 @@ ); INFOPLIST_FILE = framework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", @@ -4455,7 +4450,6 @@ ); INFOPLIST_FILE = framework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index d242feb38d..a4616e5f7e 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -5173,14 +5173,19 @@ public: completion:NULL]; } -- (void)showAnnotations:(NSArray<id <MGLAnnotation>> *)annotations animated:(BOOL)animated +- (UIEdgeInsets)defaultEdgeInsetsForShowAnnotations { CGFloat maximumPadding = 100; CGFloat yPadding = (self.frame.size.height / 5 <= maximumPadding) ? (self.frame.size.height / 5) : maximumPadding; CGFloat xPadding = (self.frame.size.width / 5 <= maximumPadding) ? (self.frame.size.width / 5) : maximumPadding; - + UIEdgeInsets edgeInsets = UIEdgeInsetsMake(yPadding, xPadding, yPadding, xPadding); + return edgeInsets; +} +- (void)showAnnotations:(NSArray<id <MGLAnnotation>> *)annotations animated:(BOOL)animated +{ + UIEdgeInsets edgeInsets = [self defaultEdgeInsetsForShowAnnotations]; [self showAnnotations:annotations edgePadding:edgeInsets animated:animated completionHandler:nil]; } |