chayesri

Override ImageTiledLayer shows that Mbtiles file is very slow

Discussion created by chayesri on Nov 9, 2018

Reading Mbtiles by overriding getURL, notice that the tile data is requested by callback onRequestRequired, but the callback is very slow and no longer requests data at high levels, why?

 

SDK Version:100.3

Demo:

public class MBTilesLayer extends ImageTiledLayer {
    String mMbTilesFilename;
    private SQLiteDatabase mapDb;
    //构造一个离线MBTiles图层
    public MBTilesLayer( String _mbTilesPath ){
        super( MbtilesUtil.newInstance().getMBTileTileinfo( _mbTilesPath ),
         MbtilesUtil.newInstance().getMBTileEnvelope( _mbTilesPath ) );
       
   mMbTilesFilename = _mbTilesPath;
       
        try {
            mapDb = SQLiteDatabase.openDatabase( mMbTilesFilename, null, SQLiteDatabase.OPEN_READONLY );
            //setBufferSize(BufferSize.NONE);
        } catch (SQLException ex) {
            Log.e(this.getName(), ex.getMessage());
            throw (ex);
        }

    }

    @Override
    protected byte[] getTile(TileKey tileKey) {

        // need to flip origin
        int nRows = (1 << tileKey.getLevel()); // Num rows = 2^level
        int tmsRow = nRows - 1 - tileKey.getRow();

        String sql = "SELECT tile_data FROM tiles WHERE zoom_level = " + Integer.toString( tileKey.getLevel() )
                + " AND tile_column = " + Integer.toString( tileKey.getColumn() ) + " AND tile_row = " + Integer.toString( tmsRow );
        System.out.println( "Sql " + sql );

        Cursor imageCur = mapDb.rawQuery(sql,null);
        if (imageCur.moveToFirst()) {
            return imageCur.getBlob(0);
        }

        return null; // Alternatively we might return a "no data" tile
    }
}

Outcomes