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; }
public MapWindow() { InitializeComponent(); // set map parameters Map.XMapStyle = "silkysand"; Map.XMapUrl = "https://api-test.cloud.ptvgroup.com/xmap/ws/XMap"; Map.XMapCredentials = "Insert your xToken here"; // get the map container grid var grid = MapElementExtensions.FindChild <Grid>(Map); // get the old interactor var pz = Map.FindRelative <Ptv.XServer.Controls.Map.Gadgets.PanAndZoom>(); // exchange the interactor grid.Children.Remove(pz); grid.Children.Add(customPanAndZoom); Map.FitInWindow = true; // check token if (!string.IsNullOrWhiteSpace(Map.XMapCredentials) && !Map.XMapCredentials.Contains("insert")) { return; } MessageBox.Show("Please adopt the Map.XMapCredentials parameter in MapWindow.xaml.cs and provide a valid token."); Process.GetCurrentProcess().Kill(); }
private void Map_Loaded(object sender, RoutedEventArgs e) { hardwareLevel.Text = "Hardware Level: " + (RenderCapability.Tier >> 16); var center = new Point(8.4, 49); // KA InitializeBasemap(); // Map.MouseDragMode = DragMode.SelectOnShift; // replace the standard pan/zoom interactor with an extended VDI interactor customPanAndZoom = new PanAndZoom { MoveWhileDragging = usePanMoveWhileDragging, UseSimpleSelectShape = usePanSimpleShape }; // get the map container grid var grid = MapElementExtensions.FindChild <Grid>(Map); // get the old interactor var pz = Map.FindRelative <Ptv.XServer.Controls.Map.Gadgets.PanAndZoom>(); // exchange the interactor grid.Children.Remove(pz); grid.Children.Add(customPanAndZoom); // create some random coordinates CreateCoordinates(center); // initialize the symbol layer AddSymbols(); // set map center Map.SetMapLocation(center, 9); }
private void OnColoredMapLinePointsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Move) { return; } if (e.Action == NotifyCollectionChangedAction.Reset) { SetMapLines(new List <MapPolyline>()); } if (e.NewItems != null) { List <MapPolyline> newPolylines = new List <MapPolyline>(); List <BasicGeoposition> currentLinePositions = new List <BasicGeoposition>(); foreach (ColoredMapLine lineCollection in e.NewItems.OfType <ColoredMapLine>()) { for (int i = 0; i <= lineCollection.Count() - 2; i++) { var startPoint = lineCollection[i]; var nextPoint = lineCollection[i + 1]; currentLinePositions.Add(startPoint.Coordinates); Color nextColor = nextPoint.LineColor; if (nextPoint == lineCollection.Last() || startPoint.LineColor != nextColor) { MapPolyline polyline = new MapPolyline(); polyline.Path = new Geopath(currentLinePositions); polyline.StrokeColor = Color.FromArgb(192, startPoint.LineColor.R, startPoint.LineColor.G, startPoint.LineColor.B); polyline.StrokeDashed = startPoint.IsLineDashed; polyline.StrokeThickness = 6; if (lineCollection.OptionalId != Guid.Empty) { MapElementExtensions.SetPoiId(polyline, lineCollection.OptionalId); } newPolylines.Add(polyline); currentLinePositions = new List <BasicGeoposition>(); } } } AddMapLines(newPolylines); } if (e.OldItems != null) { var removedLines = new List <MapPolyline>(); foreach (ColoredMapLine oldLine in e.OldItems.OfType <ColoredMapLine>()) { MapPolyline removedLine = DigiTransitMapControl.MapElements .OfType <MapPolyline>() .FirstOrDefault(line => MapElementExtensions.GetPoiId(line) == oldLine.OptionalId); if (removedLine != null) { removedLines.Add(removedLine); } } RemoveMapLines(removedLines); } }
public Window1() { InitializeComponent(); // get the map container grid var grid = MapElementExtensions.FindChild <Grid>(Map); // get the old interactor var pz = Map.FindRelative <Ptv.XServer.Controls.Map.Gadgets.PanAndZoom>(); // exchange the interactor grid.Children.Remove(pz); grid.Children.Add(customPanAndZoom); Map.FitInWindow = true; }
private static async void OnPlacesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var _this = d as DigiTransitMap; if (_this == null) { return; } //set up INotifyCollectionChangeds var oldCollection = e.OldValue as INotifyCollectionChanged; var newCollection = e.NewValue as INotifyCollectionChanged; if (oldCollection != null) { oldCollection.CollectionChanged -= _this.OnPlacesCollectionChanged; } if (newCollection != null) { newCollection.CollectionChanged += _this.OnPlacesCollectionChanged; } var newList = e.NewValue as IEnumerable <IMapPoi>; if (newList == null) { return; } List <MapIcon> icons = new List <MapIcon>(); foreach (var place in newList.OfType <IMapPoi>()) { MapIcon element = new MapIcon(); element.Image = RandomAccessStreamReference.CreateFromStream(await _themeIconSource); element.CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible; element.Location = new Geopoint(place.Coords); element.Title = place.Name; element.NormalizedAnchorPoint = new Point(0.5, 1.0); MapElementExtensions.SetPoiId(element, place.Id); icons.Add(element); } _this.SetMapIcons(icons); }
private async void OnPlacesCollectionChanged(object sender, NotifyCollectionChangedEventArgs args) { if (args.Action == NotifyCollectionChangedAction.Move) { return; } if (args.Action == NotifyCollectionChangedAction.Reset) { SetMapIcons(null); } if (args.NewItems != null) { var newIcons = new List <MapIcon>(); foreach (IMapPoi place in args.NewItems.OfType <IMapPoi>()) { var element = new MapIcon(); element.Image = RandomAccessStreamReference.CreateFromStream(await _themeIconSource); element.CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible; element.Location = new Geopoint(place.Coords); element.Title = place.Name; element.NormalizedAnchorPoint = new Point(0.5, 1.0); element.SetValue(PoiIdProperty, place.Id); MapElementExtensions.SetPoiId(element, place.Id); newIcons.Add(element); } AddMapIcons(newIcons); } if (args.OldItems != null) { var removedIcons = new List <MapIcon>(); foreach (IMapPoi place in args.OldItems.OfType <IMapPoi>()) { var removedIcon = DigiTransitMapControl.MapElements .OfType <MapIcon>() .FirstOrDefault(x => x.Location.Position.Equals(place.Coords)); removedIcons.Add(removedIcon); } RemoveMapIcons(removedIcons); } }
private static void ColoredMapLinesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { DigiTransitMap _this = d as DigiTransitMap; if (_this == null) { return; } var oldCollection = e.OldValue as INotifyCollectionChanged; var newCollection = e.NewValue as INotifyCollectionChanged; if (oldCollection != null) { oldCollection.CollectionChanged -= _this.OnColoredMapLinePointsCollectionChanged; } if (newCollection != null) { newCollection.CollectionChanged += _this.OnColoredMapLinePointsCollectionChanged; } IList <ColoredMapLine> newValue = e.NewValue as IList <ColoredMapLine>; if (newValue == null) { if (_this.DigiTransitMapControl.MapElements.OfType <MapPolyline>().Any()) { _this.SetMapLines(null); } return; } List <MapPolyline> newPolylines = new List <MapPolyline>(); List <BasicGeoposition> currentLinePositions = new List <BasicGeoposition>(); foreach (ColoredMapLine lineCollection in newValue) { for (int i = 0; i <= lineCollection.Count() - 2; i++) { var startPoint = lineCollection[i]; var nextPoint = lineCollection[i + 1]; currentLinePositions.Add(startPoint.Coordinates); Color nextColor = nextPoint.LineColor; if (nextPoint == lineCollection.Last() || startPoint.LineColor != nextColor) { MapPolyline polyline = new MapPolyline(); polyline.Path = new Geopath(currentLinePositions); polyline.StrokeColor = Color.FromArgb(192, startPoint.LineColor.R, startPoint.LineColor.G, startPoint.LineColor.B); polyline.StrokeDashed = startPoint.IsLineDashed; polyline.StrokeThickness = 6; if (lineCollection.OptionalId != Guid.Empty) { MapElementExtensions.SetPoiId(polyline, lineCollection.OptionalId); } newPolylines.Add(polyline); currentLinePositions = new List <BasicGeoposition>(); } } } _this.SetMapLines(newPolylines); }