You had mentioned using ObjectID, what did you mean by that exactly?
var queryTask = new QueryTask(context.Layers.ActiveParcelLayer.Url); queryTask.ExecuteCompleted += new EventHandler<QueryEventArgs>(queryTask_ExecuteCompleted); var query = new Query(); query.OutFields.Add("*"); query.Source = layer.Source; query.ReturnGeometry = true; query.OutSpatialReference = map.SpatialReference; query.Where = string.Format("PROP_ID in ({0})", string.Join(",", propIds)); var featureSet = queryTask.Execute(query); if (featureSet != null) { foreach (var feature in featureSet) {  var propId = GisHelper.GetPropertyId(feature);  var graphic = layer.Graphics.FirstOrDefault(   g => GisHelper.GetPropertyId(g) == propId  );  if (graphic == null)  {   graphic = feature;   layer.Graphics.Add(graphic);  }        graphic.Selected = true; } }
  if (featureSet != null)  {   foreach (var feature in featureSet)   {    feature.Selected = true;   }   context.Layers.ActiveParcelLayer.Refresh();   OnSelectionChanged();  }
Can you elaborate on this? Do you have a use case/user story?
I have an Editor assigned to my map, and the user can select features using their mouse. This all works nicely and the SelectedGraphics collection of the layer gets updated perfectly. All I want to do now is do this through code. After that, the user could use the Editor to add more features to the selection.
foreach (var feature in e.FeatureSet)    {        // Add graphics to a GraphicsLayer you have already created        // e.g. GraphicsLayer graphicsLayer = new GraphicsLayer();        graphicsLayer.Graphics.Add(feature);    } // Add layer to map map.Layers.Add(graphicsLayer);
// Zoom to selected features (define expand percentage) Envelope selectedFeatureExtent = graphicsLayer.FullExtent.Extent; double expandPercentage = 30; double widthExpand = selectedFeatureExtent.Width * (expandPercentage / 100); double heightExpand = selectedFeatureExtent.Height * (expandPercentage / 100); ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope( selectedFeatureExtent.XMin - (widthExpand / 2), selectedFeatureExtent.YMin - (heightExpand / 2), selectedFeatureExtent.XMax + (widthExpand / 2), selectedFeatureExtent.YMax + (heightExpand / 2)); map.ZoomTo(displayExtent);
public void SelectProperties(IEnumerable<int> propIds) { UnselectAll(); if (context.Layers.ActiveParcelLayer != null) { Â if (propIds.Count() > 0) Â { Â Â var queryTask = new QueryTask(context.Layers.ActiveParcelLayer.Url); Â Â queryTask.ExecuteCompleted += new EventHandler<QueryEventArgs>(queryTask_ExecuteCompleted); Â Â var query = new Query(); Â Â query.Where = string.Format("PROP_ID in ({0})", string.Join(",", propIds)); Â Â var featureSet = queryTask.Execute(query); Â Â if (featureSet != null) Â Â { Â Â Â foreach (var feature in featureSet) Â Â Â { Â Â Â Â feature.Selected = true; Â Â Â } Â Â Â context.Layers.ActiveParcelLayer.Refresh(); Â Â Â OnSelectionChanged(); Â Â } Â } } else { Â pendingSelection = new List<int>(propIds); } } void queryTask_ExecuteCompleted(object sender, QueryEventArgs e) { foreach (var feature in e.FeatureSet) { Â feature.Selected = true; } context.Layers.ActiveParcelLayer.Refresh(); OnSelectionChanged(); }
For example:   var query = new esri.tasks.Query();   query.where = "SR_ID = '" + requestID + "'"; //REQUESTID   query.outFields = ["*"];   //execute query   map.getLayer(yourLayerId).selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function (features) {   if (features.length > 0) {           for (var i = 0; i < features.length; i++) {              //do your coding           }//for   }//if
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.