Hi,
In winformsMap.TrackOverlay when drawing a line, after set first point I would like
to lock the line length ( with a length input by user in a textBox) and at mouseMoved only change the angle, keeping the same
line length for any position from mouse.
Is there some example for this.
Thanks.
Edgar
November 14, 2012, 11:46pm
2
Hi Alex,
Here is the sample code:
public class MyTrackInteractiveOverlay : TrackInteractiveOverlay { public double lineLength; private PointShape point = new PointShape(0, 0); private InMemoryFeatureLayer internalFeatureLayer; public MyTrackInteractiveOverlay() : base() { internalFeatureLayer = TrackShapeLayer.CloneDeep() as InMemoryFeatureLayer; } protected override InteractiveResult MouseMoveCore(InteractionArguments interactionArguments) { point.X = interactionArguments.WorldX; point.Y = interactionArguments.WorldY; InteractiveResult result = base.MouseMoveCore(interactionArguments); if (TrackShapeLayer.InternalFeatures.Count > 0) { LineShape line = TrackShapeLayer.InternalFeatures[TrackShapeLayer.InternalFeatures.Count - 1].GetShape() as LineShape; double currentLineLength = Math.Sqrt((point.X - line.Vertices[0].X) * (point.X - line.Vertices[0].X) + (point.Y - line.Vertices[0].Y) * (point.Y - line.Vertices[0].Y)); double newY = (point.Y - line.Vertices[0].Y) * 50 / currentLineLength + line.Vertices[0].Y; double newX = (point.X - line.Vertices[0].X) * 50 / currentLineLength + line.Vertices[0].X; line.Vertices[1] = new Vertex(newX, newY); TrackShapeLayer.InternalFeatures[TrackShapeLayer.InternalFeatures.Count - 1].WellKnownBinary = line.GetWellKnownBinary(); } return result; } public override bool IsEmpty { get { if (internalFeatureLayer.InternalFeatures.Count == 0 && TrackShapeLayer.InternalFeatures.Count == 0) { return true; } return false; } } protected override InteractiveResult MouseDoubleClickCore(InteractionArguments interactionArguments) { InteractiveResult result = base.MouseDoubleClickCore(interactionArguments); if (TrackShapeLayer.InternalFeatures.Count > 0) { LineShape line = TrackShapeLayer.InternalFeatures[TrackShapeLayer.InternalFeatures.Count - 1].GetShape() as LineShape; double currentLineLength = Math.Sqrt((point.X - line.Vertices[0].X) * (point.X - line.Vertices[0].X) + (point.Y - line.Vertices[0].Y) * (point.Y - line.Vertices[0].Y)); double newY = (point.Y - line.Vertices[0].Y) * 50 / currentLineLength + line.Vertices[0].Y; double newX = (point.X - line.Vertices[0].X) * 50 / currentLineLength + line.Vertices[0].X; line.Vertices[1] = new Vertex(newX, newY); TrackShapeLayer.InternalFeatures[TrackShapeLayer.InternalFeatures.Count - 1].WellKnownBinary = line.GetWellKnownBinary(); } internalFeatureLayer.InternalFeatures.Add(TrackShapeLayer.InternalFeatures[0]); TrackShapeLayer.InternalFeatures.Clear(); return result; } protected override void DrawCore(GeoCanvas canvas) { internalFeatureLayer.Open(); internalFeatureLayer.Draw(canvas, new Collection<SimpleCandidate>()); base.DrawCore(canvas); } } winformsMap1.TrackOverlay = new MyTrackInteractiveOverlay() { lineLength = 50 };
Hope it helps,
Edgar
Hi Edgar,
Thanks for the sample code. I did a sample with the code (based at DynamicTrackShapes), but I could not get the example to work, probably I did some mistake. At your code the lineLength variable is never used, then I change it to currentLineLength which is used in MouseMoveCore and MouseDoubleClickCore, is this correct ? I attached my sample project. Thanks in advanced. DynamicTrackShapes_SAMPLE.zip (434 KB)
Edgar
November 20, 2012, 11:58pm
4
I’m sorry Alex, I hard-coded the lockLength to 50 forcefully when I’m testing, please roll back to my code and replace the 50 with the field lineLength and everything will be OK. Regards, Edgar
Hi Edgar, Thanks a lot, now it's working. But it only works with Development Build ( I'm using 6.0.192 ) with Stable/Production Build it's not worked. Thanks, Alexandre
Edgar
November 22, 2012, 7:58pm
6
Alex, The type of "Feature" in production build is still struct, so you just need to change that two lines of code
TrackShapeLayer.InternalFeatures[TrackShapeLayer.InternalFeatures.Count - 1].WellKnownBinary = line.GetWellKnownBinary();
to
TrackShapeLayer.InternalFeatures[TrackShapeLayer.InternalFeatures.Count - 1] = new Feature(line.GetWellKnownBinary());
and it will work. Regards, Edgar
Thanks Edgar,
Now also works in the production version.
Edgar
November 25, 2012, 7:25pm
8
Glad to hear it works, please let us know if you have any questions. Regards, Edgar