getVectorTileBytes method

Future<Uint8List> getVectorTileBytes(
  1. TileIdentity tile
)

Get VectorTileBytes in binary tile TileIdentity(z, x, y)

Implementation

Future<Uint8List> getVectorTileBytes(TileIdentity tile) async {
  final max = pow(2, tile.z).toInt();
  if (tile.x >= max || tile.y >= max || tile.x < 0 || tile.y < 0) {
    throw ProviderException(
        message: 'Invalid tile coordinates $tile',
        retryable: Retryable.none,
        statusCode: 400);
  }

  _database ??= await getDBFuture;

  final resultSet =
      await _database!.query('tiles', columns: ['tile_data'], where: '''
    zoom_level = ?
    AND tile_column = ?
    AND tile_row = ?
    ''', whereArgs: [tile.z, tile.x, max - tile.y - 1]);

  if (resultSet.length == 1) {
    final tileData = resultSet.first['tile_data'];
    final ungzipTile = GZipCodec().decode(tileData as Uint8List);
    return ungzipTile as Uint8List;
  } else if (resultSet.length > 1) {
    throw ProviderException(
        message: 'Too many match tiles', retryable: Retryable.none);
  } else {
    return Uint8List(0);
  }
}