Select to view content in your preferred language

Find closest point?

907
3
05-17-2010 04:53 PM
MichaelMacDonald
Emerging Contributor
I've been trying to write a selection tool (just a simple tool that does not require the user to draw a rectangle, etc but rather just click on the map) that will work against a point layer.  The problem I've found is that its difficult to click exactly on the point when the map is zoomed out.  I'm wondering if someone has sample code for finding the nearest point based on the coordinates clicked on?

Thanks for any help you can provide!
0 Kudos
3 Replies
dotMorten_esri
Esri Notable Contributor
Instead of using a point for querying, create a small envelope around the point. Ie. this create a box 2x2 pixels around the click-point:
    new Envelope(p.X - map.Resolution, p.Y - map.Resolution,p.X + map.Resolution, p.Y + map.Resolution)
and use this to query for your points.
0 Kudos
MichaelMacDonald
Emerging Contributor
Instead of using a point for querying, create a small envelope around the point. Ie. this create a box 2x2 pixels around the click-point:
    new Envelope(p.X - map.Resolution, p.Y - map.Resolution,p.X + map.Resolution, p.Y + map.Resolution)
and use this to query for your points.


Thanks, I've tried that, can't keep to get it going properly.  It still doesn't seem to be selecting the point I want.  There is no way to use geoprocessing to grab the closest point to a mapclick is there? Or would that take significantly longer?
0 Kudos
KevinManning
New Contributor
I have the same issue with finding the closest location clicked on a map between a set of simple PolylineN objects.  I could contract the search envelope to yield just the section to click on but that would make it pretty hard to use.  Is there some sort of method to cal that would find the closest PolylineN feature based on the x y you click on a map?
0 Kudos