Commit 799c2c52 authored by Moreau Nicolas's avatar Moreau Nicolas
Browse files

Fixes coordinates error when markers are modified in the jexcel table.

Lines can be added manually, this parts still requires testing
parent a8f591d7
......@@ -342,8 +342,8 @@ class MarkersFactory extends ShapesFactory {
this.columns = [
{ title: 'id', type: 'numeric', width: '50px', name: 'id', readOnly: true },
{ title: 'label', type: 'text', width: '100px', name: 'label', readOnly: false },
{ title: 'RA', type: 'text', width: '150px', name: 'RA', readOnly: true },
{ title: 'DEC', type: 'text', width: '150px', name: 'DEC', readOnly: true },
{ title: 'RA', type: 'text', width: '150px', name: 'RA', readOnly: false },
{ title: 'DEC', type: 'text', width: '150px', name: 'DEC', readOnly: false },
{ title: 'iRA', type: 'text', width: '150px', name: 'iRA', readOnly: true },
{ title: 'iDEC', type: 'text', width: '150px', name: 'iDEC', readOnly: true },
{ title: this.pixelValueColumnName, type: 'numeric', width: '150px', name: this.pixelValueColumnName, readOnly: true }
......@@ -575,6 +575,7 @@ class MarkersFactory extends ShapesFactory {
* @param {boolean} insertBefore how the insertion is performed.
*/
setId(sheet, rowNumber, numOfRows, rowRecords, insertBefore) {
console.log("### setID");
MarkersFactory.enter(this.setId.name);
var i = insertBefore ? rowNumber : rowNumber + 1;
this.data = this.getDataAsJSON();
......@@ -677,13 +678,10 @@ class MarkersFactory extends ShapesFactory {
let self = this;
var p = new Promise((resolve, reject)=>{
const { RA, DEC } = this.validateRow(row);
console.log(RA);
console.log(DEC);
const iRaiDec = this.projection.raDecToiRaiDec(RA.decdegree, DEC.decdegree);
//const iRaiDec = this.projection.raDecToiRaiDec(5.274091711490477, 0.7119264195952342);
console.log("### changed" );
console.log(iRaiDec);
// if RA/DEC values have been modified
row.iRA = iRaiDec.iRa;
row.iDEC = iRaiDec.iDec;
if (RA && DEC) {
if (inRange(iRaiDec.iRa, 0, iRAMax) && inRange(iRaiDec.iDec, 0, iDECMax)) {
var q = self.getPixelValuePromise(iRaiDec.iRa, iRaiDec.iDec, self.viewer.getRelFITSFilePath());
......@@ -720,6 +718,8 @@ class MarkersFactory extends ShapesFactory {
).finally(() => {
this.data[y] = row;
this.jexcel.setData(this.data);
console.log("### changed");
console.log(this.data);
this.jexcel2OL();
});
MarkersFactory.exit();
......@@ -766,18 +766,21 @@ class MarkersFactory extends ShapesFactory {
var validRows = this.getDataAsJSON().filter(x => x.id != -1);
let self = this;
validRows.forEach(row => {
console.log("jExcel2OL");
console.log(row);
var RAinDD = self.checkRA(row.RA).decdegree;
var DECinDD = self.checkDEC(row.DEC).decdegree;
if (RAinDD && DECinDD) {
let iRaiDec = self.projection.absToRel(degToRad(RAinDD), degToRad(DECinDD));
//let iRaiDec = self.projection.absToRel(degToRad(RAinDD), degToRad(DECinDD));
/* var x = Math.round(this.raDDtoPixelConverter.convert(RAinDD));
var y = Math.round(this.decDDtoPixelConverter.convert(DECinDD)); */
var label = row.label;
var f = new ol.Feature({ geometry: new ol.geom.Point([iRaiDec['x'], iRaiDec['y']]) });
var f = new ol.Feature({ geometry: new ol.geom.Point([row.iRA, row.iDEC]) });
f.set("label", label);
f.setStyle(this.style_f(f));
self.numOfMarkers += 1;
self.source.addFeature(f);
console.log(f);
self.indexToMarker[row.id] = f;
}
});
......@@ -798,7 +801,7 @@ class MarkersFactory extends ShapesFactory {
MarkersFactory.enter(this.createJexcel.name);
var result = jexcel(document.getElementById(parentId), {
columns: this.columns,
allowInsertRow: false,
allowInsertRow: true,
onload: this.loaded.bind(this),
onselection: this.noteSelectedRows.bind(this),
ondeleterow: this.deleteSelectedMarkers.bind(this),
......
......@@ -128,12 +128,12 @@ class Projection {
* @returns {Object} Object containing iRa, iDec coordinates
*/
raDecToiRaiDec(ra, dec) {
const iRaiDec = this.absToRel([ra], [dec]);
// absToRel expects radians
const iRaiDec = this.absToRel([degToRad(ra)], [degToRad(dec)]);
const x = iRaiDec['x'];
const y = iRaiDec['y'];
const i_xp=Math.round(FITS_HEADER.crpix1+x/(FITS_HEADER.cdelt1)-1);
const i_yp=Math.round(FITS_HEADER.crpix2+y/(FITS_HEADER.cdelt2)-1);
const i_xp=Math.round(FITS_HEADER.crpix1+x/(degToRad(FITS_HEADER.cdelt1))-1);
const i_yp=Math.round(FITS_HEADER.crpix2+y/(degToRad(FITS_HEADER.cdelt2))-1);
// pixels to coordinates in radians
return { 'iRa': i_xp, 'iDec': i_yp };
}
......@@ -426,6 +426,11 @@ class GnomonicProjection extends Projection {
const n = a.length;
let x = new Array(n)
let y = new Array(n);
//console.log("### absToRel");
//console.log("a0 : " + this._a0);
//console.log("sind0 : " + this._sind0);
//console.log("cosd0 : " + this._cosd0);
//console.log("angle : " + this._angle);
if (Math.abs(this._sind0) >= Projection.precision) {
for (let i = 0; i < n; i++) {
const sindec = Math.sin(d[i]);
......@@ -434,6 +439,8 @@ class GnomonicProjection extends Projection {
const cosa = Math.cos(a[i] - this._a0);
const product = sindec * this._cosd0 - cosdec * this._sind0 * cosa;
const r = Math.acos((sindec - this._cosd0 * product) / this._sind0);
//console.log("product : " + product);
//console.log("r : " + r);
if (r > Projection.precision) {
const p = Math.atan2(cosdec * sina, product) + this._angle;
const expr = Math.tan(r);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment