private void AddDataSource(IDataSource2D <double> field, Guid guid) { List <PolylineGeometry> geometry = new List <PolylineGeometry>(); List <VisualPushpin> labels = new List <VisualPushpin>(); isolineBuilder.DataSource = field; IsolineCollection collection = isolineBuilder.Build(); annotater.WayBeforeText = 20.0; foreach (LevelLine segment in collection.Lines) { List <Coordinate2D> points = new List <Coordinate2D>(); points.Add(new Coordinate2D(segment.StartPoint.X, segment.StartPoint.Y)); foreach (Point point in segment.OtherPoints) { points.Add(new Coordinate2D(point.X, point.Y)); } PolyInfo style = PolyInfo.DefaultPolyline; Color color = palette.GetColor(segment.Value01); style.LineColor = System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B); geometry.Add(new PolylineGeometry(guid.ToString(), Guid.NewGuid().ToString(), new Polyline2(Wgs84CoordinateReferenceSystem.Instance, Coordinate2DCollection.CreateUnsafe(points.ToArray())), style)); } foreach (IsolineTextLabel label in annotater.Annotate(collection, new Rect())) { labels.Add(new VisualPushpin(30, 30, label.Text, LatLonAlt.CreateUsingDegrees(label.Position.Y, label.Position.X, 0), this, Guid.NewGuid().ToString())); } layers.Add(new IsolinesLayer() { Geometry = geometry, IsVisible = true, Guid = guid, Labels = labels }); AddLayerToHost(layers[layers.Count - 1]); }
private void UpdateUIRepresentation() { foreach (var path in addedPaths) { content.Children.Remove(path); } addedPaths.Clear(); if (DataSource == null) { labelGrid.Visibility = Visibility.Hidden; return; } Rect output = Plotter2D.Viewport.Output; Point mousePos = Mouse.GetPosition(this); if (!output.Contains(mousePos)) { return; } var transform = Plotter2D.Viewport.Transform; Point visiblePoint = mousePos.ScreenToData(transform); Rect visible = Plotter2D.Viewport.Visible; double isolineLevel; if (Search(visiblePoint, out isolineLevel)) { var collection = IsolineBuilder.Build(isolineLevel); string format = "G3"; if (Math.Abs(isolineLevel) < 1000) { format = "F"; } textBlock.Text = isolineLevel.ToString(format); double x = mousePos.X + labelShift.X; if (x + labelGrid.ActualWidth > output.Right) { x = mousePos.X - labelShift.X - labelGrid.ActualWidth; } double y = mousePos.Y - labelShift.Y - labelGrid.ActualHeight; if (y < output.Top) { y = mousePos.Y + labelShift.Y; } Canvas.SetLeft(labelGrid, x); Canvas.SetTop(labelGrid, y); foreach (LevelLine segment in collection.Lines) { StreamGeometry streamGeom = new StreamGeometry(); using (StreamGeometryContext context = streamGeom.Open()) { Point startPoint = segment.StartPoint.DataToScreen(transform); var otherPoints = segment.OtherPoints.DataToScreen(transform); context.BeginFigure(startPoint, false, false); context.PolyLineTo(otherPoints, true, true); } Path path = new Path { Stroke = new SolidColorBrush(Palette.GetColor(segment.Value01)), Data = streamGeom, Style = pathStyle }; content.Children.Add(path); addedPaths.Add(path); labelGrid.Visibility = Visibility.Visible; Binding pathBinding = new Binding { Path = new PropertyPath("StrokeThickness"), Source = this }; path.SetBinding(Path.StrokeThicknessProperty, pathBinding); } } else { labelGrid.Visibility = Visibility.Hidden; } }