Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/js/Aladin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,8 @@ export let Aladin = (function () {
"select", // deprecated, use objectsSelected instead
"objectsSelected",

"regionSelected",

"objectClicked",
"objectHovered",
"objectHoveredStop",
Expand Down Expand Up @@ -2257,6 +2259,10 @@ aladin.on("layerChanged", (layer, layerName, state) => {
this.fire("selectstart", { mode, callback });
};

Aladin.prototype.selectRegion = async function (region, callback) {
this.view.regionSelection(region, callback);
}

Aladin.prototype.fire = function (what, params) {
if (what === "selectstart") {
const { mode, callback } = params;
Expand Down
48 changes: 47 additions & 1 deletion src/js/FiniteStateMachine/CircleSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,30 @@ export class CircleSelect extends FSM {

if (typeof callback === "function") {
let objList = Selector.getObjects(s, view);

view.selectObjects(objList);
callback(objList);
}

var region_callback = view.aladin.callbacksByEventName['regionSelected'];
if (typeof region_callback === "function") {
let startCooWorld = view.aladin.pix2world(this.startCoo.x, this.startCoo.y);
let radius = view.aladin.angularDist(
this.startCoo.x,
this.startCoo.y,
this.coo.x,
this.coo.y
);

region_callback({
type: "circle",
startCoo: {
ra: startCooWorld[0],
dec: startCooWorld[1]
},
radius: radius,
});
}
}

// execute selection callback only
Expand All @@ -134,14 +155,36 @@ export class CircleSelect extends FSM {
view.aladin.removeStatusBarMessage('selector')
};

let api = (params) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more informative name for api?

let startCoo = params["startCoo"];
let endCoo = params["endCoo"];

let startCooPix = view.aladin.world2pix(startCoo["ra"], startCoo["dec"]);
let endCooPix = view.aladin.world2pix(endCoo["ra"], endCoo["dec"]);


this.startCoo = {
x: startCooPix[0],
y: startCooPix[1],
};

this.dispatch('mouseup', {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These uses of mouse events to define a selection region are good places to highlight as we discuss the challenges of moving between sky regions and screen coordinates. For these in particular, unless one is zoomed in a centered around the region, it's pretty easy for the sky coordinates needed to not be on the screen.

coo: {
x: endCooPix[0],
y: endCooPix[1],
},
});
}

super({
state: 'off',
transitions: {
off: {
start,
},
start: {
mousedown
mousedown,
api,
},
mousedown: {
mousemove
Expand All @@ -162,6 +205,9 @@ export class CircleSelect extends FSM {
},
mouseup: {
off,
},
api: {
mouseup
}
}
})
Expand Down
34 changes: 33 additions & 1 deletion src/js/FiniteStateMachine/PolySelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,25 @@ export class PolySelect extends FSM {
var callback = view.aladin.callbacksByEventName['objectsSelected'] || view.aladin.callbacksByEventName['select'];
if (typeof callback === "function") {
let objList = Selector.getObjects(s, view);

view.selectObjects(objList);
callback(objList);
}

var region_callback = view.aladin.callbacksByEventName['regionSelected'];
if (typeof region_callback === "function") {

region_callback({
type: "poly",
coos: this.coos.map((coo) => {
let cooWorld = view.aladin.pix2world(coo.x, coo.y);
return {
ra: cooWorld[0],
dec: cooWorld[1],
};
}),
});
}
}

this.coos = [];
Expand All @@ -216,6 +233,17 @@ export class PolySelect extends FSM {
this.dispatch('off');
};

let api = (params) => {
this.coos = params["coos"].map((coo) => {
let cooPix = view.aladin.world2pix(coo["ra"], coo["dec"]);
return {
x: cooPix[0],
y: cooPix[1],
};
});
this.dispatch("finish");
}

let fsm;
if (Utils.hasTouchScreen()) {
let mousedown = click;
Expand Down Expand Up @@ -270,7 +298,8 @@ export class PolySelect extends FSM {
start,
},
start: {
click
click,
api,
},
click: {
//mouseout,
Expand All @@ -295,6 +324,9 @@ export class PolySelect extends FSM {
},
finish: {
off
},
api: {
finish
}
}
}
Expand Down
59 changes: 58 additions & 1 deletion src/js/FiniteStateMachine/RectSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,39 @@ export class RectSelect extends FSM {
view.selectObjects(objList);
callback(objList);
}

var region_callback = view.aladin.callbacksByEventName['regionSelected'];
if (typeof region_callback === "function") {
let coos = [
[
Math.min(this.startCoo.x, this.coo.x),
Math.min(this.startCoo.y, this.coo.y),
],
[
Math.max(this.startCoo.x, this.coo.x),
Math.min(this.startCoo.y, this.coo.y),
],
[
Math.max(this.startCoo.x, this.coo.x),
Math.max(this.startCoo.y, this.coo.y),
],
[
Math.min(this.startCoo.x, this.coo.x),
Math.max(this.startCoo.y, this.coo.y),
],
];

region_callback({
type: "rect",
coos: coos.map((coo) => {
let cooWorld = view.aladin.pix2world(coo[0], coo[1]);
return {
ra: cooWorld[0],
dec: cooWorld[1],
};
}),
});
}
}

this.dispatch('off');
Expand All @@ -139,6 +172,26 @@ export class RectSelect extends FSM {
}
};

let api = (params) => {
let startCoo = params["startCoo"];
let endCoo = params["endCoo"];

let startCooPix = view.aladin.world2pix(startCoo["ra"], startCoo["dec"]);
let endCooPix = view.aladin.world2pix(endCoo["ra"], endCoo["dec"]);

this.startCoo = {
x: startCooPix[0],
y: startCooPix[1],
}

selector.dispatch("mouseup", {
coo: {
x: endCooPix[0],
y: endCooPix[1],
},
});
}

super({
state: 'off',
transitions: {
Expand All @@ -149,7 +202,8 @@ export class RectSelect extends FSM {
mousedown,
mouseup,
mouseout,
off
off,
api,
},
mousedown: {
mousemove,
Expand All @@ -173,6 +227,9 @@ export class RectSelect extends FSM {
},
mouseup: {
off,
},
api: {
mouseup,
}
}
})
Expand Down
5 changes: 5 additions & 0 deletions src/js/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,11 @@ export let View = (function () {
this.selector.start(mode, callback);
}

View.prototype.regionSelection = function(region, callback) {
this.selector.start(region["selection_type"], callback);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the callback being given to start(), it's not clear to me what its purpose is. Maybe documentation on the Aladin.prototype.selectRegion() could help with that.

Along the same lines, I wonder if the the next line, this.selector.dispatch() should be waiting for the start() to complete.

this.selector.dispatch("api", region);
}

View.prototype.setMode = function (mode) {
this.mode = mode;

Expand Down