mirror of
https://github.com/maplibre/martin.git
synced 2024-12-19 12:51:37 +03:00
9e5ed2fc02
Adds a new [.mbtiles](https://github.com/mapbox/mbtiles-spec/blob/master/1.3/spec.md) backend, without the grid support. Uses extensive tile content detection, i.e. if the content is gzipped, png, jpeg, gif, webp. From CLI, can be as easy as adding a path to a directory that contains a .mbtiles file (works just like pmtiles support) ```bash # All *.mbtiles files in this dir will be published. # The filename will be used as the source ID martin ./tests/fixtures ``` From configuration file, the path can be specified in a number of ways (same as pmtiles) ```yaml mbtiles: paths: # scan this whole dir, matching all *.mbtiles files - /dir-path # specific mbtiles file will be published as mbtiles2 source - /path/to/mbtiles2.mbtiles sources: # named source matching source name to a single file pm-src1: /tmp/mbtiles.mbtiles # named source, where the filename is explicitly set. This way we will be able to add more options later pm-src2: path: /tmp/mbtiles.mbtiles ``` Fixes #494
118 lines
3.3 KiB
Rust
118 lines
3.3 KiB
Rust
use std::collections::HashMap;
|
|
|
|
use ctor::ctor;
|
|
use indoc::indoc;
|
|
use martin::Xyz;
|
|
use tilejson::Bounds;
|
|
|
|
pub mod utils;
|
|
pub use utils::*;
|
|
|
|
#[ctor]
|
|
fn init() {
|
|
let _ = env_logger::builder().is_test(true).try_init();
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn table_source() {
|
|
let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL")).await;
|
|
assert!(!mock.0.is_empty());
|
|
|
|
let source = table(&mock, "table_source");
|
|
assert_eq!(source.schema, "public");
|
|
assert_eq!(source.table, "table_source");
|
|
assert_eq!(source.srid, 4326);
|
|
assert_eq!(source.geometry_column, "geom");
|
|
assert_eq!(source.id_column, None);
|
|
assert_eq!(source.minzoom, None);
|
|
assert_eq!(source.maxzoom, None);
|
|
assert!(source.bounds.is_some());
|
|
assert_eq!(source.extent, Some(4096));
|
|
assert_eq!(source.buffer, Some(64));
|
|
assert_eq!(source.clip_geom, Some(true));
|
|
assert_eq!(source.geometry_type, some("GEOMETRY"));
|
|
|
|
let mut properties = HashMap::new();
|
|
properties.insert("gid".to_owned(), "int4".to_owned());
|
|
assert_eq!(source.properties, Some(properties));
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn tables_tilejson_ok() {
|
|
let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL")).await;
|
|
let tilejson = source(&mock, "table_source").get_tilejson();
|
|
|
|
assert_eq!(tilejson.tilejson, "3.0.0");
|
|
assert_eq!(tilejson.version, None);
|
|
assert_eq!(tilejson.name, some("public.table_source.geom"));
|
|
assert_eq!(tilejson.scheme, None);
|
|
assert_eq!(tilejson.minzoom, None);
|
|
assert_eq!(tilejson.maxzoom, None);
|
|
assert_eq!(
|
|
tilejson.bounds,
|
|
Some(Bounds {
|
|
left: -2.0,
|
|
bottom: -1.0,
|
|
right: 142.841_315_098_691_33,
|
|
top: 45.0
|
|
})
|
|
);
|
|
assert!(tilejson.tiles.is_empty());
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn tables_tile_ok() {
|
|
let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL")).await;
|
|
let tile = source(&mock, "table_source")
|
|
.get_tile(&Xyz { z: 0, x: 0, y: 0 }, &None)
|
|
.await
|
|
.unwrap();
|
|
|
|
assert!(!tile.is_empty());
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn tables_srid_ok() {
|
|
let mock = mock_sources(mock_pgcfg(indoc! {"
|
|
connection_string: $DATABASE_URL
|
|
default_srid: 900913
|
|
"}))
|
|
.await;
|
|
|
|
let source = table(&mock, "points1");
|
|
assert_eq!(source.srid, 4326);
|
|
|
|
let source = table(&mock, "points2");
|
|
assert_eq!(source.srid, 4326);
|
|
|
|
let source = table(&mock, "points3857");
|
|
assert_eq!(source.srid, 3857);
|
|
|
|
let source = table(&mock, "points_empty_srid");
|
|
assert_eq!(source.srid, 900_913);
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn tables_multiple_geom_ok() {
|
|
let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL")).await;
|
|
|
|
let source = table(&mock, "table_source_multiple_geom");
|
|
assert_eq!(source.geometry_column, "geom1");
|
|
|
|
let source = table(&mock, "table_source_multiple_geom.1");
|
|
assert_eq!(source.geometry_column, "geom2");
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn table_source_schemas() {
|
|
let cfg = mock_pgcfg(indoc! {"
|
|
connection_string: $DATABASE_URL
|
|
auto_publish:
|
|
tables:
|
|
from_schemas: MixedCase
|
|
functions: false
|
|
"});
|
|
let sources = mock_sources(cfg).await.0;
|
|
assert_eq!(sources.keys().collect::<Vec<_>>(), vec!["MixPoints"],);
|
|
}
|