From e929978249efdc1018299cf4f7232d02316f9e7e Mon Sep 17 00:00:00 2001 From: naglepuff Date: Tue, 22 Feb 2022 15:48:24 -0500 Subject: [PATCH 1/2] Emit event for overlay annotations Also fix URL generation for tiled pixelmaps. --- .../web_client/views/imageViewerWidget/geojs.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/girder_annotation/girder_large_image_annotation/web_client/views/imageViewerWidget/geojs.js b/girder_annotation/girder_large_image_annotation/web_client/views/imageViewerWidget/geojs.js index b7d0adf5d..664e3d06a 100644 --- a/girder_annotation/girder_large_image_annotation/web_client/views/imageViewerWidget/geojs.js +++ b/girder_annotation/girder_large_image_annotation/web_client/views/imageViewerWidget/geojs.js @@ -125,12 +125,17 @@ var GeojsImageViewerWidgetExtension = function (viewer) { * @param {object} layerParams An object containing layer parameters. This should already have * generic properties for overlay annotations set, such as the URL, opacity, etc. * @param {object} pixelmapElement A pixelmap annotation element + * @param {number} levelDifference The difference in zoom level between the base image and the overlay * @returns An object containing parameters needed to create a pixelmap layer. */ - _addPixelmapLayerParams(layerParams, pixelmapElement) { + _addPixelmapLayerParams(layerParams, pixelmapElement, levelDifference) { // For pixelmap overlays, there are additional parameters to set layerParams.keepLower = false; - layerParams.url = layerParams.url + `?encoding=PNG`; + if (levelDifference > 0) { + layerParams.url = (x, y, z) => 'api/v1/item/' + pixelmapElement.girderId + `/tiles/zxy/${z - levelDifference}/${x}/${y}/?encoding=PNG`; + } else { + layerParams.url = layerParams.url + `?encoding=PNG`; + } let pixelmapData = pixelmapElement.values; if (pixelmapElement.boundaries) { let valuesWithBoundaries = new Array(pixelmapData.length * 2); @@ -183,8 +188,8 @@ var GeojsImageViewerWidgetExtension = function (viewer) { params.layer.opacity = overlay.opacity || 1; params.layer.opacity *= this._globalAnnotationOpacity; + const levelDifference = this.levels - overlayImageMetadata.levels; if (this.levels !== overlayImageMetadata.levels) { - const levelDifference = this.levels - overlayImageMetadata.levels; params.layer.url = (x, y, z) => 'api/v1/item/' + overlayImageId + `/tiles/zxy/${z - levelDifference}/${x}/${y}`; params.layer.minLevel = levelDifference; params.layer.maxLevel += levelDifference; @@ -205,7 +210,7 @@ var GeojsImageViewerWidgetExtension = function (viewer) { }; } if (overlay.type === 'pixelmap') { - params.layer = this._addPixelmapLayerParams(params.layer, overlay); + params.layer = this._addPixelmapLayerParams(params.layer, overlay, levelDifference); } return params.layer; }, @@ -387,6 +392,7 @@ var GeojsImageViewerWidgetExtension = function (viewer) { overlayLayer.id(overlay.id); overlayLayer.gcs(proj); + this.trigger('g:drawOverlayAnnotation', overlay, overlayLayer); this.viewer.scheduleAnimationFrame(this.viewer.draw, true); }).fail((response) => { console.error(`There was an error overlaying image with ID ${overlayItemId}`); From 14d38de2465f24ec1c1c27a5d361f8a82fe0d9dc Mon Sep 17 00:00:00 2001 From: naglepuff Date: Wed, 23 Feb 2022 10:49:57 -0500 Subject: [PATCH 2/2] Check if levelDifference is non-zero Previously it only checked for greater than zero, but levelDifference could be negative. Also remove extra / from layer URL. --- .../web_client/views/imageViewerWidget/geojs.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/girder_annotation/girder_large_image_annotation/web_client/views/imageViewerWidget/geojs.js b/girder_annotation/girder_large_image_annotation/web_client/views/imageViewerWidget/geojs.js index 664e3d06a..5f19cb6ef 100644 --- a/girder_annotation/girder_large_image_annotation/web_client/views/imageViewerWidget/geojs.js +++ b/girder_annotation/girder_large_image_annotation/web_client/views/imageViewerWidget/geojs.js @@ -131,8 +131,8 @@ var GeojsImageViewerWidgetExtension = function (viewer) { _addPixelmapLayerParams(layerParams, pixelmapElement, levelDifference) { // For pixelmap overlays, there are additional parameters to set layerParams.keepLower = false; - if (levelDifference > 0) { - layerParams.url = (x, y, z) => 'api/v1/item/' + pixelmapElement.girderId + `/tiles/zxy/${z - levelDifference}/${x}/${y}/?encoding=PNG`; + if (levelDifference !== 0) { + layerParams.url = (x, y, z) => 'api/v1/item/' + pixelmapElement.girderId + `/tiles/zxy/${z - levelDifference}/${x}/${y}?encoding=PNG`; } else { layerParams.url = layerParams.url + `?encoding=PNG`; }