MaplyRemoteTileInfo
@interface MaplyRemoteTileInfo : NSObject <MaplyRemoteTileInfoProtocol>
The remote tile info encapsulates settings for a remote tile source. It describes where the tile source is and presents URLs for getting the data, and information about local caching.
-
Initialize with enough information to fetch remote tiles.
This version of the init method takes all the explicit information needed to fetch remote tiles. This includes the base URL, file extension (e.g. image type), and min and max zoom levels.
Declaration
Objective-C
- (nonnull instancetype)initWithBaseURL:(NSString *_Nonnull)baseURL ext:(NSString *_Nullable)ext minZoom:(int)minZoom maxZoom:(int)maxZoom;
Swift
init(baseURL: String, ext: String?, minZoom: Int32, maxZoom: Int32)
Parameters
baseURL
The base URL for fetching TMS tiles.
ext
Extension for the images we’ll be fetching, typically @
png
or @jpg
minZoom
The minimum zoom level to fetch. This really should be 0.
maxZoom
The maximum zoom level to fetch.
Return Value
The MaplyRemoteTileSource object or nil on failure.
-
Initialize from a remote tile spec.
This version of the initializer takes an NSDictionary parsed from a JSON tile spec. Take a look at the tile spec itself here (https://github.com/mapbox/tilejson-spec). Basically it defines the available URLs (there can be multiple), the min and max zoom levels, coordinate system (not really) and file extension. In many cases the coordinate system extents can’t be trusted.
Declaration
Objective-C
- (nullable instancetype)initWithTilespec:(NSDictionary *_Nonnull)jsonSpec;
Swift
init?(tilespec jsonSpec: [AnyHashable : Any])
Parameters
jsonSpec
An NSDictionary parsed from the JSON tile spec.
-
The base URL we’re fetching from.
This is typically the top of the pyramid and we’ll tack on the level, row, and column to form a full URL.
Declaration
Objective-C
@property (readonly, nonatomic, nonnull) NSString *baseURL;
Swift
var baseURL: String { get }
-
The minimum zoom level available.
This is the lowest level we’ll try to fetch. Any levels below that will be filled in with placeholders. Those are empty, but they allow us to load tiles beneath.
Declaration
Objective-C
@property (assign, readwrite, nonatomic) int minZoom;
Swift
var minZoom: Int32 { get set }
-
The maximum zoom level available.
This is the highest level (e.g. largest) that we’ll fetch for a given pyramid tile source. The source can sparse, so you are not required to have these tiles available, but this is as high as the MaplyQuadImageTilesLayer will fetch.
Declaration
Objective-C
@property (assign, readwrite, nonatomic) int maxZoom;
Swift
var maxZoom: Int32 { get set }
-
The image type and file extension for the tiles.
This is the filename extension, which implies the image type. It’s typically @
png
or @jpg
, but it can be anything that UIImage will recognize.Declaration
Objective-C
@property (readwrite, strong, nonatomic, nonnull) NSString *ext;
Swift
var ext: String { get set }
-
The timeout assigned to the NSMutableURLRequest we’re using to fetch tiles.
This is non set by default. If set, we’ll use this value as the timeout on the NSMutableURLRequest we use for fetching tiles. This lets you extent it where appropriate or shorten it if you like.
Declaration
Objective-C
@property (assign, readwrite, nonatomic) float timeOut;
Swift
var timeOut: Float { get set }
-
Number of pixels on a side for any given tile.
This is the number of pixels on any side for a given tile and it’s typically 128 or 256. This is largely a hint for the screen space based pager. In most cases you are not required to actually return an image of the size you specify here, but it’s a good idea.
Declaration
Objective-C
@property (assign, readwrite, nonatomic) int pixelsPerSide;
Swift
var pixelsPerSide: Int32 { get set }
-
The coordinate system the image pyramid is in.
This is typically going to be MaplySphericalMercator with the web mercator extents. That’s what you’ll get from OpenStreetMap and, often, MapBox. In other cases it might be MaplyPlateCarree, which covers the whole earth. Sometimes it might even be something unique of your own.
Declaration
Objective-C
@property (readwrite, strong, nonatomic, nullable) MaplyCoordinateSystem *coordSys;
Swift
var coordSys: MaplyCoordinateSystem? { get set }
-
The cache directory for image tiles.
In general, we want to cache. The globe, in particular, is going to fetch the same tiles over and over, quite a lot. The cacheing behavior is a little dumb. It will just write files to the given directory forever. If you’re interacting with a giant image pyramid, that could be problematic.
Declaration
Objective-C
@property (readwrite, strong, nonatomic, nullable) NSString *cacheDir;
Swift
var cacheDir: String? { get set }
-
The maximum age of a cached file in seconds.
If set, tiles in the cache older than this number of seconds will not be used; rather, a new copy of the tile will be retrieved from the remote source, and the locally cached tile will be updated. This is useful for tiles that represent impermanent data, such as weather information.
Declaration
Objective-C
@property (assign, readwrite, nonatomic) int cachedFileLifetime;
Swift
var cachedFileLifetime: Int32 { get set }
-
Query string to add after the URL we’re fetching from.
Add your access tokens and other query arguments.
Declaration
Objective-C
@property (readwrite, strong, nonatomic, nullable) NSString *queryStr;
Swift
var queryStr: String? { get set }
-
If set, we’ve decided this is a replacement URL with {x},{y} and {z} in the baseURL string
Declaration
Objective-C
@property (assign, readwrite, nonatomic) _Bool replaceURL;
Swift
var replaceURL: Bool { get set }
-
Add a bounding box tiles are valid within.
By default all areas within the coordinate system are valid for paging tiles. If you call this, then only the bounding boxes you’ve added are valid. You can call this method multiple times.
Declaration
Objective-C
- (void)addBoundingBox:(MaplyBoundingBox *_Nonnull)bbox;
Swift
func add(_ bbox: UnsafeMutablePointer
Parameters
bbox
Bounding box for valid tiles in the local coordinate system.
-
Add a bounding box tiles are valid within in geo coordinates.
By default all areas within the coordinate system are valid for paging tiles. If you call this, then only the bounding boxes you’ve added are valid. You can call this method multiple times.
Declaration
Objective-C
- (void)addGeoBoundingBox:(MaplyBoundingBox *_Nonnull)bbox;
Swift
func addGeoBoundingBox(_ bbox: UnsafeMutablePointer
Parameters
bbox
Bounding box for valid tiles in geo coordinates (radians).
-
Generate the request for a given tile.
If someone outside of this request wants to fetch the data directly, they can do so by using this NSURLRequest.
Declaration
Objective-C
- (nullable NSURLRequest *)requestForTile:(MaplyTileID)tileID;
Swift
func request(forTile tileID: MaplyTileID) -> URLRequest?
Parameters
tileID
The tile we’d like the NSURLRequest for.
Return Value
An NSURLRequest object you can use to fetch data for the tile.
-
The full path for a cached tile.
This returns the full path to where a tile is or where a tile would be if it were cached.
We don’t check if the tile is there or not.
Declaration
Objective-C
- (nullable NSString *)fileNameForTile:(MaplyTileID)tileID;
Swift
func fileName(forTile tileID: MaplyTileID) -> String?
Parameters
tileID
The tile we need the filename for.
-
Check if a given tile is stored in the local cache.
This checks if the given tile ID is represented in the local cache directory.
Declaration
Objective-C
- (_Bool)tileIsLocal:(MaplyTileID)tileID frame:(int)frame;
Swift
func tileIsLocal(_ tileID: MaplyTileID, frame: Int32) -> Bool
Parameters
tileID
The tile we’d like to check for.
frame
If you’re loading individual frames this will be the frame. Otherwise, -1.
-
Check if we should even try to load a given tile.
Check whether tile level is within zoom limits for the source, and if the tile is within any MBRs that have been added.
Declaration
Objective-C
- (_Bool)validTile:(MaplyTileID)tileID bbox:(MaplyBoundingBox)bbox;
Swift
func validTile(_ tileID: MaplyTileID, bbox: MaplyBoundingBox) -> Bool
Parameters
tileID
The tile we’re asking about.
bbox
The bounding box of the tile we’re asking about, for convenience.
Return Value
True if the tile is loadable, false if not.
-
Assign a user object here to get it passed back to you.
Optional property used by developers.
Declaration
Objective-C
@property (readwrite, strong, nonatomic) id _Nullable userObject;
Swift
var userObject: Any? { get set }