/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { if (e.NavigationMode == NavigationMode.Back) return; var directory = (Directory)NavigationParameters.Instance.GetParameters(); var icon = new MapIconUserControl(directory); var position = new BasicGeoposition(); position.Latitude = directory.Latitude; position.Longitude = directory.Longitude; var geopoint = new Geopoint(position); MapControl.Children.Add(icon); MapControl.SetLocation(icon, geopoint); }
private void MapControl_Loaded(object sender, RoutedEventArgs e) { if (_isBack) return; _listView.ScrollIntoView(_listView.Items.First()); var map = VisualHelper.FindChildControl<Map>(MapHubSection, "MapControl") as Map; _mapControl = map; _mapControl.ZoomLevel = 5; _mapControl.Center = new Location(-42.897857, 170.816761); _mapControl.Children.Clear(); var geopoints = new List<Geopoint>(); _listView.Items.Cast<Directory>().Where(x => x.Latitude != 0 && x.Longitude != 0).ToObservable() .ObserveOnDispatcher().Do(x => { var icon = new MapIconUserControl(x); icon.Tapped -= icon_Tapped; icon.Tapped += icon_Tapped; var position = new BasicGeoposition(); position.Latitude = x.Latitude; position.Longitude = x.Longitude; var geopoint = new Geopoint(position); geopoints.Add(geopoint); MapLayer.SetPosition(icon, new Location(x.Latitude, x.Longitude)); _mapControl.Children.Add(icon); }).Finally(() => SetCenterOfPoints(geopoints)).Subscribe(); }
private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!(sender is Pivot)) return; var pivot = (Pivot)sender; MainCommandBar.Visibility = Visibility.Visible; LockMapAppBar.Visibility = Visibility.Collapsed; switch (pivot.SelectedIndex) { case 0: { MainCommandBar.Visibility = Visibility.Collapsed; break; } case 1: { LockMapAppBar.Visibility = Visibility.Visible; break; } } if (pivot.SelectedIndex == 1) { if (MapControl.Children.Any()) return; var semaphore = new SemaphoreSlim(1); var geopoints = new List<Geopoint>(); SchoolsListView.Items.Cast<Directory>().Where(x => x.Latitude != 0 && x.Longitude != 0).ToObservable() .ObserveOnDispatcher().Do(x => { var icon = new MapIconUserControl(x); icon.Tapped -= icon_Tapped; icon.Tapped += icon_Tapped; var position = new BasicGeoposition(); position.Latitude = x.Latitude; position.Longitude = x.Longitude; MapControl.Children.Add(icon); var geopoint = new Geopoint(position); MapControl.SetLocation(icon, geopoint); geopoints.Add(geopoint); }).Finally(async () => { await semaphore.WaitAsync(); try { await SetCenterOfPoints(geopoints); } finally { semaphore.Release(); } }).Subscribe(); } }
private void DrawNearbySchoolsChanged(IEnumerable<Directory> directories) { var existing = MapControl.Children.Where(x => x.GetType() == typeof(MapIconUserControl)); for (var i = existing.Count(); i > 0; i--) { var directory = (MapIconUserControl)existing.ElementAt(i - 1); directory.Tapped -= icon_Tapped; MapControl.Children.Remove(directory); } foreach (var directory in directories) { var icon = new MapIconUserControl(directory); icon.Tapped -= icon_Tapped; icon.Tapped += icon_Tapped; var position = new BasicGeoposition(); position.Latitude = directory.Latitude; position.Longitude = directory.Longitude; var geopoint = new Geopoint(position); MapControl.Children.Add(icon); MapControl.SetLocation(icon, geopoint); } }