private async void OnSaveMapClicked(object sender, EventArgs e)
{
try
{
// 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("http://www.arcgis.com/sharing/rest");
// Call GetCredentialAsync on the AuthenticationManager to invoke the challenge handler
await AuthenticationManager.Current.GetCredentialAsync(challengeRequest, false);
// See if the map has already been saved
if (!_mapViewModel.MapIsSaved)
{
// Map has not been saved ... save to portal for the first time
ShowSaveMapDialog();
}
else
{
// Map has previously been saved as a portal item, update it (title and description will remain the same)
_mapViewModel.UpdateMapItem();
// Report a successful update
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
dialogBuilder.SetTitle("Map Updated!");
dialogBuilder.SetMessage("Changes to map ('" + _mapViewModel.Map.Item.Title + "' were saved to ArcGIS Online");
dialogBuilder.Show();
}
}
catch (System.OperationCanceledException)
{
// user canceled the login
}
}