/** * Default constructor. * * @param projection projection for the layer. * @param minZoom minimum zoom supported by the layer. * @param maxZoom maximum zoom supported by the layer. * @param id unique layer id. Id for the layer must be depend ONLY on the layer source, otherwise * tile caching will not work properly. * @param path path to the local Sqlite database file. SQLiteException will be thrown if the * database does not exist or can not be opened in read-only mode. * @param ctx Android application context. * @throws IOException exception if file not exists */ public MBTilesMapLayer( Projection projection, int minZoom, int maxZoom, int id, String path, Context ctx) throws IOException { super(projection, minZoom, maxZoom, id, path); // TODO: use constructor without path if (!(new File(path)).exists()) { throw new IOException("not existing file: " + path); } db = new MBTilesDbHelper(ctx, path); db.open(); hasUtfGrid = db.getMetadata().containsKey("template"); }
@Override public void run() { super.run(); Log.debug("DbMapLayer task: Start loading " + " zoom=" + z + " x=" + x + " y=" + y); // y is flipped (origin=sw in mbtiles) finished(db.getTileImg(z, x, (1 << (z)) - 1 - y)); cleanUp(); }
@Override public Map<String, String> getUtfGridTooltips( MapTile clickedTile, MutableMapPos tilePos, String template) { // template will be loaded in database request, ignored here return db.getUtfGridTooltips(clickedTile, tilePos); }
/** Close database file. After calling this, new tiles will not be read from the database. */ public void close() { db.close(); db = null; }