From 1823f2619f26bb7080f316d2dcb081d5472853f4 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sat, 4 May 2013 15:20:24 -0700 Subject: [PATCH] Clean up and simplify iD.svg.Lines --- js/id/svg.js | 2 +- js/id/svg/lines.js | 80 +++++++++++++++++++++------------------------- 2 files changed, 37 insertions(+), 45 deletions(-) diff --git a/js/id/svg.js b/js/id/svg.js index 004fb4927..cbf226e63 100644 --- a/js/id/svg.js +++ b/js/id/svg.js @@ -13,7 +13,7 @@ iD.svg = { }; }, - LineString: function(projection, graph) { + Path: function(projection, graph) { var cache = {}, path = d3.geo.path().projection(projection); diff --git a/js/id/svg/lines.js b/js/id/svg/lines.js index 63ae8d131..23a02cedd 100644 --- a/js/id/svg/lines.js +++ b/js/id/svg/lines.js @@ -33,38 +33,8 @@ iD.svg.Lines = function(projection) { } return function drawLines(surface, graph, entities, filter) { - function drawPaths(group, lines, filter, klass, lineString) { - lines = lines.filter(function(line) { - return lineString(line); - }); - - var tagClasses = iD.svg.TagClasses(); - - if (klass === 'stroke') { - tagClasses.tags(iD.svg.MultipolygonMemberTags(graph)); - } - - var paths = group.selectAll('path.line') - .filter(filter) - .data(lines, iD.Entity.key); - - paths.enter() - .append('path') - .attr('class', function(d) { return 'way line ' + klass + ' ' + d.id; }); - - paths - .order() - .attr('d', lineString) - .call(tagClasses) - .call(iD.svg.MemberClasses(graph)); - - paths.exit() - .remove(); - - return paths; - } - - var lines = []; + var lines = [], + path = iD.svg.Path(projection, graph); for (var i = 0; i < entities.length; i++) { var entity = entities[i], @@ -76,25 +46,47 @@ iD.svg.Lines = function(projection) { } } + lines = lines.filter(path); lines.sort(waystack); - var lineString = iD.svg.LineString(projection, graph); + function drawPaths(klass) { + var tagClasses = iD.svg.TagClasses(); - var shadow = surface.select('.layer-shadow'), - casing = surface.select('.layer-casing'), - stroke = surface.select('.layer-stroke'), - defs = surface.select('defs'), - oneway = surface.select('.layer-oneway'); + if (klass === 'stroke') { + tagClasses.tags(iD.svg.MultipolygonMemberTags(graph)); + } - drawPaths(shadow, lines, filter, 'shadow', lineString); - drawPaths(casing, lines, filter, 'casing', lineString); - drawPaths(stroke, lines, filter, 'stroke', lineString); + var paths = surface.select('.layer-' + klass) + .selectAll('path.line') + .filter(filter) + .data(lines, iD.Entity.key); - var segments = _.flatten(lines + paths.enter() + .append('path') + .attr('class', function(d) { return 'way line ' + klass + ' ' + d.id; }); + + paths + .order() + .attr('d', path) + .call(tagClasses) + .call(iD.svg.MemberClasses(graph)); + + paths.exit() + .remove(); + } + + drawPaths('shadow'); + drawPaths('casing'); + drawPaths('stroke'); + + var segments = _(lines) .filter(function(d) { return d.isOneWay(); }) - .map(iD.svg.OneWaySegments(projection, graph, 35))); + .map(iD.svg.OneWaySegments(projection, graph, 35)) + .flatten() + .valueOf(); - var oneways = oneway.selectAll('path.oneway') + var oneways = surface.select('.layer-oneway') + .selectAll('path.oneway') .filter(filter) .data(segments, function(d) { return [d.id, d.index]; });