using System.Collections.ObjectModel; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WpfDesktopEdition; namespace Core.Presentation { class RulerTrackInteractiveOverlay : TrackInteractiveOverlay { private const string currentFeatureKey = "CurrentFeature"; private LineShape rulerLineShape; private Proj4Projection proj4; private int mouseDown; public RulerTrackInteractiveOverlay() : base() { proj4 = new Proj4Projection(); proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326); proj4.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326); proj4.Open(); 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(); if (TrackMode == TrackMode.Line) { interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw; interactiveResult.ProcessOtherOverlaysMode = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays; rulerLineShape = new LineShape(new Collection() { new Vertex(interactionArguments.WorldX, interactionArguments.WorldY), new Vertex(interactionArguments.WorldX, interactionArguments.WorldY) }); Feature newFeature = new Feature(rulerLineShape); if (TrackShapeLayer.InternalFeatures.Contains(currentFeatureKey)) TrackShapeLayer.InternalFeatures[currentFeatureKey] = newFeature; else TrackShapeLayer.InternalFeatures.Add(currentFeatureKey, newFeature); 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(TrackMode == TrackMode.Line && mouseDown > 0) { rulerLineShape.Vertices[rulerLineShape.Vertices.Count - 1] = new Vertex(interactionArguments.WorldX, interactionArguments.WorldY); 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(); if (TrackMode == TrackMode.Line) { interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw; interactiveResult.ProcessOtherOverlaysMode = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays; if (mouseDown == 1) { mouseDown = 0; TrackShapeLayer.InternalFeatures.Remove(currentFeatureKey); rulerLineShape = null; } } return interactiveResult; } protected override void DrawCore(RectangleShape targetExtent, RefreshType refreshType) { if (rulerLineShape != null) { Feature feature = new Feature(rulerLineShape); rulerLineShape = (LineShape)proj4.ConvertToExternalProjection(rulerLineShape); double length = rulerLineShape.GetLength(GeographyUnit.DecimalDegree, DistanceUnit.Feet); feature.ColumnValues.Add("length", ((int)length).ToString() + " feet"); if (TrackShapeLayer.InternalFeatures.Contains(currentFeatureKey)) TrackShapeLayer.InternalFeatures[currentFeatureKey] = feature; else TrackShapeLayer.InternalFeatures.Add(currentFeatureKey, feature); } base.DrawCore(targetExtent, refreshType); } } }