mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
First shot at way accuracy handles
This commit is contained in:
@@ -24,6 +24,13 @@ image.handle {
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
circle.accuracy-handle {
|
||||
fill:#DF2D2D;
|
||||
stroke:#DF2D2D;
|
||||
fill-opacity:0.2;
|
||||
stroke-width:1;
|
||||
}
|
||||
|
||||
circle.teaser-point {
|
||||
stroke-width: 2;
|
||||
stroke:#1DCAFF;
|
||||
|
||||
@@ -8,12 +8,8 @@ iD.modes._node = function(ll) {
|
||||
});
|
||||
};
|
||||
|
||||
iD.modes.dist = function(a, b) {
|
||||
return Math.sqrt(Math.pow(a[0] - b[0], 2) + Math.pow(a[1] - b[1], 2));
|
||||
};
|
||||
|
||||
iD.modes.chooseIndex = function(way, point, map) {
|
||||
var dist = iD.modes.dist;
|
||||
var dist = iD.Util.dist;
|
||||
var projNodes = way.nodes.map(function(n) {
|
||||
return map.projection([n.lon, n.lat]);
|
||||
});
|
||||
|
||||
@@ -16,6 +16,13 @@ iD.Map = function() {
|
||||
dblclickEnabled = true,
|
||||
dragbehavior = d3.behavior.drag()
|
||||
.origin(function(entity) {
|
||||
if (entity.accuracy) {
|
||||
var index = entity.index, wayid = entity.way;
|
||||
entity = iD.Node(entity);
|
||||
var connectedWay = map.history.graph().entity(wayid);
|
||||
connectedWay.nodes.splice(index, 0, entity.id);
|
||||
map.perform(iD.actions.addWayNode(connectedWay, entity));
|
||||
}
|
||||
var p = projection(ll2a(entity));
|
||||
only = iD.Util.trueObj([entity.id].concat(
|
||||
_.pluck(map.history.graph().parents(entity.id), 'id')));
|
||||
@@ -143,13 +150,29 @@ iD.Map = function() {
|
||||
waynodes.push(a);
|
||||
}
|
||||
}
|
||||
var wayAccuracyHandles = ways.reduce(function(mem, w) {
|
||||
return mem.concat(accuracyHandles(w));
|
||||
}, []);
|
||||
drawHandles(waynodes, filter);
|
||||
drawAccuracyHandles(wayAccuracyHandles, filter);
|
||||
drawCasings(ways, filter);
|
||||
drawFills(areas, filter);
|
||||
drawStrokes(ways, filter);
|
||||
drawMarkers(points, filter);
|
||||
}
|
||||
|
||||
function accuracyHandles(way) {
|
||||
var handles = [];
|
||||
for (var i = 0; i < way.nodes.length - 1; i++) {
|
||||
handles[i] = iD.Node(iD.Util.interp(way.nodes[i], way.nodes[i + 1], 0.5));
|
||||
handles[i].way = way.id;
|
||||
handles[i].index = i + 1;
|
||||
handles[i].accuracy = true;
|
||||
handles[i].tags = { name: 'Improve way accuracy' };
|
||||
}
|
||||
return handles;
|
||||
}
|
||||
|
||||
function drawHandles(waynodes, filter) {
|
||||
var handles = g.hit.selectAll('image.handle')
|
||||
.filter(filter)
|
||||
@@ -164,6 +187,20 @@ iD.Map = function() {
|
||||
}).classed('active', classActive);
|
||||
}
|
||||
|
||||
function drawAccuracyHandles(waynodes) {
|
||||
var handles = g.hit.selectAll('circle.accuracy-handle')
|
||||
.data(waynodes, key);
|
||||
console.log(handles);
|
||||
handles.exit().remove();
|
||||
handles.enter().append('circle')
|
||||
.attr({ r: 2, 'class': 'accuracy-handle' })
|
||||
.call(dragbehavior);
|
||||
handles.attr('transform', function(entity) {
|
||||
var p = projection(ll2a(entity));
|
||||
return 'translate(' + [~~p[0], ~~p[1]] + ')';
|
||||
}).classed('active', classActive);
|
||||
}
|
||||
|
||||
function hideVector() {
|
||||
surface.selectAll('.layer-g *').remove();
|
||||
}
|
||||
|
||||
@@ -55,3 +55,14 @@ iD.Util.qsString = function(obj) {
|
||||
return encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]);
|
||||
}).join('&');
|
||||
};
|
||||
|
||||
iD.Util.interp = function(p1, p2, t) {
|
||||
return {
|
||||
lon: p1.lon + (p2.lon - p1.lon) * t,
|
||||
lat: p1.lat + (p2.lat - p1.lat) * t
|
||||
};
|
||||
};
|
||||
|
||||
iD.Util.dist = function(a, b) {
|
||||
return Math.sqrt(Math.pow(a[0] - b[0], 2) + Math.pow(a[1] - b[1], 2));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user