Skip to content

Latest commit

 

History

History
404 lines (308 loc) · 12.9 KB

api.md

File metadata and controls

404 lines (308 loc) · 12.9 KB

Modules

TileManager

Api methods used in control and layer For advanced usage

Classes

ControlSaveTiles
TileLayerOffline

Typedefs

ControlStatus : Object

Status of ControlSaveTiles, keeps info about process during downloading ans saving tiles. Used internal and as object for events.

External

L.control

Leaflet control

L.tileLayer

Leaflet tilelayer

TileManager

Api methods used in control and layer For advanced usage

TileManager.getStorageInfo(urlTemplate) ⇒ Promise.<Array.<tileInfo>>

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')

TileManager.downloadTile(tileUrl) ⇒ Promise.<blob>

Kind: static method of TileManager

Param Type
tileUrl string

Example

import { downloadTile } from 'leaflet.offline'
downloadTile(tileInfo.url).then(blob => saveTile(tileInfo, blob))

TileManager.saveTile(tileInfo, blob) ⇒ Promise

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}`))

TileManager.getTileUrl(urlTemplate, data) ⇒ string

Kind: static method of TileManager

Param Type Description
urlTemplate string
data object x, y, z, s
data.s string subdomain

TileManager.getTileUrls(layer, bounds, zoom) ⇒ Array.<tileInfo>

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)

TileManager.getStoredTilesAsJson(layer, tiles) ⇒ object

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,
  );
});

TileManager.removeTile(key) ⇒ Promise

Remove tile by key

Kind: static method of TileManager

Param Type
key string

TileManager.getTile(key) ⇒ Promise.<Blob>

Get single tile blob

Kind: static method of TileManager

Param Type
key string

TileManager.truncate() ⇒ Promise

Remove everything

Kind: static method of TileManager

TileManager~tileInfo ⇒ Promise.<Number>

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'))

ControlSaveTiles

Kind: global class
Properties

Name Type
status ControlStatus

new ControlSaveTiles()

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>',
});

ControlSaveTiles.setLayer(layer)

Change baseLayer

Kind: static method of ControlSaveTiles

Param Type
layer TileLayerOffline

ControlSaveTiles.setOption(name, value)

Update a config option

Kind: static method of ControlSaveTiles

Param Type
name string
value mixed

TileLayerOffline

Kind: global class

new TileLayerOffline()

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);

"storagesize"

Control finished calculating storage size

Kind: event emitted by TileLayerOffline

"savestart"

Start saving tiles

Kind: event emitted by TileLayerOffline

"loadtileend"

Tile fetched

Kind: event emitted by TileLayerOffline

"loadend"

All tiles fetched

Kind: event emitted by TileLayerOffline

"savetileend"

Tile saved

Kind: event emitted by TileLayerOffline

"saveend"

All tiles saved

Kind: event emitted by TileLayerOffline

"tilesremoved"

Tile removed

Kind: event emitted by TileLayerOffline

ControlStatus : Object

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

L.control

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

L.tileLayer

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