[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.
This commit is contained in:
committed by
Minh Nguyễn
parent
c86646519a
commit
bf87eaa7b8
@@ -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());
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user