Skip to content

Commit

Permalink
Merge pull request #8 from informatics-isi-edu/multiple-annotations
Browse files Browse the repository at this point in the history
Multiple annotations
  • Loading branch information
svoinea authored Jan 14, 2020
2 parents d8f76fe + 8d49399 commit d68807e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
4 changes: 4 additions & 0 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ var myApp = (function (_config) {
// toolbar && toolbar.changeSelectingAnnotation(data);
window.parent.postMessage({messageType: type, content: data}, window.location.origin);
break;
case "errorAnnotation":
// toolbar && toolbar.changeSelectingAnnotation(data);
window.parent.postMessage({messageType: type, content: data}, window.location.origin);
break;
}
}

Expand Down
32 changes: 25 additions & 7 deletions js/viewer/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,26 @@ function Viewer(parent, config) {
this.parameters = this._utils.getParameters();

// Get config from scalebar and Openseadragon
console.log(this.parameters.info);
this._config.osd.tileSources = this.parameters.info;

this.osd = OpenSeadragon(this._config.osd);


this.osd.scalebar(this._config.scalebar);

// Add a SVG container to contain svg objects
this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
this.svg.setAttribute("id", this._config.svg.id);
this.osd.canvas.append(this.svg);

// Parse urls to load image and channels
// this.loadImages(this.parameters.images);
/* Parse urls to load image and channels, This is done when so that czi format is also supported, if the parameters are not present,
it assumes that the format of the files is in czi. The below mentioned function uses the old version of code to load the images in OpenSeadragon.
// NOTE: This also assuumes there won't be a svg for czi format(for overalpping).
*/
console.log("Parameters info", this.parameters.info);
if (this.parameters.info === undefined) {
this.loadImages(this.parameters.images);
}
this.osd.addHandler('open', this.loadAfterOSDInit);

// Since 'open' event is no longer called properly, load initial position in 'animation-finish' event
Expand Down Expand Up @@ -268,11 +276,14 @@ function Viewer(parent, config) {

// Load and import the unstructured SVG file into Openseadragon viewer
this.importAnnotationUnformattedSVG = function (svgs) {

var ignoreReferencePoint = this.parameters.ignoreReferencePoint,
ignoreDimension = this.parameters.ignoreDimension,
imgWidth = this.osd.world.getItemAt(0).getContentSize().x,
imgHeight = this.osd.world.getItemAt(0).getContentSize().y;
// console.log(this.osd.world.getItemAt(1).getBounds(true));
// console.log(this.osd.world.getItemAt(0).getBounds(true));
// console.log(this.osd.world.getItemAt(1).getContentSize());
// console.log(this.osd.world.getItemAt(0).getContentSize());

for(var i = 0; i < svgs.length; i++){
var id = Date.parse(new Date()) + parseInt(Math.random() * 1000),
Expand All @@ -284,6 +295,9 @@ function Viewer(parent, config) {

this.svgCollection[id] = new AnnotationSVG(this, id, imgWidth, imgHeight, this.scale, ignoreReferencePoint, ignoreDimension);
this.svgCollection[id].parseSVGFile(svgFile);
if(!content) {
this.dispatchEvent('errorAnnotation');
}
}
}

Expand Down Expand Up @@ -311,7 +325,11 @@ function Viewer(parent, config) {

// Check if annotation svg exists
if(_self.parameters.svgs) {
_self.importAnnotationUnformattedSVG(_self.parameters.svgs);
try {
_self.importAnnotationUnformattedSVG(_self.parameters.svgs);
} catch (err) {
_self.dispatchEvent('errorAnnotation');
}
_self.resizeSVG();
_self.dispatchEvent('disableAnnotationList', false);
} else {
Expand Down Expand Up @@ -347,6 +365,8 @@ function Viewer(parent, config) {
}
}
_self.isInitLoad = true;


};
}

Expand Down Expand Up @@ -555,10 +575,8 @@ function Viewer(parent, config) {
bottomRight.y = bottomRight.y / scale;
}
}

topLeft = w.imageToViewerElementCoordinates(new OpenSeadragon.Point(topLeft.x, topLeft.y));
bottomRight = w.imageToViewerElementCoordinates(new OpenSeadragon.Point(bottomRight.x, bottomRight.y));

svgs[i].setAttribute("x", topLeft.x + "px");
svgs[i].setAttribute("y", topLeft.y + "px");
svgs[i].setAttribute("width", bottomRight.x - topLeft.x + "px");
Expand Down
4 changes: 2 additions & 2 deletions mview.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<script type='text/javascript' src='vendor/jquery.ui.slider.js'></script>
<script type="text/javascript" src="vendor/alertify.min.js"> </script>
<script type="text/javascript" src="js/debug.js"> </script>
<!-- MEI
<!-- MEI
<script type="text/javascript" src="js/osd.debug.js"> </script>
-->

Expand Down Expand Up @@ -89,7 +89,7 @@
</li>
</ul>
</div> <!-- channels filtering -->
<!--
<!--
<div id="osd-control-panel-mini" style="display:none;">
<button id="osd-channels-control-button" title="Channel filtering" class="btn btn-default osd-control-btn" style="top:10px;left:20px;opacity:0.6" onclick="channelsClick()"/><a id="nav-toggle" href="#"><span></span></a></button>
<button id="osd-annotate-button" title="add annotation" style="top:10px;left:60px;opacity:0.7" onmouseover="annoBtnEnter()" onmouseout="annoBtnExit()" onclick="annotate()"></button>
Expand Down

0 comments on commit d68807e

Please sign in to comment.