# Snapping to a polyline feature

761
2
07-02-2021 01:04 PM
Occasional Contributor

I have an app in AppStudio that contains a map with several feature layers. The user for the application will be interacting with the layers and submitting data from app to elsewhere. I want the user to be able to click on the map (it will never be exact, therefore reasonably close) near a line feature and retrieve the coordinates for the nearest point on the line.

For example, user clicks on or near the polyline feature. This creates a Graphic that is snapped to the nearest point on the polyline feature. This allows the app to retrieve coordinates where the user tapped on the feature.

This is the workflow I would like to implement:

1) User clicks on or near polyline feature

2) Get the coordinates for the point that user tapped on and calculate distance x to polyline feature (using Geometry Engine's distance method).

3) Plot point on line that is x distance away from tapped point to line feature.

4) Place a Graphic on this final point on the line feature to indicate that the snapping has completed.

How can I achieve step 3? I have a distance that I can calculate successfully. Is the best way to do this by calculating a buffer with radius and then finding points of intersection with the line feature? Or is there a better way? All I want to do is just snap this point that is not on the line to the line.

Thanks for the help!

--------------------------------------------------
Application Developer, GeoMarvel
Tags (5)
1 Solution

Accepted Solutions
Esri Regular Contributor

We have a sample that has nearly the exact workflow you're looking for. It shows how to get the distance and "snap" a mouse click to a polyline (in the case of the sample, it's the edge of a polygon).

Let us know if this help.

2 Replies
Esri Regular Contributor

We have a sample that has nearly the exact workflow you're looking for. It shows how to get the distance and "snap" a mouse click to a polyline (in the case of the sample, it's the edge of a polygon).

Let us know if this help.

Occasional Contributor

Thanks, @JamesBallard1 ! This worked perfectly. I swear I must've looked over the methods in GeometryEngine a few times, but still missed these!

--------------------------------------------------
Application Developer, GeoMarvel