Search code examples
javascriptqtopenlayersinteraction

Openlayers DragRotate map interaction not working


I'm facing an issue when trying to use the DragRotate interaction from OpenLayers. My map is embedded in a Qt Application by using a QWebView widget. As far as I know, the DragRotate interaction is added to the map by default as you can see in the documentation: https://i.sstatic.net/nr3yv.png

Also, by default, the DragRotate interaction works by pressing Alt+Shift: https://i.sstatic.net/McIn3.png

But when I load it and try to make the map rotate it doesn't work. The rest of interactions seem to work fine. I've also tried to add the interaction manually with map.addInteraction(new ol.interaction.DragRotate()); with no success

Relevant information:

  • Windows 10
  • Qt 5.9.1. QWebEngine library
  • OpenLayers 4.3.2

Update: Just tested it in Chrome browser and the map is able to rotate by pressing Shift+Alt and dragging with left click. But still no success in the Qt Application.


Solution

  • It's been a few years but I was searching for this as well, and figured it out.

    import { altKeyOnly } from "ol/events/condition"
    
    [...rest of your code here]
    
    const dragDragRotateInteraction = new DragRotate({
      condition: altKeyOnly,
    });