render triangular midpoints to show direction of way #1085

This commit is contained in:
Bryan Housel
2014-07-16 00:30:21 -04:00
parent 85656a40cc
commit 26f8849c3a
2 changed files with 15 additions and 7 deletions
+13 -7
View File
@@ -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();
+2
View File
@@ -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]);