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