Skip to content

Commit

Permalink
Merge pull request #966 from YukaUU/yukaUU_GSoC_db_Mark_add_centerPos…
Browse files Browse the repository at this point in the history
…ition_and_Zoom

Saving Marks Should Include User's X, Y, Zoom, etc #844 #902
  • Loading branch information
birm authored Jun 11, 2024
2 parents 79c9820 + 25f96ca commit 61bbc91
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
21 changes: 15 additions & 6 deletions apps/viewer/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ function initCore() {
}
// for support QUIP 2.0
const data = Array.isArray(e.data) ? e.data[e.data.selected] : e.data;

const type = data.provenance.analysis.source;

let body;
let attributes;
let warning = null;
Expand Down Expand Up @@ -258,11 +258,20 @@ function initCore() {
if (area) attributes.area = area;
if (circumference) attributes.circumference = circumference;

const states = StatesHelper.getCurrentStates(isImageCoordinate = true);
if (!states) return;
attributes.X = states.x;
attributes.Y = states.y;
attributes.zoom = states.z;

// add center position and zoom
if (data.states != undefined) {
// Rounds a number to the specified number of decimal places.
function roundTo(num, decimalPlaces) {
const factor = 10 ** decimalPlaces;
return Math.round(num * factor) / factor;
}
const decimalPlaces = 3;
attributes.X = data.states.x,
attributes.Y = data.states.y,
attributes.zoom = roundTo(data.states.zoom, decimalPlaces);
}


body = convertHumanAnnotationToPopupBody(attributes);
if (
Expand Down
11 changes: 10 additions & 1 deletion apps/viewer/uicallbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,9 @@ function annoCallback(data) {
}
noteData.notes = resultString;

// get center position and zoom
let states = StatesHelper.getCurrentStates(true);

// save
// provenance
Loading.open($UI.annotOptPanel.elt, 'Saving Annotation...');
Expand All @@ -916,13 +919,18 @@ function annoCallback(data) {
$CAMIC.viewer,
$CAMIC.viewer.canvasDrawInstance.getImageFeatureCollection(),
),
states: {
x: states.x,
y: states.y,
zoom: states.z,
},
};

// save annotation
$CAMIC.store
.addMark(annotJson)
.then((data) => {
// server error
// server error
if (data.error) {
$UI.message.addError(`${data.text}:${data.url}`);
Loading.close();
Expand Down Expand Up @@ -1474,6 +1482,7 @@ function loadAnnotationById(camic, layerData, parentType, callback) {
}

if (callback) callback.call(layerData);
return data;
})
.catch((e) => {
console.error(e);
Expand Down
8 changes: 7 additions & 1 deletion common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,13 @@ class Tracker {
z: image_zoom,
time: new Date(),
});
}

return {
x: Math.round(x),
y: Math.round(y),
z: image_zoom,
};
};
}


Expand Down

0 comments on commit 61bbc91

Please sign in to comment.