refs #6779: mobile & Mac SDK style transition options (#7711)

This commit is contained in:
Justin R. Miller
2017-01-18 12:43:08 -08:00
committed by GitHub
parent d076ba0567
commit f6715694f9
16 changed files with 205 additions and 24 deletions

View File

@@ -35,6 +35,7 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to
- Extracting all business logic related to annotations into a seperate class cfr. to core and the iOS codebase
* Gesture handling bugs
- Avoid calls to onFling when while pinch zooming [#7666](https://github.com/mapbox/mapbox-gl-native/issues/7666)
* Support for style-wide transition animation duration and delay [#6779](https://github.com/mapbox/mapbox-gl-native/issues/6779)
## 4.2.1 - December 22, 2016

View File

@@ -166,6 +166,52 @@ public final class MapboxMap {
// Style
/**
* <p>
* Get the animation duration for style changes.
* </p>
* The default value is zero, so any changes take effect without animation.
*
* @return Duration in seconds
*/
@UiThread
public long getTransitionDuration() {
return nativeMapView.getTransitionDuration();
}
/**
* Set the animation duration for style changes.
*
* @param duration Duration in seconds
*/
@UiThread
public void setTransitionDuration(long duration) {
nativeMapView.setTransitionDuration(duration);
}
/**
* <p>
* Get the animation delay for style changes.
* </p>
* The default value is zero, so any changes begin to animate immediately.
*
* @return Delay in seconds
*/
@UiThread
public long getTransitionDelay() {
return nativeMapView.getTransitionDelay();
}
/**
* Set the animation delay for style changes.
*
* @param delay Delay in seconds
*/
@UiThread
public void setTransitionDelay(long delay) {
nativeMapView.setTransitionDelay(delay);
}
@Nullable
@UiThread
public Layer getLayer(@NonNull String layerId) {

View File

@@ -767,6 +767,22 @@ final class NativeMapView {
// Runtime style Api
public long getTransitionDuration() {
return nativeGetTransitionDuration(nativeMapViewPtr);
}
public void setTransitionDuration(long duration) {
nativeSetTransitionDuration(nativeMapViewPtr, duration);
}
public long getTransitionDelay() {
return nativeGetTransitionDelay(nativeMapViewPtr);
}
public void setTransitionDelay(long delay) {
nativeSetTransitionDelay(nativeMapViewPtr, delay);
}
public Layer getLayer(String layerId) {
if (isDestroyedOn("getLayer")) {
return null;
@@ -1098,6 +1114,14 @@ final class NativeMapView {
private native double[] nativeGetCameraValues(long nativeMapViewPtr);
private native long nativeGetTransitionDuration(long nativeMapViewPtr);
private native void nativeSetTransitionDuration(long nativeMapViewPtr, long duration);
private native long nativeGetTransitionDelay(long nativeMapViewPtr);
private native void nativeSetTransitionDelay(long nativeMapViewPtr, long delay);
private native Layer nativeGetLayer(long nativeMapViewPtr, String layerId);
private native void nativeAddLayer(long nativeMapViewPtr, long layerPtr, String before);

View File

@@ -239,6 +239,8 @@ public class RuntimeStyleActivity extends AppCompatActivity {
private void setWaterColor() {
Layer water = mapboxMap.getLayer("water");
if (water != null) {
mapboxMap.setTransitionDuration(5);
mapboxMap.setTransitionDelay(1);
water.setProperties(
visibility(VISIBLE),
fillColor(Color.RED)

View File

@@ -19,7 +19,10 @@
<!-- <module name="NewlineAtEndOfFile">
<property name="lineSeparator" value="lf" />
</module> -->
<module name="FileLength"/>
<module name="FileLength">
<property name="max" value="2042"/>
</module>
<module name="FileTabCharacter"/>
<!-- Trailing spaces -->

View File

@@ -1082,6 +1082,48 @@ void nativeFlyTo(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdouble
nativeMapView->getMap().flyTo(cameraOptions, animationOptions);
}
jlong nativeGetTransitionDuration(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr) {
assert(env);
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
const auto transitionOptions = nativeMapView->getMap().getTransitionOptions();
return transitionOptions.duration.value_or(mbgl::Duration::zero()).count();
}
void nativeSetTransitionDuration(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jlong duration) {
assert(env);
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
auto transitionOptions = nativeMapView->getMap().getTransitionOptions();
transitionOptions.duration = std::chrono::duration_cast<mbgl::Duration>(std::chrono::duration<jlong>(duration));
nativeMapView->getMap().setTransitionOptions(transitionOptions);
}
jlong nativeGetTransitionDelay(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr) {
assert(env);
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
const auto transitionOptions = nativeMapView->getMap().getTransitionOptions();
return transitionOptions.delay.value_or(mbgl::Duration::zero()).count();
}
void nativeSetTransitionDelay(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jlong delay) {
assert(env);
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
auto transitionOptions = nativeMapView->getMap().getTransitionOptions();
transitionOptions.delay = std::chrono::duration_cast<mbgl::Duration>(std::chrono::duration<jlong>(delay));
nativeMapView->getMap().setTransitionOptions(transitionOptions);
}
jni::jobject* nativeGetLayer(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jstring* layerId) {
assert(env);
assert(nativeMapViewPtr != 0);
@@ -1876,6 +1918,10 @@ void registerNatives(JavaVM *vm) {
MAKE_NATIVE_METHOD(nativeJumpTo, "(JDDDDD)V"),
MAKE_NATIVE_METHOD(nativeEaseTo, "(JDDDJDDZ)V"),
MAKE_NATIVE_METHOD(nativeFlyTo, "(JDDDJDD)V"),
MAKE_NATIVE_METHOD(nativeGetTransitionDuration, "(J)J"),
MAKE_NATIVE_METHOD(nativeSetTransitionDuration, "(JJ)V"),
MAKE_NATIVE_METHOD(nativeGetTransitionDelay, "(J)J"),
MAKE_NATIVE_METHOD(nativeSetTransitionDelay, "(JJ)V"),
MAKE_NATIVE_METHOD(nativeGetLayer, "(JLjava/lang/String;)Lcom/mapbox/mapboxsdk/style/layers/Layer;"),
MAKE_NATIVE_METHOD(nativeAddLayer, "(JJLjava/lang/String;)V"),
MAKE_NATIVE_METHOD(nativeRemoveLayerById, "(JLjava/lang/String;)V"),

View File

@@ -442,6 +442,22 @@ MGL_EXPORT
*/
- (void)removeImageForName:(NSString *)name;
#pragma mark Managing a Style’s Transition Options
/**
The duration in seconds to animate any changes to the style URL or to layout and paint attributes.
By default, this property is set to zero seconds, so any changes take effect without animation.
*/
@property (nonatomic) NSTimeInterval transitionDuration;
/**
The delay in seconds to before applying any changes to the style URL or to layout and paint attributes.
By default, this property is set to zero seconds, so any changes begin to animate immediately.
*/
@property (nonatomic) NSTimeInterval transitionDelay;
@end
NS_ASSUME_NONNULL_END

View File

@@ -502,7 +502,7 @@ static NSURL *MGLStyleURL_emerald;
newAppliedClasses.push_back([appliedClass UTF8String]);
}
mbgl::style::TransitionOptions transition { { MGLDurationInSeconds(transitionDuration) } };
mbgl::style::TransitionOptions transition { { MGLDurationInSecondsFromTimeInterval(transitionDuration) } };
self.mapView.mbglMap->setTransitionOptions(transition);
self.mapView.mbglMap->setClasses(newAppliedClasses);
}
@@ -570,6 +570,34 @@ static NSURL *MGLStyleURL_emerald;
return spriteImage ? [[MGLImage alloc] initWithMGLSpriteImage:spriteImage] : nil;
}
#pragma mark Style transitions
- (void)setTransitionDuration:(NSTimeInterval)duration
{
auto transitionOptions = self.mapView.mbglMap->getTransitionOptions();
transitionOptions.duration = MGLDurationInSecondsFromTimeInterval(duration);
self.mapView.mbglMap->setTransitionOptions(transitionOptions);
}
- (NSTimeInterval)transitionDuration
{
const mbgl::style::TransitionOptions transitionOptions = self.mapView.mbglMap->getTransitionOptions();
return MGLTimeIntervalFromDurationInSeconds(transitionOptions.duration.value_or(mbgl::Duration::zero()));
}
- (void)setTransitionDelay:(NSTimeInterval)delay
{
auto transitionOptions = self.mapView.mbglMap->getTransitionOptions();
transitionOptions.delay = MGLDurationInSecondsFromTimeInterval(delay);
self.mapView.mbglMap->setTransitionOptions(transitionOptions);
}
- (NSTimeInterval)transitionDelay
{
const mbgl::style::TransitionOptions transitionOptions = self.mapView.mbglMap->getTransitionOptions();
return MGLTimeIntervalFromDurationInSeconds(transitionOptions.delay.value_or(mbgl::Duration::zero()));
}
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p; name = %@, URL = %@>",

View File

@@ -5,6 +5,9 @@
@interface NSDate (MGLAdditions)
/// Converts from a duration in seconds to a duration object usable in mbgl.
mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration);
mbgl::Duration MGLDurationInSecondsFromTimeInterval(NSTimeInterval duration);
/// Converts from an mbgl duration object to a duration in seconds.
NSTimeInterval MGLTimeIntervalFromDurationInSeconds(mbgl::Duration duration);
@end

View File

@@ -2,9 +2,14 @@
@implementation NSDate (MGLAdditions)
mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
mbgl::Duration MGLDurationInSecondsFromTimeInterval(NSTimeInterval duration)
{
return std::chrono::duration_cast<mbgl::Duration>(std::chrono::duration<NSTimeInterval>(duration));
}
NSTimeInterval MGLTimeIntervalFromDurationInSeconds(mbgl::Duration duration)
{
return duration.count();
}
@end

View File

@@ -8,6 +8,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Improved the line wrapping behavior of point-placed labels written in Chinese, Japanese, and Yi. ([#6828](https://github.com/mapbox/mapbox-gl-native/pull/6828))
* Fixed an issue where translucent, non-view-backed point annotations along tile boundaries would be drawn darker than expected. ([#6832](https://github.com/mapbox/mapbox-gl-native/pull/6832))
* Added a Simplified Chinese localization. ([#7316](https://github.com/mapbox/mapbox-gl-native/pull/7316))
* Support for style-wide transition animation duration and delay. [#6779](https://github.com/mapbox/mapbox-gl-native/issues/6779)
## 3.4.0

View File

@@ -819,6 +819,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
- (void)styleBuildingLayer
{
self.mapView.style.transitionDuration = 5;
self.mapView.style.transitionDelay = 1;
MGLFillStyleLayer *buildingLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"building"];
buildingLayer.fillColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor blackColor]];
}

View File

@@ -1226,7 +1226,7 @@ public:
if (drift)
{
CGPoint offset = CGPointMake(velocity.x * self.decelerationRate / 4, velocity.y * self.decelerationRate / 4);
_mbglMap->moveBy({ offset.x, offset.y }, MGLDurationInSeconds(self.decelerationRate));
_mbglMap->moveBy({ offset.x, offset.y }, MGLDurationInSecondsFromTimeInterval(self.decelerationRate));
}
[self notifyGestureDidEndWithDrift:drift];
@@ -1316,7 +1316,7 @@ public:
if (velocity && duration)
{
_mbglMap->setScale(newScale, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationInSeconds(duration));
_mbglMap->setScale(newScale, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationInSecondsFromTimeInterval(duration));
}
[self notifyGestureDidEndWithDrift:velocity && duration];
@@ -1375,7 +1375,7 @@ public:
CGFloat newRadians = radians + velocity * decelerationRate * 0.1;
CGFloat newDegrees = MGLDegreesFromRadians(newRadians) * -1;
_mbglMap->setBearing(newDegrees, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationInSeconds(decelerationRate));
_mbglMap->setBearing(newDegrees, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationInSecondsFromTimeInterval(decelerationRate));
[self notifyGestureDidEndWithDrift:YES];
@@ -1504,7 +1504,7 @@ public:
CGPoint gesturePoint = [self anchorPointForGesture:doubleTap];
mbgl::ScreenCoordinate center(gesturePoint.x, gesturePoint.y);
_mbglMap->scaleBy(2, center, MGLDurationInSeconds(MGLAnimationDuration));
_mbglMap->scaleBy(2, center, MGLDurationInSecondsFromTimeInterval(MGLAnimationDuration));
__weak MGLMapView *weakSelf = self;
@@ -1532,7 +1532,7 @@ public:
CGPoint gesturePoint = [self anchorPointForGesture:twoFingerTap];
mbgl::ScreenCoordinate center(gesturePoint.x, gesturePoint.y);
_mbglMap->scaleBy(0.5, center, MGLDurationInSeconds(MGLAnimationDuration));
_mbglMap->scaleBy(0.5, center, MGLDurationInSecondsFromTimeInterval(MGLAnimationDuration));
__weak MGLMapView *weakSelf = self;
@@ -2288,7 +2288,7 @@ public:
mbgl::AnimationOptions animationOptions;
if (duration)
{
animationOptions.duration.emplace(MGLDurationInSeconds(duration));
animationOptions.duration.emplace(MGLDurationInSecondsFromTimeInterval(duration));
animationOptions.easing.emplace(MGLUnitBezierForMediaTimingFunction(function));
}
if (completion)
@@ -2329,7 +2329,7 @@ public:
_mbglMap->setZoom(zoomLevel,
MGLEdgeInsetsFromNSEdgeInsets(self.contentInset),
MGLDurationInSeconds(duration));
MGLDurationInSecondsFromTimeInterval(duration));
}
- (void)setMinimumZoomLevel:(double)minimumZoomLevel
@@ -2441,7 +2441,7 @@ public:
mbgl::AnimationOptions animationOptions;
if (duration > 0)
{
animationOptions.duration.emplace(MGLDurationInSeconds(duration));
animationOptions.duration.emplace(MGLDurationInSecondsFromTimeInterval(duration));
animationOptions.easing.emplace(MGLUnitBezierForMediaTimingFunction(function));
}
if (completion)
@@ -2489,13 +2489,13 @@ public:
{
_mbglMap->setBearing(direction,
MGLEdgeInsetsFromNSEdgeInsets(self.contentInset),
MGLDurationInSeconds(duration));
MGLDurationInSecondsFromTimeInterval(duration));
}
else
{
CGPoint centerPoint = self.userLocationAnnotationViewCenter;
_mbglMap->setBearing(direction, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y },
MGLDurationInSeconds(duration));
MGLDurationInSecondsFromTimeInterval(duration));
}
}
@@ -2548,7 +2548,7 @@ public:
mbgl::AnimationOptions animationOptions;
if (duration > 0)
{
animationOptions.duration.emplace(MGLDurationInSeconds(duration));
animationOptions.duration.emplace(MGLDurationInSecondsFromTimeInterval(duration));
animationOptions.easing.emplace(MGLUnitBezierForMediaTimingFunction(function));
}
if (completion)
@@ -2594,7 +2594,7 @@ public:
mbgl::AnimationOptions animationOptions;
if (duration >= 0)
{
animationOptions.duration = MGLDurationInSeconds(duration);
animationOptions.duration = MGLDurationInSecondsFromTimeInterval(duration);
}
if (peakAltitude >= 0)
{

View File

@@ -6,6 +6,7 @@
* Improved the line wrapping behavior of point-placed labels written in Chinese, Japanese, and Yi. ([#6828](https://github.com/mapbox/mapbox-gl-native/pull/6828))
* Fixed an issue where translucent point annotations along tile boundaries would be drawn darker than expected. ([#6832](https://github.com/mapbox/mapbox-gl-native/pull/6832))
* Added a Simplified Chinese localization. ([#7316](https://github.com/mapbox/mapbox-gl-native/pull/7316), [#7503](https://github.com/mapbox/mapbox-gl-native/pull/7503))
* Support for style-wide transition animation duration and delay. [#6779](https://github.com/mapbox/mapbox-gl-native/issues/6779)
## 0.3.0

View File

@@ -683,6 +683,9 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
}
- (IBAction)manipulateStyle:(id)sender {
self.mapView.style.transitionDuration = 5;
self.mapView.style.transitionDelay = 1;
MGLFillStyleLayer *fillStyleLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"water"];
MGLStyleValue *colorFunction = [MGLStyleValue<NSColor *> valueWithStops:@{

View File

@@ -979,7 +979,7 @@ public:
[self willChangeValueForKey:@"centerCoordinate"];
_mbglMap->setLatLng(MGLLatLngFromLocationCoordinate2D(centerCoordinate),
MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets),
MGLDurationInSeconds(animated ? MGLAnimationDuration : 0));
MGLDurationInSecondsFromTimeInterval(animated ? MGLAnimationDuration : 0));
[self didChangeValueForKey:@"centerCoordinate"];
}
@@ -987,7 +987,7 @@ public:
[self willChangeValueForKey:@"centerCoordinate"];
_mbglMap->cancelTransitions();
_mbglMap->moveBy({ delta.x, delta.y },
MGLDurationInSeconds(animated ? MGLAnimationDuration : 0));
MGLDurationInSecondsFromTimeInterval(animated ? MGLAnimationDuration : 0));
[self didChangeValueForKey:@"centerCoordinate"];
}
@@ -1023,7 +1023,7 @@ public:
[self willChangeValueForKey:@"zoomLevel"];
_mbglMap->setZoom(zoomLevel,
MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets),
MGLDurationInSeconds(animated ? MGLAnimationDuration : 0));
MGLDurationInSecondsFromTimeInterval(animated ? MGLAnimationDuration : 0));
[self didChangeValueForKey:@"zoomLevel"];
}
@@ -1035,7 +1035,7 @@ public:
[self willChangeValueForKey:@"centerCoordinate"];
[self willChangeValueForKey:@"zoomLevel"];
mbgl::ScreenCoordinate center(point.x, self.bounds.size.height - point.y);
_mbglMap->scaleBy(scaleFactor, center, MGLDurationInSeconds(animated ? MGLAnimationDuration : 0));
_mbglMap->scaleBy(scaleFactor, center, MGLDurationInSecondsFromTimeInterval(animated ? MGLAnimationDuration : 0));
[self didChangeValueForKey:@"zoomLevel"];
[self didChangeValueForKey:@"centerCoordinate"];
}
@@ -1092,7 +1092,7 @@ public:
[self willChangeValueForKey:@"direction"];
_mbglMap->setBearing(direction,
MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets),
MGLDurationInSeconds(animated ? MGLAnimationDuration : 0));
MGLDurationInSecondsFromTimeInterval(animated ? MGLAnimationDuration : 0));
[self didChangeValueForKey:@"direction"];
}
@@ -1126,7 +1126,7 @@ public:
mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera];
mbgl::AnimationOptions animationOptions;
if (duration > 0) {
animationOptions.duration.emplace(MGLDurationInSeconds(duration));
animationOptions.duration.emplace(MGLDurationInSecondsFromTimeInterval(duration));
animationOptions.easing.emplace(MGLUnitBezierForMediaTimingFunction(function));
}
if (completion) {
@@ -1162,7 +1162,7 @@ public:
mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera];
mbgl::AnimationOptions animationOptions;
if (duration >= 0) {
animationOptions.duration = MGLDurationInSeconds(duration);
animationOptions.duration = MGLDurationInSecondsFromTimeInterval(duration);
}
if (peakAltitude >= 0) {
CLLocationDegrees peakLatitude = (self.centerCoordinate.latitude + camera.centerCoordinate.latitude) / 2;
@@ -1228,7 +1228,7 @@ public:
mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), padding);
mbgl::AnimationOptions animationOptions;
if (animated) {
animationOptions.duration = MGLDurationInSeconds(MGLAnimationDuration);
animationOptions.duration = MGLDurationInSecondsFromTimeInterval(MGLAnimationDuration);
}
[self willChangeValueForKey:@"visibleCoordinateBounds"];