From 4eccd7015f8380dae44a85543c6321fe2dcff901 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 25 Apr 2013 18:41:49 -0400 Subject: [PATCH] corner destroying resampling for oneway markers --- css/map.css | 7 ++----- js/id/svg.js | 41 +++++++++++++++++++++++++++++------------ js/id/svg/lines.js | 14 ++++++++------ js/id/svg/surface.js | 5 +++-- 4 files changed, 42 insertions(+), 25 deletions(-) diff --git a/css/map.css b/css/map.css index a65a08198..a1324cc48 100644 --- a/css/map.css +++ b/css/map.css @@ -823,11 +823,8 @@ marker#oneway-marker path { opacity: .5; } -text.tag-oneway { - fill:#91CFFF; - stroke:#2C6B9B; - stroke-width:1; - pointer-events:none; +path.oneway { + stroke-width: 6px; } /* diff --git a/js/id/svg.js b/js/id/svg.js index 3a15c9c49..d574c3dda 100644 --- a/js/id/svg.js +++ b/js/id/svg.js @@ -24,6 +24,7 @@ iD.svg = { var last, next, started = false, + offset = 0, d = ''; d3.geo.stream({ @@ -32,29 +33,45 @@ iD.svg = { return n.loc; }) }, projection.stream({ - lineStart: function() { last = null; started = false; }, + lineStart: function() { last = null; started = false; offset = 0; }, lineEnd: function() { }, point: function(x, y) { - if (!started) d += 'M'; + next = [Math.floor(x), Math.floor(y)]; - if (dx && last && iD.geo.dist(last, next) > dx) { + + if (!started) { + d += 'M'; + d += next[0] + ',' + next[1]; + offset = dx; + + } else if (!dx) { + d += 'L'; + d += next[0] + ',' + next[1]; + } + + + // Resample + if (dx && last) { + var span = iD.geo.dist(last, next), angle = Math.atan2(next[1] - last[1], next[0] - last[0]), to = last.slice(); - to[0] += Math.cos(angle) * dx; - to[1] += Math.sin(angle) * dx; - while (iD.geo.dist(last, to) < (span)) { + + to[0] += Math.cos(angle) * offset; + to[1] += Math.sin(angle) * offset; + + while (iD.geo.dist(last, to) < span) { + // a dx-length line segment in that angle - if (started) d += 'L'; - d += Math.floor(to[0]) + ',' + Math.floor(to[1]); - started = started || true; + d += 'L' + Math.floor(to[0]) + ',' + Math.floor(to[1]); to[0] += Math.cos(angle) * dx; to[1] += Math.sin(angle) * dx; } + + offset = iD.geo.dist(last, to) - span; } - if (started) d += 'L'; - d += next[0] + ',' + next[1]; - started = started || true; + + started = true; last = next; } })); diff --git a/js/id/svg/lines.js b/js/id/svg/lines.js index eeee76c3b..8219f1b93 100644 --- a/js/id/svg/lines.js +++ b/js/id/svg/lines.js @@ -112,14 +112,16 @@ iD.svg.Lines = function(projection) { casing = surface.select('.layer-casing'), stroke = surface.select('.layer-stroke'), defs = surface.select('defs'), - text = surface.select('.layer-text'), + oneway = surface.select('.layer-oneway'), shadows = drawPaths(shadow, lines, filter, 'shadow', lineString), casings = drawPaths(casing, lines, filter, 'casing', lineString), - strokes = drawPaths(stroke, lines, filter, 'stroke', lineString); + strokes = drawPaths(stroke, lines, filter, 'stroke', lineString), + oneways = drawPaths(oneway, lines, filter, 'oneway', lineStringOneway); - strokes - .filter(function(d) { return d.isOneWay(); }) - .attr('marker-mid', 'url(#oneway-marker)') - .attr('d', lineStringResampled); + oneways.attr('marker-mid', 'url(#oneway-marker)'); + + function lineStringOneway(d) { + return d.isOneWay() && lineStringResampled(d); + } }; }; diff --git a/js/id/svg/surface.js b/js/id/svg/surface.js index 8c3123366..73db36475 100644 --- a/js/id/svg/surface.js +++ b/js/id/svg/surface.js @@ -34,12 +34,13 @@ iD.svg.Surface = function(context) { id: 'oneway-marker', viewBox: '0 0 10 10', refY: 2.5, + refX: 5, markerWidth: 2, markerHeight: 2, orient: 'auto' }) .append('path') - .attr('d', 'M 0 0 L 5 2.5 L 0 5 z'); + .attr('d', 'M 5 3 L 0 3 L 0 2 L 5 2 L 5 0 L 10 2.5 L 5 5 z'); var patterns = defs.selectAll('pattern') .data([ @@ -109,7 +110,7 @@ iD.svg.Surface = function(context) { maki)); var layers = selection.selectAll('.layer') - .data(['fill', 'shadow', 'casing', 'stroke', 'text', 'hit', 'halo', 'label']); + .data(['fill', 'shadow', 'casing', 'stroke', 'oneway', 'hit', 'halo', 'label']); layers.enter().append('g') .attr('class', function(d) { return 'layer layer-' + d; });