I am wondering if you have a simple example or some methodology for this. I am looking to draw a polygon using the InteractiveTrackOverlay with TrackMode as Polygon. I want to be able to snap a potential vertex of the polygon to an existing vertex. I tried doing it where I query the ‘snap-to-layer’ and move my mouse pointer (e) there. However, when I add a point, it still takes just where my mouse clicked, not the closest vertex. Is there a way that I can override the mouse click location when adding a vertex to accomplish this?
I read through the code examples, and they all deal with the EditOverlay and making edits to features that already exist. I am not sure if there is a way to tie in snapping in the creation of features, or if there is a work-around I might not be seeing. My code is below for the method I am currently using. But like I said, it only moves the line to the vertex and still captures the x-y of the mouse click, not the vertex. It can look good in the program, but when I load the data into something like ArcMap, I can see the distance between my target vertex and my mouse click.
Sub
TrackOverlay_MouseMoved(
ByVal
sender
As
Object
,
ByVal
e
As
MouseMovedTrackInteractiveOverlayEventArgs)
If
e IsNot
Nothing
Then
Dim
xOverlay
As
New
LayerOverlay
xOverlay = WpfMap_Main.Overlays(
“WorkLayers”
)
Dim
snapToLayer
As
New
ShapeFileFeatureLayer
snapToLayer = xOverlay.Layers(0)
Dim
snapToCollection
As
New
Collection(Of Feature)
Dim
currentPoint
As
New
PointShape(e.MovedVertex.X, e.MovedVertex.Y)
'grab points in the current extent - put into collection
snapToCollection = snapToLayer.QueryTools.GetFeaturesNearestTo(
New
PointShape(e.MovedVertex.X, e.MovedVertex.Y), GeographyUnit.Meter, 1, ReturningColumnsType.NoColumns)
'find distance between mouse pointer and closest feature
Dim
distance
As
Double
= currentPoint.GetDistanceTo(snapToCollection.Item(0).GetShape(), GeographyUnit.Meter, DistanceUnit.Meter)
'if less than 20 meters, snap to it
If
distance < 20
Then
Dim
snapToVertex
As
New
Vertex(snapToCollection.Item(0).GetShape)
e.MovedVertex = snapToVertex
End
If
snapToCollection.Clear()
End
If
End
Sub