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 {
|
impl StoredTile {
|
||||||
pub fn new(coords: WorldTileCoords) -> Self {
|
pub fn pending(coords: WorldTileCoords) -> Self {
|
||||||
Self {
|
Self {
|
||||||
coords,
|
coords,
|
||||||
layers: vec![],
|
layers: vec![],
|
||||||
@ -73,6 +73,14 @@ impl StoredTile {
|
|||||||
status: TileStatus::Success,
|
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.
|
/// 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.
|
/// 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
|
/// 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
|
/// If the space is occupied, the tessellated layer is added to the current
|
||||||
/// [crate::io::tile_repository::CachedTile].
|
/// [crate::io::tile_repository::StoredLayer].
|
||||||
pub fn put_tessellated_layer(&mut self, layer: StoredLayer) {
|
pub fn put_layer(&mut self, layer: StoredLayer) {
|
||||||
if let Some(entry) = layer
|
if let Some(entry) = layer
|
||||||
.get_coords()
|
.get_coords()
|
||||||
.build_quad_key()
|
.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
|
/// Returns the list of tessellated layers at the given world tile coords. None if tile is
|
||||||
/// missing from the cache.
|
/// missing from the cache.
|
||||||
pub fn iter_tessellated_layers_at(
|
pub fn iter_layers_at(
|
||||||
&self,
|
&self,
|
||||||
coords: &WorldTileCoords,
|
coords: &WorldTileCoords,
|
||||||
) -> Option<impl Iterator<Item = &StoredLayer> + '_> {
|
) -> 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)) {
|
if let Some(entry) = coords.build_quad_key().map(|key| self.tree.entry(key)) {
|
||||||
match entry {
|
match entry {
|
||||||
btree_map::Entry::Vacant(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.
|
/// 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)) {
|
if let Some(_) = coords.build_quad_key().and_then(|key| self.tree.get(&key)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn success(&mut self, coords: &WorldTileCoords) {
|
pub fn mark_tile_succeeded(&mut self, coords: &WorldTileCoords) {
|
||||||
if let Some(cached_tile) = coords
|
if let Some(cached_tile) = coords
|
||||||
.build_quad_key()
|
.build_quad_key()
|
||||||
.and_then(|key| self.tree.get_mut(&key))
|
.and_then(|key| self.tree.get_mut(&key))
|
||||||
@ -163,7 +171,7 @@ impl TileRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if a layer has been fetched.
|
/// 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
|
if let Some(cached_tile) = coords
|
||||||
.build_quad_key()
|
.build_quad_key()
|
||||||
.and_then(|key| self.tree.get_mut(&key))
|
.and_then(|key| self.tree.get_mut(&key))
|
||||||
@ -171,42 +179,4 @@ impl TileRepository {
|
|||||||
cached_tile.status = TileStatus::Failed;
|
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
|
let loaded_layers = buffer_pool
|
||||||
.get_loaded_layers_at(&world_coords)
|
.get_loaded_layers_at(&world_coords)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
if let Some(available_layers) = tile_repository
|
if let Some(available_layers) =
|
||||||
.iter_tessellated_layers_at(&world_coords)
|
tile_repository.iter_layers_at(&world_coords).map(|layers| {
|
||||||
.map(|layers| {
|
|
||||||
layers
|
layers
|
||||||
.filter(|result| !loaded_layers.contains(&result.layer_name()))
|
.filter(|result| !loaded_layers.contains(&result.layer_name()))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
|
|||||||
@ -39,7 +39,7 @@ impl<E: Environment> Stage for PopulateTileStore<E> {
|
|||||||
match result {
|
match result {
|
||||||
Message::TileTessellated(tranferred) => {
|
Message::TileTessellated(tranferred) => {
|
||||||
let coords = tranferred.coords();
|
let coords = tranferred.coords();
|
||||||
tile_repository.success(coords);
|
tile_repository.mark_tile_succeeded(coords);
|
||||||
tracing::trace!("Tile at {} finished loading", coords);
|
tracing::trace!("Tile at {} finished loading", coords);
|
||||||
log::warn!("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.layer_name(),
|
||||||
layer.get_coords()
|
layer.get_coords()
|
||||||
);
|
);
|
||||||
tile_repository.put_tessellated_layer(layer);
|
tile_repository.put_layer(layer);
|
||||||
}
|
}
|
||||||
Message::TessellatedLayer(data) => {
|
Message::TessellatedLayer(data) => {
|
||||||
let layer: StoredLayer = data.to_stored_layer();
|
let layer: StoredLayer = data.to_stored_layer();
|
||||||
@ -65,7 +65,7 @@ impl<E: Environment> Stage for PopulateTileStore<E> {
|
|||||||
layer.layer_name(),
|
layer.layer_name(),
|
||||||
layer.get_coords()
|
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);
|
return Ok(false);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if tile_repository.needs_fetching(&coords) {
|
if tile_repository.has_tile(&coords) {
|
||||||
tile_repository.create_tile(coords);
|
tile_repository.create_tile(coords);
|
||||||
|
|
||||||
tracing::info!("new tile request: {}", &coords);
|
tracing::info!("new tile request: {}", &coords);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user