Package 

Class SqlTileWriter

  • All Implemented Interfaces:
    org.osmdroid.tileprovider.modules.IFilesystemCache , org.osmdroid.util.SplashScreenable

    
    public class SqlTileWriter
     implements IFilesystemCache, SplashScreenable
                        

    An implementation of IFilesystemCache based on the original TileWriter. It writes tiles to a sqlite database cache. It supports expiration timestamps if provided by the server from which the tile was downloaded. Trimming of expired

    If the database exceeds getInstance cache exceeds 600 Mb then it will be trimmed to 500 Mb by deleting files that expire first.

    • Constructor Detail

      • SqlTileWriter

        SqlTileWriter()
    • Method Detail

      • runCleanupOperation

         void runCleanupOperation()

        this could be a long running operation, don't run on the UI thread unless necessary.This function prunes the database for old or expired tiles.

      • saveFile

         boolean saveFile(ITileSource pTileSourceInfo, long pMapTileIndex, InputStream pStream, Long pExpirationTime)

        Save an InputStream as the specified tile in the file system cache for the specified tilesource.

        Parameters:
        pTileSourceInfo - a tile source
        pMapTileIndex - a tile
        pStream - an InputStream
      • exists

         boolean exists(String pTileSource, long pMapTileIndex)

        Returns true if the given tile source and tile coordinates exist in the cache

      • exists

         boolean exists(ITileSource pTileSource, long pMapTileIndex)

        Returns true if the given tile source and tile coordinates exist in the cache

      • onDetach

         void onDetach()

        Now we use only one static instance of database, which should never be closed

      • purgeCache

         boolean purgeCache()

        purges and deletes everything from the cache database

      • purgeCache

         boolean purgeCache(String mTileSourceName)

        purges and deletes all tiles from the given tile source name from the cache database

      • importFromFileCache

         Array<int> importFromFileCache(boolean removeFromFileSystem)

        a helper method to import file system stored map tiles into the sql tile cacheon successful import, the tiles are removed from the file system.

        This can take a long time, so consider running this off of the main thread.

      • remove

         boolean remove(ITileSource pTileSourceInfo, long pMapTileIndex)

        Removes a specific tile from the cache

      • getRowCount

         long getRowCount(String tileSourceName)

        Returns the number of tiles in the cache for the specified tile source name

      • getRowCount

         long getRowCount(String pTileSourceName, int pZoom, Collection<Rect> pInclude, Collection<Rect> pExclude)

        Count cache tiles

        Parameters:
        pTileSourceName - the tile source name (possibly null)
        pZoom - the zoom level
        pInclude - a collection of bounding boxes to include (possibly null/empty)
        pExclude - a collection of bounding boxes to exclude (possibly null/empty)
      • getSize

         long getSize()

        Returns the size of the database file in bytes.

      • getFirstExpiry

         long getFirstExpiry()

        Returns the expiry time of the tile that expires first.

      • getIndex

         static long getIndex(long pX, long pY, long pZ)
      • getIndex

         static long getIndex(long pMapTileIndex)

        Gets the single column index value for a map tileUnluckily, "map tile index" and "sql pk" don't match

      • runCleanupOperation

         void runCleanupOperation(long pToBeDeleted, int pBulkSize, long pPauseMillis, boolean pIncludeUnexpired)
        Parameters:
        pToBeDeleted - Amount of bytes to delete (as tile blob size)
        pBulkSize - Number of tiles to delete in bulk
        pPauseMillis - Pause between bulk actions, in order not to play it not aggressive on the CPU
        pIncludeUnexpired - Should we also delete tiles that are not expired?
      • delete

         long delete(String pTileSourceName, int pZoom, Collection<Rect> pInclude, Collection<Rect> pExclude)

        Delete cache tiles

        Parameters:
        pTileSourceName - the tile source name (possibly null)
        pZoom - the zoom level
        pInclude - a collection of bounding boxes to include (possibly null/empty)
        pExclude - a collection of bounding boxes to exclude (possibly null/empty)