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

Using native store's filters instead of featureFilter. #180

Open
NeilujD opened this issue May 31, 2013 · 0 comments
Open

Using native store's filters instead of featureFilter. #180

NeilujD opened this issue May 31, 2013 · 0 comments

Comments

@NeilujD
Copy link

NeilujD commented May 31, 2013

I actually work with the "FeatureStore" class and I need to filter my features depending on many attributes but not just just one.

So I decided to override the "onLoad" function to use the native store's filter and it's looks like that :

onLoad: function(store, records, successful, eOpts) {
  this._removing = true;
  store.layer.removeAllFeatures();
  delete this._removing;

  // Array of the records I'll keep for the layer.
  var keepedRecords = [];

  for (var i = 0; i < records.length; i++) {

    var aRecord = records[i];
    var filtersOK = true;

    // I verify if the records match with each filters and, if not, I exclude it from the record's array.
    for (var f = 0; f < store.filters.items.length; f++) {
      var aFilter = store.filters.items[f];
      if (!aFilter.filterFn(aRecord)) {
        filtersOK = false;
        break;
      }
    }
    if (filtersOK) {
      console.log(aRecord);
      keepedRecords.push(aRecord);
    }
  }

  // Finally I add my keeped records to my layer.
  this.addFeaturesToLayer(keepedRecords);
}

For example I have this filter :

{
  property: "myAttribute",
  value: myValue
}

That works perfectly for me. I've just not ever try by modifying my filters yet but I'll do it soon.

Have you another solution tu use many filters in a FeatureStore ?

Thank you in advance,

Julien Collard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant