diff --git a/src/Layers/FeatureLayer/FeatureGrid.js b/src/Layers/FeatureLayer/FeatureGrid.js index 34ea20b50..a4559cc4a 100644 --- a/src/Layers/FeatureLayer/FeatureGrid.js +++ b/src/Layers/FeatureLayer/FeatureGrid.js @@ -44,7 +44,7 @@ export var FeatureGrid = Layer.extend({ Util.setOptions(this, options); }, - onAdd: function () { + onAdd: function (map) { this._cells = {}; this._activeCells = {}; this._resetView(); diff --git a/src/Layers/FeatureLayer/FeatureManager.js b/src/Layers/FeatureLayer/FeatureManager.js index 6dfff904d..4c4214903 100644 --- a/src/Layers/FeatureLayer/FeatureManager.js +++ b/src/Layers/FeatureLayer/FeatureManager.js @@ -133,6 +133,8 @@ export var FeatureManager = FeatureGrid.extend({ _requestFeatures: function (bounds, coords, callback) { this._activeRequests++; + var originalWhere = this.options.where; + // our first active request fires loading if (this._activeRequests === 1) { this.fire( @@ -153,6 +155,11 @@ export var FeatureManager = FeatureGrid.extend({ this.fire('drawlimitexceeded'); } + // the where changed while this request was being run so don't it. + if (this.options.where !== originalWhere) { + return; + } + // no error, features if (!error && featureCollection && featureCollection.features.length) { // schedule adding features until the next animation frame @@ -271,7 +278,11 @@ export var FeatureManager = FeatureGrid.extend({ pendingRequests--; - if (pendingRequests <= 0 && this._visibleZoom()) { + if ( + pendingRequests <= 0 && + this._visibleZoom() && + where === this.options.where // the where is still the same so use this one + ) { this._currentSnapshot = newSnapshot; // schedule adding features for the next animation frame Util.requestAnimFrame( @@ -289,6 +300,9 @@ export var FeatureManager = FeatureGrid.extend({ for (var i = this._currentSnapshot.length - 1; i >= 0; i--) { oldSnapshot.push(this._currentSnapshot[i]); } + + this._cache = {}; + for (var key in this._cells) { pendingRequests++; var coords = this._keyToCellCoords(key);