diff --git a/apps/viewer/init.js b/apps/viewer/init.js index 94f89c2b0..4eec2604d 100644 --- a/apps/viewer/init.js +++ b/apps/viewer/init.js @@ -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; @@ -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 ( diff --git a/apps/viewer/uicallbacks.js b/apps/viewer/uicallbacks.js index 69a7b5e8f..e971fda34 100644 --- a/apps/viewer/uicallbacks.js +++ b/apps/viewer/uicallbacks.js @@ -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...'); @@ -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(); @@ -1474,6 +1482,7 @@ function loadAnnotationById(camic, layerData, parentType, callback) { } if (callback) callback.call(layerData); + return data; }) .catch((e) => { console.error(e); diff --git a/common/util.js b/common/util.js index 9e367ae26..fd50cadab 100644 --- a/common/util.js +++ b/common/util.js @@ -1092,7 +1092,13 @@ class Tracker { z: image_zoom, time: new Date(), }); - } + + return { + x: Math.round(x), + y: Math.round(y), + z: image_zoom, + }; + }; }