diff options
author | Julian Rex <julian.rex@mapbox.com> | 2019-07-19 14:29:18 -0400 |
---|---|---|
committer | Julian Rex <julian.rex@mapbox.com> | 2019-07-22 11:02:53 -0400 |
commit | 1380f128e46c892fe1f94a76ac43693e804216ab (patch) | |
tree | 8bc31dfea76d1d639cdcf9811efb26c76ddc9036 | |
parent | b7ee6982e6b378bbaa61f90f8e44eb0a17445559 (diff) | |
download | qtlocation-mapboxgl-1380f128e46c892fe1f94a76ac43693e804216ab.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 065d65c663..86a305dd02 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, @@ -230,10 +218,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 @@ -249,6 +257,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; @@ -405,6 +419,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", @@ -535,22 +550,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]; @@ -564,6 +579,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; @@ -830,7 +857,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]; @@ -865,22 +892,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]; }); } }); @@ -1795,6 +1811,21 @@ CLLocationCoordinate2D randomWorldCoordinate() { return filePath; } +#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 { @@ -2080,14 +2111,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 81fb0f0b84..5f0d29a5e7 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -3947,7 +3947,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"; @@ -3986,7 +3985,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)", @@ -4301,7 +4299,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"; @@ -4316,7 +4313,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"; @@ -4402,7 +4398,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)", @@ -4451,7 +4446,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 d77f94d8ba..eb332e7c28 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -5050,14 +5050,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]; } |