From ec0145de3a1a9301b9f2f3b45221059bf004e560 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 16 May 2019 16:44:19 -0400 Subject: [PATCH] Prevent accidental loading of many tiles at low zoom This could happen because `editable` was checked before the call was scheduled not before the `loadTiles`. The user can zoom out more while the call is deferred. --- modules/core/context.js | 20 ++++++++++---------- modules/util/idle.js | 3 +-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/modules/core/context.js b/modules/core/context.js index e9ac76134..91de61ca5 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -135,21 +135,21 @@ export function coreContext() { context.loadTiles = function(projection, callback) { - if (connection && context.editable()) { - var cid = connection.getConnectionId(); - utilCallWhenIdle(function() { + utilCallWhenIdle(function() { + if (connection && context.editable()) { + var cid = connection.getConnectionId(); connection.loadTiles(projection, afterLoad(cid, callback)); - })(); - } + } + })(); }; context.loadTileAtLoc = function(loc, callback) { - if (connection && context.editable()) { - var cid = connection.getConnectionId(); - utilCallWhenIdle(function() { + utilCallWhenIdle(function() { + if (connection && context.editable()) { + var cid = connection.getConnectionId(); connection.loadTileAtLoc(loc, afterLoad(cid, callback)); - })(); - } + } + })(); }; context.loadEntity = function(entityID, callback) { diff --git a/modules/util/idle.js b/modules/util/idle.js index 103e0eded..9b2765c47 100644 --- a/modules/util/idle.js +++ b/modules/util/idle.js @@ -25,8 +25,7 @@ export function utilIdleWorker(tasks, processor, callback) { callback(results); })(); - // alternatively, each task deferred in its own callback - // seems to not work because it + // alternatively, each task deferred in its own callback seems to not work // var processed = []; // var currentPos = 0;