ThinkGeo.com    |     Documentation    |     Premium Support

Drawing circle around line using rulertrack

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.

Hi Dan,

I tried your code, it looks the ruler works well without error, and I hadn’t noticed the ellipse you mentioned.

Could you please let us know what’s the error you met, and what’s the detail question now?

Regards,

Ethan

I was hoping you could provide some help making the ellipse. I tried a few different things, mainly trying to follow what the line was doing and do a similar thing, but that didn’t work.

Edit: Here’s the error I’ve been getting mainly:

‘The shape you provided does not pass our simple validation.’ on this piece of code:

Feature feature2 = new Feature(new EllipseShape(new PointShape(rulerLineShape.Vertices[0]), length));

I don’t get the error when making the PointShape separately, or the EllipseShape, but when I make the feature out of it, it throws the error.

Hi Dan,

Our developer build a sample for you, please see whether that works for your requirement.

Post9081_RulerTrackTest.zip (13.1 KB)

Regards,

Ethan

Awesome that’s just what I was looking for. Thanks!

Hi Dan,

I am glad to hear that’s helpful.

Regards,

Ethan