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(viewer): block events to viewer when measurement tool is active #3616

Merged
Merged
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
10 changes: 7 additions & 3 deletions viewer/packages/tools/src/Measurement/MeasurementTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export class MeasurementTool extends Cognite3DViewerToolBase {
if (this._measurementMode) {
throw new Error('Measurement mode is active, call exitMeasurementMode()');
}
this._viewer.on('click', this._handlePointerClick);
this._viewer.domElement.addEventListener('pointerdown', this._handlePointerClick, { capture: true });
this._viewer.on('beforeSceneRendered', this._handleClippingPlanes);
this._events.measurementStarted.fire();
this._measurementMode = true;
Expand All @@ -251,7 +251,7 @@ export class MeasurementTool extends Cognite3DViewerToolBase {
throw new Error('Measurement mode is not active, call enterMeasurementMode()');
}
this.cancelActiveMeasurement();
this._viewer.off('click', this._handlePointerClick);
this._viewer.domElement.removeEventListener('pointerdown', this._handlePointerClick, { capture: true });
this._viewer.off('beforeSceneRendered', this._handleClippingPlanes);
this._events.measurementEnded.fire();
this._measurementMode = false;
Expand Down Expand Up @@ -377,7 +377,11 @@ export class MeasurementTool extends Cognite3DViewerToolBase {
super.dispose();
}

private async onPointerClick(event: { offsetX: number; offsetY: number }): Promise<void> {
private async onPointerClick(event: MouseEvent): Promise<void> {
if (event.target === this._viewer.canvas) {
event.stopPropagation();
}

const { offsetX, offsetY } = event;

const intersection = await this._viewer.getIntersectionFromPixel(offsetX, offsetY);
Expand Down
Loading