mirror of
https://github.com/FoggedLens/iD.git
synced 2026-04-29 15:16:07 +02:00
Make selection less laggy
This commit is contained in:
@@ -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,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')
|
||||
|
||||
Reference in New Issue
Block a user