internal static void Create(string connectionString, string name, MbTilesType type, double version, string description, MbTilesFormat format, Extent extent, params string[] kvp) { var dict = new Dictionary <string, string>(); if (!string.IsNullOrEmpty(name)) { dict.Add("name", name); } dict.Add("type", type.ToString().ToLowerInvariant()); dict.Add("version", version.ToString(CultureInfo.InvariantCulture)); if (!string.IsNullOrEmpty(description)) { dict.Add("description", description); } dict.Add("format", format.ToString().ToLower()); dict.Add("bounds", string.Format(NumberFormatInfo.InvariantInfo, "{0},{1},{2},{3}", extent.MinX, extent.MinY, extent.MaxX, extent.MaxY)); for (var i = 0; i < kvp.Length - 1; i++) { dict.Add(kvp[i++], kvp[i]); } }
public MbTilesCache(SQLiteConnection connection, ITileSchema schema = null, MbTilesType type = MbTilesType.None) : base(connection, (parent, child) => $"\"{child}\"", string.Empty, "tiles", null, null, FindTileCommand) { var wasOpen = true; if (Connection.State != ConnectionState.Open) { Connection.Open(); wasOpen = false; } if (type == MbTilesType.None) { // Type (if defined) _type = ReadType(connection); } else { _type = type; } if (schema == null) { // Format (if defined) _format = ReadFormat(connection); // Extent _extent = ReadExtent(connection); if (HasMapTable(connection)) { // it is possible to override the schema by definining it in a 'map' table. // This method depends on reading tiles from an 'images' table, which // is not part of the MBTiles spec // Declared zoom levels var declaredZoomLevels = ReadZoomLevels(connection, out _tileRange); // Create schema _schema = new GlobalMercator(Format.ToString(), declaredZoomLevels); } else { // this is actually the most regular case: _schema = new GlobalSphericalMercator(); } } else { _schema = schema; } if (!wasOpen) { Connection.Close(); } }
public MbTilesTileSource(SQLiteConnectionString connectionString, ITileSchema schema = null, MbTilesType type = MbTilesType.None) { _connectionString = connectionString; var connection = new SQLiteConnectionWithLock(connectionString, SQLiteOpenFlags.ReadOnly); using (connection.Lock()) { Type = type == MbTilesType.None ? ReadType(connection) : type; var schemaFromDatabase = ReadSchemaFromDatabase(connection); Schema = schema ?? schemaFromDatabase; // the tile range should be based on the tiles actually present. var zoomLevelsFromDatabase = schemaFromDatabase.Resolutions.Select(r => r.Key); _tileRange = ReadZoomLevelsFromTilesTable(connection, zoomLevelsFromDatabase); } }
internal MbTilesCache(SQLiteConnectionString connectionString, ITileSchema schema = null, MbTilesType type = MbTilesType.None) { if (_connectionPool == null) { throw new InvalidOperationException("You must assign a platform prior to using MbTilesCache by calling MbTilesTileSource.SetPlatform()"); } _connectionString = connectionString; var connection = _connectionPool.GetConnection(connectionString); using (connection.Lock()) { _type = type == MbTilesType.None ? ReadType(connection) : type; if (schema == null) { // Format (if defined) _format = ReadFormat(connection); // Extent _extent = ReadExtent(connection); if (HasMapTable(connection)) { // it is possible to override the schema by definining it in a 'map' table. // This method depends on reading tiles from an 'images' table, which // is not part of the MBTiles spec // Declared zoom levels var declaredZoomLevels = ReadZoomLevels(connection, out _tileRange); // Create schema _schema = new GlobalMercator(_format.ToString(), declaredZoomLevels); } else { // this is actually the most regular case: _schema = new GlobalSphericalMercator(); } } else { _schema = schema; } } }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="connectionString">The MapBox tiles file</param> /// <param name="name">The name of the TileSource</param> /// <param name="schema">The tile schema</param> /// <param name="type">The type of the MapBox tiles file</param> public MbTilesTileSource(SQLiteConnectionString connectionString, ITileSchema schema = null, MbTilesType type = MbTilesType.None, string name = DefaultName) : this(new MbTilesProvider(connectionString, schema, type), name) { }
internal MbTilesTileSource(SqliteConnection connection, ITileSchema schema = null, MbTilesType type = MbTilesType.None) { _tileSource = new MbTilesProvider(connection, schema, type); }
public MbTilesTileSource(string file, ITileSchema schema = null, MbTilesType type = MbTilesType.None) : this(new SqliteConnection(string.Format("Data Source={0}", new Uri(file))), schema, type) { }
internal MbTilesProvider(SQLiteConnectionString connectionString, ITileSchema schema = null, MbTilesType type = MbTilesType.None) { _cache = new MbTilesCache(connectionString, schema, type); }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="connectionString">The MapBox tiles file</param> /// <param name="schema">The tile schema (should be of <see cref="GlobalMercator"/></param> /// <param name="type">The type of the MapBox tiles file</param> public MbTilesTileSource(SQLiteConnectionString connectionString, ITileSchema schema = null, MbTilesType type = MbTilesType.None) : this(new MbTilesProvider(connectionString, schema, type)) { }
/// <summary> /// /// </summary> /// <param name="connectionString">The connection string to the mbtiles file</param> /// <param name="schema">The TileSchema of the mbtiles file. If this parameter is set the schema information /// within the mbtiles file will be ignored. </param> /// <param name="type">BaseLayer or Overlay</param> /// <param name="determineZoomLevelsFromTilesTable">When 'determineZoomLevelsFromTilesTable' is true the zoom levels /// will be determined from the available tiles in the 'tiles' table. This operation can take long if there are many tiles in /// the 'tiles' table. When 'determineZoomLevelsFromTilesTable' is false the zoom levels will be read from the metadata table ///(by reading 'zoommin' and 'zoommax'). If there are no zoom levels specificied in the metadata table the GlobalSphericalMercator ///default levels are assumed. This parameter will have no effect if the schema is passed in as argument. The default is false.</param> /// <param name="determineTileRangeFromTilesTable">In some cases not all tiles specified by the schema are present in each /// level. When 'determineTileRangeFromTilesTable' is 'true' the range of tiles available for each level is determined /// by the tiles present for each level in the 'tiles' table. The advantage is that requests can be faster because they do not have to /// go to the database if they are outside the TileRange. The downside is that for large files it can take long to read the TileRange /// from the tiles table. The default is false.</param> public MbTilesTileSource(SQLiteConnectionString connectionString, ITileSchema schema = null, MbTilesType type = MbTilesType.None, bool determineZoomLevelsFromTilesTable = false, bool determineTileRangeFromTilesTable = false) { _connectionString = connectionString; using (var connection = new SQLiteConnectionWithLock(connectionString)) using (connection.Lock()) { Schema = schema ?? ReadSchemaFromDatabase(connection, determineZoomLevelsFromTilesTable); Type = type == MbTilesType.None ? ReadType(connection) : type; Version = ReadString(connection, "version"); Attribution = new Attribution(ReadString(connection, "attribution")); Description = ReadString(connection, "description"); Name = ReadString(connection, "name"); Json = ReadString(connection, "json"); Compression = ReadString(connection, "compression"); if (determineTileRangeFromTilesTable) { // the tile range should be based on the tiles actually present. var zoomLevelsFromDatabase = Schema.Resolutions.Select(r => r.Key); _tileRange = ReadTileRangeForEachLevelFromTilesTable(connection, zoomLevelsFromDatabase); } } }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="connection">The connection to the MapBox tiles file</param> /// <param name="schema">The tile schema (should be of <see cref="GlobalMercator"/></param> /// <param name="type">The type of the MapBox tiles file</param> public MbTilesTileSource(SQLiteConnection connection, ITileSchema schema = null, MbTilesType type = MbTilesType.None) : this(new MbTilesProvider(connection, schema, type)) { }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="file">The MapBox tiles file</param> /// <param name="schema">The tile schema (should be of <see cref="GlobalMercator"/></param> /// <param name="type">The type of the MapBox tiles file</param> public MbTilesTileSource(string file, ITileSchema schema = null, MbTilesType type = MbTilesType.None) : this(new SQLiteConnection($"Data Source={file}"), schema, type) { }
public MbTilesProvider(SqliteConnection connection, ITileSchema schema = null, MbTilesType type = MbTilesType.None) { _cache = new MbTilesCache(connection, schema, type); }
public MbTilesProvider(SQLiteConnection connection, ITileSchema schema = null, MbTilesType type = MbTilesType.None) { _cache = new MbTilesCache(connection, schema, type); }
public MbTilesTileSource(SQLiteConnectionString connectionString, ITileSchema schema = null, MbTilesType type = MbTilesType.None, bool tileRangeOptimization = true) { _connectionString = connectionString; if (tileRangeOptimization || schema == null) { using (var connection = new SQLiteConnectionWithLock(connectionString)) using (connection.Lock()) { Type = type == MbTilesType.None ? ReadType(connection) : type; var schemaFromDatabase = ReadSchemaFromDatabase(connection); Schema = schema ?? schemaFromDatabase; // Read other stuff Version = ReadString(connection, "version"); Attribution = new Attribution(ReadString(connection, "attribution")); Description = ReadString(connection, "description"); Name = ReadString(connection, "name"); Json = ReadString(connection, "json"); Compression = ReadString(connection, "compression"); var zoomMin = ReadInt(connection, "minzoom"); ZoomMin = zoomMin < 0 ? 0 : zoomMin; var zoomMax = ReadInt(connection, "maxzoom"); ZoomMax = zoomMax < 0 ? int.MaxValue : zoomMax; // the tile range should be based on the tiles actually present. var zoomLevelsFromDatabase = schemaFromDatabase.Resolutions.Select(r => r.Key); _tileRange = ReadZoomLevelsFromTilesTable(connection, zoomLevelsFromDatabase); } } else { Schema = schema; _tileRange = null; } }