From 89dded99670516d0fcecedf8e3cc45cda86684ea Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 12 Nov 2012 17:36:23 -0500 Subject: [PATCH] Improve poi finding performance, update map style --- css/map.css | 6 +++--- index.html | 4 ++-- js/iD/Connection.js | 5 ++++- js/iD/graph/Graph.js | 18 ---------------- js/iD/renderer/Map.js | 50 +++++++++++-------------------------------- 5 files changed, 22 insertions(+), 61 deletions(-) diff --git a/css/map.css b/css/map.css index af8c90116..238d55e26 100644 --- a/css/map.css +++ b/css/map.css @@ -10,9 +10,9 @@ path, image.marker { /* interactive elements */ circle.handle { cursor: move; - stroke-width: 2; - stroke:#1DCAFF; - fill:#D3F5FF; + stroke-width: 3; + fill:#000; + stroke:#FFF694; } circle.teaser-point { diff --git a/index.html b/index.html index 5b37bca91..32d27cc25 100755 --- a/index.html +++ b/index.html @@ -15,7 +15,7 @@ + Place
@@ -30,7 +30,7 @@ Imagery © 2012 Bing, GeoEye, Getmapping, Intermap, Microsoft.

- + diff --git a/js/iD/Connection.js b/js/iD/Connection.js index ffc35e786..79743ef43 100755 --- a/js/iD/Connection.js +++ b/js/iD/Connection.js @@ -1,7 +1,7 @@ iD.Connection = function() { var apiURL = 'http://www.openstreetmap.org/api/0.6/'; - var connection = {}; + var connection = {}, refNodes = {}; // Request data within the bbox from an external OSM server. function bboxFromAPI(box, callback) { @@ -22,6 +22,7 @@ iD.Connection = function() { var nodes = [], nelems = obj.getElementsByTagName('nd'); for (var i = 0, l = nelems.length; i < l; i++) { nodes[i] = 'n' + nelems[i].attributes.ref.nodeValue; + refNodes['n' + nelems[i].attributes.ref.nodeValue] = true; } return nodes; } @@ -86,8 +87,10 @@ iD.Connection = function() { if (!dom.childNodes) return callback(new Error('Bad request')); var root = dom.childNodes[0]; var entities = {}; + refNodes = {}; var addEntity = function (obj) { var o = objectData(obj); + if (o.type === 'node') o._poi = !refNodes[o.id]; entities[o.id] = o; }; diff --git a/js/iD/graph/Graph.js b/js/iD/graph/Graph.js index 4fd2b56df..371d267d2 100644 --- a/js/iD/graph/Graph.js +++ b/js/iD/graph/Graph.js @@ -9,24 +9,6 @@ iD.Graph.prototype = { return this.entities[id]; }, - // get all points that are not part of a way. this is an expensive - // call that needs to be optimized. - pois: function() { - var included = [], pois = [], idx = {}; - for (var i in this.entities) { - if (this.entities[i].nodes) { - included = included.concat(this.entities[i].nodes); - } - } - for (var j = 0; j < included.length; j++) { idx[included[j]] = true; } - for (var k in this.entities) { - if (this.entities[k].type === 'node' && !idx[this.entities[k].id]) { - pois.push(this.entities[k]); - } - } - return pois; - }, - merge: function(graph) { var entities = _.clone(this.entities); _.defaults(entities, graph.entities); diff --git a/js/iD/renderer/Map.js b/js/iD/renderer/Map.js index fadb877d3..da8a84e9d 100755 --- a/js/iD/renderer/Map.js +++ b/js/iD/renderer/Map.js @@ -108,16 +108,18 @@ iD.Map = function(elem) { var graph = history.graph(), all = graph.intersects(getExtent()); - var ways = all.filter(function(a) { - return a.type === 'way' && !iD.Way.isClosed(a); - }).map(function(x) { - x._line = nodeline(x); - return x; - }).sort(iD.Style.waystack), - areas = all.filter(function(a) { - return a.type === 'way' && iD.Way.isClosed(a); - }), - points = graph.pois(); + var ways = [], areas = [], points = []; + + for (var i = 0; i < all.length; i++) { + var a = all[i]; + if (a.type === 'way') { + a._line = nodeline(a); + if (!iD.Way.isClosed(a)) ways.push(a); + else areas.push(a); + } else if (a._poi) { + points.push(a); + } + } var fills = fill_g.selectAll('path.area').data(areas, key), casings = casing_g.selectAll('path.casing').data(ways, key), @@ -229,44 +231,18 @@ iD.Map = function(elem) { map.operate(iD.operations.remove(d)); }); - var fastTranslate = [0,0]; - function zoomPan() { - var translate; - var fast = projection.scale() === d3.event.scale; - if (fast) { - fastTranslate[0] -= projection.translate()[0] - d3.event.translate[0]; - fastTranslate[1] -= projection.translate()[1] - d3.event.translate[1]; - } projection .translate(d3.event.translate) .scale(d3.event.scale); - if (fast) { - fastRedraw(); - } else { - redraw(); - } - } - - // Slow redraw - going out of turbo mode. - var slowDraw = _.debounce(function() { - fastTranslate = [0,0]; redraw(); - r.attr('transform', ''); - }, 500); - - function fastRedraw(translate) { - dispatch.move(map); - tileclient.redraw(); - r.attr('transform', 'translate(' + fastTranslate + ')'); - slowDraw(); + download(); } function redraw() { dispatch.move(map); tileclient.redraw(); if (getZoom() > 13) { - download(); drawVector(); } else { // TODO: hide vector features