Skip to content

Commit

Permalink
Add wasm-bindgen ffi and example (Maximkaaa#42)
Browse files Browse the repository at this point in the history
* Add wasm-bindgen ffi and example

* Add more instructions about examples
  • Loading branch information
Maximkaaa authored Feb 5, 2024
1 parent e2eb2be commit ddec270
Show file tree
Hide file tree
Showing 30 changed files with 272 additions and 147 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ Cargo.lock

# Ignore large sample files
**/*.laz

#Npm
**/package-lock.json
**/node_modules
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ them all done at the same time. So here's our current plan and priorities:

# Running examples

There are examples in `galileo` crate that can be run with `cargo run --example <name>`
command. Web examples are separate creates in `wasm_examples` directory. These are
Rust examples of using Galileo are located at [`galileo/examples`]. Refer to the [readme](galileo/examples/README.md)
for the list, description and run instructions.

There are also examples of running Galileo in a web-browser located at [`web_examples`] folder. These are
excluded from the workspace (because Cargo does not like cross-platform workspaces).
To run those you will need to [install wasm-pack](https://rustwasm.github.io/wasm-pack/installer/):

Expand Down
11 changes: 11 additions & 0 deletions galileo/examples/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
Run all simple examples with:
```shell
cargo run --example <example_name>
```

Some more complex examples are structured as separate crates. Use `cargo run` to run those. For example.
```
cd galileo/examples/with_egui
cargo run
```

<table>
<thead>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions galileo/examples/georust.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use galileo::galileo_map::MapBuilder;
use galileo::layer::feature_layer::{FeatureLayer, FeatureLayerOptions};
use galileo::symbol::point::ImagePointSymbol;
use galileo::tile_scheme::TileScheme;
use galileo::tile_scheme::TileSchema;
use galileo_types::disambig::{Disambig, Disambiguate};
use galileo_types::geo::crs::Crs;
use galileo_types::geometry_type::GeoSpace2d;
Expand Down Expand Up @@ -58,7 +58,7 @@ pub async fn run(builder: MapBuilder) {
index.z, index.x, index.y
)
},
TileScheme::web(18),
TileSchema::web(18),
)
.with_layer(point_layer)
.build()
Expand Down
6 changes: 3 additions & 3 deletions galileo/examples/las.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use galileo::render::point_paint::PointPaint;
use galileo::render::render_bundle::RenderBundle;
use galileo::render::PrimitiveId;
use galileo::symbol::Symbol;
use galileo::tile_scheme::TileScheme;
use galileo::tile_scheme::TileSchema;
use galileo::Color;
use galileo_types::cartesian::impls::point::Point3d;
use galileo_types::cartesian::traits::cartesian_point::CartesianPoint3d;
Expand Down Expand Up @@ -110,15 +110,15 @@ pub async fn run(builder: MapBuilder) {
let points = load_points();
builder
.center(latlon!(51.4549, -2.6279))
.resolution(TileScheme::web(18).lod_resolution(14).unwrap())
.resolution(TileSchema::web(18).lod_resolution(14).unwrap())
.with_raster_tiles(
|index| {
format!(
"https://tile.openstreetmap.org/{}/{}/{}.png",
index.z, index.x, index.y
)
},
TileScheme::web(18),
TileSchema::web(18),
)
.with_layer(FeatureLayer::new(
points,
Expand Down
4 changes: 2 additions & 2 deletions galileo/examples/many_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use galileo::layer::feature_layer::FeatureLayer;
use galileo::render::point_paint::PointPaint;
use galileo::render::render_bundle::RenderBundle;
use galileo::render::PrimitiveId;
use galileo::tile_scheme::TileScheme;
use galileo::tile_scheme::TileSchema;
use galileo::Color;
use galileo_types::cartesian::impls::point::Point3d;
use galileo_types::cartesian::traits::cartesian_point::CartesianPoint3d;
Expand Down Expand Up @@ -88,7 +88,7 @@ pub async fn run(builder: MapBuilder) {
index.z, index.x, index.y
)
},
TileScheme::web(18),
TileSchema::web(18),
)
.with_layer(FeatureLayer::new(
generate_points(),
Expand Down
6 changes: 3 additions & 3 deletions galileo/examples/raster_tiles.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use galileo::galileo_map::MapBuilder;
use galileo::tile_scheme::TileScheme;
use galileo::tile_scheme::TileSchema;
use galileo_types::latlon;

#[cfg(not(target_arch = "wasm32"))]
Expand All @@ -12,15 +12,15 @@ async fn main() {
pub async fn run(builder: MapBuilder) {
builder
.center(latlon!(37.566, 126.9784))
.resolution(TileScheme::web(18).lod_resolution(8).unwrap())
.resolution(TileSchema::web(18).lod_resolution(8).unwrap())
.with_raster_tiles(
|index| {
format!(
"https://tile.openstreetmap.org/{}/{}/{}.png",
index.z, index.x, index.y
)
},
TileScheme::web(18),
TileSchema::web(18),
)
.build()
.await
Expand Down
6 changes: 3 additions & 3 deletions galileo/examples/render_to_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use galileo::render::wgpu::WgpuRenderer;
use galileo::symbol::arbitrary::ArbitraryGeometrySymbol;
use galileo::tile_scheme::TileIndex;
use galileo::view::MapView;
use galileo::TileScheme;
use galileo::TileSchema;
use galileo_types::cartesian::size::Size;
use galileo_types::geo::crs::Crs;
use geojson::{FeatureCollection, GeoJson};
Expand Down Expand Up @@ -62,7 +62,7 @@ async fn main() -> Result<()> {
let width_resolution = extent.width() / image_size.width() as f64;
let height_resolution = extent.height() / image_size.height() as f64;
let resolution = (width_resolution.max(height_resolution) * 1.1)
.max(TileScheme::web(18).lod_resolution(17).unwrap());
.max(TileSchema::web(18).lod_resolution(17).unwrap());

// Create OSM layer for background
let cache_controller = Some(FileCacheController::new(".tile_cache"));
Expand All @@ -76,7 +76,7 @@ async fn main() -> Result<()> {
cache_controller,
);
let mut osm = RasterTileLayer::new(
TileScheme::web(18),
TileSchema::web(18),
tile_provider,
None::<Arc<dyn Messenger>>,
);
Expand Down
6 changes: 3 additions & 3 deletions galileo/examples/vector_tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use galileo::galileo_map::{MapBuilder, VectorTileProvider};
use galileo::layer::vector_tile_layer::style::VectorTileStyle;
use galileo::layer::vector_tile_layer::VectorTileLayer;
use galileo::lod::Lod;
use galileo::tile_scheme::{TileIndex, TileScheme, VerticalDirection};
use galileo::tile_scheme::{TileIndex, TileSchema, VerticalDirection};
use galileo_types::cartesian::impls::point::Point2d;
use galileo_types::geo::crs::Crs;
use std::sync::{Arc, RwLock};
Expand Down Expand Up @@ -64,7 +64,7 @@ pub async fn run(builder: MapBuilder, style: VectorTileStyle) {
.run();
}

pub fn tile_scheme() -> TileScheme {
pub fn tile_scheme() -> TileSchema {
const ORIGIN: Point2d = Point2d::new(-20037508.342787, 20037508.342787);
const TOP_RESOLUTION: f64 = 156543.03392800014 / 4.0;

Expand All @@ -73,7 +73,7 @@ pub fn tile_scheme() -> TileScheme {
lods.push(Lod::new(lods[(i - 1) as usize].resolution() / 2.0, i).unwrap());
}

TileScheme {
TileSchema {
origin: ORIGIN,
bounds: BoundingBox::new(
-20037508.342787,
Expand Down
7 changes: 6 additions & 1 deletion galileo/examples/with_egui/src/state/egui_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ impl EguiState {
}

pub fn handle_event(&mut self, window: &Window, event: &WindowEvent) -> EventResponse {
self.state.on_window_event(window, event)
let mut response = self.state.on_window_event(window, event);
if self.context.wants_pointer_input() {
response.consumed = true;
}

response
}

pub fn render(&mut self, wgpu_frame: &mut WgpuFrame<'_>, run_ui: impl FnOnce(&Context)) {
Expand Down
6 changes: 3 additions & 3 deletions galileo/examples/with_egui/src/state/galileo_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use galileo::{
tile_scheme::TileIndex,
view::MapView,
winit::WinitInputHandler,
TileScheme,
TileSchema,
};
use galileo_types::cartesian::impls::point::Point2d;
use galileo_types::{cartesian::size::Size, latlon};
Expand Down Expand Up @@ -70,7 +70,7 @@ impl GalileoState {

let view = MapView::new(
&latlon!(37.566, 126.9784),
TileScheme::web(18).lod_resolution(8).unwrap(),
TileSchema::web(18).lod_resolution(8).unwrap(),
);

#[cfg(not(target_arch = "wasm32"))]
Expand All @@ -92,7 +92,7 @@ impl GalileoState {
);

let layer = Box::new(galileo::layer::RasterTileLayer::new(
galileo::TileScheme::web(18),
galileo::TileSchema::web(18),
tile_provider,
None,
));
Expand Down
Loading

0 comments on commit ddec270

Please sign in to comment.