diff options
author | Jesse Bounds <jesse@rebounds.net> | 2016-11-01 11:48:09 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-01 11:48:09 -0700 |
commit | 2901bc0f6825f426cbcfd2a9ed78648dc81ab665 (patch) | |
tree | d3a050b065d3184db70c5726b4b1c5568c239624 /platform/ios/app/MBXViewController.m | |
parent | 8ffd1f69252d28bf501d5464ac9e5f6ff8942c89 (diff) | |
download | qtlocation-mapboxgl-2901bc0f6825f426cbcfd2a9ed78648dc81ab665.tar.gz |
Optimize annotation view updates (#5987)
Use queryPointAnnotations to drive annotation view updates
- Get sets of visible and offscreen annotations using the mbgl query
mechanism and updates and enqueues as required
- Query viewport adjusted if tilted (avoid apparent issue with
queryPointAnnotations when the query box is larger than the actual
viewport)
- Add a small debugging display in iOS app to see annotations going in
and out of the reuse queue
This also works around a performance issue that made getting an annotation
context expensive by implementing a map of annotations to tags. It works
around another issue with the underlying mbgl query so that even if it (rarely)
returns an incorrect result, the correct visual effect still occurs and the reuse
queue is added to and drained as expected.
Finally, this refactors MGLMapView viewForAnnotation: to use the maps to
access the requested annotation context and view. This avoids a more
expensive lookup done previously.
Along for the ride: sync up the ios and macos names (and types) for
MGLAnnotationTagContextMap
Diffstat (limited to 'platform/ios/app/MBXViewController.m')
-rw-r--r-- | platform/ios/app/MBXViewController.m | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index e8a78abff1..6eae0ef777 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -74,7 +74,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsRuntimeStylingRows) { }; typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { - MBXSettingsMiscellaneousWorldTour = 0, + MBXSettingsMiscellaneousShowReuseQueueStats = 0, + MBXSettingsMiscellaneousWorldTour, MBXSettingsMiscellaneousCustomUserDot, MBXSettingsMiscellaneousPrintLogFile, MBXSettingsMiscellaneousDeleteLogFile, @@ -102,11 +103,21 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { UITableViewDataSource, MGLMapViewDelegate> + @property (nonatomic) IBOutlet MGLMapView *mapView; +@property (weak, nonatomic) IBOutlet UILabel *hudLabel; @property (nonatomic) NSInteger styleIndex; @property (nonatomic) BOOL debugLoggingEnabled; @property (nonatomic) BOOL customUserLocationAnnnotationEnabled; @property (nonatomic) BOOL usingLocaleBasedCountryLabels; +@property (nonatomic) BOOL reuseQueueStatsEnabled; + +@end + +@interface MGLMapView (MBXViewController) + +@property (nonatomic) BOOL usingLocaleBasedCountryLabels; +@property (nonatomic) NSDictionary *annotationViewReuseQueueByIdentifier; @end @@ -140,6 +151,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self restoreState:nil]; self.debugLoggingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsDebugLoggingEnabled"]; + self.hudLabel.hidden = YES; if ([MGLAccountManager accessToken].length) { @@ -323,6 +335,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { ]]; break; case MBXSettingsMiscellaneous: + [settingsTitles addObject:@"Show Reuse Queue Stats"]; + [settingsTitles addObjectsFromArray:@[ @"Start World Tour", [NSString stringWithFormat:@"%@ Custom User Dot", (_customUserLocationAnnnotationEnabled ? @"Disable" : @"Enable")], @@ -335,6 +349,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { @"Delete Telemetry Logfile", ]]; }; + break; default: NSAssert(NO, @"All settings sections should be implemented"); @@ -495,6 +510,12 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { case MBXSettingsMiscellaneousDeleteLogFile: [self deleteTelemetryLogFile]; break; + case MBXSettingsMiscellaneousShowReuseQueueStats: + { + self.reuseQueueStatsEnabled = YES; + self.hudLabel.hidden = NO; + break; + } default: NSAssert(NO, @"All miscellaneous setting rows should be implemented"); break; @@ -1506,9 +1527,24 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { - (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { // Default Mapbox styles use {name_en} as their label language, which means + NSUInteger queuedAnnotations = 0; // that a device with an English-language locale is already effectively + { // using locale-based country labels. + } _usingLocaleBasedCountryLabels = [[self bestLanguageForUser] isEqualToString:@"en"]; } +- (void)mapViewRegionIsChanging:(MGLMapView *)mapView +{ + if (self.reuseQueueStatsEnabled) { + NSUInteger queuedAnnotations = 0; + for (NSArray *queue in self.mapView.annotationViewReuseQueueByIdentifier.allValues) + { + queuedAnnotations += queue.count; + } + self.hudLabel.text = [NSString stringWithFormat:@"Visible: %ld Queued: %ld", (long)mapView.visibleAnnotations.count, (long)queuedAnnotations]; + } +} + @end |