mirror of
https://github.com/cds-astro/aladin-lite.git
synced 2025-12-12 15:49:18 -08:00
fix: call aladin methods that calls to wasm in the positionChanged callback
This commit is contained in:
@@ -14,12 +14,12 @@
|
||||
aladin = A.aladin('#aladin-lite-div', {target: "30 0", fov: 360, fullScreen: true, cooFrame: 'galactic', showCooGridControl: true, showSimbadPointerControl: true, showCooGrid: true});
|
||||
aladin.setProjection('AIT');
|
||||
|
||||
|
||||
aladin.on("zoomChanged", () => {
|
||||
console.log("zoomChanged")
|
||||
})
|
||||
aladin.on("positionChanged", ({ra, dec, dragging}) => {
|
||||
console.log("positionChanged", ra, dec)
|
||||
|
||||
aladin.on("positionChanged", ({ra, dec}) => {
|
||||
|
||||
})
|
||||
|
||||
aladin.gotoRaDec(0, 20);
|
||||
|
||||
@@ -106,9 +106,8 @@ pub struct App {
|
||||
|
||||
ack_send: async_channel::Sender<ImageParams>,
|
||||
ack_recv: async_channel::Receiver<ImageParams>,
|
||||
|
||||
// callbacks
|
||||
callback_position_changed: js_sys::Function,
|
||||
//callback_position_changed: js_sys::Function,
|
||||
}
|
||||
|
||||
use cgmath::{Vector2, Vector3};
|
||||
@@ -131,7 +130,7 @@ impl App {
|
||||
mut shaders: ShaderManager,
|
||||
resources: Resources,
|
||||
// Callbacks
|
||||
callback_position_changed: js_sys::Function,
|
||||
//callback_position_changed: js_sys::Function,
|
||||
) -> Result<Self, JsValue> {
|
||||
let gl = gl.clone();
|
||||
//let exec = Rc::new(RefCell::new(TaskExecutor::new()));
|
||||
@@ -261,8 +260,7 @@ impl App {
|
||||
fits_recv,
|
||||
ack_send,
|
||||
ack_recv,
|
||||
|
||||
callback_position_changed,
|
||||
//callback_position_changed,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -540,8 +538,12 @@ impl App {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn set_callback_position_changed(&mut self, callback: js_sys::Function) {
|
||||
/*pub(crate) fn set_callback_position_changed(&mut self, callback: js_sys::Function) {
|
||||
self.callback_position_changed = callback;
|
||||
}*/
|
||||
|
||||
pub(crate) fn is_inerting(&self) -> bool {
|
||||
return self.inertia.is_some();
|
||||
}
|
||||
|
||||
pub(crate) fn update(&mut self, _dt: DeltaTime) -> Result<bool, JsValue> {
|
||||
@@ -560,7 +562,7 @@ impl App {
|
||||
let cur_speed = inertia.get_cur_speed();
|
||||
|
||||
// Create the javascript object to pass to the callback
|
||||
let args: js_sys::Object = js_sys::Object::new();
|
||||
/*let args: js_sys::Object = js_sys::Object::new();
|
||||
let center = self.camera.get_center().lonlat();
|
||||
js_sys::Reflect::set(
|
||||
&args,
|
||||
@@ -578,6 +580,7 @@ impl App {
|
||||
// Position has changed, we call the callback
|
||||
self.callback_position_changed
|
||||
.call1(&JsValue::null(), &args)?;
|
||||
*/
|
||||
|
||||
if cur_speed < thresh_speed {
|
||||
self.inertia = None;
|
||||
|
||||
@@ -166,13 +166,10 @@ impl WebClient {
|
||||
let shaders = ShaderManager::new(&gl, shaders).unwrap_abort();
|
||||
|
||||
// Event listeners callbacks
|
||||
let callback_position_changed = js_sys::Function::new_no_args("");
|
||||
//let callback_position_changed = js_sys::Function::new_no_args("");
|
||||
let app = App::new(
|
||||
&gl,
|
||||
aladin_div,
|
||||
shaders,
|
||||
resources,
|
||||
callback_position_changed,
|
||||
&gl, aladin_div, shaders, resources,
|
||||
//callback_position_changed,
|
||||
)?;
|
||||
|
||||
let dt = DeltaTime::zero();
|
||||
@@ -182,9 +179,14 @@ impl WebClient {
|
||||
Ok(webclient)
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = setCallbackPositionChanged)]
|
||||
/*#[wasm_bindgen(js_name = setCallbackPositionChanged)]
|
||||
pub fn set_callback_position_changed(&mut self, callback: js_sys::Function) {
|
||||
self.app.set_callback_position_changed(callback);
|
||||
}*/
|
||||
|
||||
#[wasm_bindgen(js_name = isInerting)]
|
||||
pub fn is_inerting(&self) -> bool {
|
||||
return self.app.is_inerting();
|
||||
}
|
||||
|
||||
/// Update the view
|
||||
|
||||
@@ -1773,7 +1773,7 @@ aladin.on('objectClicked', function(object, xyMouseCoords) {
|
||||
|
||||
this.callbacksByEventName[what] = myFunction;
|
||||
|
||||
if (what === "positionChanged") {
|
||||
/*if (what === "positionChanged") {
|
||||
// tell the backend about that callback
|
||||
// because it needs to be called when the inertia is done
|
||||
ALEvent.AL_USE_WASM.dispatchedTo(this.aladinDiv, {callback: (wasm) => {
|
||||
@@ -1782,9 +1782,9 @@ aladin.on('objectClicked', function(object, xyMouseCoords) {
|
||||
View.CALLBACKS_THROTTLE_TIME_MS,
|
||||
);
|
||||
|
||||
wasm.setCallbackPositionChanged(myFunctionThrottled);
|
||||
wasm.setCallbackPositionChanged(myFunctionThrottled.bind(this));
|
||||
}})
|
||||
}
|
||||
}*/
|
||||
};
|
||||
|
||||
Aladin.prototype.addListener = function(alEventName, customFn) {
|
||||
|
||||
@@ -124,7 +124,7 @@ export let View = (function () {
|
||||
() => {
|
||||
var posChangedFn = this.aladin.callbacksByEventName && this.aladin.callbacksByEventName['positionChanged'];
|
||||
if (typeof posChangedFn === 'function') {
|
||||
var pos = this.aladin.pix2world(this.width / 2, this.height / 2);
|
||||
var pos = this.aladin.pix2world(this.width / 2, this.height / 2, 'icrs');
|
||||
if (pos !== undefined) {
|
||||
posChangedFn({
|
||||
ra: pos[0],
|
||||
@@ -1246,9 +1246,12 @@ export let View = (function () {
|
||||
// Drawing code
|
||||
//try {
|
||||
this.moving = this.wasm.update(elapsedTime);
|
||||
//} catch (e) {
|
||||
// console.error(e)
|
||||
//}
|
||||
|
||||
// inertia run throttled position
|
||||
if (this.moving && this.aladin.callbacksByEventName && this.aladin.callbacksByEventName['positionChanged'] && this.wasm.isInerting()) {
|
||||
// run the trottled position
|
||||
this.throttledPositionChanged();
|
||||
}
|
||||
|
||||
////// 2. Draw catalogues////////
|
||||
const isViewRendering = this.wasm.isRendering();
|
||||
|
||||
Reference in New Issue
Block a user