diff options
| author | Daniel Schadt <kingdread@gmx.de> | 2026-08-11 13:42:08 +0200 |
|---|---|---|
| committer | Daniel Schadt <kingdread@gmx.de> | 2026-08-11 13:42:08 +0200 |
| commit | c9b4e999ee2eac4b95ee4a7560fb10cad98ebb09 (patch) | |
| tree | a01743be4a290774827c2c6d73469f3c7785ccdc | |
| parent | 9a576a8d3a8cb1d143be0ade0310f71b490cacb9 (diff) | |
| download | hittekaart-c9b4e999ee2eac4b95ee4a7560fb10cad98ebb09.tar.gz hittekaart-c9b4e999ee2eac4b95ee4a7560fb10cad98ebb09.tar.bz2 hittekaart-c9b4e999ee2eac4b95ee4a7560fb10cad98ebb09.zip | |
allow for custom name & description in MbTiles
| -rw-r--r-- | hittekaart/src/storage.rs | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/hittekaart/src/storage.rs b/hittekaart/src/storage.rs index 6cb3629..8bc8f6e 100644 --- a/hittekaart/src/storage.rs +++ b/hittekaart/src/storage.rs @@ -227,6 +227,8 @@ impl Storage for OsmAnd { } } +static MBTILES_DEFAULT_NAME: &str = "Heatmap"; + /// MBTiles storage (SQLite backed). /// /// This stores tiles into a SQLite database with the following tables: @@ -246,14 +248,21 @@ impl Storage for OsmAnd { /// meaning that `tile_row = 2^zoom - 1 - y`. /// /// The metadata table will contain two rows, one with `name = "name"` and one with `name = -/// "format"`. You can set a custom name/title of the map with the following SQL statement: +/// "format"`. You can set a custom title and description of the map using the [MbTiles::with_name] +/// and [MbTiles::with_description] methods. +/// +/// Alternatively, you can set a custom name/title of the map afterwards with the following SQL +/// statements: /// /// ```sql -/// UPDATE metadata SET value = "My cool heatmap!" WHERE name = "name"; +/// UPDATE metadata SET value = 'My cool heatmap!' WHERE name = 'name'; +/// INSERT INTO metadata(name, value) VALUES ('description', 'This is a collection of my trips!'); /// ``` #[derive(Debug)] pub struct MbTiles { connection: Connection, + name: String, + description: Option<String>, } impl MbTiles { @@ -267,7 +276,25 @@ impl MbTiles { return Err(Error::OutputAlreadyExists(path.to_path_buf())); } let connection = Connection::open(path)?; - Ok(MbTiles { connection }) + Ok(MbTiles { + connection, + name: MBTILES_DEFAULT_NAME.into(), + description: None, + }) + } + + pub fn with_name(self, name: String) -> Self { + MbTiles { + name, + .. self + } + } + + pub fn with_description(self, description: Option<String>) -> Self { + MbTiles { + description, + .. self + } } } @@ -315,12 +342,18 @@ impl Storage for MbTiles { fn finish(&mut self) -> Result<()> { self.connection.execute( "INSERT INTO metadata (name, value) VALUES (?, ?);", - params!["name", "Heatmap"], + params!["name", &self.name], )?; self.connection.execute( "INSERT INTO metadata (name, value) VALUES (?, ?);", params!["format", "png"], )?; + if let Some(desc) = &self.description { + self.connection.execute( + "INSERT INTO metadata (name, value) VALUES (?, ?);", + params!["description", desc], + )?; + } self.connection.execute("COMMIT;", ())?; Ok(()) } |
