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

Commit 2901bc0

Browse files
authored
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
1 parent 8ffd1f6 commit 2901bc0

File tree

5 files changed

+161
-55
lines changed

5 files changed

+161
-55
lines changed

platform/ios/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
4646
### Annotations
4747

4848
* MGLPolyline annotations and the exterior coordinates of MGLPolygon annotations are now able to be mutated, part or all, and changes are displayed immediately. ([#6565](https://github.com/mapbox/mapbox-gl-native/pull/6565))
49+
* Fixed an issue causing offscreen annotation views to be updated even when they were in the reuse queue. ([#5987](https://github.com/mapbox/mapbox-gl-native/pull/5987))
4950
* Fixed an issue preventing MGLAnnotationView from animating when its coordinate changes. ([#6215](https://github.com/mapbox/mapbox-gl-native/pull/6215))
5051
* Fixed an issue causing the wrong annotation view to be selected when tapping an annotation view with a center offset applied. ([#5931](https://github.com/mapbox/mapbox-gl-native/pull/5931))
5152
* Fixed an issue that assigned annotation views to polyline and polygon annotations. ([#5770](https://github.com/mapbox/mapbox-gl-native/pull/5770))

platform/ios/app/MBXViewController.m

+37-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsRuntimeStylingRows) {
7474
};
7575

7676
typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
77-
MBXSettingsMiscellaneousWorldTour = 0,
77+
MBXSettingsMiscellaneousShowReuseQueueStats = 0,
78+
MBXSettingsMiscellaneousWorldTour,
7879
MBXSettingsMiscellaneousCustomUserDot,
7980
MBXSettingsMiscellaneousPrintLogFile,
8081
MBXSettingsMiscellaneousDeleteLogFile,
@@ -102,11 +103,21 @@ @interface MBXViewController () <UITableViewDelegate,
102103
UITableViewDataSource,
103104
MGLMapViewDelegate>
104105

106+
105107
@property (nonatomic) IBOutlet MGLMapView *mapView;
108+
@property (weak, nonatomic) IBOutlet UILabel *hudLabel;
106109
@property (nonatomic) NSInteger styleIndex;
107110
@property (nonatomic) BOOL debugLoggingEnabled;
108111
@property (nonatomic) BOOL customUserLocationAnnnotationEnabled;
109112
@property (nonatomic) BOOL usingLocaleBasedCountryLabels;
113+
@property (nonatomic) BOOL reuseQueueStatsEnabled;
114+
115+
@end
116+
117+
@interface MGLMapView (MBXViewController)
118+
119+
@property (nonatomic) BOOL usingLocaleBasedCountryLabels;
120+
@property (nonatomic) NSDictionary *annotationViewReuseQueueByIdentifier;
110121

111122
@end
112123

@@ -140,6 +151,7 @@ - (void)viewDidLoad
140151
[self restoreState:nil];
141152

142153
self.debugLoggingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsDebugLoggingEnabled"];
154+
self.hudLabel.hidden = YES;
143155

144156
if ([MGLAccountManager accessToken].length)
145157
{
@@ -323,6 +335,8 @@ - (void)dismissSettings:(__unused id)sender
323335
]];
324336
break;
325337
case MBXSettingsMiscellaneous:
338+
[settingsTitles addObject:@"Show Reuse Queue Stats"];
339+
326340
[settingsTitles addObjectsFromArray:@[
327341
@"Start World Tour",
328342
[NSString stringWithFormat:@"%@ Custom User Dot", (_customUserLocationAnnnotationEnabled ? @"Disable" : @"Enable")],
@@ -335,6 +349,7 @@ - (void)dismissSettings:(__unused id)sender
335349
@"Delete Telemetry Logfile",
336350
]];
337351
};
352+
338353
break;
339354
default:
340355
NSAssert(NO, @"All settings sections should be implemented");
@@ -495,6 +510,12 @@ - (void)performActionForSettingAtIndexPath:(NSIndexPath *)indexPath
495510
case MBXSettingsMiscellaneousDeleteLogFile:
496511
[self deleteTelemetryLogFile];
497512
break;
513+
case MBXSettingsMiscellaneousShowReuseQueueStats:
514+
{
515+
self.reuseQueueStatsEnabled = YES;
516+
self.hudLabel.hidden = NO;
517+
break;
518+
}
498519
default:
499520
NSAssert(NO, @"All miscellaneous setting rows should be implemented");
500521
break;
@@ -1506,9 +1527,24 @@ - (void)mapView:(MGLMapView *)mapView tapOnCalloutForAnnotation:(id <MGLAnnotati
15061527
- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style
15071528
{
15081529
// Default Mapbox styles use {name_en} as their label language, which means
1530+
NSUInteger queuedAnnotations = 0;
15091531
// that a device with an English-language locale is already effectively
1532+
{
15101533
// using locale-based country labels.
1534+
}
15111535
_usingLocaleBasedCountryLabels = [[self bestLanguageForUser] isEqualToString:@"en"];
15121536
}
15131537

1538+
- (void)mapViewRegionIsChanging:(MGLMapView *)mapView
1539+
{
1540+
if (self.reuseQueueStatsEnabled) {
1541+
NSUInteger queuedAnnotations = 0;
1542+
for (NSArray *queue in self.mapView.annotationViewReuseQueueByIdentifier.allValues)
1543+
{
1544+
queuedAnnotations += queue.count;
1545+
}
1546+
self.hudLabel.text = [NSString stringWithFormat:@"Visible: %ld Queued: %ld", (long)mapView.visibleAnnotations.count, (long)queuedAnnotations];
1547+
}
1548+
}
1549+
15141550
@end

platform/ios/app/Main.storyboard

+38-24
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="PSe-Ot-7Ff">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="PSe-Ot-7Ff">
33
<dependencies>
44
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
6+
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
67
<capability name="Navigation items with more than one left or right bar item" minToolsVersion="7.0"/>
8+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
79
</dependencies>
810
<scenes>
911
<!--Map View Controller-->
@@ -15,24 +17,35 @@
1517
<viewControllerLayoutGuide type="bottom" id="m8o-i7-QIy"/>
1618
</layoutGuides>
1719
<view key="view" contentMode="scaleToFill" id="Z9X-fc-PUC">
18-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
20+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1921
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2022
<subviews>
2123
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="kNe-zV-9ha" customClass="MGLMapView">
22-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
23-
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
24+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2425
<gestureRecognizers/>
2526
<connections>
2627
<outlet property="delegate" destination="WaX-pd-UZQ" id="za0-3B-qR6"/>
2728
<outletCollection property="gestureRecognizers" destination="lfd-mn-7en" appends="YES" id="0PH-gH-GRm"/>
2829
</connections>
2930
</view>
31+
<label opaque="NO" userInteractionEnabled="NO" alpha="0.69999999999999996" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="58y-pX-YyB">
32+
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
33+
<constraints>
34+
<constraint firstAttribute="width" constant="180" id="OL2-l5-I2f"/>
35+
<constraint firstAttribute="height" constant="21" id="xHg-ye-wzT"/>
36+
</constraints>
37+
<fontDescription key="fontDescription" type="system" pointSize="8"/>
38+
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
39+
<nil key="highlightedColor"/>
40+
</label>
3041
</subviews>
31-
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
42+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
3243
<constraints>
3344
<constraint firstItem="kNe-zV-9ha" firstAttribute="leading" secondItem="Z9X-fc-PUC" secondAttribute="leading" id="53e-Tz-QxF"/>
3445
<constraint firstItem="kNe-zV-9ha" firstAttribute="bottom" secondItem="m8o-i7-QIy" secondAttribute="top" id="Etp-BC-E1N"/>
3546
<constraint firstAttribute="trailing" secondItem="kNe-zV-9ha" secondAttribute="trailing" id="MGr-8G-VEb"/>
47+
<constraint firstItem="58y-pX-YyB" firstAttribute="trailing" secondItem="Z9X-fc-PUC" secondAttribute="trailingMargin" id="O3a-bR-boI"/>
48+
<constraint firstItem="m8o-i7-QIy" firstAttribute="top" secondItem="58y-pX-YyB" secondAttribute="bottom" constant="20" id="cjh-ZS-Mv4"/>
3649
<constraint firstItem="kNe-zV-9ha" firstAttribute="top" secondItem="Z9X-fc-PUC" secondAttribute="top" id="qMm-e9-jxH"/>
3750
</constraints>
3851
</view>
@@ -47,7 +60,7 @@
4760
</connections>
4861
</barButtonItem>
4962
<button key="titleView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="KsN-ny-Hou">
50-
<rect key="frame" x="180" y="7" width="240" height="30"/>
63+
<rect key="frame" x="61" y="7" width="207" height="30"/>
5164
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
5265
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="17"/>
5366
<state key="normal" title="Streets"/>
@@ -75,6 +88,7 @@
7588
</rightBarButtonItems>
7689
</navigationItem>
7790
<connections>
91+
<outlet property="hudLabel" destination="58y-pX-YyB" id="MEh-ir-3IH"/>
7892
<outlet property="mapView" destination="kNe-zV-9ha" id="VNR-WO-1q4"/>
7993
</connections>
8094
</viewController>
@@ -85,60 +99,60 @@
8599
</connections>
86100
</pongPressGestureRecognizer>
87101
</objects>
88-
<point key="canvasLocation" x="1366" y="350"/>
102+
<point key="canvasLocation" x="1365.5999999999999" y="349.47526236881561"/>
89103
</scene>
90104
<!--Offline Packs-->
91105
<scene sceneID="xIg-PA-7r3">
92106
<objects>
93107
<tableViewController id="7q0-lI-zqb" customClass="MBXOfflinePacksTableViewController" sceneMemberID="viewController">
94108
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="eeN-6b-zqe">
95-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
109+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
96110
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
97-
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
111+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
98112
<prototypes>
99113
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Inactive" editingAccessoryType="detailDisclosureButton" textLabel="JtH-Ce-MI5" detailTextLabel="tTJ-jv-U9v" style="IBUITableViewCellStyleSubtitle" id="fGu-Ys-Eh1">
100-
<rect key="frame" x="0.0" y="92" width="600" height="44"/>
114+
<rect key="frame" x="0.0" y="92" width="375" height="44"/>
101115
<autoresizingMask key="autoresizingMask"/>
102116
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="fGu-Ys-Eh1" id="sUf-bc-8xG">
103-
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
117+
<frame key="frameInset" width="375" height="43.5"/>
104118
<autoresizingMask key="autoresizingMask"/>
105119
<subviews>
106120
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="My Inactive Offline Pack" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="JtH-Ce-MI5">
107-
<rect key="frame" x="15" y="6" width="174.5" height="19.5"/>
121+
<frame key="frameInset" minX="15" minY="6" width="174.5" height="19.5"/>
108122
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
109123
<fontDescription key="fontDescription" type="system" pointSize="16"/>
110-
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
124+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
111125
<nil key="highlightedColor"/>
112126
</label>
113127
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="456 resources (789 MB)" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="tTJ-jv-U9v">
114-
<rect key="frame" x="15" y="25.5" width="128" height="13.5"/>
128+
<frame key="frameInset" minX="15" minY="25.5" width="128" height="13.5"/>
115129
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
116130
<fontDescription key="fontDescription" type="system" pointSize="11"/>
117-
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
131+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
118132
<nil key="highlightedColor"/>
119133
</label>
120134
</subviews>
121135
</tableViewCellContentView>
122136
</tableViewCell>
123137
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Active" editingAccessoryType="detailDisclosureButton" textLabel="9ZK-gS-wJ4" detailTextLabel="0xK-p8-Mmh" style="IBUITableViewCellStyleSubtitle" id="mKB-tz-Zfl">
124-
<rect key="frame" x="0.0" y="136" width="600" height="44"/>
138+
<rect key="frame" x="0.0" y="136" width="375" height="44"/>
125139
<autoresizingMask key="autoresizingMask"/>
126140
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="mKB-tz-Zfl" id="nS3-aU-nBr">
127-
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
141+
<frame key="frameInset" width="375" height="43.5"/>
128142
<autoresizingMask key="autoresizingMask"/>
129143
<subviews>
130144
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="My Active Offline Pack" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="9ZK-gS-wJ4">
131-
<rect key="frame" x="15" y="6" width="163" height="19.5"/>
145+
<frame key="frameInset" minX="15" minY="6" width="163" height="19.5"/>
132146
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
133147
<fontDescription key="fontDescription" type="system" pointSize="16"/>
134-
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
148+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
135149
<nil key="highlightedColor"/>
136150
</label>
137151
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Downloading 123 of 456 resources… (789 MB downloaded)" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="0xK-p8-Mmh">
138-
<rect key="frame" x="15" y="25.5" width="310.5" height="13.5"/>
152+
<frame key="frameInset" minX="15" minY="25.5" width="310.5" height="13.5"/>
139153
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
140154
<fontDescription key="fontDescription" type="system" pointSize="11"/>
141-
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
155+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
142156
<nil key="highlightedColor"/>
143157
</label>
144158
</subviews>
@@ -189,5 +203,5 @@
189203
<image name="TrackingLocationOffMask.png" width="23" height="23"/>
190204
<image name="settings.png" width="28" height="28"/>
191205
</resources>
192-
<color key="tintColor" red="0.12156862745098039" green="0.5490196078431373" blue="0.6705882352941176" alpha="1" colorSpace="calibratedRGB"/>
206+
<color key="tintColor" red="0.12156862745098039" green="0.5490196078431373" blue="0.6705882352941176" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
193207
</document>

0 commit comments

Comments
 (0)