Skip to content

Commit

Permalink
Fix broken WASM examples (Maximkaaa#66)
Browse files Browse the repository at this point in the history
* Fix feature_layers features and add num-traits dependency

* Fix lambert wasm example

* Fix many_points wasm example
  • Loading branch information
calebfletcher authored Apr 2, 2024
1 parent 2d3da60 commit bb2206b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
26 changes: 17 additions & 9 deletions galileo/examples/many_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use galileo::layer::feature_layer::symbol::Symbol;
use galileo::layer::feature_layer::{Feature, FeatureLayer};
use galileo::render::point_paint::PointPaint;
use galileo::render::render_bundle::RenderPrimitive;
#[cfg(not(target_arch = "wasm32"))]
use galileo::tile_scheme::TileSchema;
use galileo::{Color, MapBuilder};
use galileo_types::cartesian::{CartesianPoint3d, Point3d};
Expand Down Expand Up @@ -83,16 +84,23 @@ fn generate_points() -> Vec<ColoredPoint> {
}

pub async fn run(builder: MapBuilder) {
#[cfg(not(target_arch = "wasm32"))]
let builder = builder.with_raster_tiles(
|index| {
format!(
"https://tile.openstreetmap.org/{}/{}/{}.png",
index.z, index.x, index.y
)
},
TileSchema::web(18),
);
#[cfg(target_arch = "wasm32")]
let builder = builder.with_raster_tiles(js_sys::Function::new_with_args(
"index",
"return `https://tile.openstreetmap.org/${index.z}/${index.x}/${index.y}.png`",
));

builder
.with_raster_tiles(
|index| {
format!(
"https://tile.openstreetmap.org/{}/{}/{}.png",
index.z, index.x, index.y
)
},
TileSchema::web(18),
)
.with_layer(FeatureLayer::new(
generate_points(),
ColoredPointSymbol {},
Expand Down
3 changes: 2 additions & 1 deletion wasm_examples/feature_layers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ crate-type = ["cdylib"]

[dependencies]
winit = { version ="0.29", features = ["rwh_05"] }
galileo = { path = "../../galileo", default-features = false, features = ["wgpu", "image", "web"] }
galileo = { path = "../../galileo" }
galileo-types = { path = "../../galileo-types" }
serde = { version = "1.0", features = ["derive"]}
bincode = "1.3"
Expand All @@ -25,3 +25,4 @@ web-sys = { version = "0.3", features = [
"Window",
"Element",
]}
num-traits = "0.2.17"
5 changes: 3 additions & 2 deletions wasm_examples/lambert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ crate-type = ["cdylib"]

[dependencies]
winit = { version ="0.29", features = ["rwh_05"] }
galileo = { path = "../../galileo", default-features = false, features = ["wgpu", "image", "web", "serde"] }
galileo = { path = "../../galileo" }
galileo-types = { path = "../../galileo-types" }
console_error_panic_hook = "0.1"
console_log = "1.0"
Expand All @@ -22,4 +22,5 @@ web-sys = { version = "0.3", features = [
"Document",
"Window",
"Element",
]}
]}
num-traits = "0.2.17"
5 changes: 3 additions & 2 deletions wasm_examples/many_points/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ crate-type = ["cdylib"]

[dependencies]
winit = { version ="0.29", features = ["rwh_05"] }
galileo = { path = "../../galileo", default-features = false, features = ["wgpu", "image", "web", "serde"] }
galileo = { path = "../../galileo" }
galileo-types = { path = "../../galileo-types" }
console_error_panic_hook = "0.1"
console_log = "1.0"
Expand All @@ -20,4 +20,5 @@ web-sys = { version = "0.3", features = [
"Document",
"Window",
"Element",
]}
]}
num-traits = "0.2.17"

0 comments on commit bb2206b

Please sign in to comment.