Skip to content

Commit

Permalink
doc: Added documentation and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ecyht2 committed May 6, 2024
1 parent b09a98a commit 87bd38a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src-tauri/src/mbtiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use sqlx::Connection;

use crate::error_to_string;

/// Fetches the tile data for the given MBTiles database, zoom level, column, and row.
#[tauri::command]
pub async fn fetch_mbtiles(
db: String,
Expand Down Expand Up @@ -34,6 +35,7 @@ pub async fn fetch_mbtiles(
.map_err(error_to_string)
}

/// Parse the bounds value of a MBTiles metadata.
fn parse_bounds(bounds: String) -> Result<serde_json::Value, String> {
let bounds = bounds.split(',');

Expand All @@ -52,6 +54,7 @@ fn parse_bounds(bounds: String) -> Result<serde_json::Value, String> {
}
}

/// Parse the center value of a MBTiles metadata.
fn parse_center(center: String) -> Result<serde_json::Value, String> {
let center = center.split(',');

Expand All @@ -70,6 +73,7 @@ fn parse_center(center: String) -> Result<serde_json::Value, String> {
}
}

/// Parse the metadata value of a MBTiles metadata.
fn parse_metadata(key: &str, value: String) -> Result<serde_json::Value, String> {
Ok(match key {
"name" => serde_json::Value::String(value),
Expand All @@ -87,6 +91,7 @@ fn parse_metadata(key: &str, value: String) -> Result<serde_json::Value, String>
})
}

/// Retrieves the metadata for the given MBTiles database.
#[tauri::command]
pub async fn mbtiles_metadata(db: String) -> Result<HashMap<String, serde_json::Value>, String> {
let mut con = sqlx::SqliteConnection::connect(&db)
Expand Down
21 changes: 14 additions & 7 deletions src/js/mbtiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import * as logging from "tauri-plugin-log-api";

/** MBTiles Protocol for Maplibre JS.
*
* @param {import("maplibre-gl").RequestParameters} params - Paramters for the protocol.
* @param {import("maplibre-gl").RequestParameters} params - Request parameters for the tiles.
* @returns {import("maplibre-gl").GetResourceResponse} The response to the request.
*
* @example
* import * as maplibregl from "maplibre-gl";
* import mbtiles from "./mbtiles";
* maplibregl.addProtocol("mbtiles", mbtiles);
*/
export default async function mbtiles_protocol(params) {
const url = new URL(params.url);
Expand All @@ -16,6 +21,7 @@ export default async function mbtiles_protocol(params) {
try {
const tiles_json = await invoke("mbtiles_metadata", { db: db_file });
tiles_json.tiles = tiles;
logging.debug("Fetched Metadata: " + JSON.stringify(tiles_json));
return {
data: tiles_json
};
Expand All @@ -38,13 +44,14 @@ export default async function mbtiles_protocol(params) {
const [z, x, y] = paths;

try {
const tile = await invoke("fetch_mbtiles", {
db: db_file,
zoom: z,
column: x,
row: y,
});
return {
data: await invoke("fetch_mbtiles", {
db: db_file,
zoom: z,
column: x,
row: y,
}),
data: tile,
};
} catch (e) {
logging.error(e.toString());
Expand Down

0 comments on commit 87bd38a

Please sign in to comment.