public override void RowSelected(UITableView tableView, NSIndexPath indexPath) { PreplannedMapArea selectedMap = _maps[indexPath.Row]; // Notify subscribers of the new selection. RaiseMapAreaSelected(selectedMap); }
private async void OnDownloadMapAreaClicked(object sender, RoutedEventArgs e) { if (AreasList.SelectedItem != null) { PreplannedMapArea selectedMapArea = AreasList.SelectedItem as PreplannedMapArea; await DownloadMapAreaAsync(selectedMapArea); } }
private void _mapAreaViewModel_MapSelected(object sender, PreplannedMapArea area) { // Dismiss the table view. _tableDisplayController.DismissViewController(true, null); // Download the map area. DownloadMapAreaAsync(area); }
private async void OnDownloadMapAreaClicked(object sender, RoutedEventArgs e) { // Return if selection is being cleared. if (PreplannedAreasList.SelectedIndex == -1) { return; } // Download and show the map. PreplannedMapArea selectedMapArea = PreplannedAreasList.SelectedItem as PreplannedMapArea; await DownloadMapAreaAsync(selectedMapArea); }
private void AreaSelected(object sender, SelectedItemChangedEventArgs e) { PreplannedMapArea selectedMapArea = e.SelectedItem as PreplannedMapArea; string path = Path.Combine(_offlineDataFolder, selectedMapArea.PortalItem.Title); if (Directory.Exists(path)) { DownloadButton.Text = "Display"; } else { DownloadButton.Text = "Download"; } }
private async void OnMenuDownloadMapAreaClicked(object sender, RoutedEventArgs e) { // Get the sending list item. FrameworkElement element = sender as FrameworkElement; // Get the corresponding map area. PreplannedMapArea selectedMapArea = element?.DataContext as PreplannedMapArea; // Update the other list in the UI for consistency (important if user resizes window to be wider). PreplannedAreasList.SelectedItem = selectedMapArea; // Download the map area and show it. await DownloadMapAreaAsync(selectedMapArea); }
private async void OnDownloadMapAreaClicked(string selectedArea) { try { // Get the selected map area. PreplannedMapArea area = _preplannedMapAreas.First(mapArea => mapArea.PortalItem.Title.ToString() == selectedArea); // Download and show the map. await DownloadMapAreaAsync(area); } catch (Exception ex) { // No match found. AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetMessage(ex.Message).SetTitle("Downloading map area failed.").Show(); } }
private async void OnDownloadMapAreaClicked(string selectedArea) { try { // Get the selected map area. PreplannedMapArea area = _preplannedMapAreas.First(mapArea => mapArea.PortalItem.Title.ToString() == selectedArea); // Download the map area. await DownloadMapAreaAsync(area); } catch (Exception ex) { // No match found. UIAlertController alertController = UIAlertController.Create("Downloading map area failed.", ex.Message, UIAlertControllerStyle.Alert); alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alertController, true, null); } }
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { // Gets a cell for the specified section and row. UITableViewCell cell = new UITableViewCell(UITableViewCellStyle.Subtitle, CellIdentifier); PreplannedMapArea selectedMap = _maps[indexPath.Row]; cell.TextLabel.Text = selectedMap.PortalItem.Title; try { NSData imgData = NSData.FromUrl(selectedMap.PortalItem.ThumbnailUri); cell.ImageView.Image = new UIImage(imgData); } catch (Exception ex) { Debug.WriteLine(ex); } cell.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill; return(cell); }
private async Task DownloadMapAreaAsync(PreplannedMapArea mapArea) { // Configure UI for the download. DownloadNotificationText.Visibility = Visibility.Collapsed; ProgressBar.IsIndeterminate = false; ProgressBar.Value = 0; BusyText.Text = "Downloading map area..."; BusyIndicator.Visibility = Visibility.Visible; MyMapView.Visibility = Visibility.Visible; // Get the path for the downloaded map area. string path = Path.Combine(_offlineDataFolder, mapArea.PortalItem.Title); // If the area is already downloaded, open it and don't download it again. if (Directory.Exists(path)) { MobileMapPackage localMapArea = await MobileMapPackage.OpenAsync(path); try { // Load the map. MyMapView.Map = localMapArea.Maps.First(); // Update the UI. BusyText.Text = string.Empty; BusyIndicator.Visibility = Visibility.Collapsed; // Return and don't proceed to download. return; } catch (Exception) { // Do nothing, continue as if map wasn't downloaded. } } // Create job that is used to download the map area. DownloadPreplannedOfflineMapJob job = _offlineMapTask.DownloadPreplannedOfflineMap(mapArea, path); // Subscribe to progress change events to support showing a progress bar. job.ProgressChanged += OnJobProgressChanged; try { // Download the map area. DownloadPreplannedOfflineMapResult results = await job.GetResultAsync(); // Handle possible errors and show them to the user. if (results.HasErrors) { StringBuilder errorBuilder = new StringBuilder(); // Add layer errors to the message. foreach (KeyValuePair <Layer, Exception> layerError in results.LayerErrors) { errorBuilder.AppendLine(string.Format("{0} {1}", layerError.Key.Name, layerError.Value.Message)); } // Add table errors to the message. foreach (KeyValuePair <FeatureTable, Exception> tableError in results.TableErrors) { errorBuilder.AppendLine(string.Format("{0} {1}", tableError.Key.TableName, tableError.Value.Message)); } // Show the message. MessageDialog message = new MessageDialog(errorBuilder.ToString(), "Warning!"); await message.ShowAsync(); } // Show the Map in the MapView. MyMapView.Map = results.OfflineMap; } catch (Exception ex) { // Report exception. MessageDialog message = new MessageDialog(ex.Message, "Downloading map areas failed"); await message.ShowAsync(); } finally { // Clear the loading UI. BusyText.Text = string.Empty; BusyIndicator.Visibility = Visibility.Collapsed; } }
private async Task DownloadMapAreaAsync(PreplannedMapArea mapArea) { // Show the download UI. _progressIndicator.UpdateMessageAndProgress("Downloading map area", 0); View.AddSubview(_progressIndicator); // Get the path for the downloaded map area. var path = Path.Combine(_offlineDataFolder, mapArea.PortalItem.Title); // If the area is already downloaded, open it and don't download it again. if (Directory.Exists(path)) { var localMapArea = await MobileMapPackage.OpenAsync(path); try { // Load the map. _myMapView.Map = localMapArea.Maps.First(); // Reset the UI. _progressIndicator.RemoveFromSuperview(); // Return without proceeding to download. return; } catch (Exception) { // Do nothing, continue as if map wasn't downloaded. } } // Create the job that is used to do the download. DownloadPreplannedOfflineMapJob job = _offlineMapTask.DownloadPreplannedOfflineMap(mapArea, path); // Subscribe to progress change events to support showing a progress bar. job.ProgressChanged += OnJobProgressChanged; try { // Download the map area. DownloadPreplannedOfflineMapResult results = await job.GetResultAsync(); // Handle possible errors and show them to the user. if (results.HasErrors) { var errorBuilder = new StringBuilder(); // Add layer errors to the message. foreach (KeyValuePair <Layer, Exception> layerError in results.LayerErrors) { errorBuilder.AppendLine($"{layerError.Key.Name} {layerError.Value.Message}"); } // Add table errors to the message. foreach (KeyValuePair <FeatureTable, Exception> tableError in results.TableErrors) { errorBuilder.AppendLine($"{tableError.Key.TableName} {tableError.Value.Message}"); } // Show the message. UIAlertController alertController = UIAlertController.Create("Warning!", errorBuilder.ToString(), UIAlertControllerStyle.Alert); alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alertController, true, null); } // Show the Map in the MapView. _myMapView.Map = results.OfflineMap; } catch (Exception ex) { // Report the exception. UIAlertController alertController = UIAlertController.Create("Downloading map area failed.", ex.Message, UIAlertControllerStyle.Alert); alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alertController, true, null); } finally { // Clear the loading UI. _progressIndicator.RemoveFromSuperview(); } }
private async Task DownloadMapAreaAsync(PreplannedMapArea mapArea) { // Set up UI for downloading. ProgressBar.IsIndeterminate = false; ProgressBar.Value = 0; BusyText.Text = "Downloading map area..."; BusyIndicator.Visibility = Visibility.Visible; // Create folder path where the map package will be downloaded. string path = Path.Combine(_offlineDataFolder, mapArea.PortalItem.Title); // If the area is already downloaded, open it. if (Directory.Exists(path)) { try { // Open the offline map package. MobileMapPackage localMapArea = await MobileMapPackage.OpenAsync(path); // Display the first map. MyMapView.Map = localMapArea.Maps.First(); // Update the UI. BusyText.Text = string.Empty; BusyIndicator.Visibility = Visibility.Collapsed; MessageLabel.Text = "Opened offline area."; return; } catch (Exception e) { Debug.WriteLine(e); await new MessageDialog(e.Message, "Couldn't open offline area. Proceeding to take area offline.").ShowAsync(); } } // Create download parameters. DownloadPreplannedOfflineMapParameters parameters = await _offlineMapTask.CreateDefaultDownloadPreplannedOfflineMapParametersAsync(mapArea); // Create the job. DownloadPreplannedOfflineMapJob job = _offlineMapTask.DownloadPreplannedOfflineMap(parameters, path); // Set up event to update the progress bar while the job is in progress. job.ProgressChanged += OnJobProgressChanged; try { // Download the area. DownloadPreplannedOfflineMapResult results = await job.GetResultAsync(); // Handle possible errors and show them to the user. if (results.HasErrors) { // Accumulate all layer and table errors into a single message. string errors = ""; foreach (KeyValuePair <Layer, Exception> layerError in results.LayerErrors) { errors = $"{errors}\n{layerError.Key.Name} {layerError.Value.Message}"; } foreach (KeyValuePair <FeatureTable, Exception> tableError in results.TableErrors) { errors = $"{errors}\n{tableError.Key.TableName} {tableError.Value.Message}"; } // Show the message. await new MessageDialog(errors, "Warning!").ShowAsync(); } // Show the downloaded map. MyMapView.Map = results.OfflineMap; // Update the UI. MessageLabel.Text = "Downloaded preplanned area."; } catch (Exception ex) { // Report any errors. Debug.WriteLine(ex); await new MessageDialog(ex.Message, "Downloading map area failed.").ShowAsync(); } finally { BusyText.Text = string.Empty; BusyIndicator.Visibility = Visibility.Collapsed; } }
private async void DownloadMapAreaAsync(PreplannedMapArea mapArea) { // Close the current mobile package. _mobileMapPackage?.Close(); // Set up UI for downloading. _activityIndicator.StartAnimating(); _helpLabel.Text = "Downloading map area..."; // Create folder path where the map package will be downloaded. string path = Path.Combine(_offlineDataFolder, mapArea.PortalItem.Title); // If the area is already downloaded, open it. if (Directory.Exists(path)) { try { _mobileMapPackage = await MobileMapPackage.OpenAsync(path); _myMapView.Map = _mobileMapPackage.Maps.First(); _helpLabel.Text = "Opened offline area."; _showOnlineButton.Enabled = true; _activityIndicator.StopAnimating(); return; } catch (Exception e) { Debug.WriteLine(e); new UIAlertView("Couldn't open offline map area. Proceeding to take area offline.", e.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show(); } } // Create download parameters. DownloadPreplannedOfflineMapParameters parameters = await _offlineMapTask.CreateDefaultDownloadPreplannedOfflineMapParametersAsync(mapArea); // Set the update mode to not receive updates. parameters.UpdateMode = PreplannedUpdateMode.NoUpdates; // Create the job. DownloadPreplannedOfflineMapJob job = _offlineMapTask.DownloadPreplannedOfflineMap(parameters, path); // Set up event to update the progress bar while the job is in progress. job.ProgressChanged += Job_ProgressChanged; try { // Download the area. DownloadPreplannedOfflineMapResult results = await job.GetResultAsync(); // Set the current mobile map package. _mobileMapPackage = results.MobileMapPackage; // Handle possible errors and show them to the user. if (results.HasErrors) { // Accumulate all layer and table errors into a single message. string errors = ""; foreach (KeyValuePair <Layer, Exception> layerError in results.LayerErrors) { errors = $"{errors}\n{layerError.Key.Name} {layerError.Value.Message}"; } foreach (KeyValuePair <FeatureTable, Exception> tableError in results.TableErrors) { errors = $"{errors}\n{tableError.Key.TableName} {tableError.Value.Message}"; } // Show the message. new UIAlertView("Warning!", errors, (IUIAlertViewDelegate)null, "OK", null).Show(); } // Show the downloaded map. _myMapView.Map = results.OfflineMap; } catch (Exception ex) { // Report any errors. Debug.WriteLine(ex); new UIAlertView("Downloading map area failed", ex.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show(); } finally { _activityIndicator.StopAnimating(); _helpLabel.Text = "Map area offline."; _showOnlineButton.Enabled = true; } }
private async void GeneratePreplannedMap() { ArcGISPortal portal = await ArcGISPortal.CreateAsync(); string itemID = "a9081e4d02dc49f68c6202f03bfe302f"; // Get a web map item using its ID. PortalItem webmapItem = await PortalItem.CreateAsync(portal, itemID); // Create a map from the web map item. Map onlineMap = new Map(webmapItem); // Create an OfflineMapTask from the map ... OfflineMapTask takeMapOfflineTask = await OfflineMapTask.CreateAsync(onlineMap); // ... or a web map portal item. //takeMapOfflineTask = await OfflineMapTask.CreateAsync(webmapItem); // Get a list of the available preplanned map areas. IReadOnlyList <PreplannedMapArea> preplannedMapAreaList = await takeMapOfflineTask.GetPreplannedMapAreasAsync(); // Loop through all preplanned map areas. foreach (PreplannedMapArea mapArea in preplannedMapAreaList) { // Load the preplanned map area so property values can be read. await mapArea.LoadAsync(); // Get the area of interest (geometry) for this area. Geometry aoi = mapArea.AreaOfInterest; // Get the portal item for this area, read the title and thumbnail image. PortalItem preplannedMapItem = mapArea.PortalItem; string mapTitle = preplannedMapItem.Title; RuntimeImage areaThumbnail = preplannedMapItem.Thumbnail; } PreplannedMapArea downloadMapArea = preplannedMapAreaList.First(); string pathToOutputPackage = @"C:\LaurenCDrive\TL\Readiness\Trainings\RT_Offline_Workflows\PrePlannedMap"; DownloadPreplannedOfflineMapJob preplannedMapJob = takeMapOfflineTask.DownloadPreplannedOfflineMap(downloadMapArea, pathToOutputPackage); // Generate the offline map and download it. DownloadPreplannedOfflineMapResult preplannedMapResult = await preplannedMapJob.GetResultAsync(); if (!preplannedMapResult.HasErrors) { // Job completed successfully and all content was generated. Debug.WriteLine("Map " + preplannedMapResult.MobileMapPackage.Item.Title + " was saved to " + preplannedMapResult.MobileMapPackage.Path); // Show the offline map in a MapView. MyMapView.Map = preplannedMapResult.OfflineMap; } else { // Job is finished but one or more layers or tables had errors. if (preplannedMapResult.LayerErrors.Count > 0) { // Show layer errors. foreach (var layerError in preplannedMapResult.LayerErrors) { Debug.WriteLine("Error occurred when taking " + layerError.Key.Name + " offline. Error : " + layerError.Value.Message); } } if (preplannedMapResult.TableErrors.Count > 0) { // Show table errors. foreach (var tableError in preplannedMapResult.TableErrors) { Debug.WriteLine("Error occurred when taking " + tableError.Key.TableName + " offline. Error : " + tableError.Value.Message); } } } }
private async Task DownloadMapAreaAsync(PreplannedMapArea mapArea) { // Show the UI for the download. ProgressBar.Progress = 0; BusyText.Text = "Downloading map area..."; BusyIndicator.IsVisible = true; MyMapView.IsVisible = true; // Get the path for the downloaded map area. string path = Path.Combine(_offlineDataFolder, mapArea.PortalItem.Title); // If the area is already downloaded, open it and don't download it again. if (Directory.Exists(path)) { MobileMapPackage localMapArea = await MobileMapPackage.OpenAsync(path); try { // Load the map. MyMapView.Map = localMapArea.Maps.First(); // Update the UI. BusyText.Text = string.Empty; BusyIndicator.IsVisible = false; // Return without proceeding to download. return; } catch (Exception) { // Do nothing, continue as if the map wasn't downloaded. } } // Create the job that is used to do the download. DownloadPreplannedOfflineMapJob job = _offlineMapTask.DownloadPreplannedOfflineMap(mapArea, path); // Subscribe to progress change events to support showing a progress bar. job.ProgressChanged += OnJobProgressChanged; try { // Download the map area. DownloadPreplannedOfflineMapResult results = await job.GetResultAsync(); // Handle possible errors and show them to the user. if (results.HasErrors) { StringBuilder errorBuilder = new StringBuilder(); // Add layer errors to the message. foreach (KeyValuePair <Layer, Exception> layerError in results.LayerErrors) { errorBuilder.AppendLine($"{layerError.Key.Name} {layerError.Value.Message}"); } // Add table errors to the message. foreach (KeyValuePair <FeatureTable, Exception> tableError in results.TableErrors) { errorBuilder.AppendLine($"{tableError.Key.TableName} {tableError.Value.Message}"); } // Show the message. await((Page)Parent).DisplayAlert("Warning!", errorBuilder.ToString(), "OK"); } // Show the Map in the MapView. MyMapView.Map = results.OfflineMap; } catch (Exception ex) { // Report the exception. await((Page)Parent).DisplayAlert("Downloading map area failed.", ex.Message, "OK"); } finally { // Clear the loading UI. BusyText.Text = string.Empty; BusyIndicator.IsVisible = false; } }
private async Task DownloadMapAreaAsync(PreplannedMapArea mapArea) { // Close the current mobile package. _mobileMapPackage?.Close(); // Set up UI for downloading. ProgressView.Progress = 0; BusyText.Text = "Downloading map area..."; BusyIndicator.IsVisible = true; // Create folder path where the map package will be downloaded. string path = Path.Combine(_offlineDataFolder, mapArea.PortalItem.Title); // If the area is already downloaded, open it. if (Directory.Exists(path)) { try { // Open the offline map package. _mobileMapPackage = await MobileMapPackage.OpenAsync(path); // Open the first map in the package. MyMapView.Map = _mobileMapPackage.Maps.First(); // Update the UI. BusyText.Text = string.Empty; BusyIndicator.IsVisible = false; MessageLabel.Text = "Opened offline area."; return; } catch (Exception e) { Debug.WriteLine(e); await Application.Current.MainPage.DisplayAlert("Couldn't open offline area. Proceeding to take area offline.", e.Message, "OK"); } } // Create download parameters. DownloadPreplannedOfflineMapParameters parameters = await _offlineMapTask.CreateDefaultDownloadPreplannedOfflineMapParametersAsync(mapArea); // Set the update mode to not receive updates. parameters.UpdateMode = PreplannedUpdateMode.NoUpdates; // Create the job. DownloadPreplannedOfflineMapJob job = _offlineMapTask.DownloadPreplannedOfflineMap(parameters, path); // Set up event to update the progress bar while the job is in progress. job.ProgressChanged += OnJobProgressChanged; try { // Download the area. DownloadPreplannedOfflineMapResult results = await job.GetResultAsync(); // Set the current mobile map package. _mobileMapPackage = results.MobileMapPackage; // Handle possible errors and show them to the user. if (results.HasErrors) { // Accumulate all layer and table errors into a single message. string errors = ""; foreach (KeyValuePair <Layer, Exception> layerError in results.LayerErrors) { errors = $"{errors}\n{layerError.Key.Name} {layerError.Value.Message}"; } foreach (KeyValuePair <FeatureTable, Exception> tableError in results.TableErrors) { errors = $"{errors}\n{tableError.Key.TableName} {tableError.Value.Message}"; } // Show the message. await Application.Current.MainPage.DisplayAlert("Warning!", errors, "OK"); } // Show the downloaded map. MyMapView.Map = results.OfflineMap; // Update the UI. ShowOnlineButton.IsEnabled = true; MessageLabel.Text = "Downloaded preplanned area."; DownloadButton.Text = "Display"; } catch (Exception ex) { // Report any errors. Debug.WriteLine(ex); await Application.Current.MainPage.DisplayAlert("Downloading map area failed.", ex.Message, "OK"); } finally { BusyText.Text = string.Empty; BusyIndicator.IsVisible = false; } }
private void RaiseMapAreaSelected(PreplannedMapArea selectedArea) { MapSelected?.Invoke(this, selectedArea); }
private async Task DownloadMapAreaAsync(PreplannedMapArea mapArea) { // Set up UI for download. _progressIndicator.SetMessage("Downloading map area..."); _progressIndicator.SetTitle("Downloading"); _progressIndicator.Show(); // Get the path for the downloaded map area. string path = Path.Combine(_offlineDataFolder, mapArea.PortalItem.Title); // If the map area is already downloaded, open it and don't download it again. if (Directory.Exists(path)) { MobileMapPackage localMapArea = await MobileMapPackage.OpenAsync(path); try { // Load the map area. _myMapView.Map = localMapArea.Maps.First(); // Update the UI. _progressIndicator.Dismiss(); // Return without downloading the item again. return; } catch (Exception) { // Do nothing, continue as if the map wasn't downloaded. } } // Create the job that is used to download the map area. DownloadPreplannedOfflineMapJob job = _offlineMapTask.DownloadPreplannedOfflineMap(mapArea, path); // Subscribe to progress change events to support showing a progress bar. job.ProgressChanged += OnJobProgressChanged; try { // Download the map area. DownloadPreplannedOfflineMapResult results = await job.GetResultAsync(); // Handle possible errors and show them to the user. if (results.HasErrors) { StringBuilder errorBuilder = new StringBuilder(); // Add layer errors to the message. foreach (KeyValuePair <Layer, Exception> layerError in results.LayerErrors) { errorBuilder.AppendLine($"{layerError.Key.Name} {layerError.Value.Message}"); } // Add table errors to the message. foreach (KeyValuePair <FeatureTable, Exception> tableError in results.TableErrors) { errorBuilder.AppendLine($"{tableError.Key.TableName} {tableError.Value.Message}"); } // Show the error message. AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetMessage(errorBuilder.ToString()).SetTitle("Warning!").Show(); } // Show the Map in the MapView. _myMapView.Map = results.OfflineMap; } catch (Exception ex) { // Report exception. AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetMessage(ex.Message).SetTitle("Downloading map area failed.").Show(); } finally { // Clear the loading UI. _progressIndicator.Dismiss(); } }
public MapAreaModel(PreplannedMapArea mapArea) { MapArea = mapArea; Thumbnail = mapArea.PortalItem.ThumbnailUri != null ? new BitmapImage(mapArea.PortalItem.ThumbnailUri) : null; }