MaplyRemoteTileSource
@interface MaplyRemoteTileSource : NSObject <MaplyTileSource>
The remote tile source knows how to fetch remote image pyramids.
This is the MaplyTileSource compliant object that communicates with remote servers and fetches individual tiles as needed by the MaplyQuadImageTileLayer.
It can be initialized in a couple of different ways depending on the information you have available. Either you explicitly provide the baseURL, min and max levels and such, or hand in an NSDictionary that’s been parsed from a tile spec.
The remote tile source also handles cacheing if it you give it a cacheDir to work in. By default cacheing is off (so be careful).
See
MaplyQuadImageTilesLayer-
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
- (nullable 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.
-
Read the image, but only if it’s in the cache.
MaplyRemoteTileSource uses asynchronous fetching. This method is inherently synchronous. You expect it to return the image for a tile right now. So this method only works if the tile is in the cache. Be sure to check on that first.
Declaration
Objective-C
- (nullable id)imageForTile:(MaplyTileID)tileID;
Swift
func image(forTile tileID: MaplyTileID) -> Any?
Parameters
tileID
The tile (that should be in the cache) you want to read.
-
Initialize with remote tile info.
The MaplyRemoteTileInfo object stores all the specifics about remote tile data. We actually created one of those for the other init calls in this objects. Fill that object in and then call this initializaer.
Declaration
Objective-C
- (nullable instancetype)initWithInfo: (NSObject<MaplyRemoteTileInfoProtocol> *_Nonnull)info;
Swift
init?(info: NSObjectProtocol
Parameters
info
The MaplyRemoteTileInfo describing where to fetch the tiles.
-
Description of where we fetch the tiles from and where to cache them.
Declaration
Objective-C
@property (readonly, nonatomic, nonnull) NSObject<MaplyRemoteTileInfoProtocol> *tileInfo;
Swift
var tileInfo: NSObjectProtocol
-
A delegate for tile loads and failures.
If set, you’ll get callbacks when the various tiles load (or don’t). You get called in all sorts of threads. Act accordingly.
Declaration
Objective-C
@property (readwrite, nonatomic, nullable) NSObject<MaplyRemoteTileSourceDelegate> *delegate;
Swift
weak var delegate: MaplyRemoteTileSourceDelegate? { get set }
-
Passes through the coord system from the MaplyRemoteTileInfo
Declaration
Objective-C
@property (readwrite, strong, nonatomic, nonnull) MaplyCoordinateSystem *coordSys;
Swift
var coordSys: MaplyCoordinateSystem { get set }
-
Passes through the cacheDir from the MaplyRemoteTileInfo
Declaration
Objective-C
@property (readwrite, strong, nonatomic, nullable) NSString *cacheDir;
Swift
var cacheDir: String? { get set }
-
If set, we’ll track the outstanding connections across all remote tile sources
Declaration
Objective-C
+ (void)setTrackConnections:(_Bool)track;
Swift
class func setTrackConnections(_ track: Bool)
-
Number of outstanding connections across all remote tile sources
Declaration
Objective-C
+ (int)numOutstandingConnections;
Swift
class func numOutstandingConnections() -> Int32