private async void SaveMapClicked(object sender, RoutedEventArgs e) { try { // Don't attempt to save if the OAuth settings weren't provided if (String.IsNullOrEmpty(AppClientId) || String.IsNullOrEmpty(OAuthRedirectUrl)) { MessageDialog dialog = new MessageDialog("OAuth settings were not provided.", "Cannot Save"); await dialog.ShowAsync(); SaveMapFlyout.Hide(); return; } // Show the progress bar so the user knows work is happening SaveProgressBar.Visibility = Visibility.Visible; // Get the current map Map myMap = MyMapView.Map; // Apply the current extent as the map's initial extent myMap.InitialViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry); // Export the current map view to use as 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) { // Get information for the new portal item string title = TitleTextBox.Text; string description = DescriptionTextBox.Text; string tagText = TagsTextBox.Text; // Make sure all required info was entered if (String.IsNullOrEmpty(title) || String.IsNullOrEmpty(description) || String.IsNullOrEmpty(tagText)) { throw new Exception("Please enter a title, description, and some tags to describe the map."); } // Call a function to save the map as a new portal item await SaveNewMapAsync(MyMapView.Map, title, description, tagText.Split(','), thumbnailImg); // Report a successful save MessageDialog messageDialog = new MessageDialog("Saved '" + title + "' to ArcGIS Online!", "Map Saved"); await messageDialog.ShowAsync(); } 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 ((PortalItem)myMap.Item).SetThumbnailWithImage(imageStream); await myMap.SaveAsync(); // Report update was successful MessageDialog messageDialog = new MessageDialog("Saved changes to '" + myMap.Item.Title + "'", "Updates Saved"); await messageDialog.ShowAsync(); } } catch (Exception ex) { // Report error message MessageDialog messageDialog = new MessageDialog("Error saving map to ArcGIS Online: " + ex.Message); await messageDialog.ShowAsync(); } finally { // Hide the progress bar SaveProgressBar.Visibility = Visibility.Collapsed; } }
private async void SaveMapClicked(object sender, RoutedEventArgs e) { try { // Don't attempt to save if the OAuth settings weren't provided if (string.IsNullOrEmpty(AppClientId) || string.IsNullOrEmpty(OAuthRedirectUrl)) { var dialog = new MessageDialog("OAuth settings were not provided.", "Cannot Save"); await dialog.ShowAsync(); SaveMapFlyout.Hide(); return; } // Show the progress bar so the user knows work is happening SaveProgressBar.Visibility = Visibility.Visible; // Get the current map var myMap = MyMapView.Map; // 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) { // Get information for the new portal item var title = TitleTextBox.Text; var description = DescriptionTextBox.Text; var tagText = TagsTextBox.Text; // Make sure all required info was entered if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(description) || string.IsNullOrEmpty(tagText)) { throw new Exception("Please enter a title, description, and some tags to describe the map."); } // Call a function to save the map as a new portal item await SaveNewMapAsync(MyMapView.Map, title, description, tagText.Split(',')); // Report a successful save var messageDialog = new MessageDialog("Saved '" + title + "' to ArcGIS Online!", "Map Saved"); await messageDialog.ShowAsync(); } else { // This is not the initial save, call SaveAsync to save changes to the existing portal item await myMap.SaveAsync(); // Report update was successful var messageDialog = new MessageDialog("Saved changes to '" + myMap.Item.Title + "'", "Updates Saved"); await messageDialog.ShowAsync(); } // Update the portal item thumbnail with the current map image try { // Export the current map view var mapImage = await Esri.ArcGISRuntime.UI.RuntimeImageExtensions.ToImageSourceAsync(await MyMapView.ExportImageAsync()); // Call a function that writes a temporary jpeg file of the map var imagePath = await WriteTempThumbnailImageAsync(mapImage); // Call a function to update the portal item's thumbnail with the image UpdatePortalItemThumbnailAsync(imagePath); } catch { // Throw an exception to let the user know the thumbnail was not saved (the map item was) throw new Exception("Thumbnail was not updated."); } } catch (Exception ex) { // Report error message var messageDialog = new MessageDialog("Error saving map to ArcGIS Online: " + ex.Message); await messageDialog.ShowAsync(); } finally { // Hide the progress bar SaveProgressBar.Visibility = Visibility.Collapsed; } }