@@ -117,7 +117,10 @@ - (MKMapSnapshotOptions *)options
117117 if (!_options) {
118118 _options = [[MKMapSnapshotOptions alloc ] init ];
119119 _options.region = MKCoordinateRegionForMapRect (MKMapRectWorld);
120- _options.size = self.calculatedSize ;
120+ CGSize calculatedSize = self.calculatedSize ;
121+ if (!CGSizeEqualToSize (calculatedSize, CGSizeZero)) {
122+ _options.size = calculatedSize;
123+ }
121124 }
122125 return _options;
123126}
@@ -250,6 +253,24 @@ - (void)setAnnotations:(NSArray *)annotations
250253}
251254
252255#pragma mark - Layout
256+ - (void )setSnapshotSizeIfNeeded : (CGSize)snapshotSize
257+ {
258+ if (!CGSizeEqualToSize (self.options .size , snapshotSize)) {
259+ _options.size = snapshotSize;
260+ [self resetSnapshotter ];
261+ }
262+ }
263+
264+ - (CGSize)calculateSizeThatFits : (CGSize)constrainedSize
265+ {
266+ CGSize size = self.preferredFrameSize ;
267+ if (CGSizeEqualToSize (size, CGSizeZero)) {
268+ size = constrainedSize;
269+ }
270+ [self setSnapshotSizeIfNeeded: size];
271+ return constrainedSize;
272+ }
273+
253274// Layout isn't usually needed in the box model, but since we are making use of MKMapView this is preferred.
254275- (void )layout
255276{
@@ -258,9 +279,10 @@ - (void)layout
258279 _mapView.frame = CGRectMake (0 .0f , 0 .0f , self.calculatedSize .width , self.calculatedSize .height );
259280 } else {
260281 // If our bounds.size is different from our current snapshot size, then let's request a new image from MKMapSnapshotter.
261- if (!CGSizeEqualToSize (_options.size , self.bounds .size ) && _needsMapReloadOnBoundsChange) {
262- _options.size = self.bounds .size ;
263- [self resetSnapshotter ];
282+ if (_needsMapReloadOnBoundsChange) {
283+ [self setSnapshotSizeIfNeeded: self .bounds.size];
284+ // FIXME: Adding a check for FetchData here seems to cause intermittent map load failures, but shouldn't.
285+ // if (ASInterfaceStateIncludesFetchData(self.interfaceState)) {
264286 [self takeSnapshot ];
265287 }
266288 }
0 commit comments