mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Add some log messages and use different parsing routine
This commit is contained in:
parent
7d0b6497eb
commit
3656b9140a
@ -27,9 +27,11 @@ pub fn parse_tile<P: AsRef<Path>>(path: P) -> Result<Tile, Error> {
|
||||
}
|
||||
|
||||
pub fn parse_tile_reader<B: BufRead>(reader: &mut B) -> Result<Tile, Error> {
|
||||
if reader.fill_buf()?.is_empty() {
|
||||
return Err(Error::Generic("input must not be empty".to_string()));
|
||||
}
|
||||
let proto_tile = TileProto::parse_from_reader(reader)?;
|
||||
Ok(proto_tile.decode())
|
||||
}
|
||||
|
||||
pub fn parse_tile_bytes(bytes: &[u8]) -> Result<Tile, Error> {
|
||||
let proto_tile = TileProto::parse_from_bytes(bytes)?;
|
||||
Ok(proto_tile.decode())
|
||||
}
|
||||
|
||||
@ -2,10 +2,10 @@ use std::collections::VecDeque;
|
||||
use std::io::Cursor;
|
||||
use std::sync::{Arc, Condvar, Mutex};
|
||||
|
||||
use log::info;
|
||||
use log::{error, info};
|
||||
use lyon::tessellation::VertexBuffers;
|
||||
|
||||
use vector_tile::parse_tile_reader;
|
||||
use vector_tile::parse_tile_bytes;
|
||||
use vector_tile::tile::Tile;
|
||||
|
||||
use crate::io::{static_database, TileCoords};
|
||||
@ -21,15 +21,19 @@ pub struct TesselatedTile {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Cache {
|
||||
current_id: u32,
|
||||
requests: Arc<WorkQueue<TileCoords>>,
|
||||
responses: Arc<WorkQueue<TesselatedTile>>,
|
||||
}
|
||||
|
||||
impl Drop for Cache {
|
||||
fn drop(&mut self) {
|
||||
error!("Cache dropped, even though it should never drop!");
|
||||
}
|
||||
}
|
||||
|
||||
impl Cache {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
current_id: 0,
|
||||
requests: Arc::new(WorkQueue::new()),
|
||||
responses: Arc::new(WorkQueue::new()),
|
||||
}
|
||||
@ -45,21 +49,27 @@ impl Cache {
|
||||
}
|
||||
|
||||
pub fn run_loop(&mut self) {
|
||||
let mut current_id = 0;
|
||||
loop {
|
||||
while let Some(coords) = self.requests.pop() {
|
||||
if let Some(file) = static_database::get_tile(&coords) {
|
||||
let tile = parse_tile_reader(&mut Cursor::new(file.contents()))
|
||||
.expect("failed to load tile");
|
||||
info!(
|
||||
"preparing tile {} with {}bytes",
|
||||
&coords,
|
||||
file.contents().len()
|
||||
);
|
||||
let tile = parse_tile_bytes(file.contents()).expect("failed to load tile");
|
||||
|
||||
let mut geometry: VertexBuffers<GpuVertexUniform, IndexDataType> =
|
||||
VertexBuffers::new();
|
||||
|
||||
tile.tesselate_stroke(&mut geometry, 1);
|
||||
self.responses.push(TesselatedTile {
|
||||
id: self.current_id,
|
||||
id: current_id,
|
||||
coords,
|
||||
geometry,
|
||||
});
|
||||
self.current_id += 1;
|
||||
current_id += 1;
|
||||
info!("tile ready: {:?}", &coords);
|
||||
} else {
|
||||
info!("tile failed: {:?}", &coords);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user