- TileManager
Api methods used in control and layer For advanced usage
- ControlStatus :
Object
Status of ControlSaveTiles, keeps info about process during downloading ans saving tiles. Used internal and as object for events.
- L.control
Leaflet control
- L.tileLayer
Leaflet tilelayer
Api methods used in control and layer For advanced usage
- TileManager
- static
- .getStorageInfo(urlTemplate) ⇒
Promise.<Array.<tileInfo>>
- .downloadTile(tileUrl) ⇒
Promise.<blob>
- .saveTile(tileInfo, blob) ⇒
Promise
- .getTileUrl(urlTemplate, data) ⇒
string
- .getTileUrls(layer, bounds, zoom) ⇒
Array.<tileInfo>
- .getStoredTilesAsJson(layer, tiles) ⇒
object
- .removeTile(key) ⇒
Promise
- .getTile(key) ⇒
Promise.<Blob>
- .truncate() ⇒
Promise
- .getStorageInfo(urlTemplate) ⇒
- inner
- ~tileInfo ⇒
Promise.<Number>
- ~tileInfo ⇒
- static
Kind: static method of TileManager
Param | Type |
---|---|
urlTemplate | string |
Example
import { getStorageInfo } from 'leaflet.offline'
getStorageInfo('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png')
Kind: static method of TileManager
Param | Type |
---|---|
tileUrl | string |
Example
import { downloadTile } from 'leaflet.offline'
downloadTile(tileInfo.url).then(blob => saveTile(tileInfo, blob))
TODO validate tileinfo props?
Kind: static method of TileManager
Param | Type |
---|---|
tileInfo | tileInfo |
blob | Blob |
Example
saveTile(tileInfo, blob).then(() => console.log(`saved tile from ${tileInfo.url}`))
Kind: static method of TileManager
Param | Type | Description |
---|---|---|
urlTemplate | string |
|
data | object |
x, y, z, s |
data.s | string |
subdomain |
Kind: static method of TileManager
Param | Type | Description |
---|---|---|
layer | object |
leaflet tilelayer |
bounds | object |
L.bounds |
zoom | number |
zoomlevel 0-19 |
Example
const p1 = L.point(10, 10)
const p2 = L.point(40, 60)
getTileUrls(layer, L.bounds(p1,p2), 12)
Get a geojson of tiles from one resource
Kind: static method of TileManager
Returns: object
- geojson
Param | Type |
---|---|
layer | object |
tiles | Array.<tileInfo> |
Example
const urlTemplate = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
const getGeoJsonData = () => LeafletOffline.getStorageInfo(urlTemplate)
.then((data) => LeafletOffline.getStoredTilesAsJson(baseLayer, data));
getGeoJsonData().then((geojson) => {
storageLayer = L.geoJSON(geojson).bindPopup(
(clickedLayer) => clickedLayer.feature.properties.key,
);
});
Remove tile by key
Kind: static method of TileManager
Param | Type |
---|---|
key | string |
Get single tile blob
Kind: static method of TileManager
Param | Type |
---|---|
key | string |
Remove everything
Kind: static method of TileManager
Kind: inner typedef of TileManager
Returns: Promise.<Number>
- get number of store tiles
Properties
Name | Type | Description |
---|---|---|
key | string |
storage key |
url | string |
resolved url |
urlTemplate | string |
orig url, used to find tiles per layer |
x | string |
left point of tile |
y | string |
top point coord of tile |
z | string |
tile zoomlevel |
Example
import { getStorageLength } from 'leaflet.offline'
getStorageLength().then(i => console.log(i + 'tiles in storage'))
Kind: global class
Properties
Name | Type |
---|---|
status | ControlStatus |
Shows control on map to save tiles
Example
const controlSaveTiles = L.control.savetiles(baseLayer, {
zoomlevels: [13, 16], // optional zoomlevels to save, default current zoomlevel
confirm(layer, successCallback) {
if (window.confirm(`Save ${layer._tilesforSave.length}`)) {
successCallback();
}
},
confirmRemoval(layer, successCallback) {
if (window.confirm('Remove all the tiles?')) {
successCallback();
}
},
saveText: '<i class="fa fa-download" aria-hidden="true" title="Save tiles"></i>',
rmText: '<i class="fa fa-trash" aria-hidden="true" title="Remove tiles"></i>',
});
Change baseLayer
Kind: static method of ControlSaveTiles
Param | Type |
---|---|
layer | TileLayerOffline |
Update a config option
Kind: static method of ControlSaveTiles
Param | Type |
---|---|
name | string |
value | mixed |
Kind: global class
A layer that uses stored tiles when available. Falls back to online.
Example
const tileLayerOffline = L.tileLayer
.offline('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Map data {attribution.OpenStreetMap}',
subdomains: 'abc',
minZoom: 13,
})
.addTo(map);
Control finished calculating storage size
Kind: event emitted by TileLayerOffline
Start saving tiles
Kind: event emitted by TileLayerOffline
Tile fetched
Kind: event emitted by TileLayerOffline
All tiles fetched
Kind: event emitted by TileLayerOffline
Tile saved
Kind: event emitted by TileLayerOffline
All tiles saved
Kind: event emitted by TileLayerOffline
Tile removed
Kind: event emitted by TileLayerOffline
Status of ControlSaveTiles, keeps info about process during downloading ans saving tiles. Used internal and as object for events.
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
storagesize | number |
total number of saved tiles. |
lengthToBeSaved | number |
number of tiles that will be saved in db during current process |
lengthSaved | number |
number of tiles saved during current process |
lengthLoaded | number |
number of tiles loaded during current process |
_tilesforSave | array |
tiles waiting for processing |
Leaflet control
Kind: global external
See: Control
L.control.savetiles(baseLayer) ⇒ ControlSaveTiles
Kind: static method of L.control
Param | Type | Description |
---|---|---|
baseLayer | object |
http://leafletjs.com/reference-1.2.0.html#tilelayer |
Properties
Name | Type | Description |
---|---|---|
options | Object |
|
[options.position] | string |
default topleft |
[options.saveText] | string |
html for save button, default + |
[options.rmText] | string |
html for remove button, deflault - |
[options.maxZoom] | number |
maximum zoom level that will be reached when saving tiles with saveWhatYouSee. Default 19 |
[options.parallel] | number |
parallel downloads (default 50) |
[options.saveWhatYouSee] | boolean |
save the tiles that you see on screen plus deeper zooms, ignores zoomLevels options. Default false |
[options.confirm] | function |
function called before confirm, default null. Args of function are ControlStatus and callback. |
[options.confirmRemoval] | function |
function called before confirm, default null |
Leaflet tilelayer
Kind: global external
See: TileLayer
L.tileLayer.offline(url, options) ⇒ TileLayerOffline
Kind: static method of L.tileLayer
Returns: TileLayerOffline
- an instance of TileLayerOffline
Param | Type | Description |
---|---|---|
url | string |
[description] |
options | object |
http://leafletjs.com/reference-1.2.0.html#tilelayer |