Openlayers: Keyboard zoom interaction custom zoom keys

Created on 8 Apr 2019  路  3Comments  路  Source: openlayers/openlayers

Is your feature request related to a problem? Please describe.
It's difficult to create custom keys for zooming other than + and -. This can be frustrating as you have to shift and press + in order to zoom and - is just a keyboard press.

When zooming in chrome for example, you can simply press ctrl+= and ctrl+-. Another example is sometimes arrow key zoom is asked for where zooms in and zooms out.

Describe the solution you'd like
An option in the ol/interaction/KeyboardZoom class that allows the setting of keyboard codes. Preferably something like:

import KeyboardZoom from 'ol/interaction/KeyboardZoom';
new Interaction.KeyboardZoom({
  zoomKeys: ['ArrowUp', 'Equal'],
  zoomOutKeys: ['ArrowDown', 'Minus'],
});

or even something like this to be even more flexible:

import KeyboardZoom from 'ol/interaction/KeyboardZoom';
import * as Condition from 'ol/events/condition';
new Interaction.KeyboardZoom({
  zoomKeys: [
    { code: 'Equal', condition: Condition.platformModifierKeyOnly },
    { code: 'ArrowUp', condition: Condition.always }
  ]
});
stale

Most helpful comment

To be in line with other interactions we could add two new conditions in the constructor, something like:

new KeyboardZoom({
  zoomInCondition: function(mapBrowserEvent) {...}
  zoomoutCondition: function(mapBrowserEvent) {...}
});

And a condition function could be:

zoomInCondition: function(mapBrowserEvent) {
  if (platformModifierKeyOnly(mapBrowserEvent)) {
    const code = mapBrowserEvent.originalEvent.code;
    return code === 'ArrowUp' || code === 'Equal';
  }
}

All 3 comments

To be in line with other interactions we could add two new conditions in the constructor, something like:

new KeyboardZoom({
  zoomInCondition: function(mapBrowserEvent) {...}
  zoomoutCondition: function(mapBrowserEvent) {...}
});

And a condition function could be:

zoomInCondition: function(mapBrowserEvent) {
  if (platformModifierKeyOnly(mapBrowserEvent)) {
    const code = mapBrowserEvent.originalEvent.code;
    return code === 'ArrowUp' || code === 'Equal';
  }
}

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this functionality ever added?

Was this page helpful?
0 / 5 - 0 ratings