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

Commit

Permalink
[core] [android] - allow zooming/scaling to use AnimationOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Feb 23, 2017
1 parent 9ffbfdc commit 839ddeb
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 54 deletions.
14 changes: 7 additions & 7 deletions include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ class Map : private util::noncopyable {
void resetPosition(optional<EdgeInsets> = {});

// Scale
void scaleBy(double ds, optional<ScreenCoordinate> = {}, const Duration& = Duration::zero());
void setScale(double scale, optional<ScreenCoordinate> = {}, const Duration& = Duration::zero());
void scaleBy(double ds, optional<ScreenCoordinate> = {}, const AnimationOptions& = {});
void setScale(double scale, optional<ScreenCoordinate> = {}, const AnimationOptions& = {});
double getScale() const;
void setZoom(double zoom, const Duration& = Duration::zero());
void setZoom(double zoom, optional<ScreenCoordinate>, const Duration& = Duration::zero());
void setZoom(double zoom, optional<EdgeInsets>, const Duration& = Duration::zero());
void setZoom(double zoom, const AnimationOptions& = {});
void setZoom(double zoom, optional<ScreenCoordinate>, const AnimationOptions& = {});
void setZoom(double zoom, optional<EdgeInsets>, const AnimationOptions& = {});
double getZoom() const;
void setLatLngZoom(const LatLng&, double zoom, const Duration& = Duration::zero());
void setLatLngZoom(const LatLng&, double zoom, optional<EdgeInsets>, const Duration& = Duration::zero());
void setLatLngZoom(const LatLng&, double zoom, const AnimationOptions& = {});
void setLatLngZoom(const LatLng&, double zoom, optional<EdgeInsets>, const AnimationOptions& = {});
CameraOptions cameraForLatLngBounds(const LatLngBounds&, optional<EdgeInsets>) const;
CameraOptions cameraForLatLngs(const std::vector<LatLng>&, optional<EdgeInsets>) const;
void resetZoom();
Expand Down
12 changes: 9 additions & 3 deletions platform/android/src/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,15 +558,19 @@ void nativeScaleBy(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdoub
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
mbgl::ScreenCoordinate center(cx, cy);
nativeMapView->getMap().scaleBy(ds, center, mbgl::Milliseconds(duration));
mbgl::AnimationOptions animationOptions;
animationOptions.duration.emplace(mbgl::Milliseconds(duration));
nativeMapView->getMap().scaleBy(ds, center, animationOptions);
}

void nativeSetScale(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdouble scale,
jdouble cx, jdouble cy, jlong duration) {
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
mbgl::ScreenCoordinate center(cx, cy);
nativeMapView->getMap().setScale(scale, center, mbgl::Milliseconds(duration));
mbgl::AnimationOptions animationOptions;
animationOptions.duration.emplace(mbgl::Milliseconds(duration));
nativeMapView->getMap().setScale(scale, center, animationOptions);
}

jdouble nativeGetScale(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr) {
Expand All @@ -578,7 +582,9 @@ jdouble nativeGetScale(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr) {
void nativeSetZoom(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdouble zoom, jlong duration) {
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
nativeMapView->getMap().setZoom(zoom, mbgl::Milliseconds(duration));
mbgl::AnimationOptions animationOptions;
animationOptions.duration.emplace(mbgl::Milliseconds(duration));
nativeMapView->getMap().setZoom(zoom, animationOptions);
}

jdouble nativeGetZoom(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr) {
Expand Down
28 changes: 14 additions & 14 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,51 +520,51 @@ void Map::resetPosition(optional<EdgeInsets> padding) {

#pragma mark - Scale

void Map::scaleBy(double ds, optional<ScreenCoordinate> anchor, const Duration& duration) {
void Map::scaleBy(double ds, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
impl->cameraMutated = true;
impl->transform.scaleBy(ds, anchor, duration);
impl->transform.scaleBy(ds, anchor, animation);
impl->onUpdate(Update::RecalculateStyle);
}

void Map::setScale(double scale, optional<ScreenCoordinate> anchor, const Duration& duration) {
void Map::setScale(double scale, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
impl->cameraMutated = true;
impl->transform.setScale(scale, anchor, duration);
impl->transform.setScale(scale, anchor, animation);
impl->onUpdate(Update::RecalculateStyle);
}

double Map::getScale() const {
return impl->transform.getScale();
}

void Map::setZoom(double zoom, const Duration& duration) {
void Map::setZoom(double zoom, const AnimationOptions& animation) {
impl->cameraMutated = true;
setZoom(zoom, optional<EdgeInsets> {}, duration);
setZoom(zoom, optional<EdgeInsets> {}, animation);
}

void Map::setZoom(double zoom, optional<ScreenCoordinate> anchor, const Duration& duration) {
void Map::setZoom(double zoom, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
impl->cameraMutated = true;
impl->transform.setZoom(zoom, anchor, duration);
impl->transform.setZoom(zoom, anchor, animation);
impl->onUpdate(Update::RecalculateStyle);
}

void Map::setZoom(double zoom, optional<EdgeInsets> padding, const Duration& duration) {
void Map::setZoom(double zoom, optional<EdgeInsets> padding, const AnimationOptions& animation) {
impl->cameraMutated = true;
impl->transform.setZoom(zoom, padding, duration);
impl->transform.setZoom(zoom, padding, animation);
impl->onUpdate(Update::RecalculateStyle);
}

double Map::getZoom() const {
return impl->transform.getZoom();
}

void Map::setLatLngZoom(const LatLng& latLng, double zoom, const Duration& duration) {
void Map::setLatLngZoom(const LatLng& latLng, double zoom, const AnimationOptions& animation) {
impl->cameraMutated = true;
setLatLngZoom(latLng, zoom, {}, duration);
setLatLngZoom(latLng, zoom, {}, animation);
}

void Map::setLatLngZoom(const LatLng& latLng, double zoom, optional<EdgeInsets> padding, const Duration& duration) {
void Map::setLatLngZoom(const LatLng& latLng, double zoom, optional<EdgeInsets> padding, const AnimationOptions& animation) {
impl->cameraMutated = true;
impl->transform.setLatLngZoom(latLng, zoom, padding, duration);
impl->transform.setLatLngZoom(latLng, zoom, padding, animation);
impl->onUpdate(Update::RecalculateStyle);
}

Expand Down
40 changes: 20 additions & 20 deletions src/mbgl/map/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,18 +361,18 @@ void Transform::setLatLng(const LatLng& latLng, optional<ScreenCoordinate> ancho
easeTo(camera, duration);
}

void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const Duration& duration) {
setLatLngZoom(latLng, zoom, EdgeInsets {}, duration);
void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const AnimationOptions& animation) {
setLatLngZoom(latLng, zoom, EdgeInsets {}, animation);
}

void Transform::setLatLngZoom(const LatLng& latLng, double zoom, optional<EdgeInsets> padding, const Duration& duration) {
void Transform::setLatLngZoom(const LatLng& latLng, double zoom, optional<EdgeInsets> padding, const AnimationOptions& animation) {
if (!latLng || std::isnan(zoom)) return;

CameraOptions camera;
camera.center = latLng;
camera.padding = padding;
camera.zoom = zoom;
easeTo(camera, duration);
easeTo(camera, animation);
}

LatLng Transform::getLatLng(optional<EdgeInsets> padding) const {
Expand All @@ -394,26 +394,26 @@ ScreenCoordinate Transform::getScreenCoordinate(optional<EdgeInsets> padding) co

#pragma mark - Zoom

void Transform::scaleBy(double ds, const Duration& duration) {
scaleBy(ds, optional<ScreenCoordinate> {}, duration);
void Transform::scaleBy(double ds, const AnimationOptions& animation) {
scaleBy(ds, optional<ScreenCoordinate> {}, animation);
}

void Transform::scaleBy(double ds, optional<ScreenCoordinate> anchor, const Duration& duration) {
void Transform::scaleBy(double ds, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
if (std::isnan(ds)) return;
double scale = util::clamp(state.scale * ds, state.min_scale, state.max_scale);
setScale(scale, anchor, duration);
setScale(scale, anchor, animation);
}

void Transform::setZoom(double zoom, const Duration& duration) {
setZoom(zoom, optional<ScreenCoordinate> {}, duration);
void Transform::setZoom(double zoom, const AnimationOptions& animation) {
setZoom(zoom, optional<ScreenCoordinate> {}, animation);
}

void Transform::setZoom(double zoom, optional<ScreenCoordinate> anchor, const Duration& duration) {
setScale(state.zoomScale(zoom), anchor, duration);
void Transform::setZoom(double zoom, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
setScale(state.zoomScale(zoom), anchor, animation);
}

void Transform::setZoom(double zoom, optional<EdgeInsets> padding, const Duration& duration) {
setScale(state.zoomScale(zoom), padding, duration);
void Transform::setZoom(double zoom, optional<EdgeInsets> padding, const AnimationOptions& animation) {
setScale(state.zoomScale(zoom), padding, animation);
}

double Transform::getZoom() const {
Expand All @@ -424,22 +424,22 @@ double Transform::getScale() const {
return state.scale;
}

void Transform::setScale(double scale, const Duration& duration) {
setScale(scale, optional<ScreenCoordinate> {}, duration);
void Transform::setScale(double scale, const AnimationOptions& animation) {
setScale(scale, optional<ScreenCoordinate> {}, animation);
}

void Transform::setScale(double scale, optional<ScreenCoordinate> anchor, const Duration& duration) {
void Transform::setScale(double scale, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
if (std::isnan(scale)) return;
CameraOptions camera;
camera.zoom = state.scaleZoom(scale);
camera.anchor = anchor;
easeTo(camera, duration);
easeTo(camera, animation);
}

void Transform::setScale(double scale, optional<EdgeInsets> padding, const Duration& duration) {
void Transform::setScale(double scale, optional<EdgeInsets> padding, const AnimationOptions& animation) {
optional<ScreenCoordinate> anchor;
if (padding) anchor = getScreenCoordinate(padding);
setScale(scale, anchor, duration);
setScale(scale, anchor, animation);
}

void Transform::setMinZoom(const double minZoom) {
Expand Down
20 changes: 10 additions & 10 deletions src/mbgl/map/transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,45 +48,45 @@ class Transform : private util::noncopyable {
void setLatLng(const LatLng&, const Duration& = Duration::zero());
void setLatLng(const LatLng&, optional<EdgeInsets>, const Duration& = Duration::zero());
void setLatLng(const LatLng&, optional<ScreenCoordinate>, const Duration& = Duration::zero());
void setLatLngZoom(const LatLng&, double zoom, const Duration& = Duration::zero());
void setLatLngZoom(const LatLng&, double zoom, optional<EdgeInsets>, const Duration& = Duration::zero());
void setLatLngZoom(const LatLng&, double zoom, const AnimationOptions& = {});
void setLatLngZoom(const LatLng&, double zoom, optional<EdgeInsets>, const AnimationOptions& = {});
LatLng getLatLng(optional<EdgeInsets> = {}) const;
ScreenCoordinate getScreenCoordinate(optional<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. */
void scaleBy(double ds, const Duration& = Duration::zero());
void scaleBy(double ds, const AnimationOptions& = {});
/** 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.
If unspecified, the center point is fixed within the view. */
void scaleBy(double ds, optional<ScreenCoordinate> anchor, const Duration& = Duration::zero());
void scaleBy(double ds, optional<ScreenCoordinate> anchor, const AnimationOptions& = {});
/** Sets the scale factor, keeping the given point fixed within the view.
@param scale The new scale factor. */
void setScale(double scale, const Duration& = Duration::zero());
void setScale(double scale, const AnimationOptions& = {});
/** 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.
If unspecified, the center point is fixed within the view. */
void setScale(double scale, optional<ScreenCoordinate> anchor, const Duration& = Duration::zero());
void setScale(double scale, optional<ScreenCoordinate> anchor, const AnimationOptions& = {});
/** 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, optional<EdgeInsets> padding, const Duration& = Duration::zero());
void setScale(double scale, optional<EdgeInsets> padding, const AnimationOptions& = {});
/** Sets the zoom level, keeping the given point fixed within the view.
@param zoom The new zoom level. */
void setZoom(double zoom, const Duration& = Duration::zero());
void setZoom(double zoom, const AnimationOptions& = {});
/** 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, optional<ScreenCoordinate> anchor, const Duration& = Duration::zero());
void setZoom(double zoom, optional<ScreenCoordinate> anchor, const AnimationOptions& = {});
/** 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, optional<EdgeInsets> padding, const Duration& = Duration::zero());
void setZoom(double zoom, optional<EdgeInsets> padding, const AnimationOptions& = {});
/** Returns the zoom level. */
double getZoom() const;
/** Returns the scale factor. */
Expand Down

0 comments on commit 839ddeb

Please sign in to comment.