private async void OnLoadMapClicked(object sender, EventArgs e)
{
// Challenge the user for portal credentials
CredentialRequestInfo loginInfo = new CredentialRequestInfo();
// Use the OAuth implicit grant flow
loginInfo.GenerateTokenOptions = new GenerateTokenOptions
{
TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit
};
// Indicate the url (portal) to authenticate with
loginInfo.ServiceUri = new Uri(PortalUrl);
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);
// Access the portal
ArcGISPortal portal = await ArcGISPortal.CreateAsync(new Uri(PortalUrl));
// Get the item (web map) from the portal
PortalItem item = await PortalItem.CreateAsync(portal, WebMapId);
// Make sure it's a web map
if (item.Type != PortalItemType.WebMap)
{
return;
}
// Display the web map in the map view
Map webMap = new Map(item);
_myMapView.Map = webMap;
}
catch (System.OperationCanceledException)
{
// User canceled the login
var alertBuilder = new AlertDialog.Builder(this);
alertBuilder.SetTitle("Cancel");
alertBuilder.SetMessage("Portal login was canceled.");
alertBuilder.Show();
}
catch(Exception ex)
{
// Other exception
var alertBuilder = new AlertDialog.Builder(this);
alertBuilder.SetTitle("Error");
alertBuilder.SetMessage(ex.Message);
alertBuilder.Show();
}
}