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

[FIX] Robust placement of measurement dot #1418

Merged
merged 1 commit into from
Mar 17, 2024
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 @@ -189,6 +189,10 @@ export class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
const mouseWorldPos = math.vec3();
const mouseHoverCanvasPos = math.vec2();
this._currentAngleMeasurement = null;

const getTop = el => el.offsetTop + (el.offsetParent && getTop(el.offsetParent));
const getLeft = el => el.offsetLeft + (el.offsetParent && getLeft(el.offsetParent));

this._onMouseHoverSurface = cameraControl.on(
this._snapping
? "hoverSnapOrSurface"
Expand Down Expand Up @@ -220,13 +224,9 @@ export class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
mouseHoverCanvasPos.set(canvasPos);
switch (this._mouseState) {
case MOUSE_FINDING_ORIGIN:
const canvasBoundRect = canvas.getBoundingClientRect();
const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
const canvasLeftEdge = canvasBoundRect.left + scrollLeft;
const canvasTopEdge = canvasBoundRect.top + scrollTop;
this.markerDiv.style.left = `${canvasLeftEdge + canvasPos[0] - 5}px`;
this.markerDiv.style.top = `${canvasTopEdge + canvasPos[1] - 5}px`;
this.markerDiv.style.left = `${getLeft(canvas) + canvasPos[0] - 5}px`;
this.markerDiv.style.top = `${getTop(canvas) + canvasPos[1] - 5}px`;

break;
case MOUSE_FINDING_CORNER:
if (this._currentAngleMeasurement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ export class DistanceMeasurementsMouseControl extends DistanceMeasurementsContro

this._mouseState = MOUSE_FIRST_CLICK_EXPECTED;

const getTop = el => el.offsetTop + (el.offsetParent && getTop(el.offsetParent));
const getLeft = el => el.offsetLeft + (el.offsetParent && getLeft(el.offsetParent));

this._onCameraControlHoverSnapOrSurface = cameraControl.on(
this._snapping
? "hoverSnapOrSurface"
Expand All @@ -207,16 +210,8 @@ export class DistanceMeasurementsMouseControl extends DistanceMeasurementsContro
pointerCanvasPos.set(event.canvasPos);
if (this._mouseState === MOUSE_FIRST_CLICK_EXPECTED) {

// const canvasBoundary = getCanvasBoundary();

const canvasBoundRect = canvas.getBoundingClientRect();
const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
const canvasLeftEdge = canvasBoundRect.left + scrollLeft;
const canvasTopEdge = canvasBoundRect.top + scrollTop;

this._markerDiv.style.left = `${canvasLeftEdge + canvasPos[0] - 5}px`;
this._markerDiv.style.top = `${canvasTopEdge + canvasPos[1] - 5}px`;
this._markerDiv.style.left = `${getLeft(canvas) + canvasPos[0] - 5}px`;
this._markerDiv.style.top = `${getTop(canvas) + canvasPos[1] - 5}px`;

this._markerDiv.style.background = "pink";
if (event.snappedToVertex || event.snappedToEdge) {
Expand Down
Loading