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

[WIP] [ios, macos] Calculate number of tiles for an offline region #11965

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions platform/darwin/src/MGLOfflineRegion.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

NS_ASSUME_NONNULL_BEGIN

@class MGLTileSource;

/**
An object conforming to the `MGLOfflineRegion` protocol determines which
resources are required by an `MGLOfflinePack` object. At present, only
Expand All @@ -10,6 +12,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@protocol MGLOfflineRegion <NSObject>

/**
The number of tiles needed to load one of the style’s sources within the region.
*/
-(uint64_t)countTilesForTileSource:(MGLTileSource *)tileSource;

@end

NS_ASSUME_NONNULL_END
16 changes: 16 additions & 0 deletions platform/darwin/src/MGLTilePyramidOfflineRegion.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#import "MGLOfflineRegion_Private.h"
#import "MGLGeometry_Private.h"
#import "MGLStyle.h"
#import "MGLTileSource.h"
#import "MGLVectorTileSource.h"

@interface MGLTilePyramidOfflineRegion () <MGLOfflineRegion_Private>

Expand Down Expand Up @@ -53,6 +55,20 @@ - (instancetype)initWithStyleURL:(NSURL *)styleURL bounds:(MGLCoordinateBounds)b
return self;
}

-(uint64_t)countTilesForTileSource:(MGLTileSource *)tileSource {
auto tilePyramidOfflineRegion = [self offlineRegionDefinition];

mbgl::style::SourceType sourceType;

if ([tileSource isKindOfClass:[MGLVectorTileSource class]]) {
sourceType = mbgl::style::SourceType::Vector;
} else {
sourceType = mbgl::style::SourceType::Raster;
}

return tilePyramidOfflineRegion.tileCount(sourceType, 512, {static_cast<unsigned char>(tilePyramidOfflineRegion.minZoom), static_cast<unsigned char>(tilePyramidOfflineRegion.maxZoom)});
}

- (instancetype)initWithOfflineRegionDefinition:(const mbgl::OfflineRegionDefinition &)definition {
NSURL *styleURL = [NSURL URLWithString:@(definition.styleURL.c_str())];
MGLCoordinateBounds bounds = MGLCoordinateBoundsFromLatLngBounds(definition.bounds);
Expand Down
2 changes: 2 additions & 0 deletions platform/darwin/test/MGLOfflineRegionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ - (void)testEquality {
XCTAssertEqual(original.maximumZoomLevel, original.maximumZoomLevel, @"Maximum zoom level has changed.");
}

// TODO: Add tileCount test(s)

@end