Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 45fa36e

Browse files
ASMapNode now supports MKMapSnapshotOptions as opposed to just a region property.
1 parent e35697d commit 45fa36e

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

AsyncDisplayKit/ASMapNode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
@interface ASMapNode : ASImageNode
1313

1414
/**
15-
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).
15+
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).
1616
*/
17-
@property (nonatomic, assign) MKCoordinateRegion region;
17+
@property (nonatomic, readwrite) MKMapSnapshotOptions *options;
1818

1919
/**
2020
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.

AsyncDisplayKit/ASMapNode.mm

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ @interface ASMapNode()
1515
{
1616
ASDN::RecursiveMutex _propertyLock;
1717
MKMapSnapshotter *_snapshotter;
18-
MKMapSnapshotOptions *_options;
1918
NSArray *_annotations;
2019
CLLocationCoordinate2D _centerCoordinateOfMap;
2120
}
@@ -25,7 +24,7 @@ @implementation ASMapNode
2524

2625
@synthesize needsMapReloadOnBoundsChange = _needsMapReloadOnBoundsChange;
2726
@synthesize mapDelegate = _mapDelegate;
28-
@synthesize region = _region;
27+
@synthesize options = _options;
2928
@synthesize liveMap = _liveMap;
3029

3130
#pragma mark - Lifecycle
@@ -41,11 +40,9 @@ - (instancetype)init
4140
_liveMap = NO;
4241
_centerCoordinateOfMap = kCLLocationCoordinate2DInvalid;
4342

44-
//Default world-scale view
45-
_region = MKCoordinateRegionForMapRect(MKMapRectWorld);
46-
4743
_options = [[MKMapSnapshotOptions alloc] init];
48-
_options.region = _region;
44+
//Default world-scale view
45+
_options.region = MKCoordinateRegionForMapRect(MKMapRectWorld);
4946

5047
return self;
5148
}
@@ -116,20 +113,19 @@ - (void)setNeedsMapReloadOnBoundsChange:(BOOL)needsMapReloadOnBoundsChange
116113
_needsMapReloadOnBoundsChange = needsMapReloadOnBoundsChange;
117114
}
118115

119-
- (MKCoordinateRegion)region
116+
- (MKMapSnapshotOptions *)options
120117
{
121118
ASDN::MutexLocker l(_propertyLock);
122-
return _region;
119+
return _options;
123120
}
124121

125-
- (void)setRegion:(MKCoordinateRegion)region
122+
- (void)setOptions:(MKMapSnapshotOptions *)options
126123
{
127124
ASDN::MutexLocker l(_propertyLock);
128-
_region = region;
125+
_options = options;
129126
if (self.isLiveMap) {
130-
[_mapView setRegion:_region animated:YES];
127+
[self applySnapshotOptions];
131128
} else {
132-
_options.region = _region;
133129
[self resetSnapshotter];
134130
[self takeSnapshot];
135131
}
@@ -190,6 +186,15 @@ - (void)resetSnapshotter
190186
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options];
191187
}
192188

189+
- (void)applySnapshotOptions
190+
{
191+
[_mapView setCamera:_options.camera animated:YES];
192+
[_mapView setRegion:_options.region animated:YES];
193+
[_mapView setMapType:_options.mapType];
194+
_mapView.showsBuildings = _options.showsBuildings;
195+
_mapView.showsPointsOfInterest = _options.showsPointsOfInterest;
196+
}
197+
193198
#pragma mark - Actions
194199
- (void)addLiveMap
195200
{
@@ -198,7 +203,7 @@ - (void)addLiveMap
198203
__weak ASMapNode *weakSelf = self;
199204
_mapView = [[MKMapView alloc] initWithFrame:CGRectZero];
200205
_mapView.delegate = weakSelf.mapDelegate;
201-
[_mapView setRegion:_options.region];
206+
[weakSelf applySnapshotOptions];
202207
[_mapView addAnnotations:_annotations];
203208
[weakSelf setNeedsLayout];
204209
[weakSelf.view addSubview:_mapView];
@@ -229,7 +234,7 @@ - (void)setAnnotations:(NSArray *)annotations
229234
}
230235

231236
#pragma mark - Layout
232-
// 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.
237+
// Layout isn't usually needed in the box model, but since we are making use of MKMapView this is preferred.
233238
- (void)layout
234239
{
235240
[super layout];

0 commit comments

Comments
 (0)