-
An object conforming to the
See moreMGLOfflineRegion
protocol determines which resources are required by anMGLOfflinePack
object.Declaration
Objective-C
@protocol MGLOfflineRegion <NSObject>
Swift
protocol MGLOfflineRegion : NSObjectProtocol
-
MGLOfflineStorage implements a singleton (shared object) that manages offline packs. All of this class’s instance methods are asynchronous, reflecting the fact that offline resources are stored in a database. The shared object maintains a canonical collection of offline packs in its
packs
property.Related examples
See the Download an offline map example to learn how to create and register an offline pack for a defined region.
See moreDeclaration
Objective-C
@interface MGLOfflineStorage : NSObject
Swift
class MGLOfflineStorage : NSObject
-
An
MGLOfflinePack
represents a collection of resources necessary for viewing a region offline to a local database.To create an instance of
MGLOfflinePack
, use the+[MGLOfflineStorage addPackForRegion:withContext:completionHandler:]
method. A pack created using-[MGLOfflinePack init]
is immediately invalid.Example
See moreMGLOfflineStorage.shared.addPack(for: region, withContext: context) { (pack, error) in guard let pack = pack else { // If adding the pack fails, log an error to console. print("Error:", error?.localizedDescription ?? "unknown error adding pack at \(#file)(\(#line)) in \(#function)") return } // Start an MGLOfflinePack download pack.resume() }
Declaration
Objective-C
@interface MGLOfflinePack : NSObject
Swift
class MGLOfflinePack : NSObject
-
A structure containing information about an offline pack’s current download progress.
See moreDeclaration
Objective-C
struct MGLOfflinePackProgress {}
Swift
struct MGLOfflinePackProgress
-
The state an offline pack is currently in.
See moreDeclaration
Objective-C
enum MGLOfflinePackState {}
Swift
enum MGLOfflinePackState : Int
-
An offline region defined by a style URL, geographic coordinate bounds, and range of zoom levels.
To minimize the resources required by an irregularly shaped offline region, use the MGLShapeOfflineRegion class instead.
Example
let northeast = CLLocationCoordinate2D(latitude: 40.989329, longitude: -102.062592) let southwest = CLLocationCoordinate2D(latitude: 36.986207, longitude: -109.049896) let bbox = MGLCoordinateBounds(sw: southwest, ne: northeast) let region = MGLTilePyramidOfflineRegion(styleURL: MGLStyle.lightStyleURL, bounds: bbox, fromZoomLevel: 11, toZoomLevel: 14) let context = "Tile Pyramid Region".data(using: .utf8) MGLOfflineStorage.shared.addPack(for: region, withContext: context!)
Related examples
See the Download an offline map example to learn how to define an offline region to be downloaded to a user’s device.
See moreDeclaration
Objective-C
@interface MGLTilePyramidOfflineRegion : NSObject <MGLOfflineRegion, NSSecureCoding, NSCopying>
Swift
class MGLTilePyramidOfflineRegion : NSObject, MGLOfflineRegion, NSSecureCoding, NSCopying
-
An offline region defined by a style URL, geographic shape, and range of zoom levels.
Example
var coordinates = [ CLLocationCoordinate2D(latitude: 45.522585, longitude: -122.685699), CLLocationCoordinate2D(latitude: 45.534611, longitude: -122.708873), CLLocationCoordinate2D(latitude: 45.530883, longitude: -122.678833) ] let triangle = MGLPolygon(coordinates: &coordinates, count: UInt(coordinates.count)) let region = MGLShapeOfflineRegion(styleURL: MGLStyle.lightStyleURL, shape: triangle, fromZoomLevel: 11, toZoomLevel: 14) let context = "Triangle Region".data(using: .utf8) MGLOfflineStorage.shared.addPack(for: region, withContext: context!)
This class requires fewer resources than MGLTilePyramidOfflineRegion for irregularly shaped regions.
See moreDeclaration
Objective-C
@interface MGLShapeOfflineRegion : NSObject <MGLOfflineRegion, NSSecureCoding, NSCopying>
Swift
class MGLShapeOfflineRegion : NSObject, MGLOfflineRegion, NSSecureCoding, NSCopying