Skip to content

Commit

Permalink
fix bugs found in ipyaladin
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Mar 1, 2024
1 parent c416e85 commit 8d248e8
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 201 deletions.
7 changes: 4 additions & 3 deletions src/js/Aladin.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ export let Aladin = (function () {
* let aladin = A.Aladin('#aladin-lite-div', { option1: 'value1', option2: 'value2' });
*/
var Aladin = function (aladinDiv, requestedOptions) {
this.callbacksByEventName = {}; // we store the callback functions (on 'zoomChanged', 'positionChanged', ...) here

// check that aladinDiv exists, stop immediately otherwise
if (!aladinDiv) {
console.error("Aladin div has not been found. Please check its name!");
return;
}
this.wasm = null;
Expand Down Expand Up @@ -283,8 +286,6 @@ export let Aladin = (function () {

this.view.showCatalog(options.showCatalog);

this.callbacksByEventName = {}; // we store the callback functions (on 'zoomChanged', 'positionChanged', ...) here

// FullScreen toolbar icon
this.isInFullscreen = false;
// go to full screen ?
Expand Down Expand Up @@ -770,7 +771,7 @@ export let Aladin = (function () {

this.view.changeFrame(newFrame);

var frameChangedFunction = this.view.aladin.callbacksByEventName['cooFrameChanged'];
var frameChangedFunction = this.callbacksByEventName['cooFrameChanged'];
if (typeof frameChangedFunction === 'function') {
frameChangedFunction(newFrame.label);
}
Expand Down
4 changes: 2 additions & 2 deletions src/js/DefaultActionsForContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ export let DefaultActionsForContextMenu = (function () {
]
},
{
label: "What is this?", action(e) {
GenericPointer(a.view, e);
label: "What is this?", action(o) {
GenericPointer(a.view, o);
}
},
{
Expand Down
8 changes: 6 additions & 2 deletions src/js/HiPSProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@ HiPSProperties.fetchFromUrl = async function(urlOrId) {
// 1. Ensure there is exactly one survey matching
if (metadata && Object.keys(metadata).length > 0) {
// Set the service url if not found
metadata.hips_service_url = HiPSServiceUrl;
resolve(metadata);
if (!metadata.hips_frame || !metadata.hips_order) {
reject('Bad properties: do not contain the mandatory frame or order info')
} else {
metadata.hips_service_url = HiPSServiceUrl;
resolve(metadata);
}
} else {
reject('No surveys matching at this url: ' + rootURL);
}
Expand Down
139 changes: 78 additions & 61 deletions src/js/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ export let View = (function () {
Utils.on(view.catalogCanvas, "contextmenu", function (e) {
// do something here...
e.preventDefault();
e.stopPropagation();
}, false);


Expand All @@ -538,6 +539,67 @@ export let View = (function () {
var longTouchDuration = 800;
var xystart;

var handleSelect = function(xy, tolerance) {
tolerance = tolerance || 5;
var objs = view.closestObjects(xy.x, xy.y, tolerance);
// Deselect objects if any
view.unselectObjects();
if (objs) {
var o = objs[0];

// footprint selection code adapted from Fabrizio Giordano dev. from Serco for ESA/ESDC
if (o.marker) {
// could be factorized in Source.actionClicked
view.aladin.popup.setTitle(o.popupTitle);
view.aladin.popup.setText(o.popupDesc);
view.aladin.popup.setSource(o);
view.aladin.popup.show();
}
else {
if (view.lastClickedObject) {
view.lastClickedObject.actionOtherObjectClicked && view.lastClickedObject.actionOtherObjectClicked();
}
}

// show measurements
if (o.actionClicked) {
o.actionClicked();
}

var objClickedFunction = view.aladin.callbacksByEventName['objectClicked'];
(typeof objClickedFunction === 'function') && objClickedFunction(o, xy);

if (o.isFootprint()) {
var footprintClickedFunction = view.aladin.callbacksByEventName['footprintClicked'];
if (typeof footprintClickedFunction === 'function' && o != view.lastClickedObject) {
var ret = footprintClickedFunction(o, xy);
}
}

view.lastClickedObject = o;
} else {
// If there is a past clicked object
if (view.lastClickedObject) {
//view.aladin.measurementTable.hide();
//view.aladin.sodaForm.hide();
view.aladin.popup.hide();

// Deselect the last clicked object
if (view.lastClickedObject instanceof Ellipse || view.lastClickedObject instanceof Circle || view.lastClickedObject instanceof Polyline) {
view.lastClickedObject.deselect();
} else {
// Case where lastClickedObject is a Source
view.lastClickedObject.actionOtherObjectClicked();
}

var objClickedFunction = view.aladin.callbacksByEventName['objectClicked'];
(typeof objClickedFunction === 'function') && objClickedFunction(null, xy);

view.lastClickedObject = null;
}
}
}
var touchStartTime;
Utils.on(view.catalogCanvas, "mousedown touchstart", function (e) {
e.preventDefault();
e.stopPropagation();
Expand Down Expand Up @@ -588,11 +650,14 @@ export let View = (function () {
id: 'opening-ctxmenu',
message: 'Opening menu...',
duration: 'unlimited',
offsetTimeDisplay: 200, // in ms
type: 'loading'
})
}

longTouchTimer = setTimeout(() => {onlongtouch(e); view.dragging = false;}, longTouchDuration);
touchStartTime = Date.now();

}

// zoom pinching
Expand Down Expand Up @@ -651,7 +716,7 @@ export let View = (function () {
if (view.rightClick) {
const rightClickDurationMs = Date.now() - view.rightClickTimeStart;
if (rightClickDurationMs < 300) {
view.aladin.contextMenu && view.aladin.contextMenu.show({e: e});
view.aladin.contextMenu && view.aladin.contextMenu.show({e});
}

view.rightClick = false;
Expand All @@ -669,9 +734,6 @@ export let View = (function () {

// reacting on 'click' rather on 'mouseup' is more reliable when panning the view
Utils.on(view.catalogCanvas, "click mouseout touchend touchcancel", function (e) {
//e.preventDefault();
//e.stopPropagation();

const xymouse = Utils.relMouseCoords(e);

ALEvent.CANVAS_EVENT.dispatchedTo(view.aladinDiv, {
Expand Down Expand Up @@ -755,64 +817,19 @@ export let View = (function () {
}

// popup to show ?
var objs = view.closestObjects(xymouse.x, xymouse.y, 5);
if (!wasDragging && objs) {
view.unselectObjects();

var o = objs[0];

// footprint selection code adapted from Fabrizio Giordano dev. from Serco for ESA/ESDC
if (o.marker) {
// could be factorized in Source.actionClicked
view.aladin.popup.setTitle(o.popupTitle);
view.aladin.popup.setText(o.popupDesc);
view.aladin.popup.setSource(o);
view.aladin.popup.show();
}
else {
if (view.lastClickedObject) {
view.lastClickedObject.actionOtherObjectClicked && view.lastClickedObject.actionOtherObjectClicked();
}
}

// show measurements
if (o.actionClicked) {
o.actionClicked();
}

var objClickedFunction = view.aladin.callbacksByEventName['objectClicked'];
(typeof objClickedFunction === 'function') && objClickedFunction(o, xymouse);

if (o.isFootprint()) {
var footprintClickedFunction = view.aladin.callbacksByEventName['footprintClicked'];
if (typeof footprintClickedFunction === 'function' && o != view.lastClickedObject) {
var ret = footprintClickedFunction(o, xymouse);
}
}

view.lastClickedObject = o;
} else if (!wasDragging) {
// Deselect objects if any
view.unselectObjects();

// If there is a past clicked object
if (view.lastClickedObject) {
//view.aladin.measurementTable.hide();
//view.aladin.sodaForm.hide();
view.aladin.popup.hide();

// Deselect the last clicked object
if (view.lastClickedObject instanceof Ellipse || view.lastClickedObject instanceof Circle || view.lastClickedObject instanceof Polyline) {
view.lastClickedObject.deselect();
} else {
// Case where lastClickedObject is a Source
view.lastClickedObject.actionOtherObjectClicked();
if (!wasDragging || e.type === "touchend") {
if (e.type === "touchend") {
if (e.targetTouches && e.targetTouches.length == 0) {
// Check if the user moved a lot or not
// maybe check the time between the last touch start
const elapsedTime = Date.now() - touchStartTime;
if (elapsedTime < 100) {
view.updateObjectsLookup();
handleSelect(xymouse, 10);
}
}

var objClickedFunction = view.aladin.callbacksByEventName['objectClicked'];
(typeof objClickedFunction === 'function') && objClickedFunction(null, xymouse);

view.lastClickedObject = null;
} else {
handleSelect(xymouse);
}
}

Expand Down
23 changes: 10 additions & 13 deletions src/js/gui/Box/CatalogQueryBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,11 @@ import { CtxMenuActionButtonOpener } from "../Button/CtxMenuOpener.js";
label: 'Cone search',
disable: !item.cs_service_url,
action(o) {
let box = ConeSearchBox.getInstance(aladin);
box.attach({
if (self.box) {
self.box.remove();
}
self.box = new ConeSearchBox(aladin);
self.box.attach({
callback: (cs) => {
self.fnIdSelected('coneSearch', {
baseURL: self.selectedItem.cs_service_url,
Expand All @@ -263,7 +266,7 @@ import { CtxMenuActionButtonOpener } from "../Button/CtxMenuOpener.js";
anchor: 'center center',
}
})
box._show();
self.box._show();
self.loadBtn.hideMenu()

}
Expand Down Expand Up @@ -291,20 +294,14 @@ import { CtxMenuActionButtonOpener } from "../Button/CtxMenuOpener.js";
}

_hide() {
if (this.box) {
this.box.remove();
}

if (this.loadBtn) {
this.loadBtn.hideMenu()
}

super._hide()
}

static layerSelector = undefined;

static getInstance(aladin) {
if (!CatalogQueryBox.layerSelector) {
CatalogQueryBox.layerSelector = new CatalogQueryBox(aladin);
}

return CatalogQueryBox.layerSelector;
}
}
10 changes: 0 additions & 10 deletions src/js/gui/Box/ConeSearchBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,5 @@ import { Angle } from "../../libs/astro/angle.js";
attach(options) {
this.callback = options.callback;
super.update(options)
}

static box = undefined;

static getInstance(aladin) {
if (!ConeSearchBox.box) {
ConeSearchBox.box = new ConeSearchBox(aladin);
}

return ConeSearchBox.box;
}
}
10 changes: 0 additions & 10 deletions src/js/gui/Box/GotoBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,4 @@ export class GotoBox extends Box {

super._hide()
}

static singleton;

static getInstance(aladin) {
if (!GotoBox.singleton) {
GotoBox.singleton = new GotoBox(aladin);
}

return GotoBox.singleton;
}
}
10 changes: 0 additions & 10 deletions src/js/gui/Box/GridBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,4 @@ export class GridBox extends Box {
let ctxMenu = ContextMenu.getInstance(this.aladin);
ctxMenu._hide();
}

static singleton;

static getInstance(aladin) {
if (!GridBox.singleton) {
GridBox.singleton = new GridBox(aladin);
}

return GridBox.singleton;
}
}
10 changes: 0 additions & 10 deletions src/js/gui/Box/HiPSSelectorBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,4 @@ import { Input } from "../Widgets/Input.js";
attach(callback) {
this.callback = callback;
}

static box = undefined;

static getInstance(aladin) {
if (!HiPSSelectorBox.box) {
HiPSSelectorBox.box = new HiPSSelectorBox(aladin);
}

return HiPSSelectorBox.box;
}
}
11 changes: 0 additions & 11 deletions src/js/gui/Box/ServiceQueryBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,4 @@ export class ServiceQueryBox extends Box {
subInputs,
})
}

static singleton;

static getInstance(aladin) {
if (!ServiceQueryBox.singleton) {
ServiceQueryBox.singleton = new ServiceQueryBox(aladin);
}

return ServiceQueryBox.singleton;
}

}
10 changes: 0 additions & 10 deletions src/js/gui/Box/ShortLivedBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,4 @@ export class ShortLivedBox extends Box {

super._show(options);
}

static singleton;

static getInstance(aladin) {
if (!ShortLivedBox.singleton) {
ShortLivedBox.singleton = new ShortLivedBox(aladin);
}

return ShortLivedBox.singleton;
}
}
Loading

0 comments on commit 8d248e8

Please sign in to comment.