Skip to content

Commit

Permalink
Add egui example (Maximkaaa#38)
Browse files Browse the repository at this point in the history
* Add egui example

* Add interactions of map with egui

---------

Co-authored-by: Maxim <maxim@gritsenko.biz>
  • Loading branch information
alexkirsz and Maximkaaa authored Feb 5, 2024
1 parent bfd7d7a commit e2eb2be
Show file tree
Hide file tree
Showing 15 changed files with 815 additions and 40 deletions.
12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
[workspace]
resolver = "2"
members = [
"galileo",
"galileo-mvt",
"galileo-types",
]
resolver = "2"

exclude = [
"galileo/examples/with_egui",
"wasm_examples/raster_tiles",
"wasm_examples/vector_tiles",
"wasm_examples/feature_layers",
"wasm_examples/many_points",
"wasm_examples/lambert",
"wasm_examples/with_egui",
]

[workspace.package]
version = "0.1.0-alpha.0"
authors = ["Maxim Gritsenko <maxim@gritsenko.biz>"]
categories = ["science::geo"]
edition = "2021"
repository = "https://github.com/Maximkaaa/galileo"
license = "MIT OR Apache-2.0"
keywords = ["gis", "map", "rendering"]
categories = ["science::geo"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/Maximkaaa/galileo"
version = "0.1.0-alpha.0"
65 changes: 41 additions & 24 deletions galileo/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
</td>
<td>

* Create a map with one raster tile layer (OSM)
* Set initial map position and zoom
- Create a map with one raster tile layer (OSM)
- Set initial map position and zoom

</td>
</tr>
<tr>
Expand All @@ -38,9 +38,9 @@
</td>
<td>

* Create a map with one vector tile layer (MapLibre)
* Configure layer styling with the style file
* Get information about objects in the tiles by click
- Create a map with one vector tile layer (MapLibre)
- Configure layer styling with the style file
- Get information about objects in the tiles by click

</td>
</tr>
Expand All @@ -57,11 +57,11 @@
</td>
<td>

* Create a map with feature layers without a tile base map
* Use symbols to set advanced styles for features based on their properties
* Change properties of the features when hovering mouse over them
* Modify how the features are displayed based on changed properties
* Get information about features by click
- Create a map with feature layers without a tile base map
- Use symbols to set advanced styles for features based on their properties
- Change properties of the features when hovering mouse over them
- Modify how the features are displayed based on changed properties
- Get information about features by click

</td>
</tr>
Expand All @@ -78,8 +78,8 @@
</td>
<td>

* Render feature layer in Lambert Equal Area projection
* Get and update features on cursor hover
- Render feature layer in Lambert Equal Area projection
- Get and update features on cursor hover

</td>
</tr>
Expand All @@ -96,7 +96,7 @@
</td>
<td>

* Render ~3_000_000 3D points over a map
- Render ~3_000_000 3D points over a map

</td>
</tr>
Expand All @@ -113,10 +113,10 @@
</td>
<td>

* Read ~19_000_000 points from a LAS data set (lidar laser scanning result)
* Render all the points without pre-grouping (to demonstrate renderer performance limits)
* NOTE: before running the example, load the dataset. Read module-level docs in the example file.
* NOTE 2: You probably want to run this example in `--release` mode
- Read ~19_000_000 points from a LAS data set (lidar laser scanning result)
- Render all the points without pre-grouping (to demonstrate renderer performance limits)
- NOTE: before running the example, load the dataset. Read module-level docs in the example file.
- NOTE 2: You probably want to run this example in `--release` mode

</td>
</tr>
Expand All @@ -133,9 +133,9 @@ You can generate an image yourself running this example
</td>
<td>

* Run a map without a window
* Load GEOJSON file to a feature layer
* Render the map to a `.png` file
- Run a map without a window
- Load GEOJSON file to a feature layer
- Render the map to a `.png` file

</td>
</tr>
Expand All @@ -152,10 +152,27 @@ You can generate an image yourself running this example
</td>
<td>

* Load features as `geo-types` geometries using `geo-zero` crate
* Display the features with pin images
- Load features as `geo-types` geometries using `geo-zero` crate
- Display the features with pin images

</td>
</tr>
<tr>
<td>

[with_egui](./with_egui)

</td>
<td>

![i](https://maximkaaa.github.io/galileo/with_egui.png)

</td>
<td>

- Same as the raster tiles example, but with support for [egui](https://www.egui.rs/).

</td>
</tr>
</tbody>
</table>
</table>
25 changes: 25 additions & 0 deletions galileo/examples/with_egui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
edition = "2021"
name = "with_egui"
version = "0.1.0"

[workspace]

[[bin]]
name = "with_egui"

[dependencies]
egui = "0.25.0"
egui-wgpu = "0.25.0"
egui-winit = { version = "0.25.0", default-features = false }
env_logger = { version = "0.11", default-features = false }
galileo = { path = "../../../galileo" }
galileo-types = { path = "../../../galileo-types" }
wgpu = { version = "0.18", default-features = false }
winit = { version = "0.29", default-features = false }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1.0", default-features = false, features = ["full"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies.egui-winit]
features = ["clipboard", "links", "wayland", "x11"]
64 changes: 64 additions & 0 deletions galileo/examples/with_egui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use std::sync::Arc;

use winit::{
event::{Event, KeyEvent, WindowEvent},
event_loop::{ControlFlow, EventLoop},
window::Window,
};

mod run_ui;
mod state;

pub async fn run(window: Window, event_loop: EventLoop<()>) {
let window = Arc::new(window);

let mut state = state::State::new(Arc::clone(&window)).await;

let _ = event_loop.run(move |event, ewlt| {
ewlt.set_control_flow(ControlFlow::Wait);

match event {
Event::AboutToWait => {
state.about_to_wait();
}
Event::WindowEvent {
ref event,
window_id,
} if window_id == state.window().id() => {
match event {
WindowEvent::CloseRequested
| WindowEvent::KeyboardInput {
event:
KeyEvent {
logical_key:
winit::keyboard::Key::Named(winit::keyboard::NamedKey::Escape),
..
},
..
} => ewlt.exit(),
WindowEvent::Resized(physical_size) => {
state.resize(*physical_size);
}
WindowEvent::RedrawRequested => match state.render() {
Ok(_) => {}
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
Err(wgpu::SurfaceError::OutOfMemory) => ewlt.exit(),
Err(wgpu::SurfaceError::Timeout) => {
// Ignore timeouts.
}
},
other => {
state.handle_event(other);
window.request_redraw();
return;
}
};
state.handle_event(event);
window.request_redraw();
}
_ => {}
}
});
}
17 changes: 17 additions & 0 deletions galileo/examples/with_egui/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
mod run_ui;
mod state;

use with_egui::run;

#[tokio::main]
async fn main() {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();

let event_loop = winit::event_loop::EventLoop::new().unwrap();
let window = winit::window::WindowBuilder::new()
.with_title("egui + galileo")
.build(&event_loop)
.unwrap();

run(window, event_loop).await;
}
42 changes: 42 additions & 0 deletions galileo/examples/with_egui/src/run_ui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use egui::Context;
use galileo_types::geo::impls::point::GeoPoint2d;
use galileo_types::geo::traits::point::GeoPoint;

#[derive(Clone, Default, Debug)]
pub struct UiState {
pub positions: Positions,
}

#[derive(Clone, Default, Debug)]
pub struct Positions {
pub pointer_position: Option<GeoPoint2d>,
pub map_center_position: Option<GeoPoint2d>,
}

pub fn run_ui(state: &mut UiState, ui: &Context) {
egui::Window::new("Galileo map").show(ui, |ui| {
ui.label("Pointer position:");
if let Some(pointer_position) = state.positions.pointer_position {
ui.label(format!(
"Lat: {:.4} Lon: {:.4}",
pointer_position.lat(),
pointer_position.lon()
));
} else {
ui.label("<unavaliable>");
}

ui.separator();

ui.label("Map center position:");
if let Some(map_center_position) = state.positions.map_center_position {
ui.label(format!(
"Lat: {:.4} Lon: {:.4}",
map_center_position.lat(),
map_center_position.lon()
));
} else {
ui.label("<unavaliable>");
}
});
}
Loading

0 comments on commit e2eb2be

Please sign in to comment.