コード例 #1
0
        // Create the online basemap layer (with token credentials) and add it to the map
        private async Task InitializeOnlineBasemap()
        {
            try
            {
                _onlineTiledLayer    = new ArcGISTiledMapServiceLayer(new Uri(ONLINE_BASEMAP_URL));
                _onlineTiledLayer.ID = _onlineTiledLayer.DisplayName = ONLINE_LAYER_ID;

                // Generate token credentials if using tiledbasemaps.arcgis.com
                if (!string.IsNullOrEmpty(ONLINE_BASEMAP_TOKEN_URL))
                {
                    // Set credentials and token for online basemap
                    var options = new GenerateTokenOptions()
                    {
                        Referer = new Uri(_onlineTiledLayer.ServiceUri)
                    };

                    var cred = await IdentityManager.Current.GenerateCredentialAsync(ONLINE_BASEMAP_TOKEN_URL, USERNAME, PASSWORD);

                    if (cred != null && !string.IsNullOrEmpty(cred.Token))
                    {
                        _onlineTiledLayer.Token = cred.Token;
                        IdentityManager.Current.AddCredential(cred);
                    }
                }

                await _onlineTiledLayer.InitializeAsync();

                MyMapView.Map.Layers.Add(_onlineTiledLayer);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
        }
コード例 #2
0
        public static async Task <ArcCrudEnum> Authenticate(string username, string password)
        {
            try
            {
                if (AuthenticationManager.Current.Credentials.Any())
                {
                    return(ArcCrudEnum.Success);
                }

                var opts = new GenerateTokenOptions();
                opts.TokenAuthenticationType = TokenAuthenticationType.ArcGISToken;

                var authUrl = AuthenticateUrl;
                AuthenticationManager.Current.RegisterServer(new ServerInfo
                {
                    ServerUri = new Uri(AuthenticateUrl),
                    TokenAuthenticationType = TokenAuthenticationType.ArcGISToken
                });

                var cred = await AuthenticationManager.Current.GenerateCredentialAsync
                               (new Uri(AuthenticateUrl),
                               username,
                               password,
                               opts
                               );

                AuthenticationManager.Current.AddCredential(cred);

                return(ArcCrudEnum.Success);
            }
            catch (ArcGISWebException)
            {
                return(ArcCrudEnum.Failure);
            }
        }
コード例 #3
0
		// Create the online basemap layer (with token credentials) and add it to the map
		private async Task InitializeOnlineBasemap()
		{
			try
			{
				_onlineTiledLayer = new ArcGISTiledMapServiceLayer(new Uri(ONLINE_BASEMAP_URL));
				_onlineTiledLayer.ID = _onlineTiledLayer.DisplayName = ONLINE_LAYER_ID;

				// Generate token credentials if using tiledbasemaps.arcgis.com
				if (!string.IsNullOrEmpty(ONLINE_BASEMAP_TOKEN_URL))
				{
					// Set credentials and token for online basemap
					var options = new GenerateTokenOptions()
					{
						Referer = new Uri(_onlineTiledLayer.ServiceUri)
					};

					var cred = await IdentityManager.Current.GenerateCredentialAsync(ONLINE_BASEMAP_TOKEN_URL, USERNAME, PASSWORD);

					if (cred != null && !string.IsNullOrEmpty(cred.Token))
					{
						_onlineTiledLayer.Token = cred.Token;
						IdentityManager.Current.AddCredential(cred);
					}
				}

				await _onlineTiledLayer.InitializeAsync();
				MyMapView.Map.Layers.Add(_onlineTiledLayer);
			}
			catch (Exception ex)
			{
				var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
			}
		}