diff options
author | Dave Prukop <dave.prukop@mapbox.com> | 2018-07-31 11:14:56 -0700 |
---|---|---|
committer | Dave Prukop <dave.prukop@mapbox.com> | 2018-08-02 14:53:35 -0700 |
commit | 54a76099d5969b86944b02bddddcef7b90b99a18 (patch) | |
tree | bc279456a62e742518829659f7047577b40876bf | |
parent | a5fea5febf908c8cc94222bdbccf53afafc0c1dd (diff) | |
download | qtlocation-mapboxgl-54a76099d5969b86944b02bddddcef7b90b99a18.tar.gz |
Map view can now be optionally configured to make pitch adjustments without affecting altitude
-rw-r--r-- | platform/ios/src/MGLMapView.h | 19 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 20 |
2 files changed, 35 insertions, 4 deletions
diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index ddc8be23f0..5af70ebff2 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -556,6 +556,13 @@ MGL_EXPORT IB_DESIGNABLE @property(nonatomic, getter=isHapticFeedbackEnabled) BOOL hapticFeedbackEnabled; /** + A Boolean value that determines whether the updating pitch will also affect the altitude. + + When this property is set to `YES`, pitch will work independently from altitude. + */ +@property(nonatomic, getter=isAltitudeUnaffectedByPitch) BOOL altitudeUnaffectedByPitch; + +/** A floating-point value that determines the rate of deceleration after the user lifts their finger. @@ -952,6 +959,18 @@ MGL_EXPORT IB_DESIGNABLE - (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration peakAltitude:(CLLocationDistance)peakAltitude completionHandler:(nullable void (^)(void))completion; /** + Moves the viewpoint to a different location without using a transition. + + Transition animations can be defined by other classes and use this method to + update the map. + + @param camera The new viewpoint. + @param padding The minimum padding (in screen points) that would be visible + + */ +- (void)jumpToCamera:(MGLMapCamera *)camera edgePadding:(UIEdgeInsets)insets; + +/** Returns the camera that best fits the given coordinate bounds. @param bounds The coordinate bounds to fit to the receiver’s viewport. diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index f772432eb7..c2d81426c0 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -536,6 +536,8 @@ public: [self addGestureRecognizer:_twoFingerTap]; _hapticFeedbackEnabled = YES; + + _altitudeUnaffectedByPitch = NO; _decelerationRate = MGLMapViewDecelerationRateNormal; @@ -2352,7 +2354,8 @@ public: auto camera = _mbglMap->getStyle().getDefaultCamera(); CGFloat pitch = *camera.pitch; CLLocationDirection heading = mbgl::util::wrap(*camera.angle, 0., 360.); - CLLocationDistance distance = MGLAltitudeForZoomLevel(*camera.zoom, pitch, 0, self.frame.size); + CLLocationDegrees pitchForAltitude = self.altitudeUnaffectedByPitch ? 0.0 : pitch; + CLLocationDistance distance = MGLAltitudeForZoomLevel(*camera.zoom, pitchForAltitude, 0, self.frame.size); self.camera = [MGLMapCamera cameraLookingAtCenterCoordinate:MGLLocationCoordinate2DFromLatLng(*camera.center) fromDistance:distance pitch:pitch @@ -3374,6 +3377,12 @@ public: self.cameraChangeReasonBitmask &= ~MGLCameraChangeReasonTransitionCancelled; } +- (void)jumpToCamera:(MGLMapCamera *)camera edgePadding:(UIEdgeInsets)insets +{ + mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera edgePadding:insets]; + _mbglMap->jumpTo(options); +} + - (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds { return [self cameraThatFitsCoordinateBounds:bounds edgePadding:UIEdgeInsetsZero]; @@ -3428,7 +3437,8 @@ public: double zoomLevel = cameraOptions.zoom ? *cameraOptions.zoom : self.zoomLevel; CLLocationDirection direction = cameraOptions.angle ? mbgl::util::wrap(-MGLDegreesFromRadians(*cameraOptions.angle), 0., 360.) : self.direction; CGFloat pitch = cameraOptions.pitch ? MGLDegreesFromRadians(*cameraOptions.pitch) : _mbglMap->getPitch(); - CLLocationDistance altitude = MGLAltitudeForZoomLevel(zoomLevel, pitch, centerCoordinate.latitude, self.frame.size); + CLLocationDegrees pitchForAltitude = self.altitudeUnaffectedByPitch ? 0.0 : pitch; + CLLocationDistance altitude = MGLAltitudeForZoomLevel(zoomLevel, pitchForAltitude, centerCoordinate.latitude, self.frame.size); return [MGLMapCamera cameraLookingAtCenterCoordinate:centerCoordinate fromDistance:altitude pitch:pitch heading:direction]; } @@ -3442,7 +3452,8 @@ public: options.center = MGLLatLngFromLocationCoordinate2D(camera.centerCoordinate); } options.padding = MGLEdgeInsetsFromNSEdgeInsets(insets); - options.zoom = MGLZoomLevelForAltitude(camera.altitude, camera.pitch, + CLLocationDegrees pitch = (self.altitudeUnaffectedByPitch) ? 0.0 : camera.pitch; + options.zoom = MGLZoomLevelForAltitude(camera.altitude, pitch, camera.centerCoordinate.latitude, self.frame.size); if (camera.heading >= 0) @@ -5144,10 +5155,11 @@ public: MGLMapCamera *camera = self.camera; camera.centerCoordinate = self.userLocation.location.coordinate; camera.heading = self.directionByFollowingWithCourse; + CLLocationDegrees pitch = (self.altitudeUnaffectedByPitch) ? 0.0 : camera.pitch; if (self.zoomLevel < MGLMinimumZoomLevelForUserTracking) { camera.altitude = MGLAltitudeForZoomLevel(MGLDefaultZoomLevelForUserTracking, - camera.pitch, + pitch, camera.centerCoordinate.latitude, self.frame.size); } |