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

Commit e8f5f61

Browse files
[ASMapNode] Defer creation of default options till they are needed.
1 parent 239ec6f commit e8f5f61

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

AsyncDisplayKit/ASMapNode.mm

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ - (instancetype)init
3939
_needsMapReloadOnBoundsChange = YES;
4040
_liveMap = NO;
4141
_centerCoordinateOfMap = kCLLocationCoordinate2DInvalid;
42-
43-
_options = [[MKMapSnapshotOptions alloc] init];
44-
//Default world-scale view
45-
_options.region = MKCoordinateRegionForMapRect(MKMapRectWorld);
46-
4742
return self;
4843
}
4944

@@ -176,7 +171,9 @@ - (void)takeSnapshot
176171
- (void)setUpSnapshotter
177172
{
178173
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.");
179-
_options.size = self.calculatedSize;
174+
if (!_options) {
175+
[self createInitialOptions];
176+
}
180177
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options];
181178
}
182179

@@ -186,6 +183,14 @@ - (void)resetSnapshotter
186183
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options];
187184
}
188185

186+
- (void)createInitialOptions
187+
{
188+
_options = [[MKMapSnapshotOptions alloc] init];
189+
//Default world-scale view
190+
_options.region = MKCoordinateRegionForMapRect(MKMapRectWorld);
191+
_options.size = self.calculatedSize;
192+
}
193+
189194
- (void)applySnapshotOptions
190195
{
191196
[_mapView setCamera:_options.camera animated:YES];
@@ -203,6 +208,9 @@ - (void)addLiveMap
203208
__weak ASMapNode *weakSelf = self;
204209
_mapView = [[MKMapView alloc] initWithFrame:CGRectZero];
205210
_mapView.delegate = weakSelf.mapDelegate;
211+
if (!_options) {
212+
[weakSelf createInitialOptions];
213+
}
206214
[weakSelf applySnapshotOptions];
207215
[_mapView addAnnotations:_annotations];
208216
[weakSelf setNeedsLayout];

0 commit comments

Comments
 (0)