Skip to content

Commit

Permalink
Add attribution - review-resolved fmt fix
Browse files Browse the repository at this point in the history
  • Loading branch information
siddheshzz committed Feb 23, 2025
1 parent 2e02b36 commit b296db1
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 32 deletions.
35 changes: 18 additions & 17 deletions galileo-egui/src/egui_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use egui::load::SizedTexture;
use egui::{Event, Image, ImageSource, Sense, TextureId, Ui, Vec2};
use egui_wgpu::wgpu::{FilterMode, TextureView};
use egui_wgpu::RenderState;
use galileo::layer::attribution::Attribution;
use galileo::control::{
EventProcessor, MapController, MouseButton, RawUserEvent, UserEventHandler,
};
use galileo::galileo_types::cartesian::{Point2d, Size};
use galileo::galileo_types::geo::impls::GeoPoint2d;
use galileo::layer::attribution::Attribution;
use galileo::render::WgpuRenderer;
use galileo::{Map, Messenger};

Expand Down Expand Up @@ -144,17 +144,15 @@ impl EguiMapState {
let attributions = self.collect_attributions();
if attributions.is_some() {
egui::Window::new("Attributions")
.collapsible(false)
.resizable(false)
.title_bar(false)
.anchor(egui::Align2::RIGHT_BOTTOM, [-10., -10.]) // Position bottom-right
.fixed_size([350., 150.])
.show(ui.ctx(), |ui| {
self.show_attributions(ui); // Render the attributions inside this window
});
.collapsible(false)
.resizable(false)
.title_bar(false)
.anchor(egui::Align2::RIGHT_BOTTOM, [-10., -10.]) // Position bottom-right
.fixed_size([350., 150.])
.show(ui.ctx(), |ui| {
self.show_attributions(ui); // Render the attributions inside this window
});
}



if self.event_processor.is_dragging() || response.contains_pointer() {
let events = ui.input(|input_state| input_state.events.clone());
Expand Down Expand Up @@ -193,22 +191,25 @@ impl EguiMapState {
}
fn add_attribution_entry(&mut self, ui: &mut egui::Ui, attribution: &Attribution) {
if let Some(url) = attribution.get_url() {
ui.hyperlink_to(attribution.get_text(), url);
ui.hyperlink_to(attribution.get_text(), url);
} else {
ui.label(attribution.get_text());
ui.label(attribution.get_text());
}
}

pub fn show_attributions(&mut self, ui: &mut egui::Ui) {
let attributions = self.collect_attributions().expect("Failed to collect attributions");
let attributions = self
.collect_attributions()
.expect("Failed to collect attributions");

let mut is_first = true;
for attribution in &attributions {
self.add_attribution_entry(ui,attribution);
if !is_first { ui.label(" | "); }
self.add_attribution_entry(ui, attribution);
if !is_first {
ui.label(" | ");
}
is_first = false;
}

}

fn resize_map(&mut self, size: Vec2) {
Expand Down
2 changes: 1 addition & 1 deletion galileo/examples/egui_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl eframe::App for EguiMapApp {
.with_position(&mut self.position)
.with_resolution(&mut self.resolution)
.show_ui(ui);

egui::Window::new("Galileo map").show(ctx, |ui| {
ui.label("Map center position:");
ui.label(format!(
Expand Down
5 changes: 4 additions & 1 deletion galileo/examples/vector_tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ pub(crate) fn run() {
.with_style(style)
.with_tile_schema(tile_schema())
.with_file_cache_checked(".tile_cache")
.with_attribution("© MapTiler© OpenStreetMap contributors".to_string(),"https://www.maptiler.com/copyright/".to_string())
.with_attribution(
"© MapTiler© OpenStreetMap contributors".to_string(),
"https://www.maptiler.com/copyright/".to_string(),
)
.build()
.expect("failed to create layer");

Expand Down
3 changes: 1 addition & 2 deletions galileo/src/layer/feature_layer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use maybe_sync::{MaybeSend, MaybeSync};
use num_traits::AsPrimitive;
use parking_lot::{Mutex, RwLock};

use crate::layer::attribution::Attribution;
use crate::layer::Layer;
use crate::messenger::Messenger;
use crate::render::{Canvas, RenderOptions};
use crate::view::MapView;
use crate::layer::attribution::Attribution;

mod feature;
mod feature_store;
Expand Down Expand Up @@ -391,7 +391,6 @@ where
fn attribution(&self) -> Option<Attribution> {
None
}

}

impl<P, F, S> FeatureLayer<P, F, S, CartesianSpace2d>
Expand Down
8 changes: 4 additions & 4 deletions galileo/src/layer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ use std::sync::Arc;
use maybe_sync::{MaybeSend, MaybeSync};
use parking_lot::RwLock;

use crate::layer::attribution::Attribution;
use crate::messenger::Messenger;
use crate::render::Canvas;
use crate::view::MapView;
use crate::TileSchema;
use crate::messenger::Messenger;
use crate::layer::attribution::Attribution;

pub mod attribution;
pub mod data_provider;
pub mod feature_layer;
pub mod raster_tile_layer;
pub mod vector_tile_layer;
pub mod attribution;

pub use feature_layer::{FeatureId, FeatureLayer};
pub use raster_tile_layer::RasterTileLayer;
Expand Down Expand Up @@ -47,7 +47,7 @@ pub trait Layer: MaybeSend + MaybeSync {
None
}
/// Returns the attribution of the layer, if available.
fn attribution(&self) -> Option<Attribution> ;
fn attribution(&self) -> Option<Attribution>;
}

impl<T: Layer + 'static> Layer for Arc<RwLock<T>> {
Expand Down
14 changes: 11 additions & 3 deletions galileo/src/layer/raster_tile_layer/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ impl RasterTileLayerBuilder {
messenger: None,
cache: CacheType::None,
offline_mode: false,
attribution: Some(Attribution::new("© OpenStreetMap contributors".to_string(),Some("https://www.openstreetmap.org/copyright".to_string())) ),
attribution: Some(Attribution::new(
"© OpenStreetMap contributors".to_string(),
Some("https://www.openstreetmap.org/copyright".to_string()),
)),
}
}

Expand Down Expand Up @@ -319,7 +322,7 @@ impl RasterTileLayerBuilder {
messenger,
cache,
offline_mode,
attribution
attribution,
} = self;

let tile_schema = tile_schema.unwrap_or_else(|| TileSchema::web(18));
Expand Down Expand Up @@ -354,7 +357,12 @@ impl RasterTileLayerBuilder {
}
};

Ok(RasterTileLayer::new_raw(provider, tile_schema, messenger, attribution))
Ok(RasterTileLayer::new_raw(
provider,
tile_schema,
messenger,
attribution,
))
}
}

Expand Down
2 changes: 1 addition & 1 deletion galileo/src/layer/raster_tile_layer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use web_time::{Duration, SystemTime};

use super::Layer;
use crate::decoded_image::DecodedImage;
use crate::layer::attribution::Attribution;
use crate::messenger::Messenger;
use crate::render::{Canvas, ImagePaint, PackedBundle, RenderOptions};
use crate::tile_schema::{TileIndex, TileSchema};
use crate::view::MapView;
use crate::layer::attribution::Attribution;

mod provider;
pub use provider::{RasterTileProvider, RestTileProvider};
Expand Down
6 changes: 3 additions & 3 deletions galileo/src/layer/vector_tile_layer/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct VectorTileLayerBuilder {
messenger: Option<Box<dyn Messenger>>,
cache: CacheType,
offline_mode: bool,
attribution:Option<Attribution>
attribution: Option<Attribution>,
}

enum ProviderType {
Expand Down Expand Up @@ -114,7 +114,7 @@ impl VectorTileLayerBuilder {
messenger: None,
cache: CacheType::None,
offline_mode: false,
attribution:None
attribution: None,
}
}

Expand Down Expand Up @@ -174,7 +174,7 @@ impl VectorTileLayerBuilder {
/// * `text` - A `String` containing the text of the attribution.
/// * `url` - A `String` containing the URL associated with the attribution.
///
pub fn with_attribution(mut self, text:String, url:String) -> Self {
pub fn with_attribution(mut self, text: String, url: String) -> Self {
self.attribution = Some(Attribution::new(text, Some(url)));
self
}
Expand Down

0 comments on commit b296db1

Please sign in to comment.