From 1cfeba3da4a3dcd282a6894bbd69d73fc8f47240 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 16 May 2013 15:28:24 -0700 Subject: [PATCH] Don't draw offscreen vertices (fixes #1494) --- js/id/renderer/map.js | 8 ++++---- js/id/svg/vertices.js | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index 1394c75a0..60dd6ef36 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -62,7 +62,7 @@ iD.Map = function(context) { surface.on('mouseover.vertices', function() { if (map.editable() && !transformed) { var hover = d3.event.target.__data__; - surface.call(vertices.drawHover, context.graph(), hover, map.zoom()); + surface.call(vertices.drawHover, context.graph(), hover, map.extent(), map.zoom()); dispatch.drawn(map); } }); @@ -70,7 +70,7 @@ iD.Map = function(context) { surface.on('mouseout.vertices', function() { if (map.editable() && !transformed) { var hover = d3.event.relatedTarget && d3.event.relatedTarget.__data__; - surface.call(vertices.drawHover, context.graph(), hover, map.zoom()); + surface.call(vertices.drawHover, context.graph(), hover, map.extent(), map.zoom()); dispatch.drawn(map); } }); @@ -81,7 +81,7 @@ iD.Map = function(context) { filter = d3.functor(true), extent = map.extent(), graph = context.graph(); - surface.call(vertices, graph, all, filter, map.zoom()); + surface.call(vertices, graph, all, filter, extent, map.zoom()); surface.call(midpoints, graph, all, filter, extent); dispatch.drawn(map); } @@ -138,7 +138,7 @@ iD.Map = function(context) { } else { surface .call(points, graph, all, filter) - .call(vertices, graph, all, filter, map.zoom()) + .call(vertices, graph, all, filter, extent, map.zoom()) .call(lines, graph, all, filter) .call(areas, graph, all, filter) .call(midpoints, graph, all, filter, extent) diff --git a/js/id/svg/vertices.js b/js/id/svg/vertices.js index f1179fc4e..64f8acf8e 100644 --- a/js/id/svg/vertices.js +++ b/js/id/svg/vertices.js @@ -8,14 +8,14 @@ iD.svg.Vertices = function(projection, context) { var hover; - function siblingAndChildVertices(ids, graph) { + function siblingAndChildVertices(ids, graph, extent) { var vertices = {}; function addChildVertices(entity) { var i; if (entity.type === 'way') { for (i = 0; i < entity.nodes.length; i++) { - vertices[entity.nodes[i]] = graph.entity(entity.nodes[i]); + addChildVertices(graph.entity(entity.nodes[i])); } } else if (entity.type === 'relation') { for (i = 0; i < entity.members.length; i++) { @@ -24,7 +24,7 @@ iD.svg.Vertices = function(projection, context) { addChildVertices(member); } } - } else { + } else if (entity.intersects(extent, graph)) { vertices[entity.id] = entity; } } @@ -107,8 +107,8 @@ iD.svg.Vertices = function(projection, context) { .remove(); } - function drawVertices(surface, graph, entities, filter, zoom) { - var selected = siblingAndChildVertices(context.selection(), graph), + function drawVertices(surface, graph, entities, filter, extent, zoom) { + var selected = siblingAndChildVertices(context.selection(), graph, extent), vertices = []; for (var i = 0; i < entities.length; i++) { @@ -131,8 +131,8 @@ iD.svg.Vertices = function(projection, context) { drawHover(surface, graph, zoom); } - function drawHover(surface, graph, zoom) { - var hovered = hover ? siblingAndChildVertices([hover.id], graph) : {}; + function drawHover(surface, graph, extent, zoom) { + var hovered = hover ? siblingAndChildVertices([hover.id], graph, extent) : {}; surface.select('.layer-hit').selectAll('g.vertex.vertex-hover') .call(draw, d3.values(hovered), 'vertex-hover', graph, zoom);