Esempio n. 1
0
        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]);
            }
        }
Esempio n. 2
0
        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;
                }
            }
        }