Skip to content

Commit 96277b2

Browse files
committed
Update the rotation
When the user drag the view When the user double click inside the view (resets the north to east position angle to 0)
1 parent e5ac957 commit 96277b2

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

js/models/event_handler.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ export default class EventHandler {
4949
/**
5050
* Updates the view center rotation in the model.
5151
* WARNING: This method doesn't call model.save_changes()!
52+
*
53+
* The python rotation traitlet is updated when:
54+
* - the user drag the view (positionChanged occuring).
55+
* - the user dbl click inside the view which resets the rotation to 0.
5256
*/
5357
updateRotation() {
54-
let rotation = this.model.get("_rotation");
55-
this.aladin.setRotation(rotation);
58+
if (!this.isLastDiv()) return;
59+
this.model.set("_rotation", this.aladin.getRotation());
5660
}
5761

5862
/**
@@ -96,6 +100,9 @@ export default class EventHandler {
96100
jsTargetLock.lock();
97101
const raDec = [position.ra, position.dec];
98102
this.updateWCS();
103+
// When dragging the view, north to east position angle might changes because
104+
// the spherical rotation does not keep the north pole up.
105+
this.updateRotation();
99106
this.model.set("_target", `${raDec[0]} ${raDec[1]}`);
100107
this.model.save_changes();
101108
});
@@ -128,6 +135,12 @@ export default class EventHandler {
128135
this.model.save_changes();
129136
});
130137

138+
// A better way would be to listen to a "dblclick" event through aladin.on
139+
this.aladin.view.catalogCanvas.addEventListener("dblclick", (e) => {
140+
this.updateRotation();
141+
this.model.save_changes();
142+
});
143+
131144
this.model.on("change:_fov", () => {
132145
if (jsFovLock.locked) {
133146
jsFovLock.unlock();
@@ -150,7 +163,11 @@ export default class EventHandler {
150163

151164
/* Rotation control */
152165
this.model.on("change:_rotation", () => {
153-
this.updateRotation(this.model.get("_rotation"), this.aladinDiv);
166+
// Get the rotation value from the python
167+
let rotation = this.model.get("_rotation");
168+
// And propagate it to Aladin Lite
169+
this.aladin.setRotation(rotation);
170+
154171
// Update WCS and FoV only if this is the last div
155172
this.updateWCS();
156173
this.update2AxisFoV();
@@ -203,7 +220,7 @@ export default class EventHandler {
203220
}
204221
});
205222

206-
this.aladin.on("rotationChanged", (object) => {
223+
this.aladin.on("rotationChanged", (_) => {
207224
this.updateRotation();
208225
if (!this.isLastDiv()) return;
209226
this.model.save_changes();

0 commit comments

Comments
 (0)