Utilities and source providers for creating and managing offline tile caches with Mapbox GL JS
Features:
-
Seamless fallback to offline tiles. If a source is declared as
offline-<type>
and contains cached tiles, those will always be used before a network request is made. This not only reduces network load but does not require the user to toggle a separate map or style to use offline maps. -
Stores tiles in IndexedDB, which is widely supported in modern browsers.
-
Not a fork of Mapbox GL JS
-
Cordova/Ionic friendly
IMPORTANT: you are responsible for following the terms of service associated with the tile providers you are caching. If you are caching Mapbox tiles please be aware that at the time of writing the limit is 6,000 tiles per device.
Installation goes here
Usage goes here
Class for managing offline map caches. Also sets up special source types
map
- an instance of a Mapbox GL JS mapaccessToken
- a valid Mapbox access token. Used for authenticating tile requestsprops
- database configuration object for IndexedDBdbname
- optional, defaulttile-cache
- name of the databasedbversion
- optional, default1.0
- version of the databasedbsize
- optional, default(1024*1024)*10
- size of the database in bytesdebug
- optional, defaultfalse
- enable verbose creation and error logging
callback(error)
- a callback called when the OfflineManager is set up
Wrapper for @mapbox/tile-cover
that returns the [z, x, y]
of the tile at a
given location
Retrieve information about a single cache by name
name
- required - the name of the cachecallback(error, info)
- requirederror
- something went wrong fetching the packinfo
- Object describing the cache
Retrieve all caches
callback(error, packs)
error
- something went wrong fetching the packspacks
- array of objects
Delete a single cache by name
name
- required - the name of the cache to deletecallback(error)
- requirederror
- something went wrong while deleting the cache
Delete all existing caches
callback(error)
- requirederror
- something went wrong while deleting the caches
Create a new map cache. Returns an instance of TileDownloadManager
that can be
used to abort the creation of the cache.
-
params
- required - configuration object for cachestyle
- required - the Mapbox GL style object to cache. Must contain one or more validsources
bounds
- required - an array describing the bounding box to cache in the format[minLng, minLat, maxLng, maxLat]
minZoom
- required - the minimum zoom level to cachemaxZoom
- required - the maximum zoom level to cachename
- optional - a name for the cache. Defaults to the current date and time
-
progressCallback(null, progress)
- required - a callback used to monitor progress of the downloadprogress
- an object indicating cache progressfetched
- the number of tiles successfully downloadedtotal
- the total number of tiles to be downloadedsource
- the corresponding source the above statistics refer to
-
errorCallback(error)
- required - callback used to monitor tile download errorserror
- an error object describing what went wrong
-
done(bytes)
- required - callback used to indicate all sources in the style have been successfully downloadedbytes
- the total number of bytes downloaded
Get the number of tiles needed for a given cache request. Useful for knowing a priori how many tiles will be downloaded in order to abide by service limits and inform the user of how large the download will be.
params
- required - identical to those in.makeCache()
MIT