mirror of
https://github.com/maplibre/martin.git
synced 2024-12-18 20:31:54 +03:00
add tilejson endpoint
This commit is contained in:
parent
30e4d76808
commit
e3b2d5042b
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -757,6 +757,7 @@ dependencies = [
|
|||||||
"serde 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_derive 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_derive 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"tilejson 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1393,6 +1394,16 @@ dependencies = [
|
|||||||
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tilejson"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"serde 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"serde_derive 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time"
|
name = "time"
|
||||||
version = "0.1.39"
|
version = "0.1.39"
|
||||||
@ -1895,6 +1906,7 @@ dependencies = [
|
|||||||
"checksum termcolor 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "56c456352e44f9f91f774ddeeed27c1ec60a2455ed66d692059acfb1d731bda1"
|
"checksum termcolor 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "56c456352e44f9f91f774ddeeed27c1ec60a2455ed66d692059acfb1d731bda1"
|
||||||
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
|
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
|
||||||
"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963"
|
"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963"
|
||||||
|
"checksum tilejson 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2117abf55755175b050f820472ddcd7762d7c60764af8bdfa828734276841847"
|
||||||
"checksum time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "a15375f1df02096fb3317256ce2cee6a1f42fc84ea5ad5fc8c421cfe40c73098"
|
"checksum time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "a15375f1df02096fb3317256ce2cee6a1f42fc84ea5ad5fc8c421cfe40c73098"
|
||||||
"checksum tokio 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "65bd27f59c223e7c9e406bcdadb453e143bcf1242e162ae6c0f0eb6d14487306"
|
"checksum tokio 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "65bd27f59c223e7c9e406bcdadb453e143bcf1242e162ae6c0f0eb6d14487306"
|
||||||
"checksum tokio-core 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "799492ccba3d8ed5e41f2520a7cfd504cb65bbfe5fbbbd0012e335ae5f188051"
|
"checksum tokio-core 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "799492ccba3d8ed5e41f2520a7cfd504cb65bbfe5fbbbd0012e335ae5f188051"
|
||||||
|
@ -15,4 +15,5 @@ r2d2 = "0.8"
|
|||||||
r2d2_postgres = "0.14"
|
r2d2_postgres = "0.14"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
tilejson = "0.1"
|
@ -11,6 +11,7 @@ extern crate serde;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
extern crate tilejson;
|
||||||
|
|
||||||
use actix_web::HttpServer;
|
use actix_web::HttpServer;
|
||||||
use actix::{Actor, Addr, Syn, SyncArbiter};
|
use actix::{Actor, Addr, Syn, SyncArbiter};
|
||||||
|
@ -4,6 +4,7 @@ use futures::future::Future;
|
|||||||
use mapbox_expressions_to_sql;
|
use mapbox_expressions_to_sql;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use tilejson::TileJSONBuilder;
|
||||||
|
|
||||||
use super::messages;
|
use super::messages;
|
||||||
use super::db::DbExecutor;
|
use super::db::DbExecutor;
|
||||||
@ -36,25 +37,30 @@ fn index(req: HttpRequest<State>) -> Box<Future<Item = HttpResponse, Error = Err
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn source(req: HttpRequest<State>) -> Result<HttpResponse> {
|
fn source(req: HttpRequest<State>) -> Result<HttpResponse> {
|
||||||
let sources = req.state().sources.borrow();
|
let source_ids = req.match_info()
|
||||||
|
.get("sources")
|
||||||
let source_id = req.match_info()
|
|
||||||
.get("source")
|
|
||||||
.ok_or(error::ErrorBadRequest("invalid source"))?;
|
.ok_or(error::ErrorBadRequest("invalid source"))?;
|
||||||
|
|
||||||
let source = sources.get(source_id).ok_or(error::ErrorNotFound(format!(
|
let mut tilejson_builder = TileJSONBuilder::new();
|
||||||
"source {} not found",
|
tilejson_builder.scheme("tms");
|
||||||
source_id
|
tilejson_builder.name(&source_ids);
|
||||||
)))?;
|
|
||||||
|
|
||||||
Ok(httpcodes::HTTPOk.build().json(source)?)
|
let tiles_url = format!(
|
||||||
|
"{}/{{z}}/{{x}}/{{y}}.pbf",
|
||||||
|
req.url_for("tilejson", &[source_ids]).unwrap()
|
||||||
|
);
|
||||||
|
|
||||||
|
tilejson_builder.tiles(vec![&tiles_url]);
|
||||||
|
|
||||||
|
let tilejson = tilejson_builder.finalize();
|
||||||
|
Ok(httpcodes::HTTPOk.build().json(tilejson)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tile(req: HttpRequest<State>) -> Result<Box<Future<Item = HttpResponse, Error = Error>>> {
|
fn tile(req: HttpRequest<State>) -> Result<Box<Future<Item = HttpResponse, Error = Error>>> {
|
||||||
let sources = &req.state().sources.borrow();
|
let sources = &req.state().sources.borrow();
|
||||||
|
|
||||||
let source_id = req.match_info()
|
let source_id = req.match_info()
|
||||||
.get("source")
|
.get("sources")
|
||||||
.ok_or(error::ErrorBadRequest("invalid source"))?;
|
.ok_or(error::ErrorBadRequest("invalid source"))?;
|
||||||
|
|
||||||
let source = sources.get(source_id).ok_or(error::ErrorNotFound(format!(
|
let source = sources.get(source_id).ok_or(error::ErrorNotFound(format!(
|
||||||
@ -133,8 +139,11 @@ pub fn new(
|
|||||||
.middleware(middleware::Logger::default())
|
.middleware(middleware::Logger::default())
|
||||||
.middleware(cors)
|
.middleware(cors)
|
||||||
.resource("/index.json", |r| r.method(Method::GET).a(index))
|
.resource("/index.json", |r| r.method(Method::GET).a(index))
|
||||||
.resource("/{source}.json", |r| r.method(Method::GET).f(source))
|
.resource("/{sources}.json", |r| {
|
||||||
.resource("/{source}/{z}/{x}/{y}.pbf", |r| {
|
r.name("tilejson");
|
||||||
|
r.method(Method::GET).f(source)
|
||||||
|
})
|
||||||
|
.resource("/{sources}/{z}/{x}/{y}.pbf", |r| {
|
||||||
r.method(Method::GET).f(tile)
|
r.method(Method::GET).f(tile)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user