From 26f8849c3a191130e9fa101289442b301b601b03 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Wed, 16 Jul 2014 00:30:21 -0400 Subject: [PATCH] render triangular midpoints to show direction of way #1085 --- js/id/svg/midpoints.js | 20 +++++++++++++------- test/spec/svg/midpoints.js | 2 ++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/js/id/svg/midpoints.js b/js/id/svg/midpoints.js index d743565ad..bad753409 100644 --- a/js/id/svg/midpoints.js +++ b/js/id/svg/midpoints.js @@ -75,19 +75,25 @@ iD.svg.Midpoints = function(projection, context) { .insert('g', ':first-child') .attr('class', 'midpoint'); - group.append('circle') - .attr('r', 7) + group.append('polygon') + .attr('points', '-6,8 8,0 -6,-8') .attr('class', 'shadow'); - group.append('circle') - .attr('r', 3) + group.append('polygon') + .attr('points', '-3,4 4,0 -3,-4') .attr('class', 'fill'); - groups.attr('transform', iD.svg.PointTransform(projection)); + groups.attr('transform', function(d) { + var translate = iD.svg.PointTransform(projection), + a = context.entity(d.edge[0]), + b = context.entity(d.edge[1]), + angle = iD.geo.angle(a, b, projection) * (180 / Math.PI); + return translate(d) + ' rotate(' + angle + ')'; + }); // Propagate data bindings. - groups.select('circle.shadow'); - groups.select('circle.fill'); + groups.select('polygon.shadow'); + groups.select('polygon.fill'); groups.exit() .remove(); diff --git a/test/spec/svg/midpoints.js b/test/spec/svg/midpoints.js index 55634d170..eaef0d16e 100644 --- a/test/spec/svg/midpoints.js +++ b/test/spec/svg/midpoints.js @@ -18,6 +18,7 @@ describe("iD.svg.Midpoints", function () { extent = iD.geo.Extent([0, 0], [100, 100]); context.selectedIDs = function() { return [line.id]; }; + context.entity = function(id) { return graph.entity(id); }; surface.call(iD.svg.Midpoints(projection, context), graph, [line], filter, extent); expect(surface.select('.midpoint').datum().loc).to.eql([25, 0]); @@ -57,6 +58,7 @@ describe("iD.svg.Midpoints", function () { extent = iD.geo.Extent([0, 0], [100, 100]); context.selectedIDs = function() { return [line.id]; }; + context.entity = function(id) { return graph.entity(id); }; surface.call(iD.svg.Midpoints(projection, context), graph, [line], filter, extent); expect(surface.select('.midpoint').datum().loc).to.eql([100, 0]);