UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 1.73 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{InputHandler as e}from"../../../input/InputHandler.js";import{onVisibilityChange as i}from"../../../input/VisibilityChange.js";class t extends e{constructor(e,t,s){super(!0),this.view=e,this.keys=t,this._keyToDirection=new Map,this._pressed=!1,this._addKeysMapping(t),this.registerIncoming("key-down",s,(e=>this._handleKeyDown(e))),this.registerIncoming("key-up",s,(e=>this._handleKeyUp(e))),this.registerIncoming("blur",s,(()=>this._handleStop())),this._visibilityHandle=i((e=>e?null:this._handleStop()))}onUninstall(){this._visibilityHandle?.remove(),this._handleStop()}_addKeysMapping(e){this._addKeyMapping(e.clockwise,"clockwise"),this._addKeyMapping(e.counterClockwise,"counterClockwise"),this._addKeyMapping(e.reset,"reset")}_addKeyMapping(e,i){for(const t of e)this._keyToDirection.set(t,i)}_handleKeyDown(e){e.data.repeat||this._handleKey(e,!0)}_handleKeyUp(e){this._handleKey(e,!1)}_handleStop(){this._pressed&&(this._pressed=!1,this.view.mapViewNavigation.stop())}_handleKey(e,i){const t=e.modifiers;if(t.size>0&&!t.has("Shift")||!this.view.constraints.rotationEnabled)return;const s=this._keyToDirection.get(e.data.key);if(this._pressed=null!=s,this._pressed){if(e.preventDefault(),i)switch(this.view.mapViewNavigation.begin(),s){case"clockwise":this.view.mapViewNavigation.continuousRotateClockwise();break;case"counterClockwise":this.view.mapViewNavigation.continuousRotateCounterclockwise();break;case"reset":this.view.mapViewNavigation.resetRotation()}else this._pressed=!1,this.view.mapViewNavigation.stop();e.stopPropagation()}}}export{t as KeyRotate};