web client & more blending work
This commit is contained in:
parent
fbe4b57bb4
commit
c2a3ddb1ec
9 changed files with 147 additions and 31 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@
|
||||||
target
|
target
|
||||||
node_modules
|
node_modules
|
||||||
.cache
|
.cache
|
||||||
|
wxbox_client_wasm/dist
|
29
Cargo.lock
generated
29
Cargo.lock
generated
|
@ -1051,6 +1051,16 @@ dependencies = [
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "console_error_panic_hook"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "convert_case"
|
name = "convert_case"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
|
@ -5050,6 +5060,17 @@ version = "0.2.99"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6"
|
checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-tracing"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2107431e9bd9fa9ff3c4e7d384563c849cbfae830866a74d59c3472942bd5af1"
|
||||||
|
dependencies = [
|
||||||
|
"tracing",
|
||||||
|
"tracing-subscriber",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wayland-backend"
|
name = "wayland-backend"
|
||||||
version = "0.3.7"
|
version = "0.3.7"
|
||||||
|
@ -5769,6 +5790,14 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wxbox_client_wasm"
|
name = "wxbox_client_wasm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"console_error_panic_hook",
|
||||||
|
"eframe",
|
||||||
|
"wasm-bindgen-futures",
|
||||||
|
"wasm-tracing",
|
||||||
|
"web-sys",
|
||||||
|
"wxbox_client",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wxbox_common"
|
name = "wxbox_common"
|
||||||
|
|
|
@ -178,6 +178,30 @@ impl Sub for ColorF64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl Sub<ColorF64> for f64 {
|
||||||
|
type Output = ColorF64;
|
||||||
|
|
||||||
|
fn sub(self, rhs: ColorF64) -> Self::Output {
|
||||||
|
ColorF64 {
|
||||||
|
red: rhs.red - self,
|
||||||
|
green: rhs.green - self,
|
||||||
|
blue: rhs.blue - self,
|
||||||
|
alpha: rhs.alpha - self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Mul<f64> for ColorF64 {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn mul(self, rhs: f64) -> Self::Output {
|
||||||
|
Self {
|
||||||
|
red: self.red * rhs,
|
||||||
|
blue: self.blue * rhs,
|
||||||
|
green: self.green * rhs,
|
||||||
|
alpha: self.alpha * rhs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
impl Mul for ColorF64 {
|
impl Mul for ColorF64 {
|
||||||
type Output = ColorF64;
|
type Output = ColorF64;
|
||||||
|
|
||||||
|
@ -197,20 +221,15 @@ pub fn merge(base: Pixmap, data: Pixmap, settings: &TileRequestOptions) -> Pixma
|
||||||
|
|
||||||
for x in 0..256 {
|
for x in 0..256 {
|
||||||
for y in 0..256 {
|
for y in 0..256 {
|
||||||
let mut lower: ColorF64 = base.get(x, y).into();
|
let mut c_b: ColorF64 = base.get(x, y).into();
|
||||||
lower.alpha = 1.0;
|
let a_b = 1.0;
|
||||||
let mut upper: ColorF64 = data.get(x, y).into();
|
let mut c_s: ColorF64 = data.get(x, y).into();
|
||||||
//upper.alpha = settings.data_transparency;
|
let a_s = settings.data_transparency;
|
||||||
|
|
||||||
if upper.red == 0.0 && upper.green == 0.0 && upper.blue == 0.0 && upper.alpha == 0.0 {
|
let mut co = c_s * a_s + c_b * a_b * (1.0 - a_s);
|
||||||
lower.alpha = 1.0;
|
co.alpha = 1.0;
|
||||||
new.set(x, y, lower.into());
|
|
||||||
} else {
|
|
||||||
upper.alpha = 1.0;
|
|
||||||
new.set(x, y, upper.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
// new.set(x, y, ((ColorF64 { red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0 } - ColorF64 { red: 2.0, green: 2.0, blue: 2.0, alpha: 2.0 } * upper) * (lower * lower) + ColorF64 { red: 2.0, green: 2.0, blue: 2.0, alpha: 2.0 } * lower * upper).into());
|
new.set(x, y, co.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ impl TileSource for DynamicUrlSource {
|
||||||
fn tile_url(&self, tile_id: TileId) -> String {
|
fn tile_url(&self, tile_id: TileId) -> String {
|
||||||
format!(
|
format!(
|
||||||
"{}/{}/{}/{}.png?settings={}",
|
"{}/{}/{}/{}.png?settings={}",
|
||||||
var("TILER_BASE_URL").unwrap(),
|
env!("TILER_BASE_URL"),
|
||||||
tile_id.zoom, tile_id.x, tile_id.y,
|
tile_id.zoom, tile_id.x, tile_id.y,
|
||||||
self.url_query
|
self.url_query
|
||||||
)
|
)
|
||||||
|
@ -54,7 +54,14 @@ impl WxboxApp {
|
||||||
data: "grib2/noaa_mrms_merged_composite_reflectivity_qc".to_string(),
|
data: "grib2/noaa_mrms_merged_composite_reflectivity_qc".to_string(),
|
||||||
data_transparency: 0.9,
|
data_transparency: 0.9,
|
||||||
}),
|
}),
|
||||||
Default::default(),
|
HttpOptions {
|
||||||
|
cache: if cfg!(target_arch = "wasm32") {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(".cache".into())
|
||||||
|
},
|
||||||
|
user_agent: None,
|
||||||
|
},
|
||||||
ctx.clone()
|
ctx.clone()
|
||||||
),
|
),
|
||||||
map_memory: MapMemory::default()
|
map_memory: MapMemory::default()
|
||||||
|
@ -85,11 +92,16 @@ impl eframe::App for WxboxApp {
|
||||||
.collapsible(false)
|
.collapsible(false)
|
||||||
.resizable(false)
|
.resizable(false)
|
||||||
.title_bar(false)
|
.title_bar(false)
|
||||||
.anchor(Align2::LEFT_TOP, [10.0, 10.0])
|
.anchor(Align2::RIGHT_BOTTOM, [-10.0, -10.0])
|
||||||
.show(ui.ctx(), |ui| {
|
.show(ui.ctx(), |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.hyperlink_to(attribution.text, attribution.url);
|
ui.hyperlink_to(attribution.text, attribution.url);
|
||||||
})
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
Window::new("wxbox")
|
||||||
|
.show(ui.ctx(), |ui| {
|
||||||
|
ui.label("Welcome to wxbox!")
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,3 +4,9 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
console_error_panic_hook = "0.1"
|
||||||
|
wasm-tracing = "1"
|
||||||
|
eframe = "0.30"
|
||||||
|
wxbox_client = { path = "../wxbox_client" }
|
||||||
|
wasm-bindgen-futures = "0.4"
|
||||||
|
web-sys = "0.3"
|
33
wxbox_client_wasm/index.html
Normal file
33
wxbox_client_wasm/index.html
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>wxbox</title>
|
||||||
|
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
|
||||||
|
|
||||||
|
<style>
|
||||||
|
html, body {
|
||||||
|
overflow: hidden;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas {
|
||||||
|
margin-right: auto;
|
||||||
|
margin-left: auto;
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="target"></canvas>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1,14 +0,0 @@
|
||||||
pub fn add(left: u64, right: u64) -> u64 {
|
|
||||||
left + right
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn it_works() {
|
|
||||||
let result = add(2, 2);
|
|
||||||
assert_eq!(result, 4);
|
|
||||||
}
|
|
||||||
}
|
|
30
wxbox_client_wasm/src/main.rs
Normal file
30
wxbox_client_wasm/src/main.rs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
use wxbox_client::WxboxApp;
|
||||||
|
use web_sys::wasm_bindgen::JsCast;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
console_error_panic_hook::set_once();
|
||||||
|
wasm_tracing::set_as_global_default();
|
||||||
|
|
||||||
|
let web_options = eframe::WebOptions::default();
|
||||||
|
wasm_bindgen_futures::spawn_local(async {
|
||||||
|
let document = web_sys::window()
|
||||||
|
.expect("no window?")
|
||||||
|
.document()
|
||||||
|
.expect("no document?");
|
||||||
|
|
||||||
|
let canvas = document
|
||||||
|
.get_element_by_id("target")
|
||||||
|
.expect("failed to find target canvas for rendering")
|
||||||
|
.dyn_into::<web_sys::HtmlCanvasElement>()
|
||||||
|
.expect("#target is not a canvas");
|
||||||
|
|
||||||
|
eframe::WebRunner::new()
|
||||||
|
.start(
|
||||||
|
canvas,
|
||||||
|
web_options,
|
||||||
|
Box::new(|cc| Ok(Box::new(WxboxApp::new(cc.egui_ctx.clone()))))
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("failed to start eframe")
|
||||||
|
})
|
||||||
|
}
|
|
@ -4,4 +4,4 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = "1"
|
serde = { version = "1", features = ["derive"] }
|
Loading…
Reference in a new issue