2

i would like to modify the below code in a such way that it only deactivate the zoom on double-click event please.

i tried the below posted code, but it disabled all the interactions including the mouse-wheel

code

this.map.getInteractions().forEach(x => x.setActive(false));
Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • 1
    try map.getInteractions().forEach(interaction => { if(interaction instanceof DoubleClickZoom){ interaction.setActive(false) } }) – BR75 May 02 '23 at 07:49

2 Answers2

0

You could disable default behaviour on Map initialisation:

export default function defaultMapInteractions(): Interaction[] {
    return defaultInteractions({
        doubleClickZoom: false,
        shiftDragZoom: false,
        dragPan: false,
        altShiftDragRotate: true,
        keyboard: false,
    }).extend([
        new DragPan({
            condition: (event) => {
                return (
                    
                    (primaryAction(event) && (noModifierKeys(event) || altKeyOnly(event))) ||

                
                    (event.originalEvent as PointerEvent).button === 1
                );
            },
        }),
    ]).getArray();
}

....

this.map = new olMap({
            interactions: [
                ...defaultMapInteractions(),
            ],....
BR75
  • 633
  • 7
  • 25
0

i solved it as shown in the follwoing code:

code:

import interactionDoubleClickZoom from 'ol/interaction/DoubleClickZoom';

    this.map.getInteractions().forEach(x => {
    if (x instanceof interactionDoubleClickZoom) {
        x.setActive(false)
    }
});
Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • 1
    you could disabled it from the beginning if you set doubleClickZoom: false – BR75 May 03 '23 at 07:52
  • 1
    @BR75 yes sure, but i do not want to have this interaction to be disabled in all the occasions. i mean i want to disable it on occurence of a specific event, otherwise it remains – Amrmsmb May 03 '23 at 10:48