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

Emit event for overlay annotations #787

Merged
merged 2 commits into from
Feb 23, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary since if this is non-zero the url would have already been 'api/v1/item/' + overlayImageId + /tiles/zxy/${z - levelDifference}/${x}/${y} based on the code in _generateOverlayLayerParam? The only difference I see is a / before the ?encoding=PNG

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case that levelDifference is non-zero, layerParams.url is a function, so concatenating the ?encoding=PNG wasn't working in that case.

Is there a better way to do change the function?

I've recently pushed 14d38de to make sure the levelDifference check passes if it is non-zero, not just positive, and removed those extra / characters from the url.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should eventually abstract this to have the GeoJS utility functions generate appropriate urls directly based on the level difference. For now, this is fine.

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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
},
Expand Down Expand Up @@ -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}`);
Expand Down