From 45fa36eba57b829ca63146ec8a70c2e3e3013ef6 Mon Sep 17 00:00:00 2001 From: Aaron Schubert Date: Tue, 5 Jan 2016 13:44:41 +0000 Subject: [PATCH 1/3] ASMapNode now supports MKMapSnapshotOptions as opposed to just a region property. --- AsyncDisplayKit/ASMapNode.h | 4 ++-- AsyncDisplayKit/ASMapNode.mm | 33 +++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/AsyncDisplayKit/ASMapNode.h b/AsyncDisplayKit/ASMapNode.h index bd2d23ad4b..524f844932 100644 --- a/AsyncDisplayKit/ASMapNode.h +++ b/AsyncDisplayKit/ASMapNode.h @@ -12,9 +12,9 @@ @interface ASMapNode : ASImageNode /** - The current region of ASMapNode. This can be set at any time and ASMapNode will animate the change. This property may be set from a background thread before the node is loaded, and will automatically be applied to define the region of the static snapshot (if .liveMap = NO) or the internal MKMapView (otherwise). + The current options of ASMapNode. This can be set at any time and ASMapNode will animate the change. This property may be set from a background thread before the node is loaded, and will automatically be applied to define the behavior of the static snapshot (if .liveMap = NO) or the internal MKMapView (otherwise). */ -@property (nonatomic, assign) MKCoordinateRegion region; +@property (nonatomic, readwrite) MKMapSnapshotOptions *options; /** This is the MKMapView that is the live map part of ASMapNode. This will be nil if .liveMap = NO. Note, MKMapView is *not* thread-safe. diff --git a/AsyncDisplayKit/ASMapNode.mm b/AsyncDisplayKit/ASMapNode.mm index 480360a1aa..aaebabdecb 100644 --- a/AsyncDisplayKit/ASMapNode.mm +++ b/AsyncDisplayKit/ASMapNode.mm @@ -15,7 +15,6 @@ { ASDN::RecursiveMutex _propertyLock; MKMapSnapshotter *_snapshotter; - MKMapSnapshotOptions *_options; NSArray *_annotations; CLLocationCoordinate2D _centerCoordinateOfMap; } @@ -25,7 +24,7 @@ @synthesize needsMapReloadOnBoundsChange = _needsMapReloadOnBoundsChange; @synthesize mapDelegate = _mapDelegate; -@synthesize region = _region; +@synthesize options = _options; @synthesize liveMap = _liveMap; #pragma mark - Lifecycle @@ -41,11 +40,9 @@ _liveMap = NO; _centerCoordinateOfMap = kCLLocationCoordinate2DInvalid; - //Default world-scale view - _region = MKCoordinateRegionForMapRect(MKMapRectWorld); - _options = [[MKMapSnapshotOptions alloc] init]; - _options.region = _region; + //Default world-scale view + _options.region = MKCoordinateRegionForMapRect(MKMapRectWorld); return self; } @@ -116,20 +113,19 @@ _needsMapReloadOnBoundsChange = needsMapReloadOnBoundsChange; } -- (MKCoordinateRegion)region +- (MKMapSnapshotOptions *)options { ASDN::MutexLocker l(_propertyLock); - return _region; + return _options; } -- (void)setRegion:(MKCoordinateRegion)region +- (void)setOptions:(MKMapSnapshotOptions *)options { ASDN::MutexLocker l(_propertyLock); - _region = region; + _options = options; if (self.isLiveMap) { - [_mapView setRegion:_region animated:YES]; + [self applySnapshotOptions]; } else { - _options.region = _region; [self resetSnapshotter]; [self takeSnapshot]; } @@ -190,6 +186,15 @@ _snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options]; } +- (void)applySnapshotOptions +{ + [_mapView setCamera:_options.camera animated:YES]; + [_mapView setRegion:_options.region animated:YES]; + [_mapView setMapType:_options.mapType]; + _mapView.showsBuildings = _options.showsBuildings; + _mapView.showsPointsOfInterest = _options.showsPointsOfInterest; +} + #pragma mark - Actions - (void)addLiveMap { @@ -198,7 +203,7 @@ __weak ASMapNode *weakSelf = self; _mapView = [[MKMapView alloc] initWithFrame:CGRectZero]; _mapView.delegate = weakSelf.mapDelegate; - [_mapView setRegion:_options.region]; + [weakSelf applySnapshotOptions]; [_mapView addAnnotations:_annotations]; [weakSelf setNeedsLayout]; [weakSelf.view addSubview:_mapView]; @@ -229,7 +234,7 @@ } #pragma mark - Layout -// Layout isn't usually needed in the box model, but since we are making use of MKMapView which is hidden in an ASDisplayNode this is preferred. +// Layout isn't usually needed in the box model, but since we are making use of MKMapView this is preferred. - (void)layout { [super layout]; From 239ec6feab3dc4dd1921406697cd452fd26fdd56 Mon Sep 17 00:00:00 2001 From: Aaron Schubert Date: Mon, 11 Jan 2016 19:30:56 +0000 Subject: [PATCH 2/3] [ASMapNode] Updated comment of options property. --- AsyncDisplayKit/ASMapNode.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AsyncDisplayKit/ASMapNode.h b/AsyncDisplayKit/ASMapNode.h index 524f844932..9d49f99a17 100644 --- a/AsyncDisplayKit/ASMapNode.h +++ b/AsyncDisplayKit/ASMapNode.h @@ -12,9 +12,9 @@ @interface ASMapNode : ASImageNode /** - The current options of ASMapNode. This can be set at any time and ASMapNode will animate the change. This property may be set from a background thread before the node is loaded, and will automatically be applied to define the behavior of the static snapshot (if .liveMap = NO) or the internal MKMapView (otherwise). + The current options of ASMapNode. This can be set at any time and ASMapNode will animate the change.

This property may be set from a background thread before the node is loaded, and will automatically be applied to define the behavior of the static snapshot (if .liveMap = NO) or the internal MKMapView (otherwise).

Changes to the region and camera options will only be animated when when the liveMap mode is enabled, otherwise these options will be applied statically to the new snapshot.

The options object is used to specify properties even when the liveMap mode is enabled, allowing seamless transitions between the snapshot and liveMap (as well as back to the snapshot). */ -@property (nonatomic, readwrite) MKMapSnapshotOptions *options; +@property (nonatomic, strong) MKMapSnapshotOptions *options; /** This is the MKMapView that is the live map part of ASMapNode. This will be nil if .liveMap = NO. Note, MKMapView is *not* thread-safe. @@ -38,7 +38,7 @@ @property (nonatomic, weak) id mapDelegate; /** - * @discussion This method set the annotations of the static map view and also to the live map view. Passing an empty array clears the map of any annotations. + * @discussion This method sets the annotations of the static map view and also to the live map view. Passing an empty array clears the map of any annotations. * @param annotations An array of objects that conform to the MKAnnotation protocol */ - (void)setAnnotations:(NSArray *)annotations; From e8f5f61e3b93028237bcd4445b4f1baef0af5396 Mon Sep 17 00:00:00 2001 From: Aaron Schubert Date: Mon, 11 Jan 2016 19:42:34 +0000 Subject: [PATCH 3/3] [ASMapNode] Defer creation of default options till they are needed. --- AsyncDisplayKit/ASMapNode.mm | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/AsyncDisplayKit/ASMapNode.mm b/AsyncDisplayKit/ASMapNode.mm index aaebabdecb..2f27255c8e 100644 --- a/AsyncDisplayKit/ASMapNode.mm +++ b/AsyncDisplayKit/ASMapNode.mm @@ -39,11 +39,6 @@ _needsMapReloadOnBoundsChange = YES; _liveMap = NO; _centerCoordinateOfMap = kCLLocationCoordinate2DInvalid; - - _options = [[MKMapSnapshotOptions alloc] init]; - //Default world-scale view - _options.region = MKCoordinateRegionForMapRect(MKMapRectWorld); - return self; } @@ -176,7 +171,9 @@ - (void)setUpSnapshotter { ASDisplayNodeAssert(!CGSizeEqualToSize(CGSizeZero, self.calculatedSize), @"self.calculatedSize can not be zero. Make sure that you are setting a preferredFrameSize or wrapping ASMapNode in a ASRatioLayoutSpec or similar."); - _options.size = self.calculatedSize; + if (!_options) { + [self createInitialOptions]; + } _snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options]; } @@ -186,6 +183,14 @@ _snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options]; } +- (void)createInitialOptions +{ + _options = [[MKMapSnapshotOptions alloc] init]; + //Default world-scale view + _options.region = MKCoordinateRegionForMapRect(MKMapRectWorld); + _options.size = self.calculatedSize; +} + - (void)applySnapshotOptions { [_mapView setCamera:_options.camera animated:YES]; @@ -203,6 +208,9 @@ __weak ASMapNode *weakSelf = self; _mapView = [[MKMapView alloc] initWithFrame:CGRectZero]; _mapView.delegate = weakSelf.mapDelegate; + if (!_options) { + [weakSelf createInitialOptions]; + } [weakSelf applySnapshotOptions]; [_mapView addAnnotations:_annotations]; [weakSelf setNeedsLayout];