javascript window.setTimeout executes twice in a particual case -
i have problem using settimeout. have been using lots of times , works way expect to. when put code in seperate function works in case has weird behaviour.
here code:
routepatternpoint.prototype.showonmap = function(map) { var = this; google.maps.event.addlistener(this.marker, "click", function(event) { window.settimeout(function(){ if(routepatternpoint.markerdoubleclickfix === false) { dosomething(); } routepatternpoint.markerdoubleclickfix = false; },350); }); google.maps.event.addlistener(this.marker, "dblclick", function(event) { routepatternpoint.markerdoubleclickfix = true; }); }
the problem google maps api v3 has bug when single , double click events implemented - both of them gets executed.
so solution slow down single click event , see if double click event executed. if double click event executed interrupt single click event.
unfortunatelly code not working way want decided write alert function , see happens. guess what? settimeout function inside single click event executed twice.
do have solution doing wrong?
you may want this:
routepatternpoint.prototype.showonmap = function (map) { var = this; google.maps.event.addlistener(this.marker, "click", function (event) { if (that.clickhandler) { window.cleartimeout(that.clickhandler); } that.clickhandler = window.settimeout(function () { dosomething(); }, 350); }); google.maps.event.addlistener(this.marker, "dblclick", function (event) { if (that.clickhandler) { window.cleartimeout(that.clickhandler); that.clickhandler = null; } }); }
i don't think google maps api v3 firing both single click , double click events bug. useful in many cases.
Comments
Post a Comment