From 67d95595baeff14d55b991353e28d56bcbdb0420 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 20 May 2013 11:24:04 -0700 Subject: [PATCH] Points always need full re-render (#569) --- js/id/id.js | 1 + js/id/renderer/map.js | 2 +- js/id/svg/points.js | 31 ++++++++++++++++++++----------- test/spec/svg/points.js | 8 +++----- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/js/id/id.js b/js/id/id.js index 199fab231..f43f44d1e 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -147,6 +147,7 @@ window.iD = function () { context.surface = function() { return map.surface; }; context.mouse = map.mouse; context.projection = map.projection; + context.extent = map.extent; context.redraw = map.redraw; context.pan = map.pan; context.zoomIn = map.zoomIn; diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index 08c1ad4f8..1b7ac2595 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -139,7 +139,7 @@ iD.Map = function(context) { } surface - .call(points, graph, all, filter) + .call(points) .call(vertices, graph, all, filter, map.extent(), map.zoom()) .call(lines, graph, all, filter) .call(areas, graph, all, filter) diff --git a/js/id/svg/points.js b/js/id/svg/points.js index ba27e1544..1c0ce9f2c 100644 --- a/js/id/svg/points.js +++ b/js/id/svg/points.js @@ -10,15 +10,8 @@ iD.svg.Points = function(projection, context) { return b.loc[1] - a.loc[1]; } - return function drawPoints(surface, graph, entities, filter) { - var points = []; - - for (var i = 0; i < entities.length; i++) { - var entity = entities[i]; - if (entity.geometry(graph) === 'point') { - points.push(entity); - } - } + function drawPoints(surface, points) { + points = points || drawPoints.points(); if (points.length > 100) { return surface.select('.layer-hit').selectAll('g.point').remove(); @@ -27,7 +20,6 @@ iD.svg.Points = function(projection, context) { points.sort(sortY); var groups = surface.select('.layer-hit').selectAll('g.point') - .filter(filter) .data(points, iD.Entity.key); var group = groups.enter() @@ -55,11 +47,28 @@ iD.svg.Points = function(projection, context) { groups.select('.stroke'); groups.select('.icon') .attr('xlink:href', function(entity) { - var preset = context.presets().match(entity, graph); + var preset = context.presets().match(entity, context.graph()); return preset.icon ? '#maki-' + preset.icon + '-12' : ''; }); groups.exit() .remove(); + } + + drawPoints.points = function() { + var graph = context.graph(), + entities = context.intersects(context.extent()), + points = []; + + for (var i = 0; i < entities.length; i++) { + var entity = entities[i]; + if (entity.geometry(graph) === 'point') { + points.push(entity); + } + } + + return points; }; + + return drawPoints; }; diff --git a/test/spec/svg/points.js b/test/spec/svg/points.js index 39cedbe8b..71c59fcc4 100644 --- a/test/spec/svg/points.js +++ b/test/spec/svg/points.js @@ -1,20 +1,18 @@ describe("iD.svg.Points", function () { var surface, projection = Object, - filter = d3.functor(true), context; beforeEach(function () { context = iD(); surface = d3.select(document.createElementNS('http://www.w3.org/2000/svg', 'svg')) - .call(iD.svg.Surface(iD())); + .call(iD.svg.Surface(context)); }); it("adds tag classes", function () { - var node = iD.Node({tags: {amenity: "cafe"}, loc: [0, 0], _poi: true}), - graph = iD.Graph([node]); + var point = iD.Node({tags: {amenity: "cafe"}, loc: [0, 0]}); - surface.call(iD.svg.Points(projection, context), graph, [node], filter); + surface.call(iD.svg.Points(projection, context), [point]); expect(surface.select('.point')).to.be.classed('tag-amenity'); expect(surface.select('.point')).to.be.classed('tag-amenity-cafe');