0

I have just updated from OpenLayers 6 to version 7. I now get an error regarding the interactions. I want to disable the zoom so the page can be scrolled. Only when using "platformModifierKeyOnly" zooming via scroll should be possible. This is the code that used to work:

const map = new ol.Map({
    layers: [clusterHulls, clusters, clusterCircles],
    target: 'map',
    view: view,
    interactions: ol.interaction.defaults({
        dragPan: false,
        mouseWheelZoom: false
    }).extend([
        new ol.interaction.DragPan({
            condition: function (event) {
                return this.getPointerCount() === 2 || ol.events.condition.platformModifierKeyOnly(event);
            },
        }),
        new ol.interaction.MouseWheelZoom({
            condition: ol.events.condition.platformModifierKeyOnly,
        }),
    ]),
});

But now I get the following error in the console: ol.interaction.defaults is not a function.

Unfortunately the OpenLayers documentation doesn't help much to find out what needs to be changed to get this working again.

geocodezip
  • 158,664
  • 13
  • 220
  • 245
obs
  • 797
  • 3
  • 14
  • 37
  • Have you [imported `defaults`](https://openlayers.org/en/latest/apidoc/module-ol_interaction_defaults)? – isherwood Sep 01 '22 at 16:10
  • 2
    In OL7 you need `ol.interaction.defaults.defaults` – Mike Sep 01 '22 at 16:14
  • Thanks @Mike! Is there a chance I could have found out about this in the docs? It's kind of hard for me to understand it. If you write this as an answer, I can accept it as correct. – obs Sep 01 '22 at 18:29

1 Answers1

1

In OpenLayers 7 the syntax is is ol.interaction.defaults.defaults

See https://github.com/openlayers/openlayers/issues/14020

Mike
  • 16,042
  • 2
  • 14
  • 30