summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorJustin R. Miller <incanus@codesorcery.net>2017-01-18 12:43:08 -0800
committerGitHub <noreply@github.com>2017-01-18 12:43:08 -0800
commitf6715694f918a884eda77151aa4fec05521b9536 (patch)
treebd930307db9fb13ad5751324ae57bf858f30aa2a /platform/darwin
parentd076ba05673a6ced9d3e641e2c7a2b5f3c70a80f (diff)
downloadqtlocation-mapboxgl-f6715694f918a884eda77151aa4fec05521b9536.tar.gz
refs #6779: mobile & Mac SDK style transition options (#7711)
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/MGLStyle.h16
-rw-r--r--platform/darwin/src/MGLStyle.mm30
-rw-r--r--platform/darwin/src/NSDate+MGLAdditions.h5
-rw-r--r--platform/darwin/src/NSDate+MGLAdditions.mm7
4 files changed, 55 insertions, 3 deletions
diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h
index 9bd35142c2..25096748f6 100644
--- a/platform/darwin/src/MGLStyle.h
+++ b/platform/darwin/src/MGLStyle.h
@@ -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
diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm
index 7e96c08ccc..78c719050c 100644
--- a/platform/darwin/src/MGLStyle.mm
+++ b/platform/darwin/src/MGLStyle.mm
@@ -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 = %@>",
diff --git a/platform/darwin/src/NSDate+MGLAdditions.h b/platform/darwin/src/NSDate+MGLAdditions.h
index 918aae233f..820d1bd9e2 100644
--- a/platform/darwin/src/NSDate+MGLAdditions.h
+++ b/platform/darwin/src/NSDate+MGLAdditions.h
@@ -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
diff --git a/platform/darwin/src/NSDate+MGLAdditions.mm b/platform/darwin/src/NSDate+MGLAdditions.mm
index 75072ad7ff..deac3c4881 100644
--- a/platform/darwin/src/NSDate+MGLAdditions.mm
+++ b/platform/darwin/src/NSDate+MGLAdditions.mm
@@ -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