Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving Marks Should Include User's X, Y, Zoom, etc #844 #902 #966

Merged
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
Loading