diff --git a/CHANGELOG.md b/CHANGELOG.md index ee740fad03..6760dfcde5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Improvements - Support polygon annotations with holes through geojson ([#1201](../../pull/1201)) +- Adjust queue track size based on number of tile layers ([#1202](../../pull/1202)) ## Version 1.8.3 diff --git a/src/fetchQueue.js b/src/fetchQueue.js index a6d43cce4c..06bae77c05 100644 --- a/src/fetchQueue.js +++ b/src/fetchQueue.js @@ -40,6 +40,7 @@ var fetchQueue = function (options) { this._size = options.size || 6; this._initialSize = options.initialSize || 0; this._track = options.track || 600; + this._initialTrack = this._track; this._needed = options.needed || null; this._batch = false; @@ -76,6 +77,30 @@ var fetchQueue = function (options) { } }); + /** + * Get/set the track size. This is used to determine when to check if + * entries can be discarded. + * @property {number} track The number of entries to track without checking + * for discards. + * @name geo.fetchQueue#track + */ + Object.defineProperty(this, 'track', { + get: function () { return m_this._track; }, + set: function (n) { m_this._track = n; } + }); + + /** + * Get/set the initial track size. Unless changed, this is the value used + * for track on class initialization. + * @property {number} initialTrack The number of entries to track without + * checking for discards. + * @name geo.fetchQueue#intitialTrack + */ + Object.defineProperty(this, 'initialTrack', { + get: function () { return m_this._initialTrack; }, + set: function (n) { m_this._initialTrack = n; } + }); + /** * Get the current queue size. Read only. * @property {number} length The current queue size. @@ -157,7 +182,7 @@ var fetchQueue = function (options) { defer.__fetchQueue._batch = m_this._batch; if (atEnd) { m_this._queue.push(defer); - } else if (!this._batch) { + } else if (!m_this._batch) { m_this._queue.unshift(defer); } else { for (var i = 0; i < m_this._queue.length; i += 1) { diff --git a/src/tileLayer.js b/src/tileLayer.js index 0a488c38a6..40fef5a5fa 100644 --- a/src/tileLayer.js +++ b/src/tileLayer.js @@ -16,7 +16,7 @@ var featureLayer = require('./featureLayer'); * @property {function} [tilesAtZoom=null] A function that is given a zoom * level and returns `{x: (num), y: (num)}` with the number of tiles at that * zoom level. - * @property {number} [cacheSize=400] The maximum number of tiles to cache. + * @property {number} [cacheSize=600] The maximum number of tiles to cache. * The default is 200 if keepLower is false. * @property {geo.fetchQueue} [queue] A fetch queue to use. If unspecified, a * new queue is created. @@ -193,6 +193,10 @@ var tileLayer = function (arg) { arg = $.extend(true, {}, this.constructor.defaults, arg || {}); if (!arg.cacheSize) { // this size should be sufficient for a 4k display + // where display size is (w, h), minimum tile dimension is ts, and total + // number of levels is ml, this is roughly + // sum([(math.ceil((w**2+h**2)**0.5 / (ts*2**l)) + 1) * + // (math.ceil(min(w, h) / (ts*2**l)) + 1) for l in range(ml)]) arg.cacheSize = arg.keepLower ? 600 : 200; } if ($.type(arg.subdomains) === 'string') { @@ -261,6 +265,9 @@ var tileLayer = function (arg) { }); this._queue._tileLayers = this._queue._tileLayers || []; this._queue._tileLayers.push(m_this); + if (this._queue.initialTrack && this._queue.track) { + this._queue.track = this._queue.initialTrack * this._queue._tileLayers.length; + } var m_tileOffsetValues = {}; @@ -310,10 +317,16 @@ var tileLayer = function (arg) { if (m_this._queue !== queue) { if (this._queue && this._queue._tileLayers && this._queue._tileLayers.indexOf(m_this) >= 0) { this._queue._tileLayers.splice(this._queue._tileLayers.indexOf(m_this), 1); + if (this._queue.initialTrack && this._queue.track && this._queue._tileLayers.length) { + this._queue.track = this._queue.initialTrack * this._queue._tileLayers.length; + } } m_this._queue = queue; m_this._queue._tileLayers = m_this._queue._tileLayers || []; m_this._queue._tileLayers.push(m_this); + if (m_this._queue.initialTrack && m_this._queue.track) { + m_this._queue.track = m_this._queue.initialTrack * m_this._queue._tileLayers.length; + } } } }); @@ -1736,6 +1749,9 @@ var tileLayer = function (arg) { m_exited = true; if (this._queue && this._queue._tileLayers && this._queue._tileLayers.indexOf(m_this) >= 0) { this._queue._tileLayers.splice(this._queue._tileLayers.indexOf(m_this), 1); + if (this._queue.initialTrack && this._queue.track && this._queue._tileLayers.length) { + this._queue.track = this._queue.initialTrack * this._queue._tileLayers.length; + } } return m_this; }; @@ -1765,7 +1781,7 @@ tileLayer.defaults = { topDown: false, keepLower: true, idleAfter: 'view', - // cacheSize: 400, // set depending on keepLower + // cacheSize: 600, // set depending on keepLower tileRounding: Math.round, attribution: '', animationDuration: 0 diff --git a/tests/cases/fetchQueue.js b/tests/cases/fetchQueue.js index b4472ec353..5e3f80b615 100644 --- a/tests/cases/fetchQueue.js +++ b/tests/cases/fetchQueue.js @@ -273,5 +273,17 @@ describe('geo.core.fetchQueue', function () { process(); }); + + it('track and initialTrack size', function () { + var q = geo.fetchQueue({track: 10}); + expect(q.track).toBe(10); + expect(q.initialTrack).toBe(10); + q.track = 20; + expect(q.track).toBe(20); + expect(q.initialTrack).toBe(10); + q.initialTrack = 30; + expect(q.track).toBe(20); + expect(q.initialTrack).toBe(30); + }); }); }); diff --git a/tests/cases/tileLayer.js b/tests/cases/tileLayer.js index 5a6740e101..371277f063 100644 --- a/tests/cases/tileLayer.js +++ b/tests/cases/tileLayer.js @@ -464,8 +464,10 @@ describe('geo.tileLayer', function () { var origQueue = layer2.queue; layer2.queue = layer.queue; expect(layer.queue._tileLayers.length).toBe(2); + expect(layer.queue.track).toBe(layer.queue.initialTrack * 2); layer2.queue = origQueue; expect(layer.queue._tileLayers.length).toBe(1); + expect(layer.queue.track).toBe(layer.queue.initialTrack); }); it('reference', function () { var m = map(), layer;