AnsweredAssumed Answered

How do I query or make selections against a local FeatureLayer based on a featureCollection?

Question asked by drc_ on Oct 21, 2014

When FeatureLayers are constructed with a url we can use the .queryFeatures() or selectFeatures() methods to get subsets of the data from the server. How do I get subsets of the data when my FeatureLayer is local (i.e. constructed from a featureCollectionObject)?

 

My app (JS API 3.10) has a toggle to switch between points (feature layer) and heatmap (from Patrick Weid's heatmap.js). My data is time aware and my feature layer is connected to the time slider, and it works fine. I want to time-enable my heatmap as well.

 

The solution I've implemented looks like this:

on(timeSlider, "time-extent-change", function(){
     var visibleGraphics = [];
     arrayUtils.forEach(featureLayer.graphics, function(graphic){
          if (graphic.visible == true){
               visibleGraphics.push(graphic);
          }
     });
     heatLayer.setData(visibleGraphics);
});

 


It works fine as long as the feature layer is limited to a few hundred graphics. When I get more than that this looping method is too slow. Instead of looping through every single graphic in the feature layer I'd rather be able to simply use the TimeExtent like I would with the Query object's query.timeExtent.

 

I want to do something like:

on(timeSlider, "time-extent-change", function(evt){
     var query = new Query();
     query.timeExtent = evt.timeExtent;
     featureLayer.queryFeatures(query, function(featureSet){
          heatLayer.setData(featureSet);
     }
});

 

Of course queryFeatures only works for retrieving data from the server, not for getting subsets of local data. My assumption is that this would be a lot faster than looping to find which graphics are visible. Any ideas?

Outcomes