Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Add option to prefetch low-resolution tiles #14031

Merged
merged 5 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions platform/ios/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,15 @@ MGL_EXPORT IB_DESIGNABLE
*/
@property (nonatomic, assign) MGLMapViewPreferredFramesPerSecond preferredFramesPerSecond;

/**
A Boolean value indicating whether the map should prefetch tiles.

Loads tiles at a lower zoom-level to pre-render a low resolution preview while more detailed tiles are loaded.

Default is YES.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The developer may be unfamiliar with the concept of prefetching simplified tiles, so here’s an attempt at making the mechanism easy to understand:

When this property is set to YES, the map view prefetches loads tiles designed for a low zoom level and displays them until receiving more detailed tiles for the current zoom level. The prefetched tiles typically contain simplified versions of each shape, improving the map view’s perceived performance. The default value of this property is YES.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. That's a better one. I'll change to that.

*/
@property (nonatomic, assign) BOOL prefetchesTiles;

@property (nonatomic) NSArray<NSString *> *styleClasses __attribute__((unavailable("Support for style classes has been removed.")));

- (BOOL)hasStyleClass:(NSString *)styleClass __attribute__((unavailable("Support for style classes has been removed.")));
Expand Down
12 changes: 12 additions & 0 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2630,6 +2630,18 @@ - (void)setShowsScale:(BOOL)showsScale
}
}

- (void)setPrefetchesTiles:(BOOL)prefetchesTiles{
if(!prefetchesTiles)
{
_mbglMap->setPrefetchZoomDelta(0);
}
else
{
//Reset to default value.
_mbglMap->setPrefetchZoomDelta(4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per #9438 (comment), use the constant DEFAULT_PREFETCH_ZOOM_DELTA instead of hard-coding the literal number 4. Also, the if/else statement can be written more succinctly as a ternary expression: setPrefetchZoomDelta(prefetchesTiles ? DEFAULT_PREFETCH_ZOOM_DELTA : 0).

}
}

friedbunny marked this conversation as resolved.
Show resolved Hide resolved
#pragma mark - Accessibility -

- (NSString *)accessibilityValue
Expand Down