Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs with feature layer setWhere #1211

Merged
merged 2 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Layers/FeatureLayer/FeatureGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export var FeatureGrid = Layer.extend({
Util.setOptions(this, options);
},

onAdd: function () {
onAdd: function (map) {
this._cells = {};
this._activeCells = {};
this._resetView();
Expand Down
16 changes: 15 additions & 1 deletion src/Layers/FeatureLayer/FeatureManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export var FeatureManager = FeatureGrid.extend({
_requestFeatures: function (bounds, coords, callback) {
this._activeRequests++;

const originalWhere = this.options.where;
patrickarlt marked this conversation as resolved.
Show resolved Hide resolved

// our first active request fires loading
if (this._activeRequests === 1) {
this.fire(
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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);
Expand Down