private async void SegmentButtonClicked(object sender, EventArgs e) { // Get the segmented button control that raised the event var buttonControl = sender as UISegmentedControl; // Get the selected segment in the control var selectedSegmentId = buttonControl.SelectedSegment; // Execute the appropriate action for the control if (selectedSegmentId == 0) { // Show basemap choices ShowBasemapList(); } else if (selectedSegmentId == 1) { // Create a new map _mapViewModel.ResetMap(); } else if (selectedSegmentId == 2) { // Create a challenge request for portal credentials (OAuth credential request for arcgis.com) CredentialRequestInfo challengeRequest = new CredentialRequestInfo(); // Use the OAuth implicit grant flow challengeRequest.GenerateTokenOptions = new GenerateTokenOptions { TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit }; // Indicate the url (portal) to authenticate with (ArcGIS Online) challengeRequest.ServiceUri = new Uri("https://www.arcgis.com/sharing/rest"); // Call GetCredentialAsync on the AuthenticationManager to invoke the challenge handler await AuthenticationManager.Current.GetCredentialAsync(challengeRequest, false); // Show the save map UI if (_mapInfoUI != null) { return; } // Create a view to show map item info entry controls over the map view var ovBounds = _mapView.Bounds; ovBounds.Height = ovBounds.Height + 60; _mapInfoUI = new SaveMapDialogOverlay(ovBounds, 0.75f, UIColor.White, _mapView.Map.Item); // Handle the OnMapInfoEntered event to get the info entered by the user _mapInfoUI.OnMapInfoEntered += MapItemInfoEntered; // Handle the cancel event when the user closes the dialog without choosing to save _mapInfoUI.OnCanceled += SaveCanceled; // Add the map item info UI view (will display semi-transparent over the map view) View.Add(_mapInfoUI); } // Unselect all segments (user might want to click the same control twice) buttonControl.SelectedSegment = -1; }
// 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) { try { // Get information entered by the user for the new portal item properties var title = e.Title; var description = e.Description; var tags = e.Tags; // Get the current extent var currentViewpoint = _mapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry); // Export the current map view for the item's thumbnail RuntimeImage thumbnailImg = await _mapView.ExportImageAsync(); // See if the map has already been saved (has an associated portal item) if (!_mapViewModel.MapIsSaved) { // Call a method on MapViewModel to save the map as a new portal item await _mapViewModel.SaveNewMapAsync(currentViewpoint, 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 { // Map has previously been saved as a portal item, update it (title, description, and tags will remain the same) _mapViewModel.UpdateMapItem(); // Report success 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 ex) { // Report save error UIAlertController alert = UIAlertController.Create("Error", ex.Message, UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } finally { // Get rid of the item input controls if (_mapInfoUI != null) { _mapInfoUI.Hide(); _mapInfoUI = null; } } }
private void SaveCanceled(object sender, EventArgs e) { // Remove the item input UI _mapInfoUI.Hide(); _mapInfoUI = null; }