@@ -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