mapkit js click and double click events

Hello,


I am integrating a mapkit JS map on a website. I need to use either the click or dblclick event for some custom actions, but I run into problems with both.


1) click event


Everything is working fine with this code (found on this forum here https://forums.developer.apple.com/thread/109735):


map.element.addEventListener("click", function(event) {

if (event.target.parentNode !== map.element) {

// This condition prevents clicks on controls. Binding to a

// secondary click is another option to prevent conflict

return;

}

// my code here

});


Only problem, it is also fired when the map is dragged. It is actually fired at the end of the drag, and the coordinate of the event corresponds to the point on the map used to perform the drag.

Is there a way to create a click event which will not fire when a drag is performed?


2) double click event


Using the double click instead of a simple click is an option. However, the double click triggers a zoom. I don't want to disable all zooming capabilities through isZoomEnabled. I couldn't find any construction option dealing with the double click zoom.

I tried the following to prevent the native zoom behavior but with no luck:


map.element.addEventListener("dblclick", function(event) {

event.preventDefault();  

event.stopPropagation();

});


Is there a way to disable the double click zoom without impacting the zooming via controls?


Thank you for your help!

Is there a way to create a click event which will not fire when a drag is performed?

You can use map.addEventListener("single-tap", function(e) { // your code without the target node condition })

...instead, which will not count dragging and releasing the mouse as clicks. Note that you use map.addEventListener instead of map.element.addEventListener here, so no element as these events are from MapKit directly and no DOM events. Kinda confusing but that works :)

mapkit js click and double click events
 
 
Q