Hit Test for a polygon on graphics layer?

3672
3
03-11-2013 09:58 AM
Labels (1)
EzraSidran
New Contributor
Is there a built in method to test if a point (lat/long) is inside a poly drawn on a graphics layer?
0 Kudos
3 Replies
MichaelBranscomb
Esri Frequent Contributor
Hi,

You've got a couple of options...

#1. FindGraphicsInHostCoordinates method:
This performs a hittest operation on the GraphicsLayer based on a point (i.e. click point) in UI coordinates. http://resources.arcgis.com/en/help/runtime-wpf/apiref/index.html?ESRI.ArcGIS.Client~ESRI.ArcGIS.Cli...

#2. GeometryService task:
Use a local or online Geometry server in conjunction with the GeometryService task. There are a variety of operations available which might give you some more flexibility - you probably want to use the RelationAsync() operation.
http://resources.arcgis.com/en/help/runtime-wpf/apiref/index.html?ESRI.ArcGIS.Client~ESRI.ArcGIS.Cli...

Cheers

Mike
0 Kudos
EzraSidran
New Contributor
Thanks a lot Mike!
0 Kudos
HuyHo
by
Occasional Contributor
Hi,

I am trying to get a list of graphics that's currently visible on the map using the FindGraphicsInHostCoordinates() method.  I pass in a Rect of the area on the screen where the map is displayed.  Most of the time this works. However, once in a while I would get the following exception.  I call this method while I handle the Map.ExtentChanged event.  Any idea what's going on here or how I can get around this?

Thanks.


Specified index is out of range or child at index is null. Do not call this method if VisualChildrenCount returns zero, indicating that the Visual has no children.
Parameter name: index
Actual value was 0.


   at System.Windows.FrameworkElement.GetVisualChild(Int32 index)
   at System.Windows.Media.Visual.InternalGet2DOr3DVisualChild(Int32 index)
   at System.Windows.Media.VisualTreeHelper.GetChild(DependencyObject reference, Int32 childIndex)
   at ESRI.ArcGIS.Client.Symbols.GraphicElement.HitTestCore(GeometryHitTestParameters hitTestParameters)
   at System.Windows.Media.Visual.HitTestGeometry(HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, GeometryHitTestParameters geometryParams)
   at System.Windows.Media.Visual.HitTestGeometry(HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, GeometryHitTestParameters geometryParams)
   at System.Windows.Media.Visual.HitTest(HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, HitTestParameters hitTestParameters)
   at System.Windows.Media.VisualTreeHelper.HitTest(Visual reference, HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, HitTestParameters hitTestParameters)
   at ESRI.ArcGIS.Client.GraphicsLayer.FindGraphicsInHostCoordinates(Rect intersectingRect, Int32 maxHits)
   at VTM.EsriMapControl.Common.LabelStacker.GetVisibleLabels()
0 Kudos