From affb49e3bae9d6186d0d508f03456579bc9bc080 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Thu, 1 Nov 2012 11:22:51 -0400 Subject: [PATCH] Optimize tiling, turn opacity back up on tiles --- css/map.css | 1 - js/iD/Connection.js | 4 ++-- js/iD/Graph.js | 2 ++ js/iD/renderer/Map.js | 4 +++- js/iD/renderer/tiles.js | 44 +++++++++++++++-------------------------- 5 files changed, 23 insertions(+), 32 deletions(-) diff --git a/css/map.css b/css/map.css index 47e28f5df..22b998f9f 100644 --- a/css/map.css +++ b/css/map.css @@ -1,5 +1,4 @@ image.tile { - opacity:0.6; } /* base styles */ diff --git a/js/iD/Connection.js b/js/iD/Connection.js index 76279ec65..ccb23e2f9 100755 --- a/js/iD/Connection.js +++ b/js/iD/Connection.js @@ -7,13 +7,13 @@ iD.Connection = function(graph) { var connection = {}; function all() { - return d3.values(graph.index); + return graph.nodes; } function intersects(extent) { // summary: Find all drawable entities that are within a given bounding box. // Each one is an array of entities. - return d3.values(graph.index).filter(function(e, id) { + return graph.nodes.filter(function(e, id) { return e.intersects(extent); }); } diff --git a/js/iD/Graph.js b/js/iD/Graph.js index 0de3884b9..fab7c61bf 100644 --- a/js/iD/Graph.js +++ b/js/iD/Graph.js @@ -1,5 +1,6 @@ iD.Graph = function() { this.index = {}; + this.nodes = []; }; iD.Graph.prototype = { @@ -24,6 +25,7 @@ iD.Graph.prototype = { } if (obj && (!this.index[obj.id] || !this.index[obj.id].loaded)) { this.index[obj.id] = obj; + this.nodes.push(obj); } }, diff --git a/js/iD/renderer/Map.js b/js/iD/renderer/Map.js index a6e44ed47..c7c277926 100755 --- a/js/iD/renderer/Map.js +++ b/js/iD/renderer/Map.js @@ -241,7 +241,9 @@ iD.Map = function(parentSelector) { dispatch.move(map); tileclient.redraw(); drawVector(); - download(); + if (getZoom() > 13) { + download(); + } } function getCenter() { diff --git a/js/iD/renderer/tiles.js b/js/iD/renderer/tiles.js index 1150e765f..4402953ee 100644 --- a/js/iD/renderer/tiles.js +++ b/js/iD/renderer/tiles.js @@ -2,29 +2,7 @@ iD.Tiles = function(selection, projection, width, height) { var tiles = {}; - function tilesForView() { - var t = projection.translate(), - s = projection.scale(), - z = Math.max(Math.log(s) / Math.log(2) - 8, 0); - rz = Math.floor(z), - ts = 256 * Math.pow(2, z - rz); - - // This is the 0, 0 px of the projection - var tile_origin = [s / 2 - t[0], s / 2 - t[1]], - coords = [], - cols = d3.range(Math.max(0, Math.floor((tile_origin[0] - width) / ts)), - Math.max(0, Math.ceil((tile_origin[0] + width) / ts))), - rows = d3.range(Math.max(0, Math.floor((tile_origin[1] - height) / ts)), - Math.max(0, Math.ceil((tile_origin[1] + height) / ts))); - - cols.forEach(function(x) { - rows.forEach(function(y) { coords.push([Math.floor(z), x, y, Math.floor(z) + '-' + x + '-' + y]); }); - }); - return coords; - } - function tileUrl(coord) { - var tmpl = 'http://ecn.t0.tiles.virtualearth.net/tiles/a$quadkey.jpeg?g=587&mkt=en-gb&n=z'; var u = ''; for (var zoom = coord[0]; zoom > 0; zoom--) { var byte = 0; @@ -33,7 +11,7 @@ iD.Tiles = function(selection, projection, width, height) { if ((coord[2] & mask) !== 0) byte += 2; u += byte.toString(); } - return tmpl.replace('$quadkey', u); + return 'http://ecn.t0.tiles.virtualearth.net/tiles/a' + u + '.jpeg?g=587&mkt=en-gb&n=z'; } function redraw() { @@ -45,7 +23,17 @@ iD.Tiles = function(selection, projection, width, height) { // This is the 0, 0 px of the projection var tile_origin = [s / 2 - t[0], s / 2 - t[1]], - coords = tilesForView(projection); + coords = [], + cols = d3.range(Math.max(0, Math.floor((tile_origin[0] - width) / ts)), + Math.max(0, Math.ceil((tile_origin[0] + width) / ts))), + rows = d3.range(Math.max(0, Math.floor((tile_origin[1] - height) / ts)), + Math.max(0, Math.ceil((tile_origin[1] + height) / ts))); + + cols.forEach(function(x) { + rows.forEach(function(y) { + coords.push([Math.floor(z), x, y, Math.floor(z) + '-' + x + '-' + y]); + }); + }); var tiles = selection.selectAll('image.tile') .data(coords, function(d) { return d[3]; }); @@ -56,10 +44,10 @@ iD.Tiles = function(selection, projection, width, height) { .attr('xlink:href', tileUrl); tiles.attr({ width: Math.ceil(ts), height: Math.ceil(ts) }) .attr('transform', function(d) { - return 'translate(' + [ - Math.round((d[1] * ts) - tile_origin[0]), - Math.round((d[2] * ts) - tile_origin[1]) - ] + ')'; + return 'translate(' + + Math.round((d[1] * ts) - tile_origin[0]) + ',' + + Math.round((d[2] * ts) - tile_origin[1]) + + ')'; }); }