How to stopPropagation of touch event on overlay GoogleMap

You can find out code here. I tried with global & local event both

event.preventDefault()
event.stopPropagation()
event.returnValue = false
event.cancelBubble = true;

above code working fine for mouse click events but for touch event map still receives click events.

Answers:

Answer

You can add a listener to touchend event, so you can stop the propagation of this event:

  google.maps.event.addDomListener(div, "click", function(e) {
      console.log("over click");
      e.preventDefault();
      e.stopPropagation();
      clickOverlay();
  })

  google.maps.event.addDomListener(div, "touchend", function(e) {
      console.log("over touchend");
      e.preventDefault();
      e.stopPropagation();
      clickOverlay();
  })

Here is your fiddle updated: https://jsfiddle.net/beaver71/xx1ycd7L/

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.