mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Update MBTileSource.cs
This commit is contained in:
parent
f03a627a86
commit
3b29c97bc6
|
|
@ -20,7 +20,7 @@ using ImageSource = Avalonia.Media.IImage;
|
||||||
|
|
||||||
namespace MapControl.MBTiles
|
namespace MapControl.MBTiles
|
||||||
{
|
{
|
||||||
public class MBTileSource : TileSource, IDisposable
|
public sealed class MBTileSource : TileSource, IDisposable
|
||||||
{
|
{
|
||||||
private SQLiteConnection connection;
|
private SQLiteConnection connection;
|
||||||
|
|
||||||
|
|
@ -57,28 +57,7 @@ namespace MapControl.MBTiles
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Dispose(true);
|
Close();
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing)
|
|
||||||
{
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<byte[]> ReadImageBufferAsync(int x, int y, int zoomLevel)
|
|
||||||
{
|
|
||||||
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", x);
|
|
||||||
command.Parameters.AddWithValue("@y", (1 << zoomLevel) - y - 1);
|
|
||||||
|
|
||||||
return await command.ExecuteScalarAsync() as byte[];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<ImageSource> LoadImageAsync(int x, int y, int zoomLevel)
|
public override async Task<ImageSource> LoadImageAsync(int x, int y, int zoomLevel)
|
||||||
|
|
@ -87,11 +66,13 @@ namespace MapControl.MBTiles
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var buffer = await ReadImageBufferAsync(x, y, zoomLevel);
|
using (var command = new SQLiteCommand("select tile_data from tiles where zoom_level=@z and tile_column=@x and tile_row=@y", connection))
|
||||||
|
|
||||||
if (buffer != null)
|
|
||||||
{
|
{
|
||||||
image = await LoadImageAsync(buffer);
|
command.Parameters.AddWithValue("@z", zoomLevel);
|
||||||
|
command.Parameters.AddWithValue("@x", x);
|
||||||
|
command.Parameters.AddWithValue("@y", (1 << zoomLevel) - y - 1);
|
||||||
|
|
||||||
|
image = await LoadImageAsync((byte[])await command.ExecuteScalarAsync());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue