protected void AddPolylineLocations(PathFigureCollection figures, IEnumerable <Location> locations, bool closed) { if (locations != null && locations.Count() >= 2) { var offset = GetLongitudeOffset(); if (offset != 0d) { locations = locations.Select(loc => new Location(loc.Latitude, loc.Longitude + offset)); } var points = locations.Select(loc => LocationToViewportPoint(loc)).ToList(); if (closed) { points.Add(points[0]); } var viewport = new Rect(0, 0, ParentMap.RenderSize.Width, ParentMap.RenderSize.Height); PathFigure figure = null; PolyLineSegment segment = null; for (int i = 1; i < points.Count; i++) { var p1 = points[i - 1]; var p2 = points[i]; var inside = Intersections.GetIntersections(ref p1, ref p2, viewport); if (inside) { if (figure == null) { figure = new PathFigure { StartPoint = p1, IsClosed = false, IsFilled = false }; segment = new PolyLineSegment(); figure.Segments.Add(segment); figures.Add(figure); } segment.Points.Add(p2); } if (!inside || p2 != points[i]) { figure = null; } } } }
protected void AddPolylineLocations(PathFigureCollection pathFigures, IEnumerable <Location> locations, double longitudeOffset, bool closed) { if (locations.Count() >= 2) { var points = locations.Select(location => LocationToView(location, longitudeOffset)); if (closed) { var segment = new PolyLineSegment(); foreach (var point in points.Skip(1)) { segment.Points.Add(point); } var figure = new PathFigure { StartPoint = points.First(), IsClosed = closed, IsFilled = closed }; figure.Segments.Add(segment); pathFigures.Add(figure); } else { var pointList = points.ToList(); if (closed) { pointList.Add(pointList[0]); } var viewport = new Rect(0, 0, ParentMap.RenderSize.Width, ParentMap.RenderSize.Height); PathFigure figure = null; PolyLineSegment segment = null; for (int i = 1; i < pointList.Count; i++) { var p1 = pointList[i - 1]; var p2 = pointList[i]; var inside = Intersections.GetIntersections(ref p1, ref p2, viewport); if (inside) { if (figure == null) { figure = new PathFigure { StartPoint = p1, IsClosed = false, IsFilled = false }; segment = new PolyLineSegment(); figure.Segments.Add(segment); pathFigures.Add(figure); } segment.Points.Add(p2); } if (!inside || p2 != pointList[i]) { figure = null; } } } } }