protected override void OnViewportChanged(ViewportChangedEventArgs e) { if (e.ProjectionChanged) { ClearImages(); base.OnViewportChanged(e); var task = UpdateImageAsync(); } else { AdjustBoundingBox(e.LongitudeOffset); base.OnViewportChanged(e); if (updateTimer.IsEnabled && !UpdateWhileViewportChanging) { updateTimer.Stop(); // restart } if (!updateTimer.IsEnabled) { updateTimer.Start(); } } }
protected virtual void OnViewportChanged(ViewportChangedEventArgs e) { double longitudeScale = parentMap.MapProjection.LongitudeScale; if (e.ProjectionChanged) { viewportTransform.Children[1] = parentMap.MapProjection.ViewportTransform; } if (e.ProjectionChanged || double.IsNaN(longitudeScale)) { UpdateData(); } if (!double.IsNaN(longitudeScale)) // a normal cylindrical projection { var longitudeOffset = 0d; if (Location != null) { var viewportPosition = parentMap.MapProjection.LocationToViewportPoint(Location); if (viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width || viewportPosition.Y < 0d || viewportPosition.Y > parentMap.RenderSize.Height) { var nearestLongitude = Location.NearestLongitude(Location.Longitude, parentMap.Center.Longitude); longitudeOffset = longitudeScale * (nearestLongitude - Location.Longitude); } } ((TranslateTransform)viewportTransform.Children[0]).X = longitudeOffset; } }
protected virtual void OnViewportChanged(ViewportChangedEventArgs e) { foreach (UIElement element in Children) { var location = GetLocation(element); if (location != null) { SetViewportPosition(element, parentMap, location); } } }
protected virtual void OnViewportChanged(ViewportChangedEventArgs e) { foreach (UIElement element in Children) { BoundingBox boundingBox; Location location; if ((boundingBox = GetBoundingBox(element)) != null) { SetBoundingBoxRect(element, parentMap, boundingBox); } else if ((location = GetLocation(element)) != null) { SetViewportPosition(element, parentMap, location); } } }
private void OnViewportChanged(object sender, ViewportChangedEventArgs e) { if (Children.Count == 0 || e.ProjectionChanged || Math.Abs(e.LongitudeOffset) > 180d) { Update(false); // update immediately when projection has changed or center has moved across 180° longitude } else { SetRenderTransform(); if (!UpdateWhileViewportChanging) { updateTimer.Stop(); // restart } updateTimer.Start(); } }
protected override void OnViewportChanged(ViewportChangedEventArgs e) { base.OnViewportChanged(e); if (Math.Abs(e.OriginOffset) > 180d) { var offset = 360d * Math.Sign(e.OriginOffset); ImageBoundingBox = new BoundingBox(ImageBoundingBox.West + offset, ImageBoundingBox.East + offset, ImageBoundingBox.South, ImageBoundingBox.North); foreach (var mapImage in Children.OfType <MapImage>().Where(i => i.BoundingBoxValid)) { mapImage.SetBoundingBox(mapImage.West + offset, mapImage.East + offset, mapImage.South, mapImage.North); } } updateTimer.Stop(); updateTimer.Start(); }
private void OnViewportChanged(object sender, ViewportChangedEventArgs e) { if (TileGrid == null || e.ProjectionChanged || Math.Abs(e.LongitudeOffset) > 180d) { UpdateTileGrid(); // update immediately when projection has changed or center has moved across 180° longitude } else { SetRenderTransform(); if (updateTimer.IsEnabled && !UpdateWhileViewportChanging) { updateTimer.Stop(); // restart } if (!updateTimer.IsEnabled) { updateTimer.Start(); } } }
protected override void OnViewportChanged(ViewportChangedEventArgs e) { base.OnViewportChanged(e); if (e.ProjectionChanged) { UpdateImage((BitmapSource)null); UpdateImage(); } else { if (Math.Abs(e.LongitudeOffset) > 180d && boundingBox != null && boundingBox.HasValidBounds) { var offset = 360d * Math.Sign(e.LongitudeOffset); boundingBox.West += offset; boundingBox.East += offset; foreach (UIElement element in Children) { var bbox = GetBoundingBox(element); if (bbox != null && bbox.HasValidBounds) { SetBoundingBox(element, new BoundingBox(bbox.South, bbox.West + offset, bbox.North, bbox.East + offset)); } } } if (updateTimer.IsEnabled && !UpdateWhileViewportChanging) { updateTimer.Stop(); // restart } if (!updateTimer.IsEnabled) { updateTimer.Start(); } } }
private void OnViewportChanged(object sender, ViewportChangedEventArgs e) { if (TileGrid == null || Math.Abs(e.OriginOffset) > 180d) { // immediate update when map center moves across 180° longitude UpdateTileGrid(); } else { SetRenderTransform(); if (updateTimer.IsEnabled && !UpdateWhileViewportChanging) { updateTimer.Stop(); // restart } if (!updateTimer.IsEnabled) { updateTimer.Start(); } } }
private void OnViewportChanged(object sender, ViewportChangedEventArgs e) { OnViewportChanged(e); }
protected virtual void OnViewportChanged(ViewportChangedEventArgs e) { InvalidateArrange(); }
private void OnViewportChanged(object sender, ViewportChangedEventArgs e) { UpdateData(); }
protected override void OnViewportChanged(ViewportChangedEventArgs e) { if (path == null) { path = new Path { Data = new PathGeometry() }; path.SetBinding(Shape.StrokeProperty, GetBindingExpression(StrokeProperty)?.ParentBinding ?? new Binding { Source = this, Path = new PropertyPath("Stroke") }); path.SetBinding(Shape.StrokeThicknessProperty, GetBindingExpression(StrokeThicknessProperty)?.ParentBinding ?? new Binding { Source = this, Path = new PropertyPath("StrokeThickness") }); Children.Add(path); } var bounds = ParentMap.ViewportTransform.Inverse.TransformBounds(new Rect(new Point(), ParentMap.RenderSize)); var start = ParentMap.MapTransform.Transform(new Point(bounds.X, bounds.Y)); var end = ParentMap.MapTransform.Transform(new Point(bounds.X + bounds.Width, bounds.Y + bounds.Height)); var lineDistance = GetLineDistance(); var labelStart = new Location( Math.Ceiling(start.Latitude / lineDistance) * lineDistance, Math.Ceiling(start.Longitude / lineDistance) * lineDistance); var labelEnd = new Location( Math.Floor(end.Latitude / lineDistance) * lineDistance, Math.Floor(end.Longitude / lineDistance) * lineDistance); var lineStart = new Location( Math.Min(Math.Max(labelStart.Latitude - lineDistance, -ParentMap.MapTransform.MaxLatitude), ParentMap.MapTransform.MaxLatitude), labelStart.Longitude - lineDistance); var lineEnd = new Location( Math.Min(Math.Max(labelEnd.Latitude + lineDistance, -ParentMap.MapTransform.MaxLatitude), ParentMap.MapTransform.MaxLatitude), labelEnd.Longitude + lineDistance); if (!lineStart.Equals(graticuleStart) || !lineEnd.Equals(graticuleEnd)) { graticuleStart = lineStart; graticuleEnd = lineEnd; var geometry = (PathGeometry)path.Data; geometry.Figures.Clear(); geometry.Transform = ParentMap.ViewportTransform; for (var lat = labelStart.Latitude; lat <= end.Latitude; lat += lineDistance) { var figure = new PathFigure { StartPoint = ParentMap.MapTransform.Transform(new Location(lat, lineStart.Longitude)), IsClosed = false, IsFilled = false }; figure.Segments.Add(new LineSegment { Point = ParentMap.MapTransform.Transform(new Location(lat, lineEnd.Longitude)), }); geometry.Figures.Add(figure); } for (var lon = labelStart.Longitude; lon <= end.Longitude; lon += lineDistance) { var figure = new PathFigure { StartPoint = ParentMap.MapTransform.Transform(new Location(lineStart.Latitude, lon)), IsClosed = false, IsFilled = false }; figure.Segments.Add(new LineSegment { Point = ParentMap.MapTransform.Transform(new Location(lineEnd.Latitude, lon)), }); geometry.Figures.Add(figure); } var labelFormat = GetLabelFormat(lineDistance); var childIndex = 1; // 0 for Path for (var lat = labelStart.Latitude; lat <= end.Latitude; lat += lineDistance) { for (var lon = labelStart.Longitude; lon <= end.Longitude; lon += lineDistance) { TextBlock label; if (childIndex < Children.Count) { label = (TextBlock)Children[childIndex]; } else { var renderTransform = new TransformGroup(); renderTransform.Children.Add(new TranslateTransform()); renderTransform.Children.Add(ParentMap.RotateTransform); renderTransform.Children.Add(new TranslateTransform()); label = new TextBlock { RenderTransform = renderTransform }; label.SetBinding(TextBlock.ForegroundProperty, GetBindingExpression(ForegroundProperty)?.ParentBinding ?? new Binding { Source = this, Path = new PropertyPath("Foreground") }); Children.Add(label); } childIndex++; if (FontFamily != null) { label.FontFamily = FontFamily; } label.FontSize = FontSize; label.FontStyle = FontStyle; label.FontStretch = FontStretch; label.FontWeight = FontWeight; label.Text = GetLabelText(lat, labelFormat, "NS") + "\n" + GetLabelText(Location.NormalizeLongitude(lon), labelFormat, "EW"); label.Tag = new Location(lat, lon); label.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); var translateTransform = (TranslateTransform)((TransformGroup)label.RenderTransform).Children[0]; translateTransform.X = StrokeThickness / 2d + 2d; translateTransform.Y = -label.DesiredSize.Height / 2d; } } while (Children.Count > childIndex) { Children.RemoveAt(Children.Count - 1); } } // don't use MapPanel.Location because labels may be at more than 180° distance from map center for (int i = 1; i < Children.Count; i++) { var label = (TextBlock)Children[i]; var location = (Location)label.Tag; var viewportTransform = (TranslateTransform)((TransformGroup)label.RenderTransform).Children[2]; var viewportPosition = ParentMap.LocationToViewportPoint(location); viewportTransform.X = viewportPosition.X; viewportTransform.Y = viewportPosition.Y; } base.OnViewportChanged(e); }
protected override void OnViewportChanged(ViewportChangedEventArgs e) { var projection = ParentMap.MapProjection; if (!projection.IsAzimuthal) { if (path == null) { path = new Path { Data = new PathGeometry() }; path.SetBinding(Shape.StrokeProperty, GetBinding(StrokeProperty, nameof(Stroke))); path.SetBinding(Shape.StrokeThicknessProperty, GetBinding(StrokeThicknessProperty, nameof(StrokeThickness))); path.SetBinding(Shape.StrokeDashArrayProperty, GetBinding(StrokeDashArrayProperty, nameof(StrokeDashArray))); path.SetBinding(Shape.StrokeDashOffsetProperty, GetBinding(StrokeDashOffsetProperty, nameof(StrokeDashOffset))); path.SetBinding(Shape.StrokeDashCapProperty, GetBinding(StrokeDashCapProperty, nameof(StrokeDashCap))); Children.Add(path); } var bounds = projection.ViewportRectToBoundingBox(new Rect(0d, 0d, ParentMap.RenderSize.Width, ParentMap.RenderSize.Height)); var lineDistance = GetLineDistance(); var labelStart = new Location( Math.Ceiling(bounds.South / lineDistance) * lineDistance, Math.Ceiling(bounds.West / lineDistance) * lineDistance); var labelEnd = new Location( Math.Floor(bounds.North / lineDistance) * lineDistance, Math.Floor(bounds.East / lineDistance) * lineDistance); var lineStart = new Location( Math.Min(Math.Max(labelStart.Latitude - lineDistance, -projection.MaxLatitude), projection.MaxLatitude), labelStart.Longitude - lineDistance); var lineEnd = new Location( Math.Min(Math.Max(labelEnd.Latitude + lineDistance, -projection.MaxLatitude), projection.MaxLatitude), labelEnd.Longitude + lineDistance); var geometry = (PathGeometry)path.Data; geometry.Figures.Clear(); for (var lat = labelStart.Latitude; lat <= bounds.North; lat += lineDistance) { var figure = new PathFigure { StartPoint = projection.LocationToViewportPoint(new Location(lat, lineStart.Longitude)), IsClosed = false, IsFilled = false }; figure.Segments.Add(new LineSegment { Point = projection.LocationToViewportPoint(new Location(lat, lineEnd.Longitude)) }); geometry.Figures.Add(figure); } for (var lon = labelStart.Longitude; lon <= bounds.East; lon += lineDistance) { var figure = new PathFigure { StartPoint = projection.LocationToViewportPoint(new Location(lineStart.Latitude, lon)), IsClosed = false, IsFilled = false }; figure.Segments.Add(new LineSegment { Point = projection.LocationToViewportPoint(new Location(lineEnd.Latitude, lon)) }); geometry.Figures.Add(figure); } var labelFormat = GetLabelFormat(lineDistance); var childIndex = 1; // 0 for Path for (var lat = labelStart.Latitude; lat <= bounds.North; lat += lineDistance) { for (var lon = labelStart.Longitude; lon <= bounds.East; lon += lineDistance) { TextBlock label; if (childIndex < Children.Count) { label = (TextBlock)Children[childIndex]; } else { var renderTransform = new TransformGroup(); renderTransform.Children.Add(new TranslateTransform()); renderTransform.Children.Add(ParentMap.RotateTransform); renderTransform.Children.Add(new TranslateTransform()); label = new TextBlock { RenderTransform = renderTransform }; if (FontFamily != null) { label.SetBinding(TextBlock.FontFamilyProperty, GetBinding(FontFamilyProperty, nameof(FontFamily))); } label.SetBinding(TextBlock.FontSizeProperty, GetBinding(FontSizeProperty, nameof(FontSize))); label.SetBinding(TextBlock.FontStyleProperty, GetBinding(FontStyleProperty, nameof(FontStyle))); label.SetBinding(TextBlock.FontStretchProperty, GetBinding(FontStretchProperty, nameof(FontStretch))); label.SetBinding(TextBlock.FontWeightProperty, GetBinding(FontWeightProperty, nameof(FontWeight))); label.SetBinding(TextBlock.ForegroundProperty, GetBinding(ForegroundProperty, nameof(Foreground))); Children.Add(label); } childIndex++; label.Text = GetLabelText(lat, labelFormat, "NS") + "\n" + GetLabelText(Location.NormalizeLongitude(lon), labelFormat, "EW"); label.Tag = new Location(lat, lon); label.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); var translateTransform = (TranslateTransform)((TransformGroup)label.RenderTransform).Children[0]; translateTransform.X = StrokeThickness / 2d + 2d; translateTransform.Y = -label.DesiredSize.Height / 2d; } while (Children.Count > childIndex) { Children.RemoveAt(Children.Count - 1); } } // don't use MapPanel.Location because labels may be at more than 180° distance from map center for (int i = 1; i < Children.Count; i++) { var label = (TextBlock)Children[i]; var location = (Location)label.Tag; var viewportTransform = (TranslateTransform)((TransformGroup)label.RenderTransform).Children[2]; var viewportPosition = projection.LocationToViewportPoint(location); viewportTransform.X = viewportPosition.X; viewportTransform.Y = viewportPosition.Y; } } else if (path != null) { path = null; Children.Clear(); } base.OnViewportChanged(e); }
protected override void OnViewportChanged(ViewportChangedEventArgs e) { var labels = DrawGraticule(((PathGeometry)path.Data).Figures); if (Children.Count == 0) { path.SetBinding(Shape.StrokeProperty, this.GetOrCreateBinding(StrokeProperty, nameof(Stroke))); path.SetBinding(Shape.StrokeThicknessProperty, this.GetOrCreateBinding(StrokeThicknessProperty, nameof(StrokeThickness))); path.SetBinding(Shape.StrokeDashArrayProperty, this.GetOrCreateBinding(StrokeDashArrayProperty, nameof(StrokeDashArray))); path.SetBinding(Shape.StrokeDashOffsetProperty, this.GetOrCreateBinding(StrokeDashOffsetProperty, nameof(StrokeDashOffset))); path.SetBinding(Shape.StrokeDashCapProperty, this.GetOrCreateBinding(StrokeDashCapProperty, nameof(StrokeDashCap))); Children.Add(path); } var childrenCount = 1; foreach (var label in labels) { TextBlock textBlock; if (childrenCount < Children.Count) { textBlock = (TextBlock)Children[childrenCount]; } else { textBlock = new TextBlock { RenderTransform = new MatrixTransform() }; textBlock.SetBinding(TextBlock.FontSizeProperty, this.GetOrCreateBinding(FontSizeProperty, nameof(FontSize))); textBlock.SetBinding(TextBlock.FontStyleProperty, this.GetOrCreateBinding(FontStyleProperty, nameof(FontStyle))); textBlock.SetBinding(TextBlock.FontStretchProperty, this.GetOrCreateBinding(FontStretchProperty, nameof(FontStretch))); textBlock.SetBinding(TextBlock.FontWeightProperty, this.GetOrCreateBinding(FontWeightProperty, nameof(FontWeight))); textBlock.SetBinding(TextBlock.ForegroundProperty, this.GetOrCreateBinding(ForegroundProperty, nameof(Foreground))); if (FontFamily != null) { textBlock.SetBinding(TextBlock.FontFamilyProperty, this.GetOrCreateBinding(FontFamilyProperty, nameof(FontFamily))); } Children.Add(textBlock); } textBlock.Text = label.LatitudeText + "\n" + label.LongitudeText; textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); var matrix = new Matrix(1, 0, 0, 1, 0, 0); matrix.Translate(StrokeThickness / 2d + 2d, -textBlock.DesiredSize.Height / 2d); matrix.Rotate(label.Rotation); matrix.Translate(label.X, label.Y); ((MatrixTransform)textBlock.RenderTransform).Matrix = matrix; childrenCount++; } while (Children.Count > childrenCount) { Children.RemoveAt(Children.Count - 1); } base.OnViewportChanged(e); }
protected override void OnViewportChanged(ViewportChangedEventArgs e) { InvalidateMeasure(); }
private void OnViewportChanged(object sender, ViewportChangedEventArgs e) { LocationOrViewportChanged(); }
protected override void OnViewportChanged(ViewportChangedEventArgs e) { base.OnViewportChanged(e); ViewportChanged?.Invoke(this, e); }
protected override void OnViewportChanged(ViewportChangedEventArgs e) { InvalidateVisual(); }