I have a FeatureLayer. I want to set the Graphic.Selected property for all of the Graphics that fall within a rectangle created with Draw. As I understand it Draw generates Geometries based on the Map controls spatial reference. The method for selection Graphics displayed by the FeatureLayer is FindGraphicsInHostCoordinates so I need to convert the Envelope returned by Draw to the Host Coordinates and I am using MapToScreen to accomplish this.
The problem is that the results from FindGraphicsInHostCoordinates does not include all of the graphics within the Envelope. The results are close to what I would expect if the Envelope was half as wide as what was drawn.
I don't know if the problem is in the Envelope returned by Draw, the conversion to host coordinates performed by MapToScreen or the locating of the graphics peformed by FindGraphicsInHostCoordinates. Or if maybe sleep apnea is preventing me from seeing the obvious. Here is the latest rendition of the code that I am using:
FeatureLayer sitesFeatureLayer = MyMap.Layers["NRA Site Points (FeatureLayer)"] as FeatureLayer;
Envelope selectedArea = args.Geometry as Envelope;
Point ul = MyMap.MapToScreen(new MapPoint(selectedArea.XMin, selectedArea.YMax));
Point ll = MyMap.MapToScreen(new MapPoint(selectedArea.XMin, selectedArea.YMin));
Point lr = MyMap.MapToScreen(new MapPoint(selectedArea.XMax, selectedArea.YMin));
double width = lr.X - ll.X;
double height = ll.Y - ul.Y;
Rect screenRect = new Rect(ul, new Size(width, height));
IEnumerable<Graphic> selectedSites = sitesFeatureLayer.FindGraphicsInHostCoordinates(screenRect);
foreach (Graphic feature in selectedSites) {
feature.Selected = !feature.Selected;
}
Sure hope someone has an answer to this as I am quite stumped.