Answer the question
In order to leave comments, you need to log in
Yandex Maps: how to separate double click events from single click events?
Good afternoon.
I use Yandex maps, by clicking on the map they should add a label, this is done by the "addPlacemark" function, if you click on the label, it should disappear. If you double-click on the map (double-click), then the label should not appear and immediately disappear, it is necessary that there is a simple map zoom, as by default.
This is the working code to which I am going, but obviously some kind of crutch. And the label appears with the brakes.
var dblClick;
myMap.events.add('dblclick', function (e) { dblClick = true; });
myMap.events.add('click', function (e)
{
dblClick = false;
setTimeout(function()
{
if(!dblClick)
{
addPlacemark(e.get('coords'));
}
}, 300);
e.preventDefault();
});
Answer the question
In order to leave comments, you need to log in
This question is not about the Maps API, but about the browser (I mean, exactly the same problem will arise if you want to distinguish between a click and a double click on a regular DOM element). Nothing smarter than waiting n milliseconds for the second click has been invented at this point, unfortunately.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question