From 487ec9d8370f2467696ce6c5a84876c67cdc71d5 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Sun, 1 Jul 2018 12:48:51 -0400 Subject: [PATCH] Better spinner event management re: https://github.com/openstreetmap/iD/pull/5107#issuecomment-401617938 --- modules/services/osm.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/services/osm.js b/modules/services/osm.js index 87af1beb5..037d23003 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -665,7 +665,7 @@ export default { s / 2 - projection.translate()[1] ]; - // what tiles cover the view + // what tiles cover the view? var tiler = d3_geoTile() .scaleExtent([tilezoom, tilezoom]) .scale(s) @@ -685,6 +685,8 @@ export default { }; }); + // remove inflight requests that no longer cover the view.. + var hadRequests = !_isEmpty(cache.inflight); _filter(cache.inflight, function(v, i) { var wanted = _find(tiles, function(tile) { return i === tile.id; }); if (!wanted) { @@ -693,12 +695,16 @@ export default { return !wanted; }).map(abortRequest); + if (hadRequests && !loadingNotes && _isEmpty(cache.inflight)) { + dispatch.call('loaded'); // stop the spinner + } + // issue new requests.. tiles.forEach(function(tile) { var id = tile.id; if (cache.loaded[id] || cache.inflight[id]) return; if (!loadingNotes && _isEmpty(cache.inflight)) { - dispatch.call('loading'); // start the spinner + dispatch.call('loading'); // start the spinner } cache.inflight[id] = that.loadFromAPI( @@ -717,7 +723,7 @@ export default { callback(err, _extend({ data: parsed }, tile)); } if (_isEmpty(cache.inflight)) { - dispatch.call('loaded'); // stop the spinner + dispatch.call('loaded'); // stop the spinner } }