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

Commit 28618f7

Browse files
author
Scott Goodson
committed
Re-add .region property for API compatibility and convenience, using options object internally.
1 parent 64ad48a commit 28618f7

2 files changed

Lines changed: 32 additions & 21 deletions

File tree

AsyncDisplayKit/ASMapNode.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ NS_ASSUME_NONNULL_BEGIN
1919
*/
2020
@property (nonatomic, strong) MKMapSnapshotOptions *options;
2121

22+
/** The region is simply the sub-field on the options object. If the objects object is reset,
23+
this will in effect be overwritten and become the value of the .region property on that object.
24+
Defaults to MKCoordinateRegionForMapRect(MKMapRectWorld).
25+
*/
26+
@property (nonatomic, assign) MKCoordinateRegion region;
27+
2228
/**
2329
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.
2430
*/

AsyncDisplayKit/ASMapNode.mm

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ - (void)setNeedsMapReloadOnBoundsChange:(BOOL)needsMapReloadOnBoundsChange
114114
- (MKMapSnapshotOptions *)options
115115
{
116116
ASDN::MutexLocker l(_propertyLock);
117+
if (!_options) {
118+
_options = [[MKMapSnapshotOptions alloc] init];
119+
_options.region = MKCoordinateRegionForMapRect(MKMapRectWorld);
120+
_options.size = self.calculatedSize;
121+
}
117122
return _options;
118123
}
119124

@@ -129,6 +134,16 @@ - (void)setOptions:(MKMapSnapshotOptions *)options
129134
}
130135
}
131136

137+
- (MKCoordinateRegion)region
138+
{
139+
return self.options.region;
140+
}
141+
142+
- (void)setRegion:(MKCoordinateRegion)region
143+
{
144+
self.options.region = region;
145+
}
146+
132147
#pragma mark - Snapshotter
133148

134149
- (void)takeSnapshot
@@ -174,33 +189,25 @@ - (void)takeSnapshot
174189
- (void)setUpSnapshotter
175190
{
176191
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.");
177-
if (!_options) {
178-
[self createInitialOptions];
179-
}
180-
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options];
192+
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:self.options];
181193
}
182194

183195
- (void)resetSnapshotter
184196
{
197+
// FIXME: The semantics of this method / name would suggest that we cancel + destroy the snapshotter,
198+
// but not that we create a new one. We should probably only create the new one in -takeSnapshot or something.
185199
[_snapshotter cancel];
186-
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options];
187-
}
188-
189-
- (void)createInitialOptions
190-
{
191-
_options = [[MKMapSnapshotOptions alloc] init];
192-
//Default world-scale view
193-
_options.region = MKCoordinateRegionForMapRect(MKMapRectWorld);
194-
_options.size = self.calculatedSize;
200+
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:self.options];
195201
}
196202

197203
- (void)applySnapshotOptions
198204
{
199-
[_mapView setCamera:_options.camera animated:YES];
200-
[_mapView setRegion:_options.region animated:YES];
201-
[_mapView setMapType:_options.mapType];
202-
_mapView.showsBuildings = _options.showsBuildings;
203-
_mapView.showsPointsOfInterest = _options.showsPointsOfInterest;
205+
MKMapSnapshotOptions *options = self.options;
206+
[_mapView setCamera:options.camera animated:YES];
207+
[_mapView setRegion:options.region animated:YES];
208+
[_mapView setMapType:options.mapType];
209+
_mapView.showsBuildings = options.showsBuildings;
210+
_mapView.showsPointsOfInterest = options.showsPointsOfInterest;
204211
}
205212

206213
#pragma mark - Actions
@@ -211,9 +218,6 @@ - (void)addLiveMap
211218
__weak ASMapNode *weakSelf = self;
212219
_mapView = [[MKMapView alloc] initWithFrame:CGRectZero];
213220
_mapView.delegate = weakSelf.mapDelegate;
214-
if (!_options) {
215-
[weakSelf createInitialOptions];
216-
}
217221
[weakSelf applySnapshotOptions];
218222
[_mapView addAnnotations:_annotations];
219223
[weakSelf setNeedsLayout];
@@ -227,6 +231,7 @@ - (void)addLiveMap
227231

228232
- (void)removeLiveMap
229233
{
234+
// FIXME: With MKCoordinateRegion, isn't the center coordinate fully specified? Do we need this?
230235
_centerCoordinateOfMap = _mapView.centerCoordinate;
231236
[_mapView removeFromSuperview];
232237
_mapView = nil;

0 commit comments

Comments
 (0)