in pathology/viewer/src/components/image-viewer-side-nav/image-viewer-side-nav.component.ts [654:739]
contextMenuOpened(evt: MouseEvent) {
const olMap = this.olMap;
if (!olMap) return;
const coordinate = olMap.getEventCoordinate(evt);
if (!coordinate) return;
const drawLayer = olMap.getAllLayers().find((layer) => {
return layer.get('name') === 'draw-layer';
});
const drawSource: Vector<Feature<Geometry>>|undefined =
drawLayer?.getSource() as Vector<Feature<Geometry>>;
if (!drawSource) return;
const featuresAtCoordinate = drawSource.getFeaturesAtCoordinate(coordinate);
let select = olMap.getInteractions().getArray().filter((interaction) => {
return interaction instanceof Select;
})[0] as Select;
if (!select) {
select = new Select();
olMap.addInteraction(select);
}
const selectedCollection = select.getFeatures();
if (selectedCollection.getArray().length === 0) {
selectedCollection.extend(featuresAtCoordinate);
}
if (selectedCollection.getArray().length === 1 &&
featuresAtCoordinate.length) {
selectedCollection.clear();
selectedCollection.extend(featuresAtCoordinate);
}
this.disableContextDelete = true;
this.disableContextMenuAdoptShapes = true;
this.disableContextMenuMergeShapes = true;
const features = this.getSelectedFeatures(olMap);
this.selectedContextMenuFeatures = features ?? [];
const allFeaturesByCurrentUser = features.every((feature) => {
return getFeatureAnnotationKey(feature).annotatorId === this.currentUser;
});
if (allFeaturesByCurrentUser) {
this.disableContextDelete = false;
}
this.contextMenuOverlay?.setPosition(coordinate);
if (features.length < 2) {
this.disableContextMenuAdoptShapes = true;
this.disableContextMenuMergeShapes = true;
return;
}
const feature1 = features[0];
const feature2 = features[1];
const featuresIntersecting: boolean =
areFeaturesIntersecting(feature1, feature2, olMap);
const featuresCovered: boolean =
areFeaturesCovered(feature1, feature2, olMap);
if (!featuresIntersecting) {
this.disableContextMenuAdoptShapes = true;
this.disableContextMenuMergeShapes = true;
return;
}
if (features.length >= 2) {
if (allFeaturesByCurrentUser) {
this.disableContextMenuAdoptShapes = false;
this.disableContextMenuMergeShapes = false;
} else {
const feature1AnnotationKey = getFeatureAnnotationKey(feature1);
if (feature1AnnotationKey.annotatorId === this.currentUser) {
this.disableContextMenuAdoptShapes = false;
this.disableContextMenuMergeShapes = true;
}
}
if (featuresCovered) {
this.disableContextMenuAdoptShapes = true;
}
return;
}
}