Version 4.12.2 Updated MapImages and MBTiles

This commit is contained in:
ClemensF 2019-07-17 17:56:46 +02:00
parent f74d700006
commit a25cc91c2f
9 changed files with 103 additions and 208 deletions

View file

@ -25,9 +25,19 @@ namespace MapControl.MBTiles
connection = new SQLiteConnection("Data Source=" + Path.GetFullPath(file));
}
public Task OpenAsync()
public async Task OpenAsync()
{
return connection.OpenAsync();
await connection.OpenAsync();
using (var command = new SQLiteCommand("create table if not exists metadata (name string, value string)", connection))
{
await command.ExecuteNonQueryAsync();
}
using (var command = new SQLiteCommand("create table if not exists tiles (zoom_level integer, tile_column integer, tile_row integer, tile_data blob)", connection))
{
await command.ExecuteNonQueryAsync();
}
}
public void Close()
@ -68,11 +78,6 @@ namespace MapControl.MBTiles
{
try
{
using (var command = new SQLiteCommand("create table if not exists metadata (name string, value string)", connection))
{
await command.ExecuteNonQueryAsync();
}
using (var command = new SQLiteCommand("insert or replace into metadata (name, value) values (@n, @v)", connection))
{
foreach (var keyValue in metadata)
@ -117,11 +122,6 @@ namespace MapControl.MBTiles
{
try
{
using (var command = new SQLiteCommand("create table if not exists tiles (zoom_level integer, tile_column integer, tile_row integer, tile_data blob)", connection))
{
await command.ExecuteNonQueryAsync();
}
using (var command = new SQLiteCommand("insert or replace into tiles (zoom_level, tile_column, tile_row, tile_data) values (@z, @x, @y, @b)", connection))
{
command.Parameters.AddWithValue("@z", zoomLevel);

View file

@ -11,6 +11,9 @@ using System.Windows;
namespace MapControl.MBTiles
{
/// <summary>
/// MapTileLayer that uses an MBTiles SQLite Database. See https://wiki.openstreetmap.org/wiki/MBTiles.
/// </summary>
public class MBTileLayer : MapTileLayer
{
public static readonly DependencyProperty FileProperty = DependencyProperty.Register(

View file

@ -16,48 +16,47 @@ namespace MapControl.MBTiles
{
private readonly MBTileData tileData;
public string Name { get; private set; }
public string Description { get; private set; }
public int? MinZoom { get; private set; }
public int? MaxZoom { get; private set; }
public MBTileSource(string file)
{
tileData = new MBTileData(file);
}
public string Name { get; private set; }
public string Description { get; private set; }
public int? MinZoom { get; private set; }
public int? MaxZoom { get; private set; }
public async Task Initialize()
{
await tileData.OpenAsync();
var metadata = await tileData.ReadMetadataAsync();
string name;
string description;
string minzoom;
string maxzoom;
string s;
int minZoom;
int maxZoom;
if (metadata.TryGetValue("name", out name))
{
Name = name;
}
Name = (metadata.TryGetValue("name", out s)) ? s : null;
if (metadata.TryGetValue("description", out description))
{
Description = description;
}
Description = (metadata.TryGetValue("description", out s)) ? s : null;
if (metadata.TryGetValue("minzoom", out minzoom) && int.TryParse(minzoom, out minZoom))
if (metadata.TryGetValue("minzoom", out s) && int.TryParse(s, out minZoom))
{
MinZoom = minZoom;
}
else
{
MinZoom = null;
}
if (metadata.TryGetValue("maxzoom", out maxzoom) && int.TryParse(maxzoom, out maxZoom))
if (metadata.TryGetValue("maxzoom", out s) && int.TryParse(s, out maxZoom))
{
MaxZoom = maxZoom;
}
else
{
MaxZoom = null;
}
}
public void Dispose()