mirror of
https://github.com/FoggedLens/iD.git
synced 2026-04-30 07:27:54 +02:00
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
iD.svg.Midpoints = function() {
|
|
return function(surface, graph, entities, filter, projection) {
|
|
var midpoints = [];
|
|
|
|
for (var i = 0; i < entities.length; i++) {
|
|
var entity = entities[i];
|
|
|
|
if (entity.type !== 'way')
|
|
continue;
|
|
|
|
for (var j = 0; j < entity.nodes.length - 1; j++) {
|
|
if (iD.util.geo.dist(entity.nodes[j].loc, entity.nodes[j + 1].loc) > 0.0001) {
|
|
midpoints.push({
|
|
loc: iD.util.geo.interp(entity.nodes[j].loc, entity.nodes[j + 1].loc, 0.5),
|
|
way: entity.id,
|
|
index: j + 1,
|
|
midpoint: true
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
var handles = surface.select('.layer-hit').selectAll('circle.midpoint')
|
|
.filter(filter)
|
|
.data(midpoints, function (d) { return [d.way, d.index].join(","); });
|
|
|
|
handles.enter()
|
|
.append('circle')
|
|
.attr({ r: 3, 'class': 'midpoint' });
|
|
|
|
handles.attr('transform', iD.svg.PointTransform(projection));
|
|
|
|
handles.exit()
|
|
.remove();
|
|
};
|
|
};
|