UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 1.07 kB
import{InputHandler as e}from"../../../input/InputHandler.js";class i extends e{constructor(e,i,t){super(!0),this.view=e,this.keys=i,this._pressed=!1,this._keyMap={[i.left]:"left",[i.right]:"right",[i.up]:"up",[i.down]:"down"},this.registerIncoming("key-down",t,(e=>this._handleKeyDown(e))),this.registerIncoming("key-up",t,(e=>this._handleKeyUp(e))),this.registerIncoming("blur",t,(()=>this._handleBlur()))}_handleKeyDown(e){e.data.repeat||this._handleKey(e,!0)}_handleKeyUp(e){this._handleKey(e,!1)}_handleBlur(){this._pressed&&(this._pressed=!1,this.view.mapViewNavigation.stop())}_handleKey(e,i){const t=this._keyMap[e.data.key];if(this._pressed=null!=t,this._pressed){if(i)switch(this.view.mapViewNavigation.begin(),t){case"left":this.view.mapViewNavigation.continousPanLeft();break;case"right":this.view.mapViewNavigation.continousPanRight();break;case"up":this.view.mapViewNavigation.continousPanUp();break;case"down":this.view.mapViewNavigation.continousPanDown()}else this._pressed=!1,this.view.mapViewNavigation.stop();e.stopPropagation()}}}export{i as KeyPan};