private void Ellipse_MouseEnter(object sender, MouseEventArgs e) { var ellipse = (Ellipse)sender; // the location to display the popup var location = (Point)ellipse.Tag; // create a new wpf text blox var border = new Border { BorderBrush = Brushes.Black, BorderThickness = new Thickness(2, 2, 1, 1) }; var textBlock = new TextBlock { Padding = new Thickness(2), Background = Brushes.Yellow, Foreground = Brushes.Black, Text = GeoTransform.LatLonToString(location.Y, location.X, true) }; border.Child = textBlock; popup.Child = border; // get the MapView object from the control var mapView = MapElementExtensions.FindChild <MapView>(Map); // transform var popupLocation = mapView.WgsToCanvas(Map, location); popup.Placement = PlacementMode.RelativePoint; popup.PlacementTarget = Map; popup.HorizontalOffset = popupLocation.X; popup.VerticalOffset = popupLocation.Y; popup.IsOpen = true; popup.StaysOpen = false; }
/// <summary> Updates the text which is showing the current coordinates. </summary> private void UpdateText() { if (!isActive) { return; } Point pixelPoint = Mouse.GetPosition(MapView); Point wgsPoint = MapView.CanvasToWgs(MapView.Layers, pixelPoint); if (wgsPoint.Y < -90 || wgsPoint.Y > 90 || wgsPoint.X < -180 || wgsPoint.X > 180) { CoordinatesText.Text = INVALID_COORD_TEXT; } else { switch (Map.CoordinateDiplayFormat) { case CoordinateDiplayFormat.Decimal: CoordinatesText.Text = $"{wgsPoint.Y:.000000}°, {wgsPoint.X:.000000}°"; break; case CoordinateDiplayFormat.Degree: CoordinatesText.Text = GeoTransform.LatLonToString(wgsPoint.Y, wgsPoint.X, true); break; default: throw new ArgumentOutOfRangeException(); } } }