diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-01-15 12:01:37 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-01-18 16:54:58 -0800 |
commit | bf87eaa7b8aa049358559a96f290603e13ac736b (patch) | |
tree | c28e725d66d6cee549b72f5f3bb13fbd1f61c6ad | |
parent | c86646519a4887d47003d11061a6a82e7ff4241c (diff) | |
download | qtlocation-mapboxgl-bf87eaa7b8aa049358559a96f290603e13ac736b.tar.gz |
[core, osx] Added optional padding to convenience methods
Methods that offer a convenient way to jump or ease now accept an optional padding parameter. MGLMapView specifies the padding to ensure that keyboard-based zooming and rotation respects the toolbar.
-rw-r--r-- | include/mbgl/map/map.hpp | 8 | ||||
-rw-r--r-- | platform/osx/src/MGLMapView.mm | 19 | ||||
-rw-r--r-- | src/mbgl/map/map.cpp | 37 | ||||
-rw-r--r-- | src/mbgl/map/transform.cpp | 26 | ||||
-rw-r--r-- | src/mbgl/map/transform.hpp | 28 |
5 files changed, 89 insertions, 29 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 3852bb7b6f..feb457758e 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -102,15 +102,17 @@ public: void setLatLng(const LatLng&, const EdgeInsets&, const Duration& = Duration::zero()); void setLatLng(const LatLng&, const Duration& = Duration::zero()); LatLng getLatLng(const EdgeInsets& = {}) const; - void resetPosition(); + void resetPosition(const EdgeInsets& = {}); // Scale void scaleBy(double ds, const PrecisionPoint& = { NAN, NAN }, const Duration& = Duration::zero()); void setScale(double scale, const PrecisionPoint& = { NAN, NAN }, const Duration& = Duration::zero()); double getScale() const; void setZoom(double zoom, const Duration& = Duration::zero()); + void setZoom(double zoom, const EdgeInsets&, const Duration& = Duration::zero()); double getZoom() const; void setLatLngZoom(const LatLng&, double zoom, const Duration& = Duration::zero()); + void setLatLngZoom(const LatLng&, double zoom, const EdgeInsets&, const Duration& = Duration::zero()); CameraOptions cameraForLatLngBounds(const LatLngBounds&, const EdgeInsets&); CameraOptions cameraForLatLngs(const std::vector<LatLng>&, const EdgeInsets&); void resetZoom(); @@ -120,9 +122,11 @@ public: // Rotation void rotateBy(const PrecisionPoint& first, const PrecisionPoint& second, const Duration& = Duration::zero()); void setBearing(double degrees, const Duration& = Duration::zero()); - void setBearing(double degrees, const PrecisionPoint&); + void setBearing(double degrees, const PrecisionPoint&, const Duration& = Duration::zero()); + void setBearing(double degrees, const EdgeInsets&, const Duration& = Duration::zero()); double getBearing() const; void resetNorth(const Duration& = std::chrono::milliseconds(500)); + void resetNorth(const EdgeInsets&, const Duration& = std::chrono::milliseconds(500)); // Pitch void setPitch(double pitch, const Duration& = Duration::zero()); diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm index be52ed84a9..954717e5c4 100644 --- a/platform/osx/src/MGLMapView.mm +++ b/platform/osx/src/MGLMapView.mm @@ -880,13 +880,15 @@ public: } - (void)setZoomLevel:(double)zoomLevel animated:(BOOL)animated { - _mbglMap->setZoom(zoomLevel, MGLDurationInSeconds(animated ? MGLAnimationDuration : 0)); + [self willChangeValueForKey:@"zoomLevel"]; + _mbglMap->setZoom(zoomLevel, + MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets), + MGLDurationInSeconds(animated ? MGLAnimationDuration : 0)); + [self didChangeValueForKey:@"zoomLevel"]; } - (void)zoomBy:(double)zoomDelta animated:(BOOL)animated { - [self willChangeValueForKey:@"zoomLevel"]; - _mbglMap->setZoom(self.zoomLevel + zoomDelta, MGLDurationInSeconds(animated ? MGLAnimationDuration : 0)); - [self didChangeValueForKey:@"zoomLevel"]; + [self setZoomLevel:self.zoomLevel + zoomDelta animated:animated]; } - (void)scaleBy:(double)scaleFactor atPoint:(NSPoint)point animated:(BOOL)animated { @@ -936,15 +938,14 @@ public: - (void)setDirection:(CLLocationDirection)direction animated:(BOOL)animated { [self willChangeValueForKey:@"direction"]; - _mbglMap->setBearing(direction, MGLDurationInSeconds(animated ? MGLAnimationDuration : 0)); + _mbglMap->setBearing(direction, + MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets), + MGLDurationInSeconds(animated ? MGLAnimationDuration : 0)); [self didChangeValueForKey:@"direction"]; } - (void)offsetDirectionBy:(CLLocationDegrees)delta animated:(BOOL)animated { - [self willChangeValueForKey:@"direction"]; - _mbglMap->cancelTransitions(); - _mbglMap->setBearing(_mbglMap->getBearing() + delta, MGLDurationInSeconds(animated ? MGLAnimationDuration : 0)); - [self didChangeValueForKey:@"direction"]; + [self setDirection:_mbglMap->getBearing() + delta animated:animated]; } + (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingCamera { diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index f03915c953..b0cc49968c 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -189,12 +189,15 @@ LatLng Map::getLatLng(const EdgeInsets& padding) const { return transform->getLatLng(padding); } -void Map::resetPosition() { - CameraOptions options; - options.angle = 0; - options.center = LatLng(0, 0); - options.zoom = 0; - transform->jumpTo(options); +void Map::resetPosition(const EdgeInsets& padding) { + CameraOptions camera; + camera.angle = 0; + camera.center = LatLng(0, 0); + if (padding) { + camera.padding = padding; + } + camera.zoom = 0; + transform->jumpTo(camera); update(Update::Zoom); } @@ -216,7 +219,11 @@ double Map::getScale() const { } void Map::setZoom(double zoom, const Duration& duration) { - transform->setZoom(zoom, duration); + setZoom(zoom, {}, duration); +} + +void Map::setZoom(double zoom, const EdgeInsets& padding, const Duration& duration) { + transform->setZoom(zoom, padding, duration); update(Update::Zoom); } @@ -225,7 +232,11 @@ double Map::getZoom() const { } void Map::setLatLngZoom(const LatLng& latLng, double zoom, const Duration& duration) { - transform->setLatLngZoom(latLng, zoom, duration); + setLatLngZoom(latLng, zoom, {}, duration); +} + +void Map::setLatLngZoom(const LatLng& latLng, double zoom, const EdgeInsets& padding, const Duration& duration) { + transform->setLatLngZoom(latLng, zoom, padding, duration); update(Update::Zoom); } @@ -316,12 +327,16 @@ void Map::rotateBy(const PrecisionPoint& first, const PrecisionPoint& second, co } void Map::setBearing(double degrees, const Duration& duration) { - transform->setAngle(-degrees * M_PI / 180, duration); + setBearing(degrees, EdgeInsets(), duration); +} + +void Map::setBearing(double degrees, const PrecisionPoint& center, const Duration& duration) { + transform->setAngle(-degrees * M_PI / 180, center, duration); update(Update::Repaint); } -void Map::setBearing(double degrees, const PrecisionPoint& center) { - transform->setAngle(-degrees * M_PI / 180, center); +void Map::setBearing(double degrees, const EdgeInsets& padding, const Duration& duration) { + transform->setAngle(-degrees * M_PI / 180, padding, duration); update(Update::Repaint); } diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 7596d5d543..69af657ecd 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -397,12 +397,19 @@ void Transform::setLatLng(const LatLng& latLng, const PrecisionPoint& point, con } void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const Duration& duration) { + setLatLngZoom(latLng, zoom, {}, duration); +} + +void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const EdgeInsets& padding, const Duration& duration) { if (!latLng || std::isnan(zoom)) { return; } CameraOptions camera; camera.center = latLng; + if (padding) { + camera.padding = padding; + } camera.zoom = zoom; easeTo(camera, duration); } @@ -429,8 +436,13 @@ void Transform::scaleBy(double ds, const PrecisionPoint& center, const Duration& setScale(scale, center, duration); } -void Transform::setZoom(double zoom, const Duration& duration) { - setScale(state.zoomScale(zoom), {NAN, NAN}, duration); +void Transform::setZoom(double zoom, const PrecisionPoint& anchor, const Duration& duration) { + setScale(state.zoomScale(zoom), anchor, duration); +} + +void Transform::setZoom(double zoom, const EdgeInsets& padding, const Duration& duration) { + const PrecisionPoint center = padding.getCenter(state.width, state.height); + setZoom(zoom, center, duration); } double Transform::getZoom() const { @@ -452,6 +464,11 @@ void Transform::setScale(double scale, const PrecisionPoint& anchor, const Durat easeTo(camera, duration); } +void Transform::setScale(double scale, const EdgeInsets& padding, const Duration& duration) { + const PrecisionPoint center = padding.getCenter(state.width, state.height); + setScale(scale, center, duration); +} + #pragma mark - Angle void Transform::rotateBy(const PrecisionPoint& first, const PrecisionPoint& second, const Duration& duration) { @@ -498,6 +515,11 @@ void Transform::setAngle(double angle, const PrecisionPoint& anchor, const Durat easeTo(camera, duration); } +void Transform::setAngle(double angle, const EdgeInsets& padding, const Duration& duration) { + const PrecisionPoint center = padding.getCenter(state.width, state.height); + setAngle(angle, center, duration); +} + double Transform::getAngle() const { return state.angle; } diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp index 77c03e939d..cb3378a532 100644 --- a/src/mbgl/map/transform.hpp +++ b/src/mbgl/map/transform.hpp @@ -46,21 +46,34 @@ public: void setLatLng(const LatLng&, const EdgeInsets&, const Duration& = Duration::zero()); void setLatLng(const LatLng&, const PrecisionPoint&, const Duration& = Duration::zero()); void setLatLngZoom(const LatLng&, double zoom, const Duration& = Duration::zero()); + void setLatLngZoom(const LatLng&, double zoom, const EdgeInsets&, const Duration& = Duration::zero()); LatLng getLatLng(const EdgeInsets& = {}) const; // Zoom /** Scales the map, keeping the given point fixed within the view. @param ds The difference in scale factors to scale the map by. - @param anchor A point relative to the top-left corner of the view. */ + @param anchor A point relative to the top-left corner of the view. + If unspecified, the center point is fixed within the view. */ void scaleBy(double ds, const PrecisionPoint& anchor = {NAN, NAN}, const Duration& = Duration::zero()); /** Sets the scale factor, keeping the given point fixed within the view. @param scale The new scale factor. - @param anchor A point relative to the top-left corner of the view. */ + @param anchor A point relative to the top-left corner of the view. + If unspecified, the center point is fixed within the view. */ void setScale(double scale, const PrecisionPoint& anchor = {NAN, NAN}, const Duration& = Duration::zero()); - /** Sets the zoom level. - @param zoom The new zoom level. */ - void setZoom(double zoom, const Duration& = Duration::zero()); + /** Sets the scale factor, keeping the center point fixed within the inset view. + @param scale The new scale factor. + @param padding The viewport padding that affects the fixed center point. */ + void setScale(double scale, const EdgeInsets& padding, const Duration& = Duration::zero()); + /** Sets the zoom level, keeping the given point fixed within the view. + @param zoom The new zoom level. + @param anchor A point relative to the top-left corner of the view. + If unspecified, the center point is fixed within the view. */ + void setZoom(double zoom, const PrecisionPoint& anchor = {NAN, NAN}, const Duration& = Duration::zero()); + /** Sets the zoom level, keeping the center point fixed within the inset view. + @param zoom The new zoom level. + @param padding The viewport padding that affects the fixed center point. */ + void setZoom(double zoom, const EdgeInsets& padding, const Duration& = Duration::zero()); /** Returns the zoom level. */ double getZoom() const; /** Returns the scale factor. */ @@ -78,6 +91,11 @@ public: counterclockwise from true north. @param anchor A point relative to the top-left corner of the view. */ void setAngle(double angle, const PrecisionPoint& anchor, const Duration& = Duration::zero()); + /** Sets the angle of rotation, keeping the center point fixed within the inset view. + @param angle The new angle of rotation, measured in radians + counterclockwise from true north. + @param padding The viewport padding that affects the fixed center point. */ + void setAngle(double angle, const EdgeInsets& padding, const Duration& = Duration::zero()); /** Returns the angle of rotation. @return The angle of rotation, measured in radians counterclockwise from true north. */ |