Query a feature layer that is not shown until query is executed

592
2
02-28-2014 11:57 AM
MichelleRogers1
New Contributor III
I am trying to query a feature layer that is not shown on the map until the query is actually executed.  I have a button that I am using to set off the query when it is clicked.  Here is the code that I am trying to use:

on(dom.byId("mapshow"), "click", selectHistorical);
function selectHistorical(){
 var queryTask = new QueryTask(window.historicalUrl);
 var query = new Query();
 query.returnGeometry=true;
 query.outFields=window.historicalOutFields;
 query.text = dom.byId("mydropdown").value;
 query.outSpatialReference = {"wkid":2236};
 dojo.connect(queryTask, "onComplete", function(featureSet){
  map.graphics.clear();
  dojo.forEach(featureSet.features, function(feature){
   var graphic = feature;
   map.graphics.add(graphic);
  });
 });
 queryTask.execute(query);
}


Am I missing something?  Is there a better way to go about doing this?  Any help is greatly appreciated, thanks!

Michelle
0 Kudos
2 Replies
ReneRubalcava
Frequent Contributor
Would a FeatureLayer in MODE_ONDEMAND or MODE_SELECTION meet your needs using the selectFeatures method?
https://developers.arcgis.com/javascript/jssamples/fl_selectfeatures.html
0 Kudos
MichelleRogers1
New Contributor III
Would a FeatureLayer in MODE_ONDEMAND or MODE_SELECTION meet your needs using the selectFeatures method?
https://developers.arcgis.com/javascript/jssamples/fl_selectfeatures.html


The feature layer is already included in the webpage in on demand mode.  What I am trying to do is query the layer so that the only items that show up from that layer are the items from a specific unit id.  I am posting a photo of the viewer.

[ATTACH=CONFIG]31895[/ATTACH]

The dropdown menu in the right panel has the unit id's for all police vehicles.  What I want is for the historical data (in the historical feature layer) to be shown for whatever specific unit id is selected when I click on the show on map button.

I am fairly new to coding with esri, so any help is appreciated.
0 Kudos