2

I have a working map generated by this code:

// create the map with the proper center
var map = new ol.Map({
        controls: ol.control.defaults().extend(
            [new ol.control.ScaleLine()]
        ),
        view: new ol.View({
                center: ol.proj.fromLonLat([center.long, center.lat]),
                zoom: zoom
            }),
        layers: [new ol.layer.Tile({
                    source: new ol.source.OSM()
                })],
        target: 'mapdiv'
    }
);

The map has zoom buttons and scale line, and I'm able to zoom the map with the keyboard by adding onclick events to the zoom buttons.

I want to be able to drag the map with the keyboard (with the arrow keys). So I'm trying to add the drag buttons, but I cannot find a way to get them. How can I add them?

Alternatively, is there another way to achieve keyboard dragging?

I'm not interested in rotations.

Paolo Benvenuto
  • 385
  • 4
  • 15
  • 1
    [KeyboardPan](https://openlayers.org/en/latest/apidoc/module-ol_interaction_KeyboardPan-KeyboardPan.html) is what you're looking for, it allows the user to pan the map using keyboard arrows. – Nick Jan 21 '19 at 10:55
  • 2
    KeyboardPan is already included in the default interactions, but it doesn't work as expected unless you set `keyboardEventTarget: document,` in the ol.Map options (which will also avoid needing listeners for keyboard zoom) – Mike Jan 21 '19 at 11:27

0 Answers0