From e154a94ef0225a556e81a9ce0f464b8a85bb51c6 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sun, 17 Feb 2013 11:06:36 -0800 Subject: [PATCH] Draw only visible midpoints (#804) --- js/id/renderer/map.js | 2 +- js/id/svg/midpoints.js | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index d4c082fad..be4366355 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -89,7 +89,7 @@ iD.Map = function(context) { .call(vertices, graph, all, filter) .call(lines, graph, all, filter) .call(areas, graph, all, filter) - .call(midpoints, graph, all, filter) + .call(midpoints, graph, all, filter, extent) .call(labels, graph, all, filter, dimensions, !difference); } dispatch.drawn(map); diff --git a/js/id/svg/midpoints.js b/js/id/svg/midpoints.js index fc1a5bbc3..8dc6d09b9 100644 --- a/js/id/svg/midpoints.js +++ b/js/id/svg/midpoints.js @@ -1,5 +1,5 @@ iD.svg.Midpoints = function(projection) { - return function drawMidpoints(surface, graph, entities, filter) { + return function drawMidpoints(surface, graph, entities, filter, extent) { var midpoints = {}; if (!surface.select('.layer-hit g.vertex').node()) { @@ -22,13 +22,16 @@ iD.svg.Midpoints = function(projection) { if (midpoints[id]) { midpoints[id].ways.push({id: entity.id, index: j + 1}); - } else if (iD.geo.dist(projection(a.loc), projection(b.loc)) > 40) { - midpoints[id] = { - type: 'midpoint', - id: id, - loc: iD.geo.interp(a.loc, b.loc, 0.5), - ways: [{id: entity.id, index: j + 1}] - }; + } else { + var loc = iD.geo.interp(a.loc, b.loc, 0.5); + if (extent.intersects(loc) && iD.geo.dist(projection(a.loc), projection(b.loc)) > 40) { + midpoints[id] = { + type: 'midpoint', + id: id, + loc: loc, + ways: [{id: entity.id, index: j + 1}] + }; + } } } }