private void Initialize() { // Remove the API key. ApiKeyManager.DisableKey(); // Show a light gray canvas basemap by default. _myMapView.Map = new Map(Basemap.CreateLightGrayCanvas()); }
private void Initialize() { // Remove API key. ApiKeyManager.DisableKey(); // Create new Map with basemap Map myMap = new Map(Basemap.CreateLightGrayCanvas()); // Provide used Map to the MapView _myMapView.Map = myMap; }
private async Task SelectSample(SampleInfo selectedSample) { // The following code removes the API key when using the Create and save map sample. if (nameof(SampleManager.Current.SelectedSample) != nameof(selectedSample)) { // Remove API key if opening Create and save map sample. if (selectedSample.FormalName == "AuthorMap") { ApiKeyManager.DisableKey(); } // Restore API key if leaving Create and save map sample. else if (SampleManager.Current?.SelectedSample?.FormalName == "AuthorMap") { ApiKeyManager.EnableKey(); } } // Call a function to clear existing credentials ClearCredentials(); SampleManager.Current.SelectedSample = selectedSample; try { if (selectedSample.OfflineDataItems != null) { CancellationTokenSource cancellationSource = new CancellationTokenSource(); // Show the waiting page SamplePageContainer.Content = new WaitPage(cancellationSource); SamplePageContainer.Visibility = Visibility.Visible; SampleSelectionGrid.Visibility = Visibility.Collapsed; // Wait for offline data to complete await DataManager.EnsureSampleDataPresent(selectedSample, cancellationSource.Token); } // Show the sample SamplePageContainer.Content = new SamplePage(); SamplePageContainer.Visibility = Visibility.Visible; SampleSelectionGrid.Visibility = Visibility.Collapsed; } catch (Exception exception) { // Failed to create new instance of the sample. SamplePageContainer.Visibility = Visibility.Collapsed; SampleSelectionGrid.Visibility = Visibility.Visible; CategoriesTree.SelectionMode = muxc.TreeViewSelectionMode.None; await new MessageDialog2(exception.Message).ShowAsync(); CategoriesTree.SelectionMode = muxc.TreeViewSelectionMode.Single; } }
private async void OnItemTapped(object sender, ItemTappedEventArgs e) { // Call a function to clear existing credentials. ClearCredentials(); try { // Get the selected sample. SampleInfo item = (SampleInfo)e.Item; if (item.FormalName == "AuthorMap") { // Remove API key if opening Create and save map sample. ApiKeyManager.DisableKey(); } else { // Ensure API key is set in ArcGIS Runtime environment. ApiKeyManager.EnableKey(); } // Load offline data before showing the sample. if (item.OfflineDataItems != null) { CancellationTokenSource cancellationSource = new CancellationTokenSource(); // Show the wait page. await Navigation.PushModalAsync(new WaitPage(cancellationSource) { Title = item.SampleName }, false); #if WINDOWS_UWP // Workaround for bug with Xamarin Forms UWP. await Task.WhenAll( Task.Delay(100), DataManager.EnsureSampleDataPresent(item, cancellationSource.Token) ); #else // Wait for the sample data download. await DataManager.EnsureSampleDataPresent(item, cancellationSource.Token); #endif // Remove the waiting page. await Navigation.PopModalAsync(false); } // Get the sample control from the selected sample. ContentPage sampleControl = (ContentPage)SampleManager.Current.SampleToControl(item); // Create the sample display page to show the sample and the metadata. SamplePage page = new SamplePage(sampleControl, item); // Show the sample. await Navigation.PushAsync(page, true); } catch (OperationCanceledException) { // Remove the waiting page. await Navigation.PopModalAsync(false); await Application.Current.MainPage.DisplayAlert("", "Download cancelled", "OK"); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception occurred on OnItemTapped. Exception = " + ex); } }
private async Task SelectSample(SampleInfo selectedSample) { if (selectedSample == null) { return; } // The following code removes the API key when using the Create and save map sample. if (nameof(SampleManager.Current.SelectedSample) != nameof(selectedSample)) { // Remove API key if opening Create and save map sample. if (selectedSample.FormalName == "AuthorMap") { ApiKeyManager.DisableKey(); } // Restore API key if leaving Create and save map sample. else if (SampleManager.Current?.SelectedSample?.FormalName == "AuthorMap") { ApiKeyManager.EnableKey(); } } SampleTitleBlock.Text = selectedSample.SampleName; SampleManager.Current.SelectedSample = selectedSample; DescriptionContainer.SetSample(selectedSample); ShowSampleTab(); // Call a function to clear any existing credentials from AuthenticationManager ClearCredentials(); try { if (selectedSample.OfflineDataItems != null) { CancellationTokenSource cancellationSource = new CancellationTokenSource(); // Show waiting page SampleContainer.Content = new WPF.Viewer.WaitPage(cancellationSource); // Wait for offline data to complete await DataManager.EnsureSampleDataPresent(selectedSample, cancellationSource.Token); } // Show the sample SampleContainer.Content = SampleManager.Current.SampleToControl(selectedSample); SourceCodeContainer.LoadSourceCode(); } catch (OperationCanceledException) { CategoriesRegion.Visibility = Visibility.Visible; SampleContainer.Visibility = Visibility.Collapsed; return; } catch (Exception exception) { // failed to create new instance of the sample SampleContainer.Content = new WPF.Viewer.ErrorPage(exception); } CategoriesRegion.Visibility = Visibility.Collapsed; SampleContainer.Visibility = Visibility.Visible; }