mirror of
https://github.com/cds-astro/aladin-lite.git
synced 2025-12-25 12:25:52 -08:00
Compare commits
3 Commits
hips3d
...
fix-26-col
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8187747082 | ||
|
|
950d0c693e | ||
|
|
895aa169b4 |
@@ -71,7 +71,7 @@ impl Texture3D {
|
||||
self.gl.generate_mipmap(WebGlRenderingCtx::TEXTURE_3D);
|
||||
}
|
||||
|
||||
pub fn bind(&self) -> Texture3DBound {
|
||||
pub fn bind(&self) -> Texture3DBound<'_> {
|
||||
self.gl
|
||||
.bind_texture(WebGlRenderingCtx::TEXTURE_3D, self.texture.as_ref());
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ impl Texture2DArray {
|
||||
self.gl.generate_mipmap(WebGlRenderingCtx::TEXTURE_2D_ARRAY);
|
||||
}
|
||||
|
||||
pub fn bind(&self) -> Texture2DArrayBound {
|
||||
pub fn bind(&self) -> Texture2DArrayBound<'_> {
|
||||
self.gl
|
||||
.bind_texture(WebGlRenderingCtx::TEXTURE_2D_ARRAY, self.texture.as_ref());
|
||||
|
||||
|
||||
@@ -295,7 +295,7 @@ impl Texture2D {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn bind(&self) -> Texture2DBound {
|
||||
pub fn bind(&self) -> Texture2DBound<'_> {
|
||||
self.gl
|
||||
.bind_texture(WebGlRenderingCtx::TEXTURE_2D, self.texture.as_ref());
|
||||
|
||||
|
||||
@@ -133,7 +133,6 @@ impl App {
|
||||
//let exec = Rc::new(RefCell::new(TaskExecutor::new()));
|
||||
|
||||
let projection = ProjectionType::Sin(mapproj::zenithal::sin::Sin);
|
||||
gl.enable(WebGl2RenderingContext::BLEND);
|
||||
|
||||
// TODO: https://caniuse.com/?search=scissor is not supported for safari <= 14.1
|
||||
// When it will be supported nearly everywhere, we will need to uncomment this line to
|
||||
@@ -829,6 +828,7 @@ impl App {
|
||||
// Render the scene
|
||||
// Clear all the screen first (only the region set by the scissor)
|
||||
gl.clear(WebGl2RenderingContext::COLOR_BUFFER_BIT);
|
||||
|
||||
// set the blending options
|
||||
layers.draw(camera, shaders, colormaps, projection)?;
|
||||
|
||||
|
||||
@@ -213,9 +213,13 @@ impl Layers {
|
||||
let raytracer = &self.raytracer;
|
||||
let raytracing = camera.is_raytracing(projection);
|
||||
|
||||
// The first layer or the background must be plot with no blending
|
||||
self.gl.disable(WebGl2RenderingContext::BLEND);
|
||||
|
||||
// Check whether a hips to plot is allsky
|
||||
// if neither are, we draw a font
|
||||
// if there are, we do not draw nothing
|
||||
|
||||
let mut idx_start_layer = -1;
|
||||
|
||||
for (idx, layer) in self.layers.iter().enumerate() {
|
||||
@@ -235,6 +239,8 @@ impl Layers {
|
||||
}
|
||||
}
|
||||
|
||||
let mut blending_enabled = false;
|
||||
|
||||
// Need to render transparency font
|
||||
if idx_start_layer == -1 {
|
||||
let vao = if raytracing {
|
||||
@@ -258,6 +264,9 @@ impl Layers {
|
||||
|
||||
// The background (index -1) has been drawn, we can draw the first HiPS
|
||||
idx_start_layer = 0;
|
||||
|
||||
self.gl.enable(WebGl2RenderingContext::BLEND);
|
||||
blending_enabled = true;
|
||||
}
|
||||
|
||||
let layers_to_render = &self.layers[(idx_start_layer as usize)..];
|
||||
@@ -283,6 +292,11 @@ impl Layers {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !blending_enabled {
|
||||
self.gl.enable(WebGl2RenderingContext::BLEND);
|
||||
blending_enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -3126,7 +3126,7 @@ aladin.displayFITS(
|
||||
);
|
||||
}
|
||||
if (executeDefaultSuccessAction === true) {
|
||||
self.wasm.setCenter(meta.ra, meta.dec);
|
||||
self.gotoRaDec(meta.ra, meta.dec);
|
||||
self.setFoV(meta.fov);
|
||||
}
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ export let View = (function () {
|
||||
this.fov = this.options.fov || 180.0
|
||||
|
||||
// Target position settings
|
||||
this.viewCenter = { lon, lat }; // position of center of view
|
||||
this.viewCenter = { ra: lon, dec: lat }; // position of center of view always in ICRS
|
||||
|
||||
// Coo frame setting
|
||||
const cooFrame = CooFrameEnum.fromString(this.options.cooFrame, CooFrameEnum.ICRS);
|
||||
@@ -2022,9 +2022,17 @@ export let View = (function () {
|
||||
};
|
||||
|
||||
View.prototype.updateCenter = function() {
|
||||
const [ra, dec] = this.wasm.getCenter();
|
||||
this.viewCenter.lon = ra;
|
||||
this.viewCenter.lat = dec;
|
||||
// Center position in the frame of the view
|
||||
const [lon, lat] = this.wasm.getCenter();
|
||||
|
||||
// ICRS conversion
|
||||
let [ra, dec] = this.wasm.viewToICRSCooSys(lon, lat);
|
||||
|
||||
if (ra < 0) {
|
||||
ra = ra + 360.0
|
||||
}
|
||||
|
||||
this.viewCenter = {ra, dec};
|
||||
}
|
||||
|
||||
View.prototype.showHealpixGrid = function (show) {
|
||||
@@ -2069,11 +2077,10 @@ export let View = (function () {
|
||||
return;
|
||||
}
|
||||
|
||||
this.viewCenter.lon = ra;
|
||||
this.viewCenter.lat = dec;
|
||||
this.viewCenter = {ra, dec};
|
||||
|
||||
// Put a javascript code here to do some animation
|
||||
this.wasm.setCenter(this.viewCenter.lon, this.viewCenter.lat);
|
||||
this.wasm.setCenter(this.viewCenter.ra, this.viewCenter.dec);
|
||||
|
||||
ALEvent.POSITION_CHANGED.dispatchedTo(this.aladin.aladinDiv, this.viewCenter);
|
||||
|
||||
@@ -2224,12 +2231,11 @@ export let View = (function () {
|
||||
if (!footprint.source || !footprint.source.tooSmallFootprint) {
|
||||
const originLineWidth = footprint.getLineWidth();
|
||||
let spreadedLineWidth = (originLineWidth || 1) + 3;
|
||||
|
||||
|
||||
footprint.setLineWidth(spreadedLineWidth);
|
||||
if (footprint.isShowing && footprint.isInStroke(ctx, this, x * window.devicePixelRatio, y * window.devicePixelRatio)) {
|
||||
closests.push(footprint);
|
||||
}
|
||||
|
||||
footprint.setLineWidth(originLineWidth);
|
||||
}
|
||||
})
|
||||
|
||||
@@ -47,6 +47,7 @@ export class ALEvent {
|
||||
|
||||
static UPDATE_CMAP_LIST = new ALEvent("AL:cmap.updated");
|
||||
|
||||
// Gives the center position in ICRS
|
||||
static POSITION_CHANGED = new ALEvent("AL:position.changed");
|
||||
static ZOOM_CHANGED = new ALEvent("AL:zoom.changed");
|
||||
|
||||
|
||||
@@ -41,6 +41,16 @@ import { ActionButton } from "./Widgets/ActionButton.js";
|
||||
import { Input } from "./Widgets/Input.js";
|
||||
import { Utils } from "../Utils.ts";
|
||||
|
||||
function radec2Lonlat(radec, frame) {
|
||||
// convert to the view frame
|
||||
let lonlat = radec;
|
||||
if (frame === "GAL") {
|
||||
lonlat = CooConversion.ICRSToGalactic(radec)
|
||||
}
|
||||
|
||||
return lonlat
|
||||
}
|
||||
|
||||
export class Location extends DOMElement {
|
||||
// constructor
|
||||
constructor(aladin) {
|
||||
@@ -141,20 +151,15 @@ export class Location extends DOMElement {
|
||||
ALEvent.CANVAS_EVENT.listenedBy(aladin.aladinDiv, function (e) {
|
||||
let param = e.detail;
|
||||
|
||||
if (param.type === 'mouseout') {
|
||||
let radec = aladin.getRaDec();
|
||||
// convert to the view frame
|
||||
let lonlat = radec;
|
||||
if (aladin.getFrame() === "GAL") {
|
||||
lonlat = CooConversion.ICRSToGalactic(radec)
|
||||
}
|
||||
let frame = aladin.getFrame();
|
||||
|
||||
if (param.type === 'mouseout') {
|
||||
let [ra, dec] = aladin.getRaDec();
|
||||
|
||||
let [lon, lat] = lonlat;
|
||||
//self.field.el.blur()
|
||||
self.update({
|
||||
lon, lat,
|
||||
frame: aladin.view.cooFrame,
|
||||
isViewCenter: true,
|
||||
ra, dec,
|
||||
frame,
|
||||
center: true,
|
||||
}, aladin);
|
||||
}
|
||||
|
||||
@@ -170,39 +175,46 @@ export class Location extends DOMElement {
|
||||
self.update({
|
||||
mouseX: param.xy.x,
|
||||
mouseY: param.xy.y,
|
||||
frame: aladin.view.cooFrame,
|
||||
isViewCenter: false,
|
||||
frame,
|
||||
center: false,
|
||||
}, aladin);
|
||||
}
|
||||
});
|
||||
|
||||
ALEvent.POSITION_CHANGED.listenedBy(aladin.aladinDiv, function (e) {
|
||||
// center position in ICRS
|
||||
let {ra, dec} = e.detail;
|
||||
let frame = aladin.getFrame();
|
||||
|
||||
self.update({
|
||||
lon: e.detail.lon,
|
||||
lat: e.detail.lat,
|
||||
isViewCenter: true,
|
||||
frame: aladin.view.cooFrame
|
||||
ra,
|
||||
dec,
|
||||
center: true,
|
||||
frame
|
||||
}, aladin);
|
||||
});
|
||||
|
||||
ALEvent.FRAME_CHANGED.listenedBy(aladin.aladinDiv, function (e) {
|
||||
let [lon, lat] = aladin.getRaDec();
|
||||
let [ra, dec] = aladin.getRaDec();
|
||||
let frame = aladin.getFrame();
|
||||
|
||||
self.update({
|
||||
lon, lat,
|
||||
isViewCenter: true,
|
||||
frame: e.detail.cooFrame
|
||||
ra, dec,
|
||||
center: true,
|
||||
frame
|
||||
}, aladin);
|
||||
});
|
||||
|
||||
this.aladin = aladin;
|
||||
|
||||
let [lon, lat] = aladin.getRaDec();
|
||||
let [ra, dec] = aladin.getRaDec();
|
||||
let frame = aladin.getFrame();
|
||||
|
||||
this.update({
|
||||
lon, lat,
|
||||
isViewCenter: true,
|
||||
frame: aladin.view.cooFrame
|
||||
ra,
|
||||
dec,
|
||||
frame,
|
||||
center: true
|
||||
}, aladin)
|
||||
};
|
||||
|
||||
@@ -210,6 +222,7 @@ export class Location extends DOMElement {
|
||||
|
||||
update(options, aladin) {
|
||||
let self = this;
|
||||
// lon and lat must be given in cooFrame
|
||||
const updateFromLonLatFunc = (lon, lat, cooFrame) => {
|
||||
var coo = new Coo(lon, lat, Location.prec);
|
||||
if (cooFrame == CooFrameEnum.ICRS) {
|
||||
@@ -224,21 +237,21 @@ export class Location extends DOMElement {
|
||||
self.field.removeClass('aladin-not-valid');
|
||||
self.field.removeClass('aladin-valid');
|
||||
|
||||
self.field.element().style.color = options.isViewCenter ? 'var(--aladin-color)' : 'white';
|
||||
//self.field.el.blur()
|
||||
self.field.element().style.color = options.center ? 'var(--aladin-color)' : 'white';
|
||||
};
|
||||
|
||||
if (options.lon && options.lat) {
|
||||
updateFromLonLatFunc(options.lon, options.lat, options.frame, true);
|
||||
if (options.ra && options.dec) {
|
||||
let [lon, lat] = radec2Lonlat([options.ra, options.dec], options.frame)
|
||||
updateFromLonLatFunc(lon, lat, options.frame);
|
||||
} else if (options.mouseX && options.mouseY) {
|
||||
try {
|
||||
let radec = aladin.pix2world(options.mouseX, options.mouseY); // This is given in the frame of the view
|
||||
if (radec) {
|
||||
if (radec[0] < 0) {
|
||||
radec = [radec[0] + 360.0, radec[1]];
|
||||
let lonlat = aladin.pix2world(options.mouseX, options.mouseY); // This is given in the frame of the view
|
||||
if (lonlat) {
|
||||
if (lonlat[0] < 0) {
|
||||
lonlat = [lonlat[0] + 360.0, lonlat[1]];
|
||||
}
|
||||
|
||||
updateFromLonLatFunc(radec[0], radec[1], options.frame, false);
|
||||
updateFromLonLatFunc(lonlat[0], lonlat[1], options.frame);
|
||||
}
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
@@ -317,7 +317,9 @@ export let Circle = (function() {
|
||||
};
|
||||
|
||||
Circle.prototype.isInStroke = function(ctx, view, x, y) {
|
||||
this.draw(ctx, view, true);
|
||||
if (!this.draw(ctx, view, true)) {
|
||||
return false;
|
||||
}
|
||||
return ctx.isPointInStroke(x, y);
|
||||
};
|
||||
|
||||
|
||||
@@ -337,7 +337,7 @@ export let Ellipse = (function() {
|
||||
};
|
||||
|
||||
Ellipse.prototype.isInStroke = function(ctx, view, x, y) {
|
||||
if (!this.draw(ctx, view, true, true)) {
|
||||
if (!this.draw(ctx, view, true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -232,6 +232,7 @@ export let Polyline = (function() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
noSmallCheck = noSmallCheck===true || false;
|
||||
noStroke = noStroke===true || false;
|
||||
|
||||
@@ -269,20 +270,29 @@ export let Polyline = (function() {
|
||||
let ymin = Number.POSITIVE_INFINITY
|
||||
let ymax = Number.NEGATIVE_INFINITY;
|
||||
|
||||
|
||||
|
||||
let behind = true;
|
||||
for (var k=0; k<len; k++) {
|
||||
var xyview = view.aladin.world2pix(this.raDecArray[k][0], this.raDecArray[k][1]);
|
||||
|
||||
if (!xyview) {
|
||||
return false;
|
||||
xyView.push(undefined);
|
||||
} else {
|
||||
behind = false;
|
||||
let [x, y] = xyview
|
||||
xyView.push({x, y});
|
||||
|
||||
xmin = Math.min(xmin, x);
|
||||
ymin = Math.min(ymin, y);
|
||||
xmax = Math.max(xmax, x);
|
||||
ymax = Math.max(ymax, y);
|
||||
}
|
||||
|
||||
xyView.push({x: xyview[0], y: xyview[1]});
|
||||
|
||||
xmin = Math.min(xmin, xyview[0]);
|
||||
ymin = Math.min(ymin, xyview[1]);
|
||||
xmax = Math.max(xmax, xyview[0]);
|
||||
ymax = Math.max(ymax, xyview[1]);
|
||||
}
|
||||
|
||||
if (behind)
|
||||
return false;
|
||||
|
||||
// 2. do not draw the polygon if it lies outside the view
|
||||
if (xmax < 0 || xmin > view.width || ymax < 0 || ymin > view.height) {
|
||||
return false;
|
||||
@@ -290,7 +300,7 @@ export let Polyline = (function() {
|
||||
|
||||
// do not draw neither if the polygone does not lie inside lineWidth
|
||||
if (!noSmallCheck) {
|
||||
this.isTooSmall = (xmax - xmin) < this.lineWidth || (ymax - ymin) < this.lineWidth;
|
||||
this.isTooSmall = (xmax - xmin) < this.lineWidth && (ymax - ymin) < this.lineWidth;
|
||||
|
||||
if (this.isTooSmall) {
|
||||
return false;
|
||||
@@ -302,6 +312,10 @@ export let Polyline = (function() {
|
||||
|
||||
if (view.projection === ProjectionEnum.SIN) {
|
||||
drawLine = (v0, v1) => {
|
||||
if (v0 === undefined || v1 === undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const l = {x1: v0.x, y1: v0.y, x2: v1.x, y2: v1.y};
|
||||
|
||||
if (Polyline.isInsideView(l.x1, l.y1, l.x2, l.y2, view.width, view.height)) {
|
||||
@@ -311,6 +325,9 @@ export let Polyline = (function() {
|
||||
|
||||
if (this.closed && this.fill) {
|
||||
fillPoly = (v0, v1, index) => {
|
||||
if (v0 === undefined || v1 === undefined)
|
||||
return false;
|
||||
|
||||
const l = {x1: v0.x, y1: v0.y, x2: v1.x, y2: v1.y};
|
||||
|
||||
if (index === 0) {
|
||||
@@ -391,7 +408,6 @@ export let Polyline = (function() {
|
||||
v1 = v1 + 1;
|
||||
}
|
||||
|
||||
//ctx.globalAlpha = 1;
|
||||
ctx.save();
|
||||
ctx.fillStyle = this.fillColor;
|
||||
ctx.globalAlpha = this.opacity;
|
||||
@@ -409,30 +425,41 @@ export let Polyline = (function() {
|
||||
for (var j = 0; j < this.raDecArray.length; j++) {
|
||||
var xy = view.aladin.world2pix(this.raDecArray[j][0], this.raDecArray[j][1]);
|
||||
if (!xy) {
|
||||
return false;
|
||||
pointXY.push(undefined)
|
||||
} else {
|
||||
pointXY.push({
|
||||
x: xy[0],
|
||||
y: xy[1]
|
||||
});
|
||||
}
|
||||
pointXY.push({
|
||||
x: xy[0],
|
||||
y: xy[1]
|
||||
});
|
||||
}
|
||||
|
||||
const lastPointIdx = pointXY.length - 1;
|
||||
for (var l = 0; l < lastPointIdx; l++) {
|
||||
const line = {x1: pointXY[l].x, y1: pointXY[l].y, x2: pointXY[l + 1].x, y2: pointXY[l + 1].y}; // new segment
|
||||
_drawLine(line, ctx, true);
|
||||
let v1 = pointXY[l];
|
||||
let v2 = pointXY[l + 1];
|
||||
|
||||
if (ctx.isPointInStroke(x, y)) { // x,y is on line?
|
||||
return true;
|
||||
if (v1 && v2) {
|
||||
const line = {x1: v1.x, y1: v1.y, x2: v2.x, y2: v2.y}; // new segment
|
||||
_drawLine(line, ctx, true);
|
||||
|
||||
if (ctx.isPointInStroke(x, y)) { // x, y is on line?
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this.closed) {
|
||||
const line = {x1: pointXY[lastPointIdx].x, y1: pointXY[lastPointIdx].y, x2: pointXY[0].x, y2: pointXY[0].y}; // new segment
|
||||
_drawLine(line, ctx, true);
|
||||
let v1 = pointXY[lastPointIdx];
|
||||
let v2 = pointXY[0];
|
||||
|
||||
if (ctx.isPointInStroke(x, y)) { // x,y is on line?
|
||||
return true;
|
||||
if (v1 && v2) {
|
||||
const line = {x1: v1.x, y1: v1.y, x2: v2.x, y2: v2.y}; // new segment
|
||||
_drawLine(line, ctx, true);
|
||||
|
||||
if (ctx.isPointInStroke(x, y)) { // x,y is on line?
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user