public UserLocationsView() { InitializeComponent(); dpDataSince.SelectedDate = _viewSince = DateTime.Now.AddDays(-1); dpDataSince.SelectedDateChanged += (o, e) => { _viewSince = dpDataSince.SelectedDate ?? DateTime.MinValue; Refresh(); }; btSearch.Click += (o, e) => { if (!string.IsNullOrEmpty(tbSearch.Text)) { _gmapControl.SetPositionByKeywords(tbSearch.Text); } }; tbSearch.KeyDown += (o, e) => { if (e.Key == Key.Enter && !string.IsNullOrEmpty(tbSearch.Text)) { _gmapControl.SetPositionByKeywords(tbSearch.Text); UpdateCurrentCoords(); } }; wfHost.Child = _gmapControl = new GMapControl(); _gmapControl.Bearing = 0; _gmapControl.MaxZoom = 18; _gmapControl.MinZoom = 2; _gmapControl.Zoom = 1; _gmapControl.MapProvider = GMapProviders.GoogleMap; _gmapControl.Bearing = 0; _gmapControl.CanDragMap = true; _gmapControl.DragButton = MouseButtons.Left; _gmapControl.MaxZoom = 18; _gmapControl.MinZoom = 2; _gmapControl.MouseWheelZoomType = GMap.NET.MouseWheelZoomType.MousePositionWithoutCenter; _gmapControl.ShowTileGridLines = false; _gmapControl.OnMarkerClick += (o, e) => { if (o.Tag is UserAndDevice) { UserNavigated?.Invoke(this, new EventsArgs <UserAndDevice>((UserAndDevice)o.Tag)); } else if (o.Tag is Place) { PlaceNavigated?.Invoke(this, new EventsArgs <string>(((Place)o.Tag).PlaceName)); } }; _gmapControl.OnMapDrag += UpdateCurrentCoords; _gmapControl.OnMapZoomChanged += UpdateCurrentCoords; }
private void SurfaceOnMouseLeftButtonDown(object sender, MouseEventArgs e) { _mouseDownPosition = e.GetPosition(null); _mouseMoved = false; var time = DateTime.UtcNow.TimeOfDay; if ((time - _lastMouseDownTime).TotalMilliseconds < DoubleClickDelay) { _mouseMoved = true; var surface = (FrameworkElement)sender; var point = e.GetPosition(surface); var origin = _position + new Vector2( (float)((point.X / surface.ActualWidth * 2 - 1) / _scale * Aspect), (float)((1 - point.Y / surface.ActualHeight * 2) / _scale)) .Rotate(-_rotation); var minDistance = float.PositiveInfinity; _selectedUserId = -1; var nodes = _nodesBuffer.GetData(); for (var i = 0; i < _users.Length; i++) { var distance = (nodes[i].Position - origin).Length(); if (distance < PhotoRadius && distance < minDistance) { minDistance = distance; _selectedUserId = i; } } if (_selectedUserId != -1) { var user = _users[_selectedUserId].Model; UserSelected?.Invoke(user); UserNavigated?.Invoke(user); } } _lastMouseDownTime = time; }