how to deactivate zoom on double-click using setActive(false)

213 Views Asked by At

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));
2

There are 2 best solutions below

2
Amrmsmb On BEST ANSWER

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)
    }
});
0
BR75 On

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(),
            ],....