public void SetDefaultValues () { Cb = 0x48; Flags = RuntimeImage.ILOnly; CodeManagerTable = DataDirectory.Zero; ExportAddressTableJumps = DataDirectory.Zero; ManagedNativeHeader = DataDirectory.Zero; }
private async void SaveMapAsync(object sender, OnSaveMapEventArgs e) { AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this); // Get the current map Map 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 string title = e.MapTitle; string description = e.MapDescription; 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 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(); // Get the file stream from the new thumbnail image Stream imageStream = await thumbnailImg.GetEncodedBufferAsync(); // Update the item thumbnail ((PortalItem)myMap.Item).SetThumbnail(imageStream); 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; } }
private async Task SaveNewMapAsync(Map myMap, string title, string description, string[] tags, RuntimeImage img) { // Challenge the user for portal credentials (OAuth credential request for arcgis.com) CredentialRequestInfo loginInfo = new CredentialRequestInfo { // Use the OAuth implicit grant flow GenerateTokenOptions = new GenerateTokenOptions { TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit }, // Indicate the url (portal) to authenticate with (ArcGIS Online) ServiceUri = new Uri("https://www.arcgis.com/sharing/rest") }; try { // Get a reference to the (singleton) AuthenticationManager for the app AuthenticationManager thisAuthenticationManager = AuthenticationManager.Current; // Call GetCredentialAsync on the AuthenticationManager to invoke the challenge handler await thisAuthenticationManager.GetCredentialAsync(loginInfo, false); } catch (System.OperationCanceledException) { // user canceled the login throw new Exception("Portal log in was canceled."); } // Get the ArcGIS Online portal (will use credential from login above) ArcGISPortal agsOnline = await ArcGISPortal.CreateAsync(); // Save the current state of the map as a portal item in the user's default folder await myMap.SaveAsAsync(agsOnline, null, title, description, tags, img); }
private async void SaveMapClicked(object sender, RoutedEventArgs e) { try { // 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); // Get the current map view for the item 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[] 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."); } // Call a function to save the map as a new portal item await SaveNewMapAsync(MyMapView.Map, title, description, tags, thumbnailImg); // Report a successful save MessageBox.Show("Saved '" + title + "' to ArcGIS Online!", "Map Saved"); } 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).SetThumbnail(imageStream); await myMap.SaveAsync(); // Report update was successful MessageBox.Show("Saved changes to '" + myMap.Item.Title + "'", "Updates Saved"); } } catch (Exception ex) { // Report error message MessageBox.Show("Error saving map to ArcGIS Online: " + ex.Message); } finally { // Hide the progress bar SaveProgressBar.Visibility = Visibility.Hidden; } }