Solved! Go to Solution.
Hi Mortein,
Thanks for your answer. I finally managed to use the geometry service to perform the intersection query. Now I am able to select the graphics on the map and it gets selected but still have one step to go as this selects all the graphics on the map. Can you just tell me the way to select the selected graphics at a time. Below is my new code.
void spatialQueryPolygon(Object sender, DrawEventArgs e)
{
GraphicsLayer graphicLayer1 = edmsMap.Layers[selectedProgramTypeName] as GraphicsLayer;
GraphicsLayer graphicLayer = edmsMap.Layers["graphicsLayer"] as GraphicsLayer;
//GraphicCollection _theGraphicsCollection = graphicLayer.Graphics;
geometryService.RelationCompleted += new EventHandler<RelationEventArgs>(geometryService_RelationCompleted);
string sclRelationship = "dim(g1.interior, g2) != null";
geometryService.RelationAsync(graphicLayer1.Graphics.ToList(), graphicLayer1.Graphics.ToList(),
GeometryRelation.esriGeometryRelationRelation, sclRelationship);
}
void geometryService_RelationCompleted(object sender, RelationEventArgs e)
{
string results = "";
for (int i = 0; i < e.Results.Count; i++)
{
results += string.Format("Point {0} is within polygon {1}.\n", e.Results.Graphic1Index,
e.Results.Graphic2Index);
GraphicsLayer graphicLayer1 = edmsMap.Layers[selectedProgramTypeName] as GraphicsLayer;
GraphicCollection graphicCollection = graphicLayer1.Graphics;
foreach (Graphic graphic in graphicCollection)
{
ESRI.ArcGIS.Client.Symbols.SimpleLineSymbol SimpleLineSymbol;
SimpleLineSymbol = (ESRI.ArcGIS.Client.Symbols.SimpleLineSymbol)(LayoutRoot.Resources["DefaultLineSymbol"]);
graphic.Symbol = (ESRI.ArcGIS.Client.Symbols.SimpleLineSymbol)SimpleLineSymbol;
}
}
}
Regards,
Saurabh.
Are you saying you don't want to select all the graphics? Because your code loops through ALL the graphics in your layer and selects them one by one. Not sure why you do that, if you don't want to do that.
Yes Morten.. That exactly what I want... I dont want to select all the graphics, just want to select the selected graphics for the user drawn polygon; but not finding a proper way to do the loop for selecting the single graphics.May be my loop is wrongly typed. Can u provide me a better way..
Regards,
saurabh.
Have you tried using Editor.Select? This SDK sample demonstrates how you can do this by simply having an Editor as your Button's DataContext and then using Select command as Button.Command property. Editor SelectionMode can be set to Polygon if you are working with FeatureLayers. You can include/exclude layers from your map by setting Editor.LayerIDs property.