diff --git a/js/ui/control/navigation.js b/js/ui/control/navigation.js index 9ded33a22ae..13fce8c3399 100644 --- a/js/ui/control/navigation.js +++ b/js/ui/control/navigation.js @@ -59,6 +59,7 @@ Navigation.prototype = util.inherit(Control, { this._map.setBearing(this._map.getBearing() - d); this._prevX = e.screenX; + this._moved = true; e.preventDefault(); }, @@ -67,6 +68,11 @@ Navigation.prototype = util.inherit(Control, { document.removeEventListener('mousemove', this._onCompassMove); document.removeEventListener('mouseup', this._onCompassUp); DOM.enableDrag(); + + if (this._moved) { + this._moved = false; + DOM.suppressClick(); + } }, _createButton: function(className, fn) { diff --git a/js/util/browser/dom.js b/js/util/browser/dom.js index de5f43363ef..95a5ffe5ab4 100644 --- a/js/util/browser/dom.js +++ b/js/util/browser/dom.js @@ -35,3 +35,16 @@ var transformProp = testProp(['transform', 'WebkitTransform']); exports.setTransform = function(el, value) { el.style[transformProp] = value; }; + +// Suppress the next click, but only if it's immediate. +function suppressClick(e) { + e.preventDefault(); + e.stopPropagation(); + window.removeEventListener('click', suppressClick, true); +} +exports.suppressClick = function() { + window.addEventListener('click', suppressClick, true); + window.setTimeout(function() { + window.removeEventListener('click', suppressClick, true); + }, 0); +};