Optimize tiling, turn opacity back up on tiles

This commit is contained in:
Tom MacWright
2012-11-01 11:22:51 -04:00
parent 2e39f47d36
commit affb49e3ba
5 changed files with 23 additions and 32 deletions

View File

@@ -1,5 +1,4 @@
image.tile {
opacity:0.6;
}
/* base styles */

View File

@@ -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);
});
}

View File

@@ -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);
}
},

View File

@@ -241,7 +241,9 @@ iD.Map = function(parentSelector) {
dispatch.move(map);
tileclient.redraw();
drawVector();
download();
if (getZoom() > 13) {
download();
}
}
function getCenter() {

View File

@@ -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]) +
')';
});
}