PDF.js Express Version
7.3.1
Detailed description of issue
I want to manually select the sides of an annotation. Here I am splitting the annotation side in half when clicked on Split button and iterate over all the sides on Next button click. This annotation popup appears when I click(select) an annotation.
So here instead of clicking on Next button to iterate over all the sides to select that req. side(for split), I should be able to manually select that side by a mouse click on that side of annotation. Is it possible to select manually ?
Ex:
Select one side of an annotation that we want to split -
After split -
Expected behaviour
Should be able to select a particular side of an annotation(AREA / LINEAR) USING MOUSE
Code snippet (Angular)
const { annotManager, Annotations } = instance;
// keep track of the currently selected segments for polygon annotations
const polygonSelectedSegments = {};
const getSelectedSegment = polygon => {
return polygonSelectedSegments[polygon.Id] || 0;
};
const updateSelectedSegment = polygon => {
// subtract 1 because the path length is the number of points, not segments
const pathLength = polygon.getPath().length - 1;
// update the selected segment, wrap back to zero
polygonSelectedSegments[polygon.Id] = (getSelectedSegment(polygon) + 1) % pathLength;
};
// this button "selects" the next segment of the polygon
instance.annotationPopup.add({
type: 'actionButton',
label: 'Next',
dataElement: 'polygonNextButton',
onClick: () => {
const annot = annotManager.getSelectedAnnotations()[0];
updateSelectedSegment(annot);
annotManager.redrawAnnotation(annot);
}
});
// this button splits the currently selected segment of the polygon
instance.annotationPopup.add({
type: 'actionButton',
label: 'Split',
dataElement: 'polygonSplitButton',
onClick: () => {
const annot = annotManager.getSelectedAnnotations()[0];
const selectedSegment = getSelectedSegment(annot);
const path = annot.getPath();
const firstPoint = path[selectedSegment];
const secondPoint = path[selectedSegment + 1];
const newPoint = {
x: (firstPoint.x + secondPoint.x) / 2,
y: (firstPoint.y + secondPoint.y) / 2
};
path.splice(selectedSegment + 1, 0, newPoint);
annotManager.redrawAnnotation(annot);
}
});