Search in sources :

Example 6 with SQLiteTileSource

use of net.osmand.plus.SQLiteTileSource in project Osmand by osmandapp.

the class TilesCache method getTileForMap.

protected synchronized T getTileForMap(String tileId, ITileSource map, int x, int y, int zoom, boolean loadFromInternetIfNeeded, boolean sync, boolean loadFromFs, boolean deleteBefore) {
    if (tileId == null) {
        tileId = calculateTileId(map, x, y, zoom);
        if (tileId == null) {
            return null;
        }
    }
    if (deleteBefore) {
        cache.remove(tileId);
        if (map instanceof SQLiteTileSource) {
            ((SQLiteTileSource) map).deleteImage(x, y, zoom);
        } else {
            File f = new File(dirWithTiles, tileId);
            if (f.exists()) {
                f.delete();
            }
        }
        tilesOnFS.put(tileId, null);
    }
    if (loadFromFs && cache.get(tileId) == null && map != null) {
        boolean locked = map instanceof SQLiteTileSource && ((SQLiteTileSource) map).isLocked();
        if (!loadFromInternetIfNeeded && !locked && !tileExistOnFileSystem(tileId, map, x, y, zoom)) {
            return null;
        }
        String url = loadFromInternetIfNeeded ? map.getUrlToLoad(x, y, zoom) : null;
        File toSave = null;
        if (url != null) {
            if (map instanceof SQLiteTileSource) {
                toSave = new File(dirWithTiles, calculateTileId(((SQLiteTileSource) map).getBase(), x, y, zoom));
            } else {
                toSave = new File(dirWithTiles, tileId);
            }
        }
        TileLoadDownloadRequest req = new TileLoadDownloadRequest(dirWithTiles, url, toSave, tileId, map, x, y, zoom, map.getReferer());
        if (sync) {
            return getRequestedTile(req);
        } else {
            asyncLoadingThread.requestToLoadTile(req);
        }
    }
    return cache.get(tileId);
}
Also used : File(java.io.File) TileLoadDownloadRequest(net.osmand.plus.resources.AsyncLoadingThread.TileLoadDownloadRequest) SQLiteTileSource(net.osmand.plus.SQLiteTileSource)

Aggregations

SQLiteTileSource (net.osmand.plus.SQLiteTileSource)6 File (java.io.File)4 Bitmap (android.graphics.Bitmap)2 QuadRect (net.osmand.data.QuadRect)2 ITileSource (net.osmand.map.ITileSource)2 TileSourceTemplate (net.osmand.map.TileSourceManager.TileSourceTemplate)2 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 AsyncTask (android.os.AsyncTask)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 OsmandSettings (net.osmand.plus.OsmandSettings)1 TileLoadDownloadRequest (net.osmand.plus.resources.AsyncLoadingThread.TileLoadDownloadRequest)1