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

Add additional behaviors to image overlays #761

Merged
merged 4 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -508,7 +508,7 @@ class AnnotationSchema:
'group': groupSchema,
},
'required': ['girderId', 'type'],
'additionalProperties': False,
'additionalProperties': True,
Copy link
Member

Choose a reason for hiding this comment

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

Probably the correct thing to do is to make the overlay annotation inherit from the baseShapeSchema, except that we don't want to get the line and lineWidth properties. We can do this in a separate PR -- baseShapeSchema would inherit from baseElementSchema which would exclude those properties and then the overlay annotation would inherit from that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created #762

'description': 'An image to overlay onto another like an '
'annotation.'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ var GeojsImageViewerWidgetExtension = function (viewer) {
params.layer.renderer = 'canvas';
}
params.layer.opacity = overlay.opacity || 1;
params.layer.opacity *= this._globalAnnotationOpacity;

if (this.levels !== overlayImageMetadata.levels) {
const levelDifference = this.levels - overlayImageMetadata.levels;
Expand Down Expand Up @@ -189,6 +190,7 @@ var GeojsImageViewerWidgetExtension = function (viewer) {
var geo = window.geo;
options = _.defaults(options || {}, {fetch: true});
var geojson = annotation.geojson();
const overlays = annotation.overlays() || [];
var present = _.has(this._annotations, annotation.id);
var centroidFeature;
if (present) {
Expand All @@ -203,8 +205,20 @@ var GeojsImageViewerWidgetExtension = function (viewer) {
centroidFeature = feature;
}
});
if (this._annotations[annotation.id].overlays) {
// Ensure that overlay elements that have been deleted are not rendered on a re-draw
_.each(this._annotations[annotation.id].overlays, (overlay) => {
const oldOverlayIds = this._annotations[annotation.id].overlays.map((overlay) => overlay.id);
const updatedOverlayIds = overlays.map((overlay) => overlay.id);
_.each(oldOverlayIds, (id) => {
if (!updatedOverlayIds.includes(id)) {
const overlayLayer = this.viewer.layers().find((layer) => layer.id() === id);
this.viewer.deleteLayer(overlayLayer);
}
});
});
}
}
const overlays = annotation.overlays() || [];
this._annotations[annotation.id] = {
features: centroidFeature ? [centroidFeature] : [],
options: options,
Expand Down Expand Up @@ -500,6 +514,20 @@ var GeojsImageViewerWidgetExtension = function (viewer) {
feature.updateStyleFromArray('strokeOpacity', strokeOpacityArray);
feature._lastFeatureProp = prop;
});
// Also modify opacity of image overlay layers
const overlays = this._annotations[annotationId].overlays || null;
if (overlays) {
_.each(overlays, (overlay) => {
const overlayLayer = this.viewer.layers().find((layer) => layer.id() === overlay.id);
if (overlayLayer) {
let newOpacity = (overlay.opacity || 1) * this._globalAnnotationOpacity;
if (this._highlightAnnotation && annotationId !== this._highlightAnnotation) {
newOpacity = newOpacity * 0.25;
}
overlayLayer.opacity(newOpacity);
}
});
}
},

/**
Expand Down Expand Up @@ -660,6 +688,15 @@ var GeojsImageViewerWidgetExtension = function (viewer) {
feature.layer().opacity(opacity);
}
}));
_.each(this._annotations, (annotation) => {
_.each(annotation.overlays, (overlay) => {
const overlayLayer = this.viewer.layers().find((layer) => layer.id() === overlay.id);
if (overlayLayer) {
const overlayOpacity = overlay.opacity || 1;
overlayLayer.opacity(opacity * overlayOpacity);
}
});
});
return this;
},

Expand Down