From cfd2b6a619cfd078148e3c340a185b83e3aa7654 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Mon, 2 Jun 2014 17:39:51 -0400 Subject: [PATCH] Group line parts so that they can be properly depth sorted. --- js/id/svg/lines.js | 49 ++++++++++++++++++++++---------------------- js/id/svg/surface.js | 2 +- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/js/id/svg/lines.js b/js/id/svg/lines.js index 8ea4418a7..02f7c6994 100644 --- a/js/id/svg/lines.js +++ b/js/id/svg/lines.js @@ -47,39 +47,38 @@ iD.svg.Lines = function(projection) { } lines = lines.filter(path); - // lines.sort(waystack); lines.sort(function(a, b) { return a.layer() - b.layer(); }); - function drawPaths(klass) { - var paths = surface.select('.layer-' + klass) - .selectAll('path.line') - .filter(filter) - .data(lines, iD.Entity.key); + var groups = surface.select('.layer-line') + .selectAll('g') + .filter(filter) + .data(lines, iD.Entity.key); - var enter = paths.enter() + var enter = groups.enter() + .append('g') + .attr('class', function(d) { return d.id; }); + + ['shadow', 'casing', 'stroke'].forEach(function(klass) { + enter .append('path') - .attr('class', function(d) { return 'way line ' + klass + ' ' + d.id; }); + .attr('class', function(d) { return 'way line ' + klass + ' ' + d.id; }) + .call(iD.svg.TagClasses()); + }); - // Optimization: call simple TagClasses only on enter selection. This - // works because iD.Entity.key is defined to include the entity v attribute. - if (klass !== 'stroke') { - enter.call(iD.svg.TagClasses()); - } else { - paths.call(iD.svg.TagClasses() - .tags(iD.svg.MultipolygonMemberTags(graph))); - } + groups + .order(); - paths - .order() - .attr('d', path); + groups.selectAll('path') + .attr('d', path); - paths.exit() - .remove(); - } + // Optimization: call simple TagClasses only on enter selection. This + // works because iD.Entity.key is defined to include the entity v attribute. + groups.selectAll('path.stroke') + .call(iD.svg.TagClasses().tags(iD.svg.MultipolygonMemberTags(graph))); + + groups.exit() + .remove(); - drawPaths('shadow'); - drawPaths('casing'); - drawPaths('stroke'); var segments = _(lines) .filter(function(d) { return d.isOneWay(); }) diff --git a/js/id/svg/surface.js b/js/id/svg/surface.js index 3b11461dd..fd9fb322b 100644 --- a/js/id/svg/surface.js +++ b/js/id/svg/surface.js @@ -1,7 +1,7 @@ iD.svg.Surface = function() { return function (selection) { var layers = selection.selectAll('.layer') - .data(['fill', 'shadow', 'casing', 'stroke', 'oneway', 'hit', 'halo', 'label']); + .data(['fill', 'shadow', 'casing', 'stroke', 'line', 'oneway', 'hit', 'halo', 'label']); layers.enter().append('g') .attr('class', function(d) { return 'layer layer-' + d; });