Fix stackChanged

This commit is contained in:
Matthieu Baumann
2026-03-04 15:14:19 +01:00
parent f41765adcd
commit bf290e13e4
11 changed files with 4625 additions and 4609 deletions
+4 -4
View File
@@ -10,6 +10,10 @@
import A from '../src/js/A.js';
A.init.then(() => {
var aladin = A.aladin('#aladin-lite-div', {showContextMenu: true, target: '05 37 58 +08 17 35', fov: 12, backgroundColor: 'rgb(120, 0, 0)'});
aladin.on('stackChanged', function(state) {
console.log(state)
});
var cat = A.catalog({sourceSize: 20, onClick: (s) => {console.log("kjk", s)}});
aladin.addCatalog(cat);
cat.addSources([A.source(83.784490, 9.934156, {name: 'Meissa'}), A.source(88.792939, 7.407064, {name: 'Betelgeuse'}), A.source(81.282764, 6.349703, {name: 'Bellatrix'})]);
@@ -68,10 +72,6 @@
console.log(pos)
});
aladin.on('stackChanged', function(state) {
console.log(state)
});
cat.sources[0].actionClicked();
});
</script>
+1
View File
@@ -12,6 +12,7 @@
A.init.then(() => {
// Start up Aladin Lite
aladin = A.aladin('#aladin-lite-div', {target: 'M 1', fov: 0.2, showContextMenu: true, fullScreen: true});
var overlay = A.graphicOverlay({color: 'purple', lineWidth: 3, lineDash: [2, 2]});
aladin.addOverlay(overlay);
overlay.addFootprints([
+1 -2
View File
@@ -49,8 +49,7 @@ version = "0.7.3"
[dependencies.moclib]
package = "moc"
git = "https://github.com/cds-astro/cds-moc-rust"
branch = "main"
version = "0.19.1"
[dependencies.serde]
version = "^1.0.183"
+6 -3
View File
@@ -64,12 +64,15 @@ impl Texture3D {
metadata,
};
let voxel_count = F::NUM_CHANNELS * (width as usize) * (height as usize) * (depth as usize);
let zeros = vec![0xff; voxel_count as usize];
s.bind().tex_sub_image_3d_with_opt_u8_array(0, 0, 0,
let zeros = vec![0xff; voxel_count];
s.bind().tex_sub_image_3d_with_opt_u8_array(
0,
0,
0,
width,
height,
depth,
Some(&zeros[..])
Some(&zeros[..]),
);
Ok(s)
}
+22 -32
View File
@@ -106,7 +106,6 @@ pub struct App {
pub projection: ProjectionType,
cubic_tile_send: async_channel::Sender<WorkerResponse>,
cubic_tile_recv: async_channel::Receiver<WorkerResponse>,
// Async data receivers
@@ -215,11 +214,7 @@ impl App {
let vel_history = vec![];
let worker = create_worker()?;
// Send the ack to the js promise so that she finished
let cubic_tile_send2 = cubic_tile_send.clone();
let onmessage = Closure::<
dyn FnMut(web_sys::MessageEvent),
>::new(
let onmessage = Closure::<dyn FnMut(web_sys::MessageEvent)>::new(
move |event: web_sys::MessageEvent| {
let data = event.data();
@@ -238,26 +233,26 @@ impl App {
bytes,
tile_size: meta.tile_size,
tile_depth: meta.tile_depth,
time_request: meta.time_request,
cell: meta.cell,
hips_cdid: meta.hips_cdid
hips_cdid: meta.hips_cdid,
};
let cubic_tile_send3 = cubic_tile_send2.clone();
let c = cubic_tile_send.clone();
wasm_bindgen_futures::spawn_local(async move {
cubic_tile_send3.send(response).await.unwrap_throw();
c.send(response).await.unwrap_throw();
})
},
);
worker.set_onmessage(Some(
onmessage.as_ref().unchecked_ref(),
));
worker.set_onmessage(Some(onmessage.as_ref().unchecked_ref()));
// 🚨 VERY IMPORTANT: prevent the closure from being dropped
onmessage.forget();
gl.blend_func(WebGl2RenderingContext::SRC_ALPHA, WebGl2RenderingContext::ONE_MINUS_SRC_ALPHA);
gl.blend_func(
WebGl2RenderingContext::SRC_ALPHA,
WebGl2RenderingContext::ONE_MINUS_SRC_ALPHA,
);
Ok(App {
gl,
@@ -312,7 +307,6 @@ impl App {
//img_send,
img_recv,
ack_img_send,
cubic_tile_send,
cubic_tile_recv,
browser_features_support, //ack_img_recv,
@@ -595,7 +589,15 @@ impl App {
})
}
if let Ok(WorkerResponse { cell, hips_cdid, tile_size, tile_depth, bytes, time_request, .. }) = self.cubic_tile_recv.try_recv() {
if let Ok(WorkerResponse {
cell,
hips_cdid,
tile_size,
tile_depth,
bytes,
..
}) = self.cubic_tile_recv.try_recv()
{
if let Some(HiPS::D3(hips)) = self.layers.get_mut_hips_from_cdid(&hips_cdid) {
hips.push_tile_from_png(
&cell,
@@ -761,7 +763,7 @@ impl App {
js_sys::Reflect::set(
&msg,
&"bitmap".into(),
&image,
image,
)?;
js_sys::Reflect::set(
&msg,
@@ -773,16 +775,11 @@ impl App {
&"tileDepth".into(),
&JsValue::from_f64(*tile_depth as f64),
)?;
js_sys::Reflect::set(
&msg,
&"timeRequest".into(),
&JsValue::from_f64(tile.request.time_request.as_millis() as f64),
)?;
js_sys::Reflect::set(
&msg,
&"cell".into(),
&serde_wasm_bindgen::to_value(&cell)
.expect("Failed to serialize")
.expect("Failed to serialize"),
)?;
js_sys::Reflect::set(
@@ -792,7 +789,7 @@ impl App {
)?;
// Transfer ownership (zero-copy)
let transfer = js_sys::Array::of1(&image);
let transfer = js_sys::Array::of1(image);
self.worker.post_message_with_transfer(
&msg, &transfer,
@@ -1873,9 +1870,6 @@ pub struct WorkerResponse {
pub bytes: Vec<u8>,
#[serde(rename = "timeRequest")]
pub time_request: f32,
#[serde(rename = "HiPSCDid")]
pub hips_cdid: String,
@@ -1890,9 +1884,6 @@ pub struct WorkerResponseMeta {
#[serde(rename = "tileDepth")]
pub tile_depth: u32,
#[serde(rename = "timeRequest")]
pub time_request: f32,
#[serde(rename = "HiPSCDid")]
pub hips_cdid: String,
@@ -1904,7 +1895,7 @@ pub fn create_worker() -> Result<Worker, JsValue> {
// JS source code of the worker
let worker_source = r#"
self.onmessage = (e) => {
const { bitmap, tileDepth, tileSize, timeRequest, HiPS, cell } = e.data;
const { bitmap, tileDepth, tileSize, HiPS, cell } = e.data;
// Compute tiling layout
const numCols = Math.floor(bitmap.width / tileSize);
@@ -1974,7 +1965,6 @@ pub fn create_worker() -> Result<Worker, JsValue> {
{
tileSize,
tileDepth,
timeRequest,
HiPSCDid: HiPS,
cell,
bytes: decodedBytes,
+2 -4
View File
@@ -1,7 +1,6 @@
use std::cmp::Ordering;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[derive(serde::Deserialize, serde::Serialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Deserialize, serde::Serialize)]
pub struct HEALPixCell(pub u8, pub u64);
#[derive(Debug)]
@@ -493,8 +492,7 @@ impl Ord for HEALPixCell {
}
/// A simple object describing a cubic tile of a HiPS3D
#[derive(Eq, Hash, PartialEq, Clone, Debug)]
#[derive(serde::Deserialize, serde::Serialize)]
#[derive(Eq, Hash, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct HEALPixFreqCell {
pub hpx: HEALPixCell,
pub f_hash: u64,
+5 -1
View File
@@ -579,7 +579,11 @@ use std::fmt::Display;
impl Display for Angle<f64> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.fmt {
AngleFormatter::Sexagesimal { mut prec, plus, hours } => {
AngleFormatter::Sexagesimal {
mut prec,
plus,
hours,
} => {
let unit = if hours {
// to preserve the same angular precision the new prec is p+log10(15) ≈ p+1.18 < p+2
prec += 2;
+4556 -4556
View File
File diff suppressed because it is too large Load Diff
+25 -4
View File
@@ -308,6 +308,29 @@ export let Aladin = (function () {
const self = this;
ALEvent.GRAPHIC_OVERLAY_LAYER_ADDED.listenedBy(
aladinDiv,
(e) => {
const {overlay} = e.detail;
let callback = this.callbacksByEventName["stackChanged"];
callback && callback({
change: 'added',
overlay,
});
}
);
ALEvent.GRAPHIC_OVERLAY_LAYER_REMOVED.listenedBy(
aladinDiv, (e) => {
const {overlay} = e.detail;
let callback = this.callbacksByEventName["stackChanged"];
callback && callback({
change: 'removed',
overlay,
});
}
);
ALEvent.LAYER_ADDED.listenedBy(aladinDiv, (e) => {
const {layer} = e.detail;
let callback = this.callbacksByEventName["stackChanged"];
@@ -1601,7 +1624,7 @@ export let Aladin = (function () {
this.view.addCatalog(catalog);
ALEvent.GRAPHIC_OVERLAY_LAYER_ADDED.dispatchedTo(this.aladinDiv, {
layer: catalog,
overlay: catalog,
});
};
@@ -1614,9 +1637,7 @@ export let Aladin = (function () {
Aladin.prototype.addOverlay = function (overlay) {
this.view.addOverlay(overlay);
ALEvent.GRAPHIC_OVERLAY_LAYER_ADDED.dispatchedTo(this.aladinDiv, {
layer: overlay,
});
ALEvent.GRAPHIC_OVERLAY_LAYER_ADDED.dispatchedTo(this.aladinDiv, { overlay });
};
+1 -1
View File
@@ -199,7 +199,7 @@ export let MOC = (function() {
self.view.insertOverlay(self, idx);
// Tell the MOC has been fully loaded and can be sent as an event
ALEvent.GRAPHIC_OVERLAY_LAYER_ADDED.dispatchedTo(self.view.aladinDiv, {layer: self});
ALEvent.GRAPHIC_OVERLAY_LAYER_ADDED.dispatchedTo(self.view.aladinDiv, {overlay: self});
self.view.requestRedraw();
})
+2 -2
View File
@@ -2123,7 +2123,7 @@ export let View = (function () {
this.mocs = [];
this.allOverlayLayers.forEach((overlay) => {
ALEvent.GRAPHIC_OVERLAY_LAYER_REMOVED.dispatchedTo(this.aladinDiv, { layer: overlay });
ALEvent.GRAPHIC_OVERLAY_LAYER_REMOVED.dispatchedTo(this.aladinDiv, { overlay });
})
this.allOverlayLayers = [];
@@ -2159,7 +2159,7 @@ export let View = (function () {
this.overlays.splice(indexToDelete, 1);
}
ALEvent.GRAPHIC_OVERLAY_LAYER_REMOVED.dispatchedTo(this.aladinDiv, { layer: overlay });
ALEvent.GRAPHIC_OVERLAY_LAYER_REMOVED.dispatchedTo(this.aladinDiv, { overlay });
this.mustClearCatalog = true;
this.requestRedraw();