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

Commit

Permalink
Revert "[ios] Removed MGLAnnotationView.flat"
Browse files Browse the repository at this point in the history
This reverts commit f2fdc23.
  • Loading branch information
1ec5 committed Jul 10, 2016
1 parent 71014fb commit 86b3470
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions platform/ios/Mapbox.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class MapDelegate: NSObject, MGLMapViewDelegate {
let av = PlaygroundAnnotationView(reuseIdentifier: "annotation")
av.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
av.centerOffset = CGVector(dx: -15, dy: -15)
av.flat = true
let centerView = UIView(frame: CGRectInset(av.bounds, 3, 3))
centerView.backgroundColor = UIColor.whiteColor()
av.addSubview(centerView)
Expand Down
4 changes: 4 additions & 0 deletions platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,10 @@ - (MGLAnnotationView *)mapView:(MGLMapView *)mapView viewForAnnotation:(id<MGLAn
annotationView = [[MBXAnnotationView alloc] initWithReuseIdentifier:MBXViewControllerAnnotationViewReuseIdentifer];
annotationView.frame = CGRectMake(0, 0, 10, 10);
annotationView.backgroundColor = [UIColor whiteColor];

// uncomment to flatten the annotation view against the map when the map is tilted
// this currently causes severe performance issues when more than 2k annotations are visible
// annotationView.flat = YES;

// uncomment to make the annotation view draggable
// also note that having two long press gesture recognizers on overlapping views (`self.view` & `annotationView`) will cause weird behaviour
Expand Down
15 changes: 15 additions & 0 deletions platform/ios/src/MGLAnnotationView.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ typedef NS_ENUM(NSUInteger, MGLAnnotationViewDragState) {
*/
@property (nonatomic) CGVector centerOffset;

/**
A Boolean value indicating whether the view lies flat against the map as it
tilts.
If this option is unset, the annotation view remains unchanged as the map’s
pitch increases, so that the view appears to stand upright on the tilted map.
If this option is set, the annotation view tilts as the map’s pitch increases,
so that the view appears to lie flat against the tilted map.
For example, you would set this option if the annotation view depicts an arrow
that should always point due south. You would unset this option if the arrow
should always point down towards the ground.
*/
@property (nonatomic, assign, getter=isFlat) BOOL flat;

/**
A Boolean value that determines whether the annotation view grows and shrinks
as the distance between the viewpoint and the annotation view changes on a
Expand Down
12 changes: 6 additions & 6 deletions platform/ios/src/MGLAnnotationView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ - (void)updateTransform
}

self.layer.transform = CATransform3DIdentity;
if ( ! self.scalesWithViewingDistance)
MGLMapCamera *camera = self.mapView.camera;
if (self.flat)
{
return;
self.layer.transform = CATransform3DRotate(self.layer.transform, MGLRadiansFromDegrees(camera.pitch), 1.0, 0, 0);
}

CGFloat superviewHeight = CGRectGetHeight(self.superview.frame);
if (superviewHeight > 0.0) {
if ( ! self.scalesWithViewingDistance && superviewHeight > 0.0) {
// Find the maximum amount of scale reduction to apply as the view's center moves from the top
// of the superview to the bottom. For example, if this view's center has moved 25% of the way
// from the top of the superview towards the bottom then the maximum scale reduction is 1 - .25
Expand All @@ -108,16 +109,15 @@ - (void)updateTransform
// 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 = MAX(camera.pitch, 0) / 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
// map view is 50% pitched then the annotation view should be reduced by 37.5% (.75 * .5). The
// reduction is then normalized for a scale of 1.0.
CGFloat pitchAdjustedScale = 1.0 - maxScaleReduction * pitchIntensity;

CATransform3D transform = self.layer.transform;
self.layer.transform = CATransform3DScale(transform, pitchAdjustedScale, pitchAdjustedScale, 1);
self.layer.transform = CATransform3DScale(self.layer.transform, pitchAdjustedScale, pitchAdjustedScale, 1);
}
}

Expand Down

0 comments on commit 86b3470

Please sign in to comment.