Search in sources :

Example 1 with TileLoadDownloadRequest

use of net.osmand.plus.resources.AsyncLoadingThread.TileLoadDownloadRequest in project Osmand by osmandapp.

the class ResourceManager method tileDownloaded.

public synchronized void tileDownloaded(DownloadRequest request) {
    if (request instanceof TileLoadDownloadRequest) {
        TileLoadDownloadRequest req = ((TileLoadDownloadRequest) request);
        TilesCache cache = getTilesCache(req.tileSource);
        if (cache != null) {
            cache.tilesOnFS.put(req.tileId, Boolean.TRUE);
        }
    }
}
Also used : TileLoadDownloadRequest(net.osmand.plus.resources.AsyncLoadingThread.TileLoadDownloadRequest)

Example 2 with TileLoadDownloadRequest

use of net.osmand.plus.resources.AsyncLoadingThread.TileLoadDownloadRequest 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

TileLoadDownloadRequest (net.osmand.plus.resources.AsyncLoadingThread.TileLoadDownloadRequest)2 File (java.io.File)1 SQLiteTileSource (net.osmand.plus.SQLiteTileSource)1