Skip to content

Commit

Permalink
Initial commit (#4269)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilscognite authored Feb 28, 2024
1 parent 54bbcb9 commit e475849
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export class FlexibleCameraManager implements IFlexibleCameraManager {
private readonly _markers?: undefined | FlexibleCameraMarkers;
private readonly _currentBoundingBox: Box3 = new Box3();
private _isDisposed = false;
private _isEnableClickAndDoubleClick = true;
private _nearAndFarNeedsUpdate = false;
private _isEnabled = true;

// For the wheel event
private _prevTime = 0;
Expand Down Expand Up @@ -286,16 +286,23 @@ export class FlexibleCameraManager implements IFlexibleCameraManager {
}

public get isEnabled(): boolean {
return this._isEnabled;
return this.controls.isEnabled;
}

public get isEnableClickAndDoubleClick(): boolean {
return this._isEnableClickAndDoubleClick;
}

public get isDisposed(): boolean {
return this._isDisposed;
}

private set isEnabled(value: boolean) {
this._isEnabled = value;
this.controls.isEnabled = true;
this.controls.isEnabled = value;
}

public set isEnableClickAndDoubleClick(value: boolean) {
this._isEnableClickAndDoubleClick = value;
}

private getPosition(): Vector3 {
Expand Down Expand Up @@ -412,14 +419,14 @@ export class FlexibleCameraManager implements IFlexibleCameraManager {
};

private readonly onClick = async (event: PointerEventData) => {
if (!this.isEnabled) return;
if (!this.isEnabled || !this.isEnableClickAndDoubleClick) return;
if (this.options.mouseClickType !== FlexibleMouseActionType.None) {
await this.mouseAction(event, this.options.mouseClickType);
}
};

private readonly onDoubleClick = async (event: PointerEventData) => {
if (!this.isEnabled) return;
if (!this.isEnabled || !this.isEnableClickAndDoubleClick) return;
if (this.options.mouseDoubleClickType !== FlexibleMouseActionType.None) {
await this.mouseAction(event, this.options.mouseDoubleClickType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,14 +629,14 @@ export class FlexibleControls extends EventDispatcher<FlexibleControlsEvent> {
};

const dispose = () => {
document.removeEventListener('pointerdown', onTouchStart);
this._domElement.removeEventListener('pointerdown', onTouchStart);
this._domElement.removeEventListener('pointerup', onTouchEnd);
document.removeEventListener('pointermove', onTouchMove);
document.removeEventListener('pointerup', onTouchEnd);
};

document.addEventListener('pointerdown', onTouchStart);
this._domElement.addEventListener('pointerdown', onTouchStart);
this._domElement.addEventListener('pointerup', onTouchEnd, { passive: false });
document.addEventListener('pointermove', onTouchMove, { passive: false });
document.addEventListener('pointerup', onTouchEnd, { passive: false });
}

private rotate(delta: Vector2) {
Expand Down
8 changes: 8 additions & 0 deletions viewer/packages/tools/src/Measurement/MeasurementTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { MeasurementLabels } from './MeasurementLabels';
import { HtmlOverlayTool, HtmlOverlayToolOptions } from '../HtmlOverlay/HtmlOverlayTool';
import rulerSvg from '!!raw-loader!./styles/ruler.svg';
import { MetricsLogger } from '@reveal/metrics';
import { FlexibleCameraManager } from '@reveal/camera-manager';

type MeasurementEvents = 'added' | 'started' | 'ended' | 'disposed';

Expand Down Expand Up @@ -242,6 +243,10 @@ export class MeasurementTool extends Cognite3DViewerToolBase {
this._events.measurementStarted.fire();
this._measurementMode = true;
this._showMeasurements = true;

if (this._viewer.cameraManager instanceof FlexibleCameraManager) {
this._viewer.cameraManager.isEnableClickAndDoubleClick = false;
}
}

/**
Expand All @@ -256,6 +261,9 @@ export class MeasurementTool extends Cognite3DViewerToolBase {
this._viewer.off('beforeSceneRendered', this._handleClippingPlanes);
this._events.measurementEnded.fire();
this._measurementMode = false;
if (this._viewer.cameraManager instanceof FlexibleCameraManager) {
this._viewer.cameraManager.isEnableClickAndDoubleClick = true;
}
}

/**
Expand Down

0 comments on commit e475849

Please sign in to comment.