Files
iD/js/id/svg/points.js
2013-03-26 13:38:17 -04:00

67 lines
2.0 KiB
JavaScript

iD.svg.Points = function(projection, context) {
function markerPath(selection, klass) {
selection
.attr('class', klass)
.attr('transform', 'translate(-8, -23)')
.attr('d', 'M 17,8 C 17,13 11,21 8.5,23.5 C 6,21 0,13 0,8 C 0,4 4,-0.5 8.5,-0.5 C 13,-0.5 17,4 17,8 z');
}
function sortY(a, b) {
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);
}
}
if (points.length > 100) {
return surface.select('.layer-hit').selectAll('g.point').remove();
}
points.sort(sortY);
var groups = surface.select('.layer-hit').selectAll('g.point')
.filter(filter)
.data(points, iD.Entity.key);
var group = groups.enter()
.append('g')
.attr('class', 'node point')
.order();
group.append('path')
.call(markerPath, 'shadow');
group.append('path')
.call(markerPath, 'stroke');
group.append('use')
.attr('class', 'icon')
.attr('transform', 'translate(-6, -20)')
.attr('clip-path', 'url(#clip-square-12)');
groups.attr('transform', iD.svg.PointTransform(projection))
.call(iD.svg.TagClasses())
.call(iD.svg.MemberClasses(graph));
// Selecting the following implicitly
// sets the data (point entity) on the element
groups.select('.shadow');
groups.select('.stroke');
groups.select('.icon')
.attr('xlink:href', function(entity) {
var preset = context.presets().match(entity, graph);
return preset.icon ? '#maki-' + preset.icon + '-12' : '';
});
groups.exit()
.remove();
};
};