mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Fix names and remove unsed functions
This commit is contained in:
parent
00a4753825
commit
2070339fb6
@ -58,7 +58,7 @@ pub struct StoredTile {
|
||||
}
|
||||
|
||||
impl StoredTile {
|
||||
pub fn new(coords: WorldTileCoords) -> Self {
|
||||
pub fn pending(coords: WorldTileCoords) -> Self {
|
||||
Self {
|
||||
coords,
|
||||
layers: vec![],
|
||||
@ -73,6 +73,14 @@ impl StoredTile {
|
||||
status: TileStatus::Success,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn failed(coords: WorldTileCoords) -> Self {
|
||||
Self {
|
||||
coords,
|
||||
layers: vec![],
|
||||
status: TileStatus::Failed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Stores and provides access to a quad tree of cached tiles with world tile coords.
|
||||
@ -94,10 +102,10 @@ impl TileRepository {
|
||||
|
||||
/// Inserts a tessellated layer into the quad tree at its world tile coords.
|
||||
/// If the space is vacant, the tessellated layer is inserted into a new
|
||||
/// [crate::io::tile_repository::CachedTile].
|
||||
/// [crate::io::tile_repository::StoredLayer].
|
||||
/// If the space is occupied, the tessellated layer is added to the current
|
||||
/// [crate::io::tile_repository::CachedTile].
|
||||
pub fn put_tessellated_layer(&mut self, layer: StoredLayer) {
|
||||
/// [crate::io::tile_repository::StoredLayer].
|
||||
pub fn put_layer(&mut self, layer: StoredLayer) {
|
||||
if let Some(entry) = layer
|
||||
.get_coords()
|
||||
.build_quad_key()
|
||||
@ -122,7 +130,7 @@ impl TileRepository {
|
||||
|
||||
/// Returns the list of tessellated layers at the given world tile coords. None if tile is
|
||||
/// missing from the cache.
|
||||
pub fn iter_tessellated_layers_at(
|
||||
pub fn iter_layers_at(
|
||||
&self,
|
||||
coords: &WorldTileCoords,
|
||||
) -> Option<impl Iterator<Item = &StoredLayer> + '_> {
|
||||
@ -137,7 +145,7 @@ impl TileRepository {
|
||||
if let Some(entry) = coords.build_quad_key().map(|key| self.tree.entry(key)) {
|
||||
match entry {
|
||||
btree_map::Entry::Vacant(entry) => {
|
||||
entry.insert(StoredTile::new(coords));
|
||||
entry.insert(StoredTile::pending(coords));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@ -146,14 +154,14 @@ impl TileRepository {
|
||||
}
|
||||
|
||||
/// Checks if a layer has been fetched.
|
||||
pub fn needs_fetching(&self, coords: &WorldTileCoords) -> bool {
|
||||
pub fn has_tile(&self, coords: &WorldTileCoords) -> bool {
|
||||
if let Some(_) = coords.build_quad_key().and_then(|key| self.tree.get(&key)) {
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub fn success(&mut self, coords: &WorldTileCoords) {
|
||||
pub fn mark_tile_succeeded(&mut self, coords: &WorldTileCoords) {
|
||||
if let Some(cached_tile) = coords
|
||||
.build_quad_key()
|
||||
.and_then(|key| self.tree.get_mut(&key))
|
||||
@ -163,7 +171,7 @@ impl TileRepository {
|
||||
}
|
||||
|
||||
/// Checks if a layer has been fetched.
|
||||
pub fn fail(&mut self, coords: &WorldTileCoords) {
|
||||
pub fn mark_tile_failed(&mut self, coords: &WorldTileCoords) {
|
||||
if let Some(cached_tile) = coords
|
||||
.build_quad_key()
|
||||
.and_then(|key| self.tree.get_mut(&key))
|
||||
@ -171,42 +179,4 @@ impl TileRepository {
|
||||
cached_tile.status = TileStatus::Failed;
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes all the cached tessellate layers that are not contained within the given
|
||||
/// layers hashset.
|
||||
pub fn retain_missing_layer_names(
|
||||
&self,
|
||||
coords: &WorldTileCoords,
|
||||
layers: &mut HashSet<String>,
|
||||
) {
|
||||
if let Some(cached_tile) = coords.build_quad_key().and_then(|key| self.tree.get(&key)) {
|
||||
let tessellated_set: HashSet<String> = cached_tile
|
||||
.layers
|
||||
.iter()
|
||||
.map(|tessellated_layer| tessellated_layer.layer_name().to_string())
|
||||
.collect();
|
||||
|
||||
layers.retain(|layer| !tessellated_set.contains(layer));
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if a layer is missing from the given layers set at the given coords.
|
||||
pub fn is_layers_missing(&self, coords: &WorldTileCoords, layers: &HashSet<String>) -> bool {
|
||||
if let Some(cached_tile) = coords.build_quad_key().and_then(|key| self.tree.get(&key)) {
|
||||
let tessellated_set: HashSet<&str> = cached_tile
|
||||
.layers
|
||||
.iter()
|
||||
.map(|tessellated_layer| tessellated_layer.layer_name())
|
||||
.collect();
|
||||
|
||||
for layer in layers {
|
||||
if !tessellated_set.contains(layer.as_str()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,9 +164,8 @@ impl UploadStage {
|
||||
let loaded_layers = buffer_pool
|
||||
.get_loaded_layers_at(&world_coords)
|
||||
.unwrap_or_default();
|
||||
if let Some(available_layers) = tile_repository
|
||||
.iter_tessellated_layers_at(&world_coords)
|
||||
.map(|layers| {
|
||||
if let Some(available_layers) =
|
||||
tile_repository.iter_layers_at(&world_coords).map(|layers| {
|
||||
layers
|
||||
.filter(|result| !loaded_layers.contains(&result.layer_name()))
|
||||
.collect::<Vec<_>>()
|
||||
|
||||
@ -39,7 +39,7 @@ impl<E: Environment> Stage for PopulateTileStore<E> {
|
||||
match result {
|
||||
Message::TileTessellated(tranferred) => {
|
||||
let coords = tranferred.coords();
|
||||
tile_repository.success(coords);
|
||||
tile_repository.mark_tile_succeeded(coords);
|
||||
tracing::trace!("Tile at {} finished loading", coords);
|
||||
log::warn!("Tile at {} finished loading", coords);
|
||||
}
|
||||
@ -51,7 +51,7 @@ impl<E: Environment> Stage for PopulateTileStore<E> {
|
||||
layer.layer_name(),
|
||||
layer.get_coords()
|
||||
);
|
||||
tile_repository.put_tessellated_layer(layer);
|
||||
tile_repository.put_layer(layer);
|
||||
}
|
||||
Message::TessellatedLayer(data) => {
|
||||
let layer: StoredLayer = data.to_stored_layer();
|
||||
@ -65,7 +65,7 @@ impl<E: Environment> Stage for PopulateTileStore<E> {
|
||||
layer.layer_name(),
|
||||
layer.get_coords()
|
||||
);
|
||||
tile_repository.put_tessellated_layer(layer);
|
||||
tile_repository.put_layer(layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ impl<E: Environment> RequestStage<E> {
|
||||
return Ok(false);
|
||||
}*/
|
||||
|
||||
if tile_repository.needs_fetching(&coords) {
|
||||
if tile_repository.has_tile(&coords) {
|
||||
tile_repository.create_tile(coords);
|
||||
|
||||
tracing::info!("new tile request: {}", &coords);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user