Files
aladin-lite/src/js/FiniteStateMachine/RectSelect.js
bmatthieu3 4bc8c81ad4 feat: color picker and read pixel
This PR targets: #253, #76 and to some extent, maybe #208

It features:
* api: readPixel on a HiPS object method taking x, y pixel values on the
  screen. When no screen coo are given, the one of the center screen is
used.
* api: HiPS.probe a general method using HiPS.readPixel under the hood.
  It allow to probe the survey pixel values on a pixel, along a screen line and
along a great circle arc on the sky
* fix: readPixel could throw an exception if the tile has not been
  received. If so, now, we return a JS null value
* fix: retrieve pixels on fits HiPS bitpix=-32
* feat: a new aladin mode called TOOL_COLOR_PICKER.
* tool: showColorPickerControl: when clicking on it, enter the
  TOOL_COLOR_PICKER mode. The user can move the mouse on a pixel to know
its value. With a click, the pixel value is copied to its clipboard
* fix: restore samp button to connect to a hub
* fix: call redraw when calling gotoRaDec to update instantly the
  imageCanvas #208
* a new global readCanvas method on the Aladin object that
will simply read the final image Canvas. User can give a pixel coo, a
line (2 pixel coos), a rect (2 pixel coos for the box)
2025-05-07 16:29:55 +02:00

179 lines
5.1 KiB
JavaScript

// Copyright 2015 - UDS/CNRS
// The Aladin Lite program is distributed under the terms
// of the GNU General Public License version 3.
//
// This file is part of Aladin Lite.
//
// Aladin Lite is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Aladin Lite is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// The GNU General Public License is available in COPYING file
// along with Aladin Lite.
//
import { FSM } from "../FiniteStateMachine";
import { View } from "../View";
import { Selector } from "../Selector";
/******************************************************************************
* Aladin Lite project
*
* Class Selector
*
* A selector
*
* Author: Matthieu Baumann[CDS]
*
*****************************************************************************/
export class RectSelect extends FSM {
// constructor
constructor(options, view) {
let start = (params) => {
const {callback} = params;
this.callback = callback;
}
let mousedown = (params) => {
const {coo} = params;
// start a new selection
this.startCoo = coo;
}
let mousemove = (params) => {
const {coo} = params;
this.coo = coo;
view.requestRedraw();
};
let draw = () => {
let ctx = view.catalogCtx;
// draw the selection
let colorValue = (typeof options.color === 'function') ? options.color(this.startCoo, this.coo) : options.color;
ctx.fillStyle = colorValue + '7f';
ctx.strokeStyle = colorValue;
ctx.lineWidth = options.lineWidth;
var w = this.coo.x - this.startCoo.x;
var h = this.coo.y - this.startCoo.y;
ctx.fillRect(this.startCoo.x, this.startCoo.y, w, h);
ctx.strokeRect(this.startCoo.x, this.startCoo.y, w, h);
}
let mouseup = (params) => {
var x, y;
const {coo} = params;
this.coo = coo;
// finish the selection
var w = this.coo.x - this.startCoo.x;
var h = this.coo.y - this.startCoo.y;
x = this.startCoo.x;
y = this.startCoo.y;
if (w < 0) {
x = x + w;
w = -w;
}
if (h < 0) {
y = y + h;
h = -h;
}
let s = {
x, y, w, h,
label: 'rect',
contains(s) {
return s.x >= x && s.x <= x + w && s.y >= y && s.y <= y + h;
},
bbox() {
return {x, y, w, h}
}
};
(typeof this.callback === 'function') && this.callback(s, Selector.getObjects(s, view));
// TODO: remove these modes in the future
view.aladin.showReticle(true)
view.setCursor('default');
// execute general callback
if (view.aladin.callbacksByEventName) {
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);
}
}
this.dispatch('off');
};
let off = () => {
view.aladin.showReticle(true)
view.setMode(View.PAN)
view.setCursor('default');
// in case of a mouseout we would like to erase the selection draw
// in the canvas
view.requestRedraw();
view.aladin.removeStatusBarMessage('selector')
}
let mouseout = (params) => {
if (this.startCoo) {
mouseup(params);
}
};
super({
state: 'off',
transitions: {
off: {
start,
},
start: {
mousedown,
mouseup,
mouseout,
off
},
mousedown: {
mousemove,
off
},
mousemove: {
draw,
mouseup,
mouseout,
off
},
draw: {
mousemove,
mouseup,
mouseout,
off
},
mouseout: {
off,
mousedown
},
mouseup: {
off,
}
}
})
};
}