Make selection less laggy

This commit is contained in:
John Firebaugh
2013-02-12 14:04:39 -08:00
parent 4f611dcf25
commit 3f19a293aa
2 changed files with 9 additions and 59 deletions
+3 -58
View File
@@ -1,13 +1,6 @@
iD.behavior.Select = function(context) {
var behavior = function(selection) {
var timeout = null,
// the position of the first mousedown
pos = null;
function click(event) {
d3.event = event;
function click() {
var datum = d3.event.target.__data__;
if (datum instanceof iD.Entity) {
if (d3.event.shiftKey) {
@@ -20,59 +13,11 @@ iD.behavior.Select = function(context) {
}
}
function mousedown() {
var datum = d3.event.target.__data__;
pos = [d3.event.clientX, d3.event.clientY];
if (datum instanceof iD.Entity || (datum && datum.type === 'midpoint')) {
selection
.on('mousemove.select', mousemove)
.on('touchmove.select', mousemove);
// we've seen a mousedown within 400ms of this one, so ignore
// both because they will be a double click
if (timeout !== null) {
window.clearTimeout(timeout);
selection.on('mousemove.select', null);
timeout = null;
} else {
// queue the click handler to fire in 400ms if no other clicks
// are detected
timeout = window.setTimeout((function(event) {
return function() {
click(event);
timeout = null;
selection.on('mousemove.select', null);
};
// save the event for the click handler
})(d3.event), 200);
}
}
}
// allow mousemoves to cancel the click
function mousemove() {
if (iD.geo.dist([d3.event.clientX, d3.event.clientY], pos) > 4) {
window.clearTimeout(timeout);
timeout = null;
}
}
function mouseup() {
selection.on('mousemove.select', null);
if (pos && d3.event.clientX === pos[0] && d3.event.clientY === pos[1] &&
!(d3.event.target.__data__ instanceof iD.Entity)) {
context.enter(iD.modes.Browse(context));
}
}
selection
.on('mousedown.select', mousedown)
.on('mouseup.select', mouseup)
.on('touchstart.select', mousedown);
selection.on('click.select', click);
};
behavior.off = function(selection) {
selection.on('mousedown.select', null);
selection.on('click.select', null);
};
return behavior;
+6 -1
View File
@@ -6,6 +6,7 @@ iD.modes.Select = function(context, selection, initial) {
var inspector = iD.ui.inspector().initial(!!initial),
keybinding = d3.keybinding('select'),
radialTime = null,
behaviors = [
iD.behavior.Hover(),
iD.behavior.Select(context),
@@ -174,7 +175,9 @@ iD.modes.Select = function(context, selection, initial) {
loc = entity.loc;
}
context.surface().call(radialMenu, context.projection(loc));
radialTime = window.setTimeout(function() {
context.surface().call(radialMenu, context.projection(loc));
}, 300);
}
};
@@ -183,6 +186,8 @@ iD.modes.Select = function(context, selection, initial) {
changeTags(singular(), inspector.tags());
}
if (radialTime) window.clearTimeout(radialTime);
context.container()
.select('.inspector-wrap')
.style('display', 'none')