Oh, could you verify that the geometries have the same SpatialReference as the MapPoint? If they are found to be not equal, Intersects() will return false.
You can use Intersects() method http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Geometry.Envelope~Intersects.htmlSomething like this, where args.Geometry is the MapPoint created by Draw. This code-snippet allows me to select all graphics that contain the MapPoint. foreach (var g in graphicsLayer.Graphics) { if (g.Geometry.Extent.Intersects(args.Geometry.Extent)) g.Selected = true; }
foreach (var g in graphicsLayer.Graphics) { if (g.Geometry.Extent.Intersects(args.Geometry.Extent)) g.Selected = true; }
You can do the following in the MouseClick event of your Map control to get the graphics that intersect your MapPoint.Assumptions in the code snippet:- MyMap: The Map control in your application- MyFeatureLayer: The FeatureLayer in your map you are intersecting the map point- MyGraphicsLayer: The layer to show the intersecting result(s) FeatureLayer featureLayer = MyMap.Layers["MyFeatureLayer"] asFeatureLayer; System.Windows.Point screenPnt = MyMap.MapToScreen(e.MapPoint); GeneralTransform generalTransform = MyMap.TransformToVisual(Application.Current.RootVisual); System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt); IEnumerable<Graphic> results = featureLayer.FindGraphicsInHostCoordinates(transformScreenPnt); GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] asGraphicsLayer; foreach (Graphic graphic in results) { Graphic g = newGraphic() { Geometry = graphic.Geometry }; graphicsLayer.Graphics.Add(g); }
FeatureLayer featureLayer = MyMap.Layers["MyFeatureLayer"] asFeatureLayer; System.Windows.Point screenPnt = MyMap.MapToScreen(e.MapPoint); GeneralTransform generalTransform = MyMap.TransformToVisual(Application.Current.RootVisual); System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt); IEnumerable<Graphic> results = featureLayer.FindGraphicsInHostCoordinates(transformScreenPnt); GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] asGraphicsLayer; foreach (Graphic graphic in results) { Graphic g = newGraphic() { Geometry = graphic.Geometry }; graphicsLayer.Graphics.Add(g); }
I used MainWindow, but it always returned me null.
If you are using WPF: GeneralTransform generalTransform = MyMap.TransformToVisual(Application.Current.MainWindow); System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt); IEnumerable<Graphic> selected = parcelGraphicsLayer.FindGraphicsInHostCoordinates(transformScreenPnt);
GeneralTransform generalTransform = MyMap.TransformToVisual(Application.Current.MainWindow); System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt); IEnumerable<Graphic> selected = parcelGraphicsLayer.FindGraphicsInHostCoordinates(transformScreenPnt);
You can try this SDK sample http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SpatialQuery. It uses QueryTask based on the geometry (i.e. MapPoint if DrawMode is Point). You can modify this sample, you will not need a Draw object. You can obtain MapPoint through any of the mouse events. System.Windows.Point screenPoint = args.GetPosition(MyMap); ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = MyMap.ScreenToMap(screenPoint);
System.Windows.Point screenPoint = args.GetPosition(MyMap); ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = MyMap.ScreenToMap(screenPoint);
My scenario:- I have a drawing "point" icon for my map. When I click on a region in US, I want to highlight that region. I can get the highlight done. When clicking on a region, I don't want to run the query task again to get the region that contains the point. So, my design is I go thru the existing graphic list and find the region that "intersects" with that point, then do the highlight.Something like this:if (graphic.Geometry.Extent.Intersects(e.Geometry.Extent)){ graphic.Select(); }e is DrawEventArgs. graphic is from graphic layer on the map.However, I got a problem that sometimes 2 regions contain that point and the result is both of them are selected. Please see the attached image, my clicking point is at the crossed symbol x. When I click at that point, both regions A and B are selected while I only want region B is selected.Is there a way to fix this? Looks like to me graphic geometry is a rectangle and that causes the point to be inside both regions in the image?I appreciate your help!
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.