mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-05-07 13:37:47 +00:00
File scoped namespaces
This commit is contained in:
parent
c14377f976
commit
65aba44af6
152 changed files with 11962 additions and 12115 deletions
|
|
@ -13,74 +13,73 @@ using Microsoft.UI.Xaml.Media;
|
|||
using ImageSource = Avalonia.Media.IImage;
|
||||
#endif
|
||||
|
||||
namespace MapControl.MBTiles
|
||||
namespace MapControl.MBTiles;
|
||||
|
||||
public sealed partial class MBTileSource : TileSource, IDisposable
|
||||
{
|
||||
public sealed partial class MBTileSource : TileSource, IDisposable
|
||||
private static ILogger Logger => field ??= ImageLoader.LoggerFactory?.CreateLogger<MBTileSource>();
|
||||
|
||||
private SQLiteConnection connection;
|
||||
|
||||
public IDictionary<string, string> Metadata { get; } = new Dictionary<string, string>();
|
||||
|
||||
public async Task OpenAsync(string file)
|
||||
{
|
||||
private static ILogger Logger => field ??= ImageLoader.LoggerFactory?.CreateLogger<MBTileSource>();
|
||||
Close();
|
||||
|
||||
private SQLiteConnection connection;
|
||||
connection = new SQLiteConnection("Data Source=" + FilePath.GetFullPath(file) + ";Read Only=True");
|
||||
|
||||
public IDictionary<string, string> Metadata { get; } = new Dictionary<string, string>();
|
||||
await connection.OpenAsync();
|
||||
|
||||
public async Task OpenAsync(string file)
|
||||
using var command = new SQLiteCommand("select * from metadata", connection);
|
||||
|
||||
var reader = await command.ExecuteReaderAsync();
|
||||
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
Close();
|
||||
|
||||
connection = new SQLiteConnection("Data Source=" + FilePath.GetFullPath(file) + ";Read Only=True");
|
||||
|
||||
await connection.OpenAsync();
|
||||
|
||||
using var command = new SQLiteCommand("select * from metadata", connection);
|
||||
|
||||
var reader = await command.ExecuteReaderAsync();
|
||||
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
Metadata[(string)reader["name"]] = (string)reader["value"];
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if (connection != null)
|
||||
{
|
||||
Metadata.Clear();
|
||||
connection.Dispose();
|
||||
connection = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
public override async Task<ImageSource> LoadImageAsync(int zoomLevel, int column, int row)
|
||||
{
|
||||
ImageSource image = null;
|
||||
|
||||
try
|
||||
{
|
||||
using var command = new SQLiteCommand("select tile_data from tiles where zoom_level=@z and tile_column=@x and tile_row=@y", connection);
|
||||
|
||||
command.Parameters.AddWithValue("@z", zoomLevel);
|
||||
command.Parameters.AddWithValue("@x", column);
|
||||
command.Parameters.AddWithValue("@y", (1 << zoomLevel) - row - 1);
|
||||
|
||||
var buffer = (byte[])await command.ExecuteScalarAsync();
|
||||
|
||||
if (buffer?.Length > 0)
|
||||
{
|
||||
image = await ImageLoader.LoadImageAsync(buffer);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger?.LogError(ex, "LoadImageAsync");
|
||||
}
|
||||
|
||||
return image;
|
||||
Metadata[(string)reader["name"]] = (string)reader["value"];
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if (connection != null)
|
||||
{
|
||||
Metadata.Clear();
|
||||
connection.Dispose();
|
||||
connection = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
public override async Task<ImageSource> LoadImageAsync(int zoomLevel, int column, int row)
|
||||
{
|
||||
ImageSource image = null;
|
||||
|
||||
try
|
||||
{
|
||||
using var command = new SQLiteCommand("select tile_data from tiles where zoom_level=@z and tile_column=@x and tile_row=@y", connection);
|
||||
|
||||
command.Parameters.AddWithValue("@z", zoomLevel);
|
||||
command.Parameters.AddWithValue("@x", column);
|
||||
command.Parameters.AddWithValue("@y", (1 << zoomLevel) - row - 1);
|
||||
|
||||
var buffer = (byte[])await command.ExecuteScalarAsync();
|
||||
|
||||
if (buffer?.Length > 0)
|
||||
{
|
||||
image = await ImageLoader.LoadImageAsync(buffer);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger?.LogError(ex, "LoadImageAsync");
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue