private void SaveButtonClick(object sender, EventArgs e) { // Get the values entered in the text fields. string title = _titleTextField.Text.Trim(); string description = _descriptionTextField.Text.Trim(); string[] tags = _tagsTextField.Text.Split(','); // Make sure all required info was entered. if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(description) || tags.Length == 0) { new UIAlertView("Error", "Please enter a title, description, and some tags to describe the map.", (IUIAlertViewDelegate)null, "OK", null).Show(); return; } // Fire the OnMapInfoEntered event and provide the map item values. if (OnMapInfoEntered != null) { // Create a new MapSavedEventArgs to contain the user's values. var mapSaveEventArgs = new MapSavedEventArgs(title, description, tags); // Raise the event. OnMapInfoEntered(sender, mapSaveEventArgs); } }
// Handle the OnMapInfoEntered event from the item input UI. // MapSavedEventArgs contains the title, description, and tags that were entered. private async void MapItemInfoEntered(object sender, MapSavedEventArgs e) { // Get the current map. var myMap = _myMapView.Map; try { // Show the activity indicator so the user knows work is happening. _activityIndicator.StartAnimating(); // Get information entered by the user for the new portal item properties. string title = e.Title; string description = e.Description; string[] tags = e.Tags; // Apply the current extent as the map's initial extent. myMap.InitialViewpoint = _myMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry); // Export the current map view for the item's thumbnail. RuntimeImage thumbnailImg = await _myMapView.ExportImageAsync(); // 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, thumbnailImg); // Report a successful save. UIAlertController alert = UIAlertController.Create("Saved map", "Saved " + title + " to ArcGIS Online", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } else { // This is not the initial save, call SaveAsync to save changes to the existing portal item. await myMap.SaveAsync(); // Get the file stream from the new thumbnail image. Stream imageStream = await thumbnailImg.GetEncodedBufferAsync(); // Update the item thumbnail. (myMap.Item as PortalItem).SetThumbnailWithImage(imageStream); await myMap.SaveAsync(); // Report update was successful. UIAlertController alert = UIAlertController.Create("Updated map", "Saved changes to " + title, UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } } catch (Exception) { // Report save error. UIAlertController alert = UIAlertController.Create("Error", "Unable to save " + e.Title, UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } finally { // Get rid of the item input controls. _mapInfoUi.Hide(); _mapInfoUi = null; // Hide the progress bar. _activityIndicator.StopAnimating(); } }