summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Wray <jason@mapbox.com>2018-01-17 19:56:42 -0500
committerJason Wray <jason@mapbox.com>2018-01-18 13:59:43 -0500
commit42845ad63fc2147426b6379ed4acd51d3328a0e4 (patch)
treee6fe8d1f9fc8ab4bfce3e253fd8d2c019a229920
parentb863871bf245cf78c4ecbbe3ccfbb2b3e0950760 (diff)
downloadqtlocation-mapboxgl-42845ad63fc2147426b6379ed4acd51d3328a0e4.tar.gz
[ios] Optimize MGLAnnotationView scale transform when not pitchedupstream/fb-unpitched-annotation-view-scaling
-rw-r--r--platform/ios/CHANGELOG.md4
-rw-r--r--platform/ios/src/MGLAnnotationView.h4
-rw-r--r--platform/ios/src/MGLAnnotationView.mm13
3 files changed, 18 insertions, 3 deletions
diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md
index e1e142fc14..0172ad7afb 100644
--- a/platform/ios/CHANGELOG.md
+++ b/platform/ios/CHANGELOG.md
@@ -17,6 +17,10 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Fixed a memory leak that occurred when creating a map snapshot. ([#10585](https://github.com/mapbox/mapbox-gl-native/pull/10585))
+### Annotations
+
+* Improved performance of `MGLAnnotationView`-backed annotations that have `scalesWithViewingDistance` enabled. ([#10951](https://github.com/mapbox/mapbox-gl-native/pull/10951))
+
### Other changes
* Long-pressing the attribution button causes the SDK’s version number to be displayed in the action sheet that appears. ([#10650](https://github.com/mapbox/mapbox-gl-native/pull/10650))
diff --git a/platform/ios/src/MGLAnnotationView.h b/platform/ios/src/MGLAnnotationView.h
index 4fa0f196ab..8006ec3e40 100644
--- a/platform/ios/src/MGLAnnotationView.h
+++ b/platform/ios/src/MGLAnnotationView.h
@@ -171,6 +171,10 @@ MGL_EXPORT
The default value of this property is `YES`. Set this property to `NO` if the
view’s legibility is important.
+
+ @note Scaling many on-screen annotation views can contribute to poor map
+ performance. Consider disabling this property if your use case involves
+ hundreds or thousands of annotation views.
*/
@property (nonatomic, assign) BOOL scalesWithViewingDistance;
diff --git a/platform/ios/src/MGLAnnotationView.mm b/platform/ios/src/MGLAnnotationView.mm
index 94d0649413..4585479582 100644
--- a/platform/ios/src/MGLAnnotationView.mm
+++ b/platform/ios/src/MGLAnnotationView.mm
@@ -12,6 +12,7 @@
@property (nonatomic, readwrite, nullable) NSString *reuseIdentifier;
@property (nonatomic, readwrite) CATransform3D lastAppliedScaleTransform;
@property (nonatomic, readwrite) CATransform3D lastAppliedRotateTransform;
+@property (nonatomic, readwrite) CGFloat lastPitch;
@property (nonatomic, weak) UIPanGestureRecognizer *panGestureRecognizer;
@property (nonatomic, weak) UILongPressGestureRecognizer *longPressRecognizer;
@property (nonatomic, weak) MGLMapView *mapView;
@@ -137,12 +138,18 @@
// along the y axis of its superview.
CGFloat maxScaleReduction = 1.0 - self.center.y / superviewHeight;
+ // Since it is possible for the map view to report a pitch less than 0 due to the nature of
+ // how the gesture information is captured, the value is guarded with MAX.
+ CGFloat pitch = MAX(self.mapView.camera.pitch, 0);
+
+ // Return early if the map view currently has no pitch and was not previously pitched.
+ if (!pitch && !_lastPitch) return;
+ _lastPitch = pitch;
+
// The pitch intensity represents how much the map view is actually pitched compared to
// what is possible. The value will range from 0% (not pitched at all) to 100% (pitched as much
// as the map view will allow). The map view's maximum pitch is defined in `mbgl::util::PITCH_MAX`.
- // Since it is possible for the map view to report a pitch less than 0 due to the nature of
- // how the gesture information is captured, the value is guarded with MAX.
- CGFloat pitchIntensity = MAX(self.mapView.camera.pitch, 0) / MGLDegreesFromRadians(mbgl::util::PITCH_MAX);
+ CGFloat pitchIntensity = pitch / MGLDegreesFromRadians(mbgl::util::PITCH_MAX);
// The pitch adjusted scale is the inverse proportion of the maximum possible scale reduction
// multiplied by the pitch intensity. For example, if the maximum scale reduction is 75% and the