From 20766160633a26d69c80a00cc1b23364f09de824 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 13 Nov 2012 17:53:06 -0500 Subject: [PATCH] Always-on handles, start intersecting elements again, fetch elements early --- css/map.css | 8 ++++---- index.html | 2 -- js/iD/graph/Graph.js | 19 ++++++++++++++++++- js/iD/graph/Way.js | 2 +- js/iD/renderer/Map.js | 26 +++++++++++++++----------- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/css/map.css b/css/map.css index 53b6bca07..d9d858359 100644 --- a/css/map.css +++ b/css/map.css @@ -20,11 +20,11 @@ g.marker.active circle { } /* interactive elements */ -circle.handle { +rect.handle { cursor: move; - stroke-width: 2; - fill:#000; - stroke:#FFF694; + stroke-width: 1; + stroke:#000; + fill:#FFF694; } circle.teaser-point { diff --git a/index.html b/index.html index 3bc776320..b8e54bd20 100755 --- a/index.html +++ b/index.html @@ -69,9 +69,7 @@ }); var m = d3.select('#map'); - iD.Hash().map(map); - var controller = iD.Controller(map); d3.selectAll('button#place').on('click', function() { diff --git a/js/iD/graph/Graph.js b/js/iD/graph/Graph.js index 371d267d2..e179fa249 100644 --- a/js/iD/graph/Graph.js +++ b/js/iD/graph/Graph.js @@ -30,8 +30,25 @@ iD.Graph.prototype = { // get all objects that intersect an extent. intersects: function(extent) { var items = []; + function nodeIntersect(entity) { + return entity.lon > extent[0][0] && + entity.lon < extent[1][0] && + entity.lat < extent[0][1] && + entity.lat > extent[1][1]; + } for (var i in this.entities) { - if (this.entities[i]) items.push(this.entities[i]); + var entity = this.entities[i]; + if (entity.type === 'node' && nodeIntersect(entity)) { + items.push(entity); + } else if (entity.type === 'way') { + var w = this.fetch(entity.id); + for (var j = 0; j < w.nodes.length; j++) { + if (nodeIntersect(w.nodes[j])) { + items.push(w); + break; + } + } + } } return items; }, diff --git a/js/iD/graph/Way.js b/js/iD/graph/Way.js index 3a8b2b5bb..c6d1f6dbc 100644 --- a/js/iD/graph/Way.js +++ b/js/iD/graph/Way.js @@ -9,6 +9,6 @@ iD.Way = { isClosed: function(w) { - return (!w.nodes.length) || w.nodes[w.nodes.length - 1] === w.nodes[0]; + return (!w.nodes.length) || w.nodes[w.nodes.length - 1].id === w.nodes[0].id; } }; diff --git a/js/iD/renderer/Map.js b/js/iD/renderer/Map.js index 9498fd777..c68a1b5fd 100755 --- a/js/iD/renderer/Map.js +++ b/js/iD/renderer/Map.js @@ -56,14 +56,11 @@ iD.Map = function(elem) { }), // geo linegen = d3.svg.line() - .defined(function(d) { - return !!history.entity(d); - }) .x(function(d) { - return projection(ll2a(history.entity(d)))[0]; + return projection(ll2a(d))[0]; }) .y(function(d) { - return projection(ll2a(history.entity(d)))[1]; + return projection(ll2a(d))[1]; }), // Abstract linegen so that it pulls from `.children`. This // makes it possible to call simply `.attr('d', nodeline)`. @@ -189,16 +186,23 @@ iD.Map = function(elem) { return 'translate(' + pt + ')'; }); - var handles = hit_g.selectAll('circle.handle') - .data(active_entity ? graph.fetch(active_entity.id).nodes : []); + var handles = hit_g.selectAll('rect.handle') + // TODO: this could be faster + .data(areas.reduce(function(memo, w) { + return memo.concat(w.nodes); + }, ways.reduce(function(memo, w) { + return memo.concat(w.nodes); + }, [])), key); handles.exit().remove(); - handles.enter().append('circle') - .attr('class', 'handle') - .attr('r', 3) + handles.enter().append('rect') + .attr({width: 4, height: 4, 'class': 'handle'}) .call(dragbehavior); handles.attr('transform', function(entity) { - return 'translate(' + projection(ll2a(entity)) + ')'; + var p = projection(ll2a(entity)); + p[0] -= 2; + p[1] -= 2; + return 'translate(' + p + ') rotate(45, 2, 2)'; }); }