diff --git a/src/Controls/GlobeControls.js b/src/Controls/GlobeControls.js index 2ca60aa20e..cfabd5b2a9 100644 --- a/src/Controls/GlobeControls.js +++ b/src/Controls/GlobeControls.js @@ -234,7 +234,6 @@ class GlobeControls extends THREE.EventDispatcher { this._onEndingMove = null; this._onMouseWheel = this.onMouseWheel.bind(this); - this._onContextMenuListener = this.onContextMenuListener.bind(this); this._onTravel = this.travel.bind(this); this._onTouchStart = this.onTouchStart.bind(this); this._onTouchEnd = this.onTouchEnd.bind(this); @@ -257,7 +256,6 @@ class GlobeControls extends THREE.EventDispatcher { this.states.addEventListener(this.states.PAN._event, this._onPan, false); this.states.addEventListener(this.states.PANORAMIC._event, this._onPanoramic, false); - this.view.domElement.addEventListener('contextmenu', this._onContextMenuListener, false); this.view.domElement.addEventListener('wheel', this._onMouseWheel, false); this.view.domElement.addEventListener('touchstart', this._onTouchStart, false); this.view.domElement.addEventListener('touchend', this._onTouchEnd, false); @@ -873,17 +871,12 @@ class GlobeControls extends THREE.EventDispatcher { } } - onContextMenuListener(event) { - event.preventDefault(); - } - onTouchEnd() { this.handleEndMovement({ previous: this.state }); this.state = this.states.NONE; } dispose() { - this.view.domElement.removeEventListener('contextmenu', this._onContextMenuListener, false); this.view.domElement.removeEventListener('wheel', this._onMouseWheel, false); this.view.domElement.removeEventListener('touchstart', this._onTouchStart, false); this.view.domElement.removeEventListener('touchend', this._onTouchEnd, false); diff --git a/src/Controls/StateControl.js b/src/Controls/StateControl.js index 11af73ac74..2ddc981ad2 100644 --- a/src/Controls/StateControl.js +++ b/src/Controls/StateControl.js @@ -153,6 +153,7 @@ class StateControl extends THREE.EventDispatcher { this._onKeyUp = this.onKeyUp.bind(this); this._onBlur = this.onBlur.bind(this); + this._onContextMenu = this.onContextMenu.bind(this); this._domElement.addEventListener('pointerdown', this._onPointerDown, false); @@ -164,6 +165,8 @@ class StateControl extends THREE.EventDispatcher { // Reset key/mouse when window loose focus window.addEventListener('blur', this._onBlur); + // disable context menu when right-clicking + this._domElement.addEventListener('contextmenu', this._onContextMenu, false); // TODO : this shall be removed when switching keyboard management form Controls to StateControls this._handleTravelInEvent = (event) => { @@ -350,6 +353,10 @@ class StateControl extends THREE.EventDispatcher { this.onPointerUp(); } + onContextMenu(event) { + event.preventDefault(); + } + /** * Remove all event listeners created within this instance of `StateControl` */ @@ -366,6 +373,7 @@ class StateControl extends THREE.EventDispatcher { this._domElement.removeEventListener('keyup', this._onKeyUp, false); window.removeEventListener('blur', this._onBlur); + this._domElement.removeEventListener('contextmenu', this._onContextMenu, false); this._domElement.removeEventListener(this.TRAVEL_IN.trigger, this._handleTravelInEvent, false); this._domElement.removeEventListener(this.TRAVEL_OUT.trigger, this._handleTravelInEvent, false); diff --git a/test/unit/globecontrol.js b/test/unit/globecontrol.js index a5ab74e67d..18fea5ddb1 100644 --- a/test/unit/globecontrol.js +++ b/test/unit/globecontrol.js @@ -210,10 +210,6 @@ describe('GlobeControls', function () { controls.onTouchMove(event); }); - it('onContextMenuListener', function () { - controls.onContextMenuListener(event); - }); - it('lookAtCoordinate with animation', function (done) { const rig = getRig(viewer.camera.camera3D); let i; diff --git a/test/unit/statecontrol.js b/test/unit/statecontrol.js index 2f446769af..e017afd47d 100644 --- a/test/unit/statecontrol.js +++ b/test/unit/statecontrol.js @@ -245,6 +245,10 @@ describe('StateControl', function () { assert.ok(states.NONE === states.currentState); }); + it('context menu should not appear', function () { + states.onContextMenu(event); + }); + it('should dispose event listeners', function () { states.dispose(); });