1

When I hold down the Ctrl (control) key on my keyboard and attempt to pan any OL3 map with my mouse, the pan doesn't happen.

Because of the particular needs of my application, I need panning to work when the ctrl key is held down, just as it does when Ctrl is not held down.

I couldn't see anywhere in the OL3 documentation about ctrl-drag being treated specially, so I don't know where to look to disable this behavior.

Any ideas?

1

I've made some tests and the behaviour is not exact the same, but it does the job. Here's a plunker.

It is a clone of ol.interaction.DragPan.handleDragEvent_

It is done on pointermove event:

map.on('pointermove', function(evt){

    if(evt.dragging && evt.originalEvent.ctrlKey){


        var centroid = [evt.originalEvent.clientX, evt.originalEvent.clientY];
        var lastCentroid = interactions.getArray()[dragpan_index].lastCentroid;

        if(lastCentroid){
            var deltaX = lastCentroid[0] - centroid[0];
            var deltaY = centroid[1] - lastCentroid[1];

            var center = [deltaX, deltaY];
            var view = map.getView();
            ol.coordinate.scale(center, view.getResolution());
            ol.coordinate.rotate(center, view.getRotation());
            ol.coordinate.add(center, view.getCenter());
            center = view.constrainCenter(center);
            map.render();
            view.setCenter(center);

        }
        interactions.getArray()[dragpan_index].lastCentroid = centroid;
    }
});
  • Thank you very much for taking the time to put this together. It helped me immensely, not only with this problem, but another custom behavior I wanted while panning. I modified your approach to not create the default DragPan interaction at all (i.e., my map has no DragPan interaction per se, and I just do all that needs to be done in this on pointermove function). – M Katz Jun 22 '15 at 22:42
  • Glad to help! You're welcome. – Jonatas Walker Jun 22 '15 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.