fix excessive note tiling and network request

This commit is contained in:
Thomas Hervey
2018-07-19 10:51:39 -04:00
parent c563abaf7a
commit 386d375b7a
5 changed files with 32 additions and 10 deletions
+4 -1
View File
@@ -84,7 +84,10 @@ function loadTiles(which, url, projection) {
var s = projection.scale() * 2 * Math.PI;
var currZoom = Math.floor(Math.max(Math.log(s) / Math.log(2) - 8, 0));
var tiles = geoTile.filterNullIsland(geoTile.getTiles(tileZoom, projection, projection.clipExtent()[1], 0));
var dimension = projection.clipExtent()[1];
var tiles = geoTile.getTiles(projection, dimension, tileZoom, 0);
tiles = geoTile.filterNullIsland(tiles);
geoTile.removeInflightRequests(which, tiles, abortRequest, ',0');
tiles.forEach(function(tile) {
+4 -1
View File
@@ -79,7 +79,10 @@ function loadTiles(which, url, projection) {
var s = projection.scale() * 2 * Math.PI,
currZoom = Math.floor(Math.max(Math.log(s) / Math.log(2) - 8, 0));
var tiles = geoTile.filterNullIsland(geoTile.getTiles(tileZoom, projection, projection.clipExtent()[1], 0));
var dimension = projection.clipExtent()[1];
var tiles = geoTile.getTiles(projection, dimension, tileZoom, 0);
tiles = geoTile.filterNullIsland(tiles);
geoTile.removeInflightRequests(which, tiles, abortRequest, ',0');
tiles.forEach(function(tile) {
+3 -3
View File
@@ -778,13 +778,13 @@ export default {
tilezoom = _tileZoom;
}
var tiles = geoTile.filterNullIsland(geoTile.getTiles(_tileZoom, projection, dimensions, 0));
// get tiles
var tiles = geoTile.getTiles(projection, dimensions, tilezoom, 0);
tiles = geoTile.filterNullIsland(tiles);
// remove inflight requests that no longer cover the view..
var hadRequests = !_isEmpty(cache.inflight);
geoTile.removeInflightRequests(cache, tiles, abortRequest);
if (hadRequests && !loadingNotes && _isEmpty(cache.inflight)) {
dispatch.call('loaded'); // stop the spinner
}
+3 -1
View File
@@ -94,7 +94,9 @@ function loadTiles(which, url, projection, margin) {
var s = projection.scale() * 2 * Math.PI;
var currZoom = Math.floor(Math.max(Math.log(s) / Math.log(2) - 8, 0));
var tiles = geoTile.filterNullIsland(geoTile.getTiles(tileZoom, projection, projection.clipExtent()[1], margin));
var dimension = projection.clipExtent()[1];
var tiles = geoTile.getTiles(projection, dimension, tileZoom, margin);
tiles = geoTile.filterNullIsland(tiles);
tiles.forEach(function (tile) {
loadNextTilePage(which, currZoom, url, tile);
+18 -4
View File
@@ -66,12 +66,14 @@ export function utilTile() {
return tiles;
}
/**
* getTiles() returns array of d3 geo tiles.
* Using d3.geo.tiles.js from lib, gets tile extents for each grid tile in a grid created from
* an area around (and including) the current map view extents.
*/
tile.getTiles = function(tileZoom, projection, dimensions, margin) {
tile.getTiles = function(projection, dimensions, tilezoom, margin) {
// s is the current map scale
// z is the 'Level of Detail', or zoom-level, where Level 1 is far from the earth, and Level 23 is close to the ground.
// ts ('tile size') here is the formula for determining the width/height of the map in pixels, but with a modification.
@@ -79,23 +81,24 @@ export function utilTile() {
// As used here, by subtracting constant 'tileZoom' from z (the level), you end up with a much smaller value for the tile size (in pixels).
var s = projection.scale() * 2 * Math.PI;
var z = Math.max(Math.log(s) / Math.log(2) - 8, 0);
var ts = 256 * Math.pow(2, z - tileZoom);
var ts = 256 * Math.pow(2, z - tilezoom);
var origin = [
s / 2 - projection.translate()[0],
s / 2 - projection.translate()[1]
];
var tiler = this
.scaleExtent([tileZoom, tileZoom])
.scaleExtent([tilezoom, tilezoom])
.scale(s)
.size(dimensions)
.translate(projection.translate())
.margin(margin || 0); // request nearby tiles so we can connect sequences.
return tiler()
var tiles = tiler()
.map(function(tile) {
var x = tile[0] * ts - origin[0];
var y = tile[1] * ts - origin[1];
return {
id: tile.toString(),
xyz: tile,
@@ -105,14 +108,18 @@ export function utilTile() {
)
};
});
return tiles;
};
tile.filterNullIsland = function(tiles) {
return tiles.filter(function(t) {
return !nearNullIsland(t.xyz[0], t.xyz[1], t.xyz[2]);
});
};
// remove inflight requests that no longer cover the view..
tile.removeInflightRequests = function(cache, tiles, callback, modifier) {
return _filter(cache.inflight, function(v, i) {
@@ -124,36 +131,42 @@ export function utilTile() {
}).map(callback); // abort request
};
tile.scaleExtent = function(val) {
if (!arguments.length) return _scaleExtent;
_scaleExtent = val;
return tile;
};
tile.size = function(val) {
if (!arguments.length) return _size;
_size = val;
return tile;
};
tile.scale = function(val) {
if (!arguments.length) return _scale;
_scale = val;
return tile;
};
tile.translate = function(val) {
if (!arguments.length) return _translate;
_translate = val;
return tile;
};
tile.zoomDelta = function(val) {
if (!arguments.length) return _zoomDelta;
_zoomDelta = +val;
return tile;
};
// number to extend the rows/columns beyond those covering the viewport
tile.margin = function(val) {
if (!arguments.length) return _margin;
@@ -161,5 +174,6 @@ export function utilTile() {
return tile;
};
return tile;
}