Cache bounds and be smarter about reassigning marker properties

This commit is contained in:
Tom MacWright
2012-10-27 13:56:22 -04:00
parent 89c61fbae4
commit 45ddfc4066
2 changed files with 12 additions and 4 deletions

View File

@@ -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;
},
// ---------------------

View File

@@ -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) + ')';
});