mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 13:38:26 +02:00
Hide labels along selected ways, or near selected vertices
(closes #3636)
This commit is contained in:
@@ -360,9 +360,13 @@ export function rendererMap(context) {
|
||||
|
||||
|
||||
map.mouse = function() {
|
||||
var e = mousemove || d3.event, s;
|
||||
while ((s = e.sourceEvent)) e = s;
|
||||
return mouse(e);
|
||||
var event = mousemove || d3.event;
|
||||
if (event) {
|
||||
var s;
|
||||
while ((s = event.sourceEvent)) { event = s; }
|
||||
return mouse(event);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
|
||||
+38
-8
@@ -584,35 +584,65 @@ export function svgLabels(projection, context) {
|
||||
// debug
|
||||
drawCollisionBoxes(label, rskipped, 'debug-skipped');
|
||||
drawCollisionBoxes(label, rdrawn, 'debug-drawn');
|
||||
|
||||
selection.call(filterLabels);
|
||||
}
|
||||
|
||||
|
||||
function hideOnMouseover() {
|
||||
if (d3.event.buttons) return;
|
||||
|
||||
var layers = d3.select(this)
|
||||
function filterLabels(selection) {
|
||||
var layers = selection
|
||||
.selectAll('.layer-label, .layer-halo');
|
||||
|
||||
layers.selectAll('.proximate')
|
||||
.classed('proximate', false);
|
||||
|
||||
var mouse = context.mouse(),
|
||||
pad = 20,
|
||||
bbox = { minX: mouse[0] - pad, minY: mouse[1] - pad, maxX: mouse[0] + pad, maxY: mouse[1] + pad },
|
||||
ids = _.map(rdrawn.search(bbox), 'id');
|
||||
graph = context.graph(),
|
||||
selectedIDs = context.selectedIDs(),
|
||||
ids = [],
|
||||
pad, bbox;
|
||||
|
||||
// hide labels near the mouse
|
||||
if (mouse) {
|
||||
pad = 20;
|
||||
bbox = { minX: mouse[0] - pad, minY: mouse[1] - pad, maxX: mouse[0] + pad, maxY: mouse[1] + pad };
|
||||
ids.push.apply(ids, _.map(rdrawn.search(bbox), 'id'));
|
||||
}
|
||||
|
||||
// hide labels along selected ways, or near selected vertices
|
||||
for (var i = 0; i < selectedIDs.length; i++) {
|
||||
var entity = graph.entity(selectedIDs[i]);
|
||||
var geometry = entity.geometry(graph);
|
||||
|
||||
if (geometry === 'line') {
|
||||
ids.push(selectedIDs[i]);
|
||||
} else if (geometry === 'vertex') {
|
||||
var point = context.projection(entity.loc);
|
||||
pad = 10;
|
||||
bbox = { minX: point[0] - pad, minY: point[1] - pad, maxX: point[0] + pad, maxY: point[1] + pad };
|
||||
ids.push.apply(ids, _.map(rdrawn.search(bbox), 'id'));
|
||||
}
|
||||
}
|
||||
|
||||
layers.selectAll(utilEntitySelector(ids))
|
||||
.classed('proximate', true);
|
||||
}
|
||||
|
||||
|
||||
var throttleFilterLabels = _.throttle(filterLabels, 100);
|
||||
|
||||
|
||||
drawLabels.observe = function(selection) {
|
||||
selection.on('mousemove.hidelabels', hideOnMouseover);
|
||||
var listener = function() { throttleFilterLabels(selection); };
|
||||
selection.on('mousemove.hidelabels', listener);
|
||||
context.on('enter.hidelabels', listener);
|
||||
};
|
||||
|
||||
|
||||
drawLabels.off = function(selection) {
|
||||
throttleFilterLabels.cancel();
|
||||
selection.on('mousemove.hidelabels', null);
|
||||
context.on('enter.hidelabels', null);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user