A
A
Arman2015-01-03 11:13:40
JavaScript
Arman, 2015-01-03 11:13:40

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();
    });


Maybe someone knows how to do it right? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
forgotten, 2015-01-06
@Arik

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 question

Ask a Question

731 491 924 answers to any question