diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-06-13 14:47:13 -0700 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-06-14 10:02:06 +0200 |
commit | b9702ef41a4cfdd0ab3107cfe5cec16ba3a4c230 (patch) | |
tree | 21a11f25139c129561d6830932a9eee4f2be895d /platform/macos/app/DroppedPinAnnotation.m | |
parent | 1e41c151f6edfba69037c854a5cb7abc18bb55e7 (diff) | |
download | qtlocation-mapboxgl-b9702ef41a4cfdd0ab3107cfe5cec16ba3a4c230.tar.gz |
[macos] Renamed OS X SDK to macOS SDK
Also renamed as many references to OS X as possible to macOS in documentation.
Diffstat (limited to 'platform/macos/app/DroppedPinAnnotation.m')
-rw-r--r-- | platform/macos/app/DroppedPinAnnotation.m | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/platform/macos/app/DroppedPinAnnotation.m b/platform/macos/app/DroppedPinAnnotation.m new file mode 100644 index 0000000000..5b19fd7401 --- /dev/null +++ b/platform/macos/app/DroppedPinAnnotation.m @@ -0,0 +1,68 @@ +#import "DroppedPinAnnotation.h" + +#import "LocationCoordinate2DTransformer.h" +#import "TimeIntervalTransformer.h" + +#import <Mapbox/Mapbox.h> + +static MGLCoordinateFormatter *DroppedPinCoordinateFormatter; + +@implementation DroppedPinAnnotation { + NSTimer *_timer; + NSTimeInterval _priorShownTimeInterval; + NSDate *_dateShown; + + NSValueTransformer *_timeIntervalTransformer; +} + ++ (void)initialize { + if (self == [DroppedPinAnnotation class]) { + DroppedPinCoordinateFormatter = [[MGLCoordinateFormatter alloc] init]; + } +} + +- (instancetype)init { + if (self = [super init]) { + _timeIntervalTransformer = [NSValueTransformer valueTransformerForName: + NSStringFromClass([TimeIntervalTransformer class])]; + [self update:nil]; + } + return self; +} + +- (void)dealloc { + [self pause]; +} + +- (void)setCoordinate:(CLLocationCoordinate2D)coordinate { + super.coordinate = coordinate; + [self update:nil]; +} + +- (NSTimeInterval)elapsedShownTime { + return _priorShownTimeInterval - _dateShown.timeIntervalSinceNow; +} + +- (void)resume { + _dateShown = [NSDate date]; + _timer = [NSTimer scheduledTimerWithTimeInterval:1 + target:self + selector:@selector(update:) + userInfo:nil + repeats:YES]; +} + +- (void)pause { + [_timer invalidate]; + _timer = nil; + _priorShownTimeInterval -= _dateShown.timeIntervalSinceNow; + _dateShown = nil; +} + +- (void)update:(NSTimer *)timer { + NSString *coordinate = [DroppedPinCoordinateFormatter stringFromCoordinate:self.coordinate]; + NSString *elapsedTime = [_timeIntervalTransformer transformedValue:@(self.elapsedShownTime)]; + self.subtitle = [NSString stringWithFormat:@"%@\nSelected for %@", coordinate, elapsedTime]; +} + +@end |