Point position = e.ScreenPoint; FeatureLayer featureLayer = MyMap.Layers["Stops"] as FeatureLayer; IEnumerable<Graphic> clickedFeatures = featureLayer.FindGraphicsInHostCoordinates(position); MessageBox.Show(clickedFeatures.Count().ToString());
I guess you missed the transformation to host coordinates.
Please look at Morten's answer in this thread : http://forums.arcgis.com/threads/3093-Graphic-Selection-based-on-Draw-Envelope-issue
Point position = e.ScreenPoint; Point screenPointRelativeToHost = MyMap.TransformToVisual(Application.Current.RootVisual).Transform(position);
GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; GeneralTransform generalTransform = MyMap.TransformToVisual(Application.Current.RootVisual); System.Windows.Point transformScreenPnt = generalTransform.Transform(e.GetPosition(this.MyMap)); var graphics = graphicsLayer.FindGraphicsInHostCoordinates(transformScreenPnt);
MapPoint pointInMap= e.MapPoint; Point clickPosition= MyMap.MapToScreen(pointInMap); GeneralTransform generalTransform = MyMap.TransformToVisual(Application.Current.RootVisual); Point transformScreenPnt = generalTransform.Transform(clickPosition); var graphics = graphicsLayer.FindGraphicsInHostCoordinates(transformScreenPnt);
//only returns the top most graphic System.Windows.Media.GeneralTransform generalTransform = MyMap.TransformToVisual(Application.Current.MainWindow); Point RightMouseButtonDownLocation = generalTransform.Transform(e.GetPosition(MyMap)); var graphics = MyFeatureLayer.FindGraphicsInHostCoordinates(RightMouseButtonDownLocation).ToList(); ///----------- TRIED THIS WAY TOO ----------- //only returns the top most graphic Point RightMouseButtonDownLocation = e.GetPosition(Application.Current.MainWindow); var graphics = MyFeatureLayer.FindGraphicsInHostCoordinates(RightMouseButtonDownLocation).ToList();
Point RightMouseButtonDownLocation = e.GetPosition(Application.Current.MainWindow); Rect rect = new Rect(RightMouseButtonDownLocation, RightMouseButtonDownLocation); rect.Inflate(1,1); //THE FIX -inflate making the box 1px x 1px var graphics = MyFeatureLayer.FindGraphicsInHostCoordinates(rect);