Steve,
Thanks for your post and question.
The requirements you mentioned is somehow complex, we may need to create a brand new TrackInterativeOverlay to make it. I took a try and hope following code is what we are going to achieve.
private void TrackAndEditShapes_Load(object sender, EventArgs e)
{
winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new WorldMapKitWmsDesktopOverlay();
winformsMap1.Overlays.Add("WorldOverlay", worldMapKitDesktopOverlay);
RulerInteractiveOverlay ruleinterativeOverlay = new RulerInteractiveOverlay();
winformsMap1.TrackOverlay = ruleinterativeOverlay;
winformsMap1.TrackOverlay.TrackMode = TrackMode.Line;
winformsMap1.CurrentExtent = new RectangleShape(-139.2, 92.4, 120.9, -93.2);
winformsMap1.Refresh();
}
public class RulerInteractiveOverlay : TrackInteractiveOverlay
{
private const string currentFeatureKey = "CurrentFeature";
private LineShape rulerLineShape;
private int mouseDown;
public RulerInteractiveOverlay()
: base()
{
TrackShapeLayer.Open();
TrackShapeLayer.Columns.Add(new FeatureSourceColumn("length"));
TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.FromArgb(100, 255, 0, 0), 1, true);
TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen.LineJoin = DrawingLineJoin.Round;
TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.InnerPen.LineJoin = DrawingLineJoin.Round;
TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.CenterPen.LineJoin = DrawingLineJoin.Round;
TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new TextStyle("length", new GeoFont("Verdana", 10, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.DarkGreen));
TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.YOffsetInPixel = 5;
TrackShapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
}
protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)
{
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) });
if (!TrackShapeLayer.InternalFeatures.Contains(currentFeatureKey))
{
TrackShapeLayer.InternalFeatures.Add(currentFeatureKey, new Feature(rulerLineShape));
}
mouseDown++;
return interactiveResult;
}
protected override InteractiveResult MouseMoveCore(InteractionArguments interactionArguments)
{
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)
{
InteractiveResult interactiveResult = new InteractiveResult();
interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw;
interactiveResult.ProcessOtherOverlaysMode = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;
if (mouseDown == 2)
{
mouseDown = 0;
Feature feature =new Feature( TrackShapeLayer.InternalFeatures[currentFeatureKey].GetShape());
double length = ((LineShape)feature.GetShape()).GetLength(GeographyUnit.DecimalDegree, DistanceUnit.Kilometer);
feature.ColumnValues.Add("length", ((int)length).ToString() + " km");
Lock.EnterWriteLock();
TrackShapeLayer.InternalFeatures.Add(feature.Id, feature);
TrackShapeLayer.InternalFeatures.Remove(currentFeatureKey);
Lock.ExitWriteLock();
}
return interactiveResult;
}
protected override void DrawCore(GeoCanvas canvas)
{
Collection<SimpleCandidate> labelingInAllLayers = new Collection<SimpleCandidate>();
try
{
if (rulerLineShape != null)
{
Feature feature = new Feature(rulerLineShape);
double length = rulerLineShape.GetLength(GeographyUnit.DecimalDegree, DistanceUnit.Kilometer);
feature.ColumnValues.Add("length", ((int)length).ToString() + " km");
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();
}
}
}
Thanks.
Yale