@@ -31,8 +31,10 @@ class KeyboardHandler implements Handler {
3131 _panStep : number ;
3232 _bearingStep : number ;
3333 _pitchStep : number ;
34- _rotationDisabled : boolean ;
34+ _bearingDisabled : boolean ;
35+ _pitchDisabled : boolean ;
3536 _panDisabled : boolean ;
37+ _zoomDisabled : boolean ;
3638
3739 /**
3840 * @private
@@ -42,8 +44,10 @@ class KeyboardHandler implements Handler {
4244 this . _panStep = stepOptions . panStep ;
4345 this . _bearingStep = stepOptions . bearingStep ;
4446 this . _pitchStep = stepOptions . pitchStep ;
45- this . _rotationDisabled = false ;
47+ this . _bearingDisabled = false ;
48+ this . _pitchDisabled = false ;
4649 this . _panDisabled = false ;
50+ this . _zoomDisabled = false ;
4751 }
4852
4953 blur ( ) {
@@ -56,6 +60,7 @@ class KeyboardHandler implements Handler {
5660
5761 keydown ( e : KeyboardEvent ) : HandlerResult | null | undefined {
5862 if ( e . altKey || e . ctrlKey || e . metaKey ) return ;
63+ if ( ! this . isEnabled ( ) ) return ;
5964
6065 let zoomDir = 0 ;
6166 let bearingDir = 0 ;
@@ -117,8 +122,11 @@ class KeyboardHandler implements Handler {
117122 return ;
118123 }
119124
120- if ( this . _rotationDisabled ) {
125+ if ( this . _bearingDisabled ) {
121126 bearingDir = 0 ;
127+ }
128+
129+ if ( this . _pitchDisabled ) {
122130 pitchDir = 0 ;
123131 }
124132
@@ -127,6 +135,10 @@ class KeyboardHandler implements Handler {
127135 yDir = 0 ;
128136 }
129137
138+ if ( this . _zoomDisabled ) {
139+ zoomDir = 0 ;
140+ }
141+
130142 return {
131143 cameraAnimation : ( map : Map ) => {
132144 const zoom = map . getZoom ( ) ;
@@ -176,7 +188,7 @@ class KeyboardHandler implements Handler {
176188 * const isKeyboardEnabled = map.keyboard.isEnabled();
177189 */
178190 isEnabled ( ) : boolean {
179- return this . _enabled ;
191+ return this . _enabled && ! ( this . _bearingDisabled && this . _pitchDisabled && this . _panDisabled && this . _zoomDisabled ) ;
180192 }
181193
182194 /**
@@ -193,25 +205,40 @@ class KeyboardHandler implements Handler {
193205 }
194206
195207 /**
196- * Disables the "keyboard pan /rotate" interaction, leaving the
208+ * Disables the "keyboard pitch /rotate" interaction, leaving the
197209 * "keyboard zoom" interaction enabled.
198210 *
199211 * @example
200212 * map.keyboard.disableRotation();
201213 */
202214 disableRotation ( ) {
203- this . _rotationDisabled = true ;
215+ this . _pitchDisabled = true ;
216+ this . _bearingDisabled = true ;
204217 }
205218
206219 /**
207- * Enables the "keyboard pan /rotate" interaction.
220+ * Enables the "keyboard pitch /rotate" interaction.
208221 *
209222 * @example
210223 * map.keyboard.enable();
211224 * map.keyboard.enableRotation();
212225 */
213226 enableRotation ( ) {
214- this . _rotationDisabled = false ;
227+ this . _pitchDisabled = false ;
228+ this . _bearingDisabled = false ;
229+ }
230+
231+ /**
232+ * Returns a Boolean indicating whether the "keyboard pitch/rotate"
233+ * interaction is enabled.
234+ *
235+ * @returns {boolean } `true` if the "keyboard pitch/rotate"
236+ * interaction is enabled.
237+ * @example
238+ * const isRotationEnabled = map.keyboard.isRotationEnabled();
239+ */
240+ isRotationEnabled ( ) : boolean {
241+ return ! this . _pitchDisabled && ! this . _bearingDisabled ;
215242 }
216243
217244 /**
@@ -235,6 +262,120 @@ class KeyboardHandler implements Handler {
235262 enablePan ( ) {
236263 this . _panDisabled = false ;
237264 }
265+
266+ /**
267+ * Returns a Boolean indicating whether the "keyboard pan" interaction is
268+ * enabled.
269+ *
270+ * @returns {boolean } `true` if the "keyboard pan" interaction is enabled.
271+ * @example
272+ * const isPanEnabled = map.keyboard.isPanEnabled();
273+ */
274+ isPanEnabled ( ) : boolean {
275+ return ! this . _panDisabled ;
276+ }
277+
278+ /**
279+ * Disables the "keyboard zoom" interaction (plus/minus keys), leaving the
280+ * "keyboard pan" and "keyboard rotate/pitch" interactions enabled.
281+ *
282+ * @example
283+ * map.keyboard.disableZoom();
284+ */
285+ disableZoom ( ) {
286+ this . _zoomDisabled = true ;
287+ }
288+
289+ /**
290+ * Enables the "keyboard zoom" interaction (plus/minus keys).
291+ *
292+ * @example
293+ * map.keyboard.enable();
294+ * map.keyboard.enableZoom();
295+ */
296+ enableZoom ( ) {
297+ this . _zoomDisabled = false ;
298+ }
299+
300+ /**
301+ * Returns a Boolean indicating whether the "keyboard zoom" interaction is
302+ * enabled.
303+ *
304+ * @returns {boolean } `true` if the "keyboard zoom" interaction is enabled.
305+ * @example
306+ * const isZoomEnabled = map.keyboard.isZoomEnabled();
307+ */
308+ isZoomEnabled ( ) : boolean {
309+ return ! this . _zoomDisabled ;
310+ }
311+
312+ /**
313+ * Disables the "keyboard pitch" interaction (Shift+Up/Down), leaving the
314+ * "keyboard pan" and "keyboard rotate" interactions enabled.
315+ *
316+ * @example
317+ * map.keyboard.disablePitch();
318+ */
319+ disablePitch ( ) {
320+ this . _pitchDisabled = true ;
321+ }
322+
323+ /**
324+ * Enables the "keyboard pitch" interaction (Shift+Up/Down).
325+ *
326+ * @example
327+ * map.keyboard.enable();
328+ * map.keyboard.enablePitch();
329+ */
330+ enablePitch ( ) {
331+ this . _pitchDisabled = false ;
332+ }
333+
334+ /**
335+ * Returns a Boolean indicating whether the "keyboard pitch" interaction is
336+ * enabled.
337+ *
338+ * @returns {boolean } `true` if the "keyboard pitch" interaction is enabled.
339+ * @example
340+ * const isPitchEnabled = map.keyboard.isPitchEnabled();
341+ */
342+ isPitchEnabled ( ) : boolean {
343+ return ! this . _pitchDisabled ;
344+ }
345+
346+ /**
347+ * Disables the "keyboard bearing" interaction (Shift+Left/Right), leaving the
348+ * "keyboard pan" and "keyboard pitch" interactions enabled.
349+ *
350+ * @example
351+ * map.keyboard.disableBearing();
352+ */
353+ disableBearing ( ) {
354+ this . _bearingDisabled = true ;
355+ }
356+
357+ /**
358+ * Enables the "keyboard bearing" interaction (Shift+Left/Right).
359+ *
360+ * @example
361+ * map.keyboard.enable();
362+ * map.keyboard.enableBearing();
363+ */
364+ enableBearing ( ) {
365+ this . _bearingDisabled = false ;
366+ }
367+
368+ /**
369+ * Returns a Boolean indicating whether the "keyboard bearing" interaction is
370+ * enabled.
371+ *
372+ * @returns {boolean } `true` if the "keyboard bearing" interaction is enabled.
373+ * @example
374+ * const isBearingEnabled = map.keyboard.isBearingEnabled();
375+ */
376+ isBearingEnabled ( ) : boolean {
377+ return ! this . _bearingDisabled ;
378+ }
238379}
239380
240381function easeOut ( t : number ) {
0 commit comments