"Snap" point in ArcGISDynamicMapServiceLayer?

517
1
08-04-2010 01:04 PM
deleted-user-Jie3eyjOl9XM
Occasional Contributor
I doubt this can be done, but maybe someone has some ideas. Using the Javascript API, I want to snap a point to a line.

I am accessing an ArcGISDynamicMapServiceLayer. It contains polylines, and a query task. I know that I can execute a query to find lines that are close to the point. But, what I need is the EXACT closest point along that line. Is there a simple way?

One thought is to enumerate all the points along that line, compute the straightline distance, and search for the minimum. But, I don't know how to compute that line to points.
0 Kudos
1 Reply
deleted-user-Jie3eyjOl9XM
Occasional Contributor
Looking back at my own account, I forgot to close out this thread.

I snapped the point to the line, the hard way. I enumerated all vertices in the line, looking for the closest vertex. Then, I moved the point to that vertex.

This will not always give you a good answer, since this will actually snap to the closest vertex, not the closest point along the line. An improvement is to first densify the line (adding points along the line at a given distance interval), which is part of the JS API.

Ultimately, most people would just use the SnappingManager with the editor toolbar, but this was a special situation.
0 Kudos