From c9b4e999ee2eac4b95ee4a7560fb10cad98ebb09 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 11 Aug 2026 13:42:08 +0200 Subject: allow for custom name & description in MbTiles --- hittekaart/src/storage.rs | 41 +++++++++++++++++++++++++++++++++++++---- 1 file 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, } 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) -> 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(()) } -- cgit v1.2.3