From 45ddfc406620dfdec3e55c1494ef9cf3daf1478c Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Sat, 27 Oct 2012 13:56:22 -0400 Subject: [PATCH] Cache bounds and be smarter about reassigning marker properties --- js/iD/Way.js | 8 +++++++- js/iD/renderer/Map.js | 8 +++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/js/iD/Way.js b/js/iD/Way.js index f16ec7a06..96f7c1340 100644 --- a/js/iD/Way.js +++ b/js/iD/Way.js @@ -32,6 +32,7 @@ iD.Way.prototype = { addNode: function(node) { node.entity.addParent(this); this.nodes.push(node); + this._bounds = null; return this; }, @@ -63,9 +64,14 @@ iD.Way.prototype = { }; }, + updateBounds: function() { + this._bounds = d3.geo.bounds(this.toGeoJSON()); + }, + bounds: function() { // TODO: cache - return d3.geo.bounds(this.toGeoJSON()); + if (!this._bounds) this.updateBounds(); + return this._bounds; }, // --------------------- diff --git a/js/iD/renderer/Map.js b/js/iD/renderer/Map.js index a83d41574..13085494e 100755 --- a/js/iD/renderer/Map.js +++ b/js/iD/renderer/Map.js @@ -261,10 +261,12 @@ iD.Map = function(obj) { .attr('class', classes('stroke')); markers.enter().append('image') - .on('click', selectClick); - markers.attr('class', classes('marker')) + .attr('class', classes('marker')) + .on('click', selectClick) .attr({ width: 16, height: 16 }) - .attr('xlink:href', markerimage) + .attr('xlink:href', markerimage); + + markers .attr('transform', function(d) { return 'translate(' + projection(d) + ')'; });