mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-21 15:56:56 +02:00
Set vertex attributes on update selection not enter (re: 01ca07f)
This commit is contained in:
+44
-20
@@ -44,11 +44,7 @@ iD.svg.Vertices = function(projection, context) {
|
||||
return vertices;
|
||||
}
|
||||
|
||||
function draw(groups, vertices, klass, graph, zoom) {
|
||||
groups = groups.data(vertices, function(entity) {
|
||||
return iD.Entity.key(entity) + ',' + zoom;
|
||||
});
|
||||
|
||||
function draw(selection, vertices, klass, graph, zoom) {
|
||||
var icons = {},
|
||||
z;
|
||||
|
||||
@@ -60,6 +56,10 @@ iD.svg.Vertices = function(projection, context) {
|
||||
z = 2;
|
||||
}
|
||||
|
||||
var groups = selection.data(vertices, function(entity) {
|
||||
return iD.Entity.key(entity);
|
||||
});
|
||||
|
||||
function icon(entity) {
|
||||
if (entity.id in icons) return icons[entity.id];
|
||||
icons[entity.id] =
|
||||
@@ -68,27 +68,50 @@ iD.svg.Vertices = function(projection, context) {
|
||||
return icons[entity.id];
|
||||
}
|
||||
|
||||
function circle(klass) {
|
||||
var rads = radiuses[klass];
|
||||
function classCircle(klass) {
|
||||
return function(entity) {
|
||||
var i = icon(entity),
|
||||
c = i ? 0.5 : 0,
|
||||
r = rads[i ? 3 : z];
|
||||
this.setAttribute('class', 'node vertex ' + klass + ' ' + entity.id);
|
||||
this.setAttribute('cx', c);
|
||||
this.setAttribute('cy', -c);
|
||||
this.setAttribute('r', r);
|
||||
};
|
||||
}
|
||||
|
||||
var enter = groups.enter().append('g')
|
||||
function setAttributes(selection) {
|
||||
['shadow','stroke','fill'].forEach(function(klass) {
|
||||
var rads = radiuses[klass];
|
||||
selection.selectAll('.' + klass)
|
||||
.each(function(entity) {
|
||||
var i = z && icon(entity),
|
||||
c = i ? 0.5 : 0,
|
||||
r = rads[i ? 3 : z];
|
||||
this.setAttribute('cx', c);
|
||||
this.setAttribute('cy', -c);
|
||||
this.setAttribute('r', r);
|
||||
if (i && klass === 'fill') {
|
||||
this.setAttribute('visibility', 'hidden');
|
||||
} else {
|
||||
this.removeAttribute('visibility');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
selection.selectAll('use')
|
||||
.each(function() {
|
||||
if (z) {
|
||||
this.removeAttribute('visibility');
|
||||
} else {
|
||||
this.setAttribute('visibility', 'hidden');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var enter = groups.enter()
|
||||
.append('g')
|
||||
.attr('class', function(d) { return 'node vertex ' + klass + ' ' + d.id; });
|
||||
|
||||
enter.append('circle')
|
||||
.each(circle('shadow'));
|
||||
.each(classCircle('shadow'));
|
||||
|
||||
enter.append('circle')
|
||||
.each(circle('stroke'));
|
||||
.each(classCircle('stroke'));
|
||||
|
||||
// Vertices with icons get a `use`.
|
||||
enter.filter(function(d) { return icon(d); })
|
||||
@@ -97,14 +120,15 @@ iD.svg.Vertices = function(projection, context) {
|
||||
.attr('clip-path', 'url(#clip-square-12)')
|
||||
.attr('xlink:href', function(d) { return '#maki-' + icon(d) + '-12'; });
|
||||
|
||||
// Vertices with tags get a `circle`.
|
||||
enter.filter(function(d) { return !icon(d) && d.hasInterestingTags(); })
|
||||
// Vertices with tags get a fill.
|
||||
enter.filter(function(d) { return d.hasInterestingTags(); })
|
||||
.append('circle')
|
||||
.each(circle('fill'));
|
||||
.each(classCircle('fill'));
|
||||
|
||||
groups
|
||||
.attr('transform', iD.svg.PointTransform(projection))
|
||||
.classed('shared', function(entity) { return graph.isShared(entity); });
|
||||
.classed('shared', function(entity) { return graph.isShared(entity); })
|
||||
.call(setAttributes);
|
||||
|
||||
groups.exit()
|
||||
.remove();
|
||||
|
||||
Reference in New Issue
Block a user