Move cache management out of tiler, it's responsibilty of service

Also remove some unused code and eslint warnings
This commit is contained in:
Bryan Housel
2018-07-21 11:11:39 -04:00
parent ff64455370
commit 02713e48fb
5 changed files with 53 additions and 80 deletions

View File

@@ -1,5 +1,4 @@
/* global Mapillary:false */
import _filter from 'lodash-es/filter';
import _find from 'lodash-es/find';
import _flatten from 'lodash-es/flatten';
import _forEach from 'lodash-es/forEach';
@@ -44,18 +43,6 @@ function abortRequest(i) {
}
function nearNullIsland(x, y, z) {
if (z >= 7) {
var center = Math.pow(2, z - 1);
var width = Math.pow(2, z - 6);
var min = center - (width / 2);
var max = center + (width / 2) - 1;
return x >= min && x <= max && y >= min && y <= max;
}
return false;
}
function maxPageAtZoom(z) {
if (z < 15) return 2;
if (z === 15) return 5;
@@ -66,28 +53,23 @@ function maxPageAtZoom(z) {
}
function localeTimestamp(s) {
if (!s) return null;
var detected = utilDetect();
var options = {
day: 'numeric', month: 'short', year: 'numeric',
hour: 'numeric', minute: 'numeric', second: 'numeric',
timeZone: 'UTC'
};
var d = new Date(s);
if (isNaN(d.getTime())) return null;
return d.toLocaleString(detected.locale, options);
}
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 dimension = projection.clipExtent()[1];
var tiles = geoTile.getTiles(projection, dimension, tileZoom, 0);
var tiles = geoTile.getTiles(projection, dimension, tileZoom);
geoTile.removeInflightRequests(which, tiles, abortRequest, ',0');
// abort inflight requests that are no longer needed
var cache = _mlyCache[which];
_forEach(cache.inflight, function(v, k) {
var wanted = _find(tiles, function(tile) { return k.indexOf(tile.id + ',') === 0; });
if (!wanted) {
abortRequest(v);
delete cache.inflight[k];
}
});
tiles.forEach(function(tile) {
loadNextTilePage(which, currZoom, url, tile);

View File

@@ -1,4 +1,3 @@
import _filter from 'lodash-es/filter';
import _find from 'lodash-es/find';
import _flatten from 'lodash-es/flatten';
import _forEach from 'lodash-es/forEach';
@@ -53,18 +52,6 @@ function abortRequest(i) {
}
function nearNullIsland(x, y, z) {
if (z >= 7) {
var center = Math.pow(2, z - 1),
width = Math.pow(2, z - 6),
min = center - (width / 2),
max = center + (width / 2) - 1;
return x >= min && x <= max && y >= min && y <= max;
}
return false;
}
function maxPageAtZoom(z) {
if (z < 15) return 2;
if (z === 15) return 5;
@@ -76,13 +63,22 @@ function maxPageAtZoom(z) {
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 s = projection.scale() * 2 * Math.PI;
var currZoom = Math.floor(Math.max(Math.log(s) / Math.log(2) - 8, 0));
var dimension = projection.clipExtent()[1];
var tiles = geoTile.getTiles(projection, dimension, tileZoom, 0);
var tiles = geoTile.getTiles(projection, dimension, tileZoom);
geoTile.removeInflightRequests(which, tiles, abortRequest, ',0');
// abort inflight requests that are no longer needed
var cache = _oscCache[which];
_forEach(cache.inflight, function(v, k) {
var wanted = _find(tiles, function(tile) { return k.indexOf(tile.id + ',') === 0; });
if (!wanted) {
abortRequest(v);
delete cache.inflight[k];
}
});
tiles.forEach(function(tile) {
loadNextTilePage(which, currZoom, url, tile);

View File

@@ -2,7 +2,6 @@ import _chunk from 'lodash-es/chunk';
import _cloneDeep from 'lodash-es/cloneDeep';
import _extend from 'lodash-es/extend';
import _forEach from 'lodash-es/forEach';
import _filter from 'lodash-es/filter';
import _find from 'lodash-es/find';
import _groupBy from 'lodash-es/groupBy';
import _isEmpty from 'lodash-es/isEmpty';
@@ -778,12 +777,19 @@ export default {
tilezoom = _tileZoom;
}
// get tiles
var tiles = geoTile.getTiles(projection, dimensions, tilezoom, 0);
// determine the needed tiles to cover the view
var tiles = geoTile.getTiles(projection, dimensions, tilezoom);
// remove inflight requests that no longer cover the view..
// abort inflight requests that are no longer needed
var hadRequests = !_isEmpty(cache.inflight);
geoTile.removeInflightRequests(cache, tiles, abortRequest);
_forEach(cache.inflight, function(v, k) {
var wanted = _find(tiles, function(tile) { return k === tile.id; });
if (!wanted) {
abortRequest(v);
delete cache.inflight[k];
}
});
if (hadRequests && !loadingNotes && _isEmpty(cache.inflight)) {
dispatch.call('loaded'); // stop the spinner
}

View File

@@ -1,4 +1,5 @@
import _extend from 'lodash-es/extend';
import _find from 'lodash-es/find';
import _flatten from 'lodash-es/flatten';
import _forEach from 'lodash-es/forEach';
import _map from 'lodash-es/map';
@@ -53,6 +54,7 @@ var _pannellumViewer;
var _sceneOptions;
var _dataUrlArray = [];
/**
* abortRequest().
*/
@@ -60,19 +62,6 @@ function abortRequest(i) {
i.abort();
}
/**
* nearNullIsland().
*/
function nearNullIsland(x, y, z) {
if (z >= 7) {
var center = Math.pow(2, z - 1);
var width = Math.pow(2, z - 6);
var min = center - (width / 2);
var max = center + (width / 2) - 1;
return x >= min && x <= max && y >= min && y <= max;
}
return false;
}
/**
* localeTimeStamp().
@@ -99,6 +88,17 @@ function loadTiles(which, url, projection, margin) {
.margin(margin)
.getTiles(projection, dimension, tileZoom);
// abort inflight requests that are no longer needed
var cache = _ssCache[which];
_forEach(cache.inflight, function(v, k) {
var wanted = _find(tiles, function(tile) { return k.indexOf(tile.id + ',') === 0; });
if (!wanted) {
abortRequest(v);
delete cache.inflight[k];
}
});
tiles.forEach(function (tile) {
loadNextTilePage(which, currZoom, url, tile);
});

View File

@@ -1,5 +1,3 @@
import _filter from 'lodash-es/filter';
import _find from 'lodash-es/find';
import { range as d3_range } from 'd3-array';
import { geoExtent } from '../geo';
@@ -19,7 +17,10 @@ export function utilTiler() {
}
function nearNullIsland(x, y, z) {
function nearNullIsland(tile) {
var x = tile[0];
var y = tile[1];
var z = tile[2];
if (z >= 7) {
var center = Math.pow(2, z - 1);
var width = Math.pow(2, z - 6);
@@ -93,7 +94,7 @@ export function utilTiler() {
return tiler()
.map(function(tile) {
if (_skipNullIsland && nearNullIsland(tile[0], tile[1], tile[2])) {
if (_skipNullIsland && nearNullIsland(tile)) {
return false;
}
var x = tile[0] * ts - origin[0];
@@ -110,18 +111,6 @@ export function utilTiler() {
};
// remove inflight requests that no longer cover the view..
tiler.removeInflightRequests = function(cache, tiles, callback, modifier) {
return _filter(cache.inflight, function(v, i) {
var wanted = _find(tiles, function(tile) { return i === tile.id + modifier; });
if (!wanted) {
delete cache.inflight[i];
}
return !wanted;
}).map(callback); // abort request
};
tiler.scaleExtent = function(val) {
if (!arguments.length) return _scaleExtent;
_scaleExtent = val;