Package com.massifmaps.datasources
Class PersistentCacheTileDataSource
java.lang.Object
com.massifmaps.datasources.TileDataSource
com.massifmaps.datasources.CacheTileDataSource
com.massifmaps.datasources.PersistentCacheTileDataSource
A tile data source that loads tiles from another tile data source
and caches them in an offline sqlite database. Tiles will remain in the database
even after the application is closed.
The database contains table "persistent_cache" with the following fields:
"tileId" (tile id), "compressed" (compressed tile image),
"time" (the time the tile was cached in milliseconds from epoch),
"metaData" (the tile's meta data map as JSON).
Default cache capacity is 50MB.
and caches them in an offline sqlite database. Tiles will remain in the database
even after the application is closed.
The database contains table "persistent_cache" with the following fields:
"tileId" (tile id), "compressed" (compressed tile image),
"time" (the time the tile was cached in milliseconds from epoch),
"metaData" (the tile's meta data map as JSON).
Default cache capacity is 50MB.
-
Constructor Summary
ConstructorsConstructorDescriptionPersistentCacheTileDataSource(TileDataSource dataSource, String databasePath) Constructs a PersistentCacheTileDataSource object from tile data source
and a sqlite database. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear the cache.voidclose()Closes the cache database.longReturns the tile cache capacity.booleanReturns the state of cache only mode.booleanisOpen()Returns the status of the cache database.Loads the specified tile.
Note: the tile coordinate system used here is vertically flipped relative to layer tile coordinate system.voidsetCacheOnlyMode(boolean enabled) Switches the datasource to 'cache only' mode or switches back from the mode.
If enabled, tiles are loaded from the cache only and the original data source is not used.
By default, cache only mode is off.voidsetCapacity(long capacityInBytes) Sets the cache capacity.voidstartDownloadArea(MapBounds mapBounds, int minZoom, int maxZoom, int fetchDelay, TileDownloadListener tileDownloadListener) Starts downloading the specified area.voidStops all background downloader processes.Methods inherited from class com.massifmaps.datasources.CacheTileDataSource
getContainerMetaData, getDataExtent, getDataSource, getMaxZoom, getMinZoom, notifyTilesChangedMethods inherited from class com.massifmaps.datasources.TileDataSource
buildTagValues, containsMetaDataKey, getMaxOverzoomLevel, getMaxZoomWithOverzoom, getMetaData, getMetaDataElement, getProjection, isMaxOverzoomLevelSet, setMaxOverzoomLevel, setMetaData, setMetaDataElement
-
Constructor Details
-
PersistentCacheTileDataSource
Constructs a PersistentCacheTileDataSource object from tile data source
and a sqlite database. The sqlite database must be writable, if it doesn't exist, an empty one
will be created instead.- Parameters:
dataSource- The datasource to be cached.databasePath- The path to the sqlite database, where the tiles will be cached.
-
-
Method Details
-
isCacheOnlyMode
public boolean isCacheOnlyMode()Returns the state of cache only mode.- Returns:
- True when cache only mode is enabled, false otherwise.
-
setCacheOnlyMode
public void setCacheOnlyMode(boolean enabled) Switches the datasource to 'cache only' mode or switches back from the mode.
If enabled, tiles are loaded from the cache only and the original data source is not used.
By default, cache only mode is off.- Parameters:
enabled- True when the mode should be enabled, false otherwise.
-
startDownloadArea
public void startDownloadArea(MapBounds mapBounds, int minZoom, int maxZoom, int fetchDelay, TileDownloadListener tileDownloadListener) Starts downloading the specified area. The area will be stored in the cache.
Note that is the area is too big or cache is already filled, subsequent downloaded tiles
may push existing tile out of the cache.- Parameters:
mapBounds- The bounds of the area to download. The coordinate system of the bounds must be the same as specified in the data source projection.minZoom- The minimum zoom of the tiles to load.maxZoom- The maximum zoom of the tiles to load.fetchDelay- delay between tiles requests. Used to be easy on the serverstileDownloadListener- The tile download listener to use that will receive download related callbacks.
-
stopAllDownloads
public void stopAllDownloads()Stops all background downloader processes. -
isOpen
public boolean isOpen()Returns the status of the cache database.- Returns:
- True if the persistent cache database is open and working, false otherwise.
-
close
public void close()Closes the cache database. The datasource will still work afterwards,
but all requests will be directed to the original datasource. -
loadTile
Description copied from class:TileDataSourceLoads the specified tile.
Note: the tile coordinate system used here is vertically flipped relative to layer tile coordinate system.- Overrides:
loadTilein classTileDataSource- Parameters:
mapTile- The tile to load.- Returns:
- The tile data. If the tile is not available, null may be returned.
-
clear
public void clear()Description copied from class:CacheTileDataSourceClear the cache.- Overrides:
clearin classCacheTileDataSource
-
getCapacity
public long getCapacity()Description copied from class:CacheTileDataSourceReturns the tile cache capacity.- Overrides:
getCapacityin classCacheTileDataSource- Returns:
- The tile cache capacity in bytes.
-
setCapacity
public void setCapacity(long capacityInBytes) Description copied from class:CacheTileDataSourceSets the cache capacity.- Overrides:
setCapacityin classCacheTileDataSource- Parameters:
capacityInBytes- The new tile cache capacity in bytes.
-