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));
asked May 2, 2023 at 7:14
1
  • 1
    try map.getInteractions().forEach(interaction => { if(interaction instanceof DoubleClickZoom){ interaction.setActive(false) } }) Commented May 2, 2023 at 7:49

2 Answers 2

1

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)
 }
});
answered May 3, 2023 at 6:02
Sign up to request clarification or add additional context in comments.

2 Comments

you could disabled it from the beginning if you set doubleClickZoom: false
@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
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(),
 ],....
answered May 2, 2023 at 7:54

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.