From bd1a34153ab91de97b57bf5589cd852672cd4cb8 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 3 Dec 2012 17:08:53 -0500 Subject: [PATCH] First shot at way accuracy handles --- css/map.css | 7 +++++++ js/id/actions/modes.js | 6 +----- js/id/renderer/map.js | 37 +++++++++++++++++++++++++++++++++++++ js/id/util.js | 11 +++++++++++ 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/css/map.css b/css/map.css index addce6fbf..06eb66c2e 100644 --- a/css/map.css +++ b/css/map.css @@ -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; diff --git a/js/id/actions/modes.js b/js/id/actions/modes.js index b7072f136..7a94e21c7 100644 --- a/js/id/actions/modes.js +++ b/js/id/actions/modes.js @@ -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]); }); diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index cee9ab0eb..aa242f820 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -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(); } diff --git a/js/id/util.js b/js/id/util.js index b0ded6130..4e4b1fce5 100644 --- a/js/id/util.js +++ b/js/id/util.js @@ -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)); +};