// A click handler for the save map button private void SaveMapButtonClick(object sender, EventArgs e) { try { // Get information for the new portal item var title = _mapTitleTextbox.Text; var description = _mapDescriptionTextbox.Text; var tags = _tagsTextbox.Text.Split(','); // Make sure all required info was entered if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(description) || tags.Length == 0) { throw new Exception("Please enter a title, description, and some tags to describe the map."); } // Create a new OnSaveMapEventArgs object to store the information entered by the user var mapSavedArgs = new OnSaveMapEventArgs(title, description, tags); // Raise the OnSaveClicked event so the main activity can handle the event and save the map OnSaveClicked(this, mapSavedArgs); // Close the dialog this.Dismiss(); } catch (Exception ex) { // Show the exception message (dialog will stay open so user can try again) var alertBuilder = new AlertDialog.Builder(this.Activity); alertBuilder.SetTitle("Error"); alertBuilder.SetMessage(ex.Message); alertBuilder.Show(); } }
private async void SaveMapAsync(object sender, OnSaveMapEventArgs e) { var alertBuilder = new AlertDialog.Builder(this); // Get the current map var myMap = _myMapView.Map; try { // Show the progress bar so the user knows work is happening _progressBar.Visibility = ViewStates.Visible; // Get information entered by the user for the new portal item properties var title = e.MapTitle; var description = e.MapDescription; var tags = e.Tags; // Apply the current extent as the map's initial extent myMap.InitialViewpoint = _myMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry); // See if the map has already been saved (has an associated portal item) if (myMap.Item == null) { // Call a function to save the map as a new portal item await SaveNewMapAsync(myMap, title, description, tags); // Report a successful save alertBuilder.SetTitle("Map Saved"); alertBuilder.SetMessage("Saved '" + title + "' to ArcGIS Online!"); alertBuilder.Show(); } else { // This is not the initial save, call SaveAsync to save changes to the existing portal item await myMap.SaveAsync(); // Report update was successful alertBuilder.SetTitle("Updates Saved"); alertBuilder.SetMessage("Saved changes to '" + myMap.Item.Title + "'"); alertBuilder.Show(); } } catch (Exception ex) { // Show the exception message alertBuilder.SetTitle("Unable to save map"); alertBuilder.SetMessage(ex.Message); alertBuilder.Show(); } finally { // Hide the progress bar _progressBar.Visibility = ViewStates.Invisible; } }