mirror of
https://github.com/cds-astro/aladin-lite.git
synced 2025-12-12 15:49:18 -08:00
Modify objects returned from selector and finish poly select impl
This commit is contained in:
committed by
Matthieu Baumann
parent
a83cfaab25
commit
6f2730893f
@@ -112,7 +112,7 @@ export class CircleSelect extends FSM {
|
||||
}
|
||||
|
||||
// execute selection callback only
|
||||
(typeof this.callback === 'function') && this.callback(s);
|
||||
(typeof this.callback === 'function') && this.callback(s, Selector.getObjects(s, view));
|
||||
|
||||
this.dispatch("off");
|
||||
};
|
||||
|
||||
@@ -22,6 +22,7 @@ import { ActionButton } from "../gui/Widgets/ActionButton";
|
||||
import { View } from "../View";
|
||||
import finishIconUrl from '../../../assets/icons/finish.svg';
|
||||
import { Utils } from "../Utils";
|
||||
import { Selector } from "../Selector";
|
||||
|
||||
/******************************************************************************
|
||||
* Aladin Lite project
|
||||
@@ -174,17 +175,32 @@ export class PolySelect extends FSM {
|
||||
let s = {
|
||||
vertices: this.coos,
|
||||
label: 'polygon',
|
||||
contains(s) {
|
||||
let x = s.x;
|
||||
let y = s.y;
|
||||
|
||||
let inside = false;
|
||||
for (let i = 0, j = this.vertices.length - 1; i < this.vertices.length; j = i++) {
|
||||
let xi = this.vertices[i].x, yi = this.vertices[i].y;
|
||||
let xj = this.vertices[j].x, yj = this.vertices[j].y;
|
||||
|
||||
let intersect = ((yi > y) !== (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
|
||||
if (intersect) inside = !inside;
|
||||
}
|
||||
return inside;
|
||||
},
|
||||
bbox() {
|
||||
return {x, y, w, h}
|
||||
}
|
||||
};
|
||||
(typeof this.callback === 'function') && this.callback(s);
|
||||
(typeof this.callback === 'function') && this.callback(s, Selector.getObjects(s, view));
|
||||
|
||||
// execute general callback
|
||||
if (view.aladin.callbacksByEventName) {
|
||||
var callback = view.aladin.callbacksByEventName['objectsSelected'] || view.aladin.callbacksByEventName['select'];
|
||||
if (typeof callback === "function") {
|
||||
console.warn('polygon selection is not fully implemented, PolySelect.contains is needed for finding sources inside a polygon')
|
||||
let objList = Selector.getObjects(s, view);
|
||||
callback(objList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,6 +273,7 @@ export class PolySelect extends FSM {
|
||||
//mouseout,
|
||||
mousemove,
|
||||
draw,
|
||||
finish,
|
||||
},
|
||||
mouseout: {
|
||||
start,
|
||||
|
||||
@@ -99,7 +99,7 @@ export class RectSelect extends FSM {
|
||||
}
|
||||
};
|
||||
|
||||
(typeof this.callback === 'function') && this.callback(s);
|
||||
(typeof this.callback === 'function') && this.callback(s, Selector.getObjects(s, view));
|
||||
|
||||
// TODO: remove these modes in the future
|
||||
view.aladin.showReticle(true)
|
||||
|
||||
@@ -110,7 +110,7 @@ export class Selector {
|
||||
|
||||
var objList = [];
|
||||
var cat, sources, s;
|
||||
var footprints, f;
|
||||
var overlayItems, f;
|
||||
var objListPerCatalog = [];
|
||||
if (view.catalogs) {
|
||||
for (var k = 0; k < view.catalogs.length; k++) {
|
||||
@@ -130,11 +130,11 @@ export class Selector {
|
||||
}
|
||||
}
|
||||
// footprints
|
||||
footprints = cat.getFootprints();
|
||||
if (footprints) {
|
||||
overlayItems = cat.getFootprints();
|
||||
if (overlayItems) {
|
||||
const {x, y, w, h} = selection.bbox();
|
||||
for (var l = 0; l < footprints.length; l++) {
|
||||
f = footprints[l];
|
||||
for (var l = 0; l < overlayItems.length; l++) {
|
||||
f = overlayItems[l];
|
||||
if (f.intersectsBBox(x, y, w, h, view)) {
|
||||
objListPerCatalog.push(f);
|
||||
}
|
||||
@@ -148,6 +148,27 @@ export class Selector {
|
||||
}
|
||||
}
|
||||
|
||||
if (view.overlays) {
|
||||
const {x, y, w, h} = selection.bbox();
|
||||
for (var k = 0; k < view.overlays.length; k++) {
|
||||
let overlay = view.overlays[k];
|
||||
if (!overlay.isShowing) {
|
||||
continue;
|
||||
}
|
||||
var overlayItems = overlay.overlayItems;
|
||||
for (var l = 0; l < overlayItems.length; l++) {
|
||||
let o = overlayItems[l];
|
||||
if (!o.isShowing) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (o.intersectsBBox(x, y, w, h, view)) {
|
||||
objList.push(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return objList;
|
||||
}
|
||||
}
|
||||
@@ -207,7 +207,7 @@ export let View = (function () {
|
||||
const cooFrame = CooFrameEnum.fromString(this.options.cooFrame, CooFrameEnum.J2000);
|
||||
this.changeFrame(cooFrame);
|
||||
|
||||
this.selector = new Selector(this);
|
||||
this.selector = new Selector(this, this.options.selector);
|
||||
|
||||
// current reference image survey displayed
|
||||
this.imageLayers = new Map();
|
||||
|
||||
@@ -466,7 +466,50 @@ export let Polyline = (function() {
|
||||
};
|
||||
|
||||
Polyline.prototype.intersectsBBox = function(x, y, w, h) {
|
||||
// todo
|
||||
for (let i = 0; i < this.radecArray.length - 1; i++) {
|
||||
let p1 = this.radecArray[i];
|
||||
let p2 = this.radecArray[i + 1];
|
||||
|
||||
let xy1 = AladinUtils.radecToViewXy(p1[0], p1[1], this.overlay.view.aladin);
|
||||
let xy2 = AladinUtils.radecToViewXy(p2[0], p2[1], this.overlay.view.aladin);
|
||||
|
||||
if (!xy1 || !xy2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
xy1 = {x: xy1[0], y: xy1[1]};
|
||||
xy2 = {x: xy2[0], y: xy2[1]};
|
||||
|
||||
// Check if line segment intersects with the bounding box
|
||||
if (this.lineIntersectsBox(xy1, xy2, x, y, w, h)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
Polyline.prototype.lineIntersectsBox = function(p1, p2, x, y, w, h) {
|
||||
// Check if line segment is completely outside the box
|
||||
if ((p1.x < x && p2.x < x) ||
|
||||
(p1.y < y && p2.y < y) ||
|
||||
(p1.x > x + w && p2.x > x + w) ||
|
||||
(p1.y > y + h && p2.y > y + h)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let m = (p2.y - p1.y) / (p2.x - p1.x); // Slope of the line
|
||||
let c = p1.y - m * p1.x; // y-intercept of the line
|
||||
|
||||
// Check if line intersects with the sides of the box
|
||||
if ((p1.y >= y && p1.y <= y + h) ||
|
||||
(p2.y >= y && p2.y <= y + h) ||
|
||||
(m * x + c >= y && m * x + c <= y + h) ||
|
||||
(m * (x + w) + c >= y && m * (x + w) + c <= y + h)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
// static methods
|
||||
|
||||
Reference in New Issue
Block a user