@@ -36,11 +36,11 @@ - (instancetype)initWithRegion:(MKCoordinateRegion)region
3636 }
3737 self.backgroundColor = ASDisplayNodeDefaultPlaceholderColor ();
3838 self.clipsToBounds = YES ;
39-
39+
4040 _needsMapReloadOnBoundsChange = YES ;
4141 _liveMap = NO ;
4242 _centerCoordinateOfMap = kCLLocationCoordinate2DInvalid ;
43-
43+
4444 _options = [[MKMapSnapshotOptions alloc ] init ];
4545 _options.region = region;
4646
@@ -49,29 +49,28 @@ - (instancetype)initWithRegion:(MKCoordinateRegion)region
4949
5050- (void )didLoad
5151{
52- [super didLoad ];
53- if (self.isLiveMap && !_mapNode) {
54- self.userInteractionEnabled = YES ;
55- [self addLiveMap ];
56- }
52+ [super didLoad ];
53+ if (self.isLiveMap && !_mapNode) {
54+ self.userInteractionEnabled = YES ;
55+ [self addLiveMap ];
56+ }
5757}
5858
5959- (void )fetchData
6060{
61- [super fetchData ];
62- if (_liveMap && !_mapNode) {
63- [self addLiveMap ];
64- }
65- else {
66- [self setUpSnapshotter ];
67- [self takeSnapshot ];
68- }
61+ [super fetchData ];
62+ if (_liveMap && !_mapNode) {
63+ [self addLiveMap ];
64+ } else {
65+ [self setUpSnapshotter ];
66+ [self takeSnapshot ];
67+ }
6968}
7069
7170- (void )clearFetchedData
7271{
73- [super clearFetchedData ];
74- [self removeLiveMap ];
72+ [super clearFetchedData ];
73+ [self removeLiveMap ];
7574}
7675
7776#pragma mark - Settings
@@ -148,11 +147,11 @@ - (void)takeSnapshot
148147
149148- (void )setUpSnapshotter
150149{
151- if (!_snapshotter) {
152- 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." );
153- _options.size = self.calculatedSize ;
154- _snapshotter = [[MKMapSnapshotter alloc ] initWithOptions: _options];
155- }
150+ if (!_snapshotter) {
151+ 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." );
152+ _options.size = self.calculatedSize ;
153+ _snapshotter = [[MKMapSnapshotter alloc ] initWithOptions: _options];
154+ }
156155}
157156
158157- (void )resetSnapshotter
@@ -195,16 +194,16 @@ - (void)removeLiveMap
195194
196195- (void )setAnnotations : (NSArray *)annotations
197196{
198- ASDN::MutexLocker l (_propertyLock);
199- _annotations = [annotations copy ];
200- if (annotations.count != _annotations.count ) {
201- // Redraw
202- [self setNeedsDisplay ];
203- if (_mapView) {
204- [_mapView removeAnnotations: _mapView.annotations];
205- [_mapView addAnnotations: annotations];
206- }
197+ ASDN::MutexLocker l (_propertyLock);
198+ _annotations = [annotations copy ];
199+ if (annotations.count != _annotations.count ) {
200+ // Redraw
201+ [self setNeedsDisplay ];
202+ if (_mapView) {
203+ [_mapView removeAnnotations: _mapView.annotations];
204+ [_mapView addAnnotations: annotations];
207205 }
206+ }
208207}
209208
210209
@@ -215,13 +214,12 @@ - (void)layout
215214 [super layout ];
216215 if (_mapView) {
217216 _mapView.frame = CGRectMake (0 .0f , 0 .0f , self.calculatedSize .width , self.calculatedSize .height );
218- }
219- else {
217+ } else {
220218 // If our bounds.size is different from our current snapshot size, then let's request a new image from MKMapSnapshotter.
221219 if (!CGSizeEqualToSize (_options.size , self.bounds .size ) && _needsMapReloadOnBoundsChange) {
222- _options.size = self.bounds .size ;
223- [self resetSnapshotter ];
224- [self takeSnapshot ];
220+ _options.size = self.bounds .size ;
221+ [self resetSnapshotter ];
222+ [self takeSnapshot ];
225223 }
226224 }
227225}
0 commit comments