I’m currently using the RulerTrackInteractiveOverlay to draw a line with the label for the line showing the distance. I want to add on to this, and draw a circle around the line, with the line itself being the radius.
What I’m currently trying is creating an ellipse, with the center point being set to the line’s starting point, and the radius being set to the length of the line. It’s throwing some strange errors though. Any tips on getting this to work would be great. Here’s the class for the ruleroverlay:
public class RulerTrackInteractiveOverlay : TrackInteractiveOverlay
{
private const string currentFeatureKey = "CurrentFeature";
private LineShape rulerLineShape;
private int mouseDown;
public RulerTrackInteractiveOverlay()
: base()
{
TrackShapeLayer.Open();
TrackShapeLayer.Columns.Add(new FeatureSourceColumn("length"));
//Sets the appearance of the ruler
TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.FromArgb(150, GeoColor.StandardColors.DarkRed), 4, false);
TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new TextStyle("length", new GeoFont("Arial", 10, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.Black));
TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.TextLineSegmentRatio = 100;
TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.YOffsetInPixel = 10;
TrackShapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
}
protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)
{
//Sets the first and last point of the line where the user clicks.
InteractiveResult interactiveResult = new InteractiveResult();
interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw;
interactiveResult.ProcessOtherOverlaysMode = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;
rulerLineShape = new LineShape(new Collection<Vertex>() { new Vertex(interactionArguments.WorldX, interactionArguments.WorldY), new Vertex(interactionArguments.WorldX, interactionArguments.WorldY) });
TrackShapeLayer.InternalFeatures.Add(currentFeatureKey, new Feature(rulerLineShape));
mouseDown++;
return interactiveResult;
}
protected override InteractiveResult MouseMoveCore(InteractionArguments interactionArguments)
{
//Updates the line with the last point to where the mouse pointer is being dragged.
InteractiveResult interactiveResult = new InteractiveResult();
if (mouseDown > 0)
{
Lock.EnterWriteLock();
rulerLineShape.Vertices[rulerLineShape.Vertices.Count - 1] = new Vertex(interactionArguments.WorldX, interactionArguments.WorldY);
Lock.ExitWriteLock();
interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw;
interactiveResult.ProcessOtherOverlaysMode = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;
}
return interactiveResult;
}
protected override InteractiveResult MouseUpCore(InteractionArguments interactionArguments)
{
//Removes the line of the ruler at finishing dragging (at mouse up event).
InteractiveResult interactiveResult = new InteractiveResult();
interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw;
interactiveResult.ProcessOtherOverlaysMode = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;
if (mouseDown == 1)
{
mouseDown = 0;
Lock.EnterWriteLock();
TrackShapeLayer.InternalFeatures.Remove(currentFeatureKey);
Lock.ExitWriteLock();
}
return interactiveResult;
}
protected override void DrawCore(GeoCanvas canvas)
{
//Draws the line and update the distance text of the ruler.
Collection<SimpleCandidate> labelingInAllLayers = new Collection<SimpleCandidate>();
try
{
if (rulerLineShape != null)
{
Feature feature = new Feature(rulerLineShape);
double length = rulerLineShape.GetLength(GeographyUnit.Meter, DistanceUnit.Feet);
feature.ColumnValues.Add("length", ((int)length).ToString() + " feet");
Lock.EnterWriteLock();
{
if (TrackShapeLayer.InternalFeatures.Contains(currentFeatureKey))
{
TrackShapeLayer.InternalFeatures[currentFeatureKey] = feature;
}
else
{
TrackShapeLayer.InternalFeatures.Add(currentFeatureKey, feature);
}
}
Lock.ExitWriteLock();
}
TrackShapeLayer.Open();
TrackShapeLayer.Draw(canvas, labelingInAllLayers);
canvas.Flush();
}
finally
{
TrackShapeLayer.Close();
}
}
}
Keep in mind, I’m trying to get the ellipse to update in real time with the line as the line is being drawn.