Please give a brief summary of your issue:
We would like to implement a customized annotation based on the PerimeterMeasurementCreateTool and the related annotation. We already read the API documentation PDFTron WebViewer Namespace: Core but couldn’t find a way to get the perimeter measurement data based on the created annotation.
The Angle is a calculated value from the paths of the Perimeter measurement annotation:
const getAngleInRadians = (pt1, pt2, pt3) => {
let angle;
if (pt1 && pt2) {
if (pt3) {
// calculate the angle using Law of cosines
const AB = Math.sqrt(
Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2)
);
const BC = Math.sqrt(
Math.pow(pt2.x - pt3.x, 2) + Math.pow(pt2.y - pt3.y, 2)
);
const AC = Math.sqrt(
Math.pow(pt3.x - pt1.x, 2) + Math.pow(pt3.y - pt1.y, 2)
);
angle = Math.acos((BC * BC + AB * AB - AC * AC) / (2 * BC * AB));
} else {
angle = Math.atan2(pt2.y - pt1.y, pt2.x - pt1.x);
angle = Math.abs(angle);
angle = angle > Math.PI / 2 ? Math.PI - angle : angle;
}
}
return angle;
}
const path = perimeterAnnotation.getPath();
const angle = getAngleInRadians(path[path.length - 3], path[path.length - 2], path[path.length - 1]);
const angleInDegree = ((angle / Math.PI) * 180).toFixed(4);
I can see that having an API to get measurement data is useful in some situations, and I will discuss with my colleagues about creating an API for that.