Hi,
Similar to the edit interactive overlay method, I would like to snap a point object created in TrackOverlay to an existing snapping grid item. Currently, using the edit interactive overlay method, as in the examples on the wiki, means that I must first create an object in an approximate location and then edit it to get it to snap to the exact location I want. The process is very tedious when creating several objects at a time.
I notice that there is no VertexMovingTrackInteractiveOverlay event, so maybe this is more complicated.
What is the best approach?
Thanks,
Damian
Snap TrackOverlay Point to Snap Grid
Hi Damian,
I want to make sure what’s the Snap Grid, do you meant you have a layer which looks like chess board, and when you track any point on track interactive overlay, the point will automatic snap to the nearest line of the Snap Grid?
If I misunderstand the requirement, please let me know.
Regards,
Don
Hi Don,
Yes, I have a grid of regularly spaced points that are currently in an EditInteractiveOverlay which is customized as per the snapping grid examples on the wiki.
I want TrackOverlay to do this same functionality so I can combine the ability to create an object and have it snap to one of the points.
Thanks,
Damian
Hi Damian,
I think the sample you mentioned is this: wiki.thinkgeo.com/wiki/Source_Code_DesktopEditionSample_SnappingToVertex_CS_091127.zip
If you want to implement that in TrackInteractiveOverlay, I think it’s more simple.
You can just use VertexAdding, then calculate the snapping target point and assign it to e.AddingVertex.
Regards,
Don
Hi Don,
I don’t think it’s that simple. First off VertexAdding event only captures when the item is added, but with TrackMode Point, the user can still drag it around and so nothing ever happens. Instead I’ve gone with TrackEnded which appears to fire when the user stops dragging the point and let’s go of the button.
However, there is something I didn’t expect. At first, I was trying to assign closestPoint in the snap grid to the e.TrackShape item. But I found that this doesn’t actually assign that point to the feature that gets added to the TrackInteractiveOverlay internal features. Is that how it should work? For the moment, I am using the sender and writing the new feature out explicitly to the last element. See below.
private void TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e)
{
PointShape currentPoint = new PointShape(e.TrackShape.GetWellKnownBinary());
PointShape closestPoint = FindNearestSnappingPoint(currentPoint);
if (closestPoint == null) return;
e.TrackShape = closestPoint; // This doesn’t do anything
TrackInteractiveOverlay track = sender as TrackInteractiveOverlay;
track.TrackShapeLayer.InternalFeatures[track.TrackShapeLayer.InternalFeatures.Count - 1] = new Feature(closestPoint);
}
Unfortunately, that is still not really what I wanted. I thought that I would be able to use TrackEnding and have the point snap to the grid when the user stops moving the mouse. This way, the user could see if it snapped to the correct location before actually creating the object. When using TrackEnding with the above code, the internal feature of the TrackInteractiveOverlay doesn’t keep the entry I give it (appears to get overwritten somewhere else). Can you please see how to make that work?
Thanks,
Damian
Hi Damian,
For TrackEnded, assign value to e.TrackShape won’t works, because new shape have been added to layer. But for TrackEnding, it should works, here we maybe have a bug, I will ask our developer look into it for make sure that. But for now, please directly replace the shape in layer for implement that.
For a workaround, do you think this will works?
1. When user drag the point, we render a virtual point on your grid line, this can shows where the point will be placed after release. We can use MouseDown MouseMove and MouseUp event for that.
2. We still use TrackEnded to capture when we need replace the point, when user release the point, we will use the virtual point replace track shape.
Do you think this can works?
Regards,
Don
Hi Don,
Thanks. Please keep me informed if this issue with TrackEnding is confirmed and fixed. It is the simplest approach by far.
I believe your method of a virtual point will work, but it will be difficult to keep my user from being confused as they are already used to the method working with EditInteractiveOverlay and a single point. Still, I will give it a go and see what they say.
Regards,
Damian
Hi Damian,
We have fixed that, please get the latest 8.0.251.0 or higher version to get the fix of TrackEnding.
Regards,
Don
Thanks Don. It’s working well.
Regards,
Damian
Hi Damian,
I am glad to hear that works for you.
Any question please let us know.
Regards,
Don
Hi Don,
Seems this same issue is occurring on the TrackStarted and TrackStarting events. The resultant shape doesn’t use e.StartingVertex or e.StartedVertex vertices when you assign it.
I need these methods to use snapping with line, multiline, rectangle and polygon items.
Regards,
Damian
Hi Damian,
I am not sure whether TrackStarted is designed like this, I will talk with out developer, for TrackStarting I will let them know this also, any update I will reply you here.
Regards,
Don
Hi Damian,
TrackStarting event should works, please get it from the latest version 8.0.270.0 or higher version.
Regards,
Don
Hi Don,
I think the build server is stuck. It’s showing 8.0.0.268 since last Friday.
Regards,
Damian
Hi Damian,
Thanks for your notification, we will check it and do the fix later.
Regards,
Johnny
Hi,
That seems to help, but now I am working with multipoint line item and polygon item and it seems that the VertexAdding and VertexAdded have same issue where the updated point is not being saved.
Also, I am not 100% sure, but I think when you end the multipoint line, polygon or rectangle track modes that the last point does not have a TrackEnding or TrackEnded event firing as I can not get the last point to snap.
In either case, it may be good if you guys spend a few minutes to build a test app that can show creating all track mode types while snapping to a grid. I think it would be a great edition to the wiki examples.
Regards,
Damian
Thanks for your suggestion, we will see if we can make some enhancements to the WIKI in future. I checked the code but seems like everything is ok, would you please create a issued sample for us? I guess you are meaning the TrackInteractiveOverlay.
Thanks,
Johnny
See attached test project.
DrawingTool_ItemClick event sets everything up for snapping to the grid. Points and lines work fine. Rectangles, Polygons and Multiline all have problems as indicated by my comments.
Regards,
Damian
SnapToGridMethods.zip (55 KB)
Hi Damian,
Thanks for your sample, we will look at it and see how to enhancement it.
Regards,
Don
Hi Damian,
Sorry for let you wait, attached is the new project which can works well for Point, StraightLine, Line, Polygon and RectangleShape.
And you should want to get the latest Desktop Edition 8.0.297.0 or higher version which contains the enhancement.
Any issue please let me know.
Regards,
Don
SnapToGridMethods_2.0.zip (15.7 KB)