diff --git a/src/Samples/Toolkit.SampleApp.Maui/MainPage.xaml b/src/Samples/Toolkit.SampleApp.Maui/MainPage.xaml
index 93a793f6c..83f1bd03f 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/MainPage.xaml
+++ b/src/Samples/Toolkit.SampleApp.Maui/MainPage.xaml
@@ -2,6 +2,7 @@
+
@@ -9,4 +10,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Samples/Toolkit.SampleApp.Maui/MainPage.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/MainPage.xaml.cs
index 9982e4fab..52f6f9b4e 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/MainPage.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/MainPage.xaml.cs
@@ -1,4 +1,7 @@
-namespace Toolkit.SampleApp.Maui;
+using Esri.ArcGISRuntime;
+using Esri.ArcGISRuntime.Mapping;
+
+namespace Toolkit.SampleApp.Maui;
public partial class MainPage : ContentPage
{
@@ -6,6 +9,22 @@ public MainPage()
{
InitializeComponent();
SamplesList.ItemsSource = SampleDatasource.Current.Samples;
+ CheckAPIKey();
+ }
+
+ private async void CheckAPIKey()
+ {
+ string key = Preferences.Get("APIKey", string.Empty);
+ if (!string.IsNullOrWhiteSpace(key))
+ {
+ try
+ {
+ var basemap = new Basemap(BasemapStyle.ArcGISStreets) { ApiKey = key };
+ await basemap.LoadAsync();
+ ArcGISRuntimeEnvironment.ApiKey = key;
+ }
+ catch { }
+ }
}
private async void SamplesList_ItemSelected(object? sender, SelectedItemChangedEventArgs e)
@@ -14,15 +33,69 @@ private async void SamplesList_ItemSelected(object? sender, SelectedItemChangedE
if (sample != null)
{
SamplesList.SelectedItem = null;
+ ApiKeyWindow.IsVisible = false;
+ ApiKeyTask?.TrySetResult(false);
+ if (sample.ApiKeyRequired && string.IsNullOrEmpty(ArcGISRuntimeEnvironment.ApiKey))
+ {
+ bool ok = await ShowApiKeyWindow();
+ if (!ok) return;
+ }
try
{
await Navigation.PushAsync(Activator.CreateInstance(sample.Page) as Page);
}
- catch(Exception ex)
+ catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
}
}
-}
+ private TaskCompletionSource? ApiKeyTask;
+
+ private Task ShowApiKeyWindow()
+ {
+ ApiKeyTask?.TrySetResult(false);
+ ApiKeyWindow.IsVisible = true;
+ ApiKeyTask = new TaskCompletionSource();
+ return ApiKeyTask.Task;
+ }
+
+ private void CancelApiKey_Click(object sender, EventArgs e)
+ {
+ ApiKeyWindow.IsVisible = false;
+ ApiKeyTask?.TrySetResult(false);
+ }
+
+ private async void SaveApiKey_Click(object sender, EventArgs e)
+ {
+ string key = ApiKeyInput.Text;
+ if (!string.IsNullOrWhiteSpace(key))
+ {
+ // Test API Key
+ try
+ {
+ var basemap = new Basemap(BasemapStyle.ArcGISStreets) { ApiKey = key };
+ await basemap.LoadAsync();
+ ArcGISRuntimeEnvironment.ApiKey = key;
+ Preferences.Set("APIKey", key);
+ ApiKeyWindow.IsVisible = false;
+ ApiKeyTask?.TrySetResult(true);
+ }
+ catch (System.Exception ex)
+ {
+ _ = DisplayAlert("Invalid API Key", ex.Message, "OK");
+ }
+ }
+ }
+
+ private void DashboardLinkTapped(object sender, TappedEventArgs e)
+ {
+ Microsoft.Maui.ApplicationModel.Launcher.OpenAsync("https://developers.arcgis.com/api-keys/");
+ }
+
+ private void MoreInfoLinkTapped(object sender, TappedEventArgs e)
+ {
+ Microsoft.Maui.ApplicationModel.Launcher.OpenAsync("https://developers.arcgis.com/net/security-and-authentication/#api-keys");
+ }
+}
\ No newline at end of file
diff --git a/src/Samples/Toolkit.SampleApp.Maui/SampleDatasource.cs b/src/Samples/Toolkit.SampleApp.Maui/SampleDatasource.cs
index afdd9694f..07ed2fc42 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/SampleDatasource.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/SampleDatasource.cs
@@ -27,26 +27,28 @@ public static SampleDatasource Current
}
}
}
- public class SampleInfoAttributeAttribute : Attribute
+ public class SampleInfoAttribute : Attribute
{
- public SampleInfoAttributeAttribute()
+ public SampleInfoAttribute()
{
}
public string? Category { get; set; }
public string? Description { get; set; }
public string? DisplayName { get; set; }
+ public bool ApiKeyRequired { get; set; }
}
public class Sample
{
public Sample(Type page)
{
Page = page;
- var attr = page.GetTypeInfo().GetCustomAttribute(typeof(SampleInfoAttributeAttribute)) as SampleInfoAttributeAttribute;
+ var attr = page.GetTypeInfo().GetCustomAttribute(typeof(SampleInfoAttribute)) as SampleInfoAttribute;
if (attr != null)
{
Name = attr.DisplayName;
Category = attr.Category;
Description = attr.Description;
+ ApiKeyRequired = attr.ApiKeyRequired;
}
if (string.IsNullOrEmpty(Name))
{
@@ -71,5 +73,7 @@ public Sample(Type page)
public string? Description { get; set; }
public string? Category { get; set; }
+
+ public bool ApiKeyRequired { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/BasemapGalleryAppearanceSample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/BasemapGalleryAppearanceSample.xaml.cs
index 0aa916a33..88cc90e8a 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/BasemapGalleryAppearanceSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/BasemapGalleryAppearanceSample.xaml.cs
@@ -4,7 +4,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "BasemapGallery", Description = "Appearance customization sample")]
+ [SampleInfo(Category = "BasemapGallery", Description = "Appearance customization sample", ApiKeyRequired = true)]
public partial class BasemapGalleryAppearanceSample : ContentPage
{
public BasemapGalleryAppearanceSample()
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/BasemapGalleryBehaviorSample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/BasemapGalleryBehaviorSample.xaml.cs
index 4f973d297..e9c0a8db8 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/BasemapGalleryBehaviorSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/BasemapGalleryBehaviorSample.xaml.cs
@@ -5,7 +5,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "BasemapGallery", Description = "Exercises various bindings, properties, and interaction behaviors")]
+ [SampleInfo(Category = "BasemapGallery", Description = "Exercises various bindings, properties, and interaction behaviors", ApiKeyRequired = true)]
public partial class BasemapGalleryBehaviorSample : ContentPage
{
public BasemapGalleryBehaviorSample()
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/BookmarksViewSample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/BookmarksViewSample.xaml.cs
index b0f83e8bd..1a6137a9a 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/BookmarksViewSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/BookmarksViewSample.xaml.cs
@@ -6,7 +6,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "BookmarksView", Description = "BookmarksView with MapView sample")]
+ [SampleInfo(Category = "BookmarksView", Description = "BookmarksView with MapView sample")]
public partial class BookmarksViewSample : ContentPage
{
private const string webMapOneUrl = "https://arcgisruntime.maps.arcgis.com/home/item.html?id=e50fafe008ac4ce4ad2236de7fd149c3";
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/BookmarksViewTemplatedSample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/BookmarksViewTemplatedSample.xaml.cs
index 4d6f8d375..34365b04e 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/BookmarksViewTemplatedSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/BookmarksViewTemplatedSample.xaml.cs
@@ -3,7 +3,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "BookmarksView", Description = "BookmarksView with custom item templates")]
+ [SampleInfo(Category = "BookmarksView", Description = "BookmarksView with custom item templates")]
public partial class BookmarksViewTemplatedSample : ContentPage
{
public BookmarksViewTemplatedSample()
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/CompassMapViewSample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/CompassMapViewSample.xaml.cs
index 3831ebbe6..3ad16d2dd 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/CompassMapViewSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/CompassMapViewSample.xaml.cs
@@ -8,7 +8,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "Compass", Description = "Compass with MapView sample")]
+ [SampleInfo(Category = "Compass", Description = "Compass with MapView sample")]
public partial class CompassMapViewSample : ContentPage
{
public CompassMapViewSample()
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/CompassSceneViewSample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/CompassSceneViewSample.xaml.cs
index 153b644a7..47b93eaea 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/CompassSceneViewSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/CompassSceneViewSample.xaml.cs
@@ -3,7 +3,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "Compass", Description = "Compass with SceneView sample")]
+ [SampleInfo(Category = "Compass", Description = "Compass with SceneView sample")]
public partial class CompassSceneViewSample : ContentPage
{
public CompassSceneViewSample()
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/FloorFilterSample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/FloorFilterSample.xaml.cs
index 44f3e3267..59f9a8175 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/FloorFilterSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/FloorFilterSample.xaml.cs
@@ -1,7 +1,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "FloorFilter", Description = "Demonstrates FloorFilter with a floor-aware map.")]
+ [SampleInfo(Category = "FloorFilter", Description = "Demonstrates FloorFilter with a floor-aware map.")]
public partial class FloorFilterSample : ContentPage
{
public FloorFilterSample()
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/LegendSample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/LegendSample.xaml.cs
index 843cd04f7..8984e7c36 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/LegendSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/LegendSample.xaml.cs
@@ -4,7 +4,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "Legend", Description = "Legend with MapView sample")]
+ [SampleInfo(Category = "Legend", Description = "Legend with MapView sample")]
public partial class LegendSample : ContentPage
{
public LegendSample ()
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/OverviewMapSample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/OverviewMapSample.xaml.cs
index b29168ad2..4c9d215aa 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/OverviewMapSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/OverviewMapSample.xaml.cs
@@ -5,7 +5,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "OverviewMap", Description = "Demonstrates various scenarios for the OverviewMap control.")]
+ [SampleInfo(Category = "OverviewMap", Description = "Demonstrates various scenarios for the OverviewMap control.")]
public partial class OverviewMapSample : ContentPage
{
private bool _symbolToggle;
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/PopupViewerSample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/PopupViewerSample.xaml.cs
index 91e780a72..4c8120d60 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/PopupViewerSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/PopupViewerSample.xaml.cs
@@ -8,7 +8,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "PopupViewer", Description = "Use PopupViewer to display detailed feature information")]
+ [SampleInfo(Category = "PopupViewer", Description = "Use PopupViewer to display detailed feature information")]
public partial class PopupViewerSample : ContentPage
{
public PopupViewerSample()
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/ScaleLineSample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/ScaleLineSample.xaml.cs
index 72a67570e..127c5e4d1 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/ScaleLineSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/ScaleLineSample.xaml.cs
@@ -3,7 +3,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "ScaleLine", Description = "Demonstrates ScaleLine.")]
+ [SampleInfo(Category = "ScaleLine", Description = "Demonstrates ScaleLine.")]
public partial class ScaleLineSample : ContentPage
{
public ScaleLineSample ()
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/SearchViewCustomizationSample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/SearchViewCustomizationSample.xaml.cs
index 28e6ed1b4..12bf96ed0 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/SearchViewCustomizationSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/SearchViewCustomizationSample.xaml.cs
@@ -6,7 +6,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "SearchView", Description = "Exercises bindings and advanced customization options.")]
+ [SampleInfo(Category = "SearchView", Description = "Exercises bindings and advanced customization options.", ApiKeyRequired = true)]
public partial class SearchViewCustomizationSample : ContentPage
{
public SearchViewCustomizationSample()
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/SearchViewSample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/SearchViewSample.xaml.cs
index 1cb56f36b..29d9d010d 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/SearchViewSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/SearchViewSample.xaml.cs
@@ -3,7 +3,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "SearchView", Description = "Demonstrates SearchView used with a map.")]
+ [SampleInfo(Category = "SearchView", Description = "Demonstrates SearchView used with a map.", ApiKeyRequired = true)]
public partial class SearchViewSample : ContentPage
{
public SearchViewSample()
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/SearchViewSceneSample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/SearchViewSceneSample.xaml.cs
index 78aa19638..400c4c206 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/SearchViewSceneSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/SearchViewSceneSample.xaml.cs
@@ -3,7 +3,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "SearchView", Description = "Demonstrates SearchView used with a scene.")]
+ [SampleInfo(Category = "SearchView", Description = "Demonstrates SearchView used with a scene.", ApiKeyRequired = true)]
public partial class SearchViewSceneSample : ContentPage
{
public SearchViewSceneSample()
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/SymbolDisplaySample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/SymbolDisplaySample.xaml.cs
index 1b9411694..f988eab08 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/SymbolDisplaySample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/SymbolDisplaySample.xaml.cs
@@ -5,7 +5,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "SymbolDisplay", Description = "Renders a symbol")]
+ [SampleInfo(Category = "SymbolDisplay", Description = "Renders a symbol")]
public partial class SymbolDisplaySample : ContentPage
{
public SymbolDisplaySample()
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/SymbolEditorSample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/SymbolEditorSample.xaml.cs
index 9b9a64549..5182d3d0a 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/SymbolEditorSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/SymbolEditorSample.xaml.cs
@@ -3,7 +3,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "SymbolDisplay", Description = "Dynamically edit a symbol")]
+ [SampleInfo(Category = "SymbolDisplay", Description = "Dynamically edit a symbol")]
public partial class SymbolEditorSample : ContentPage
{
public SymbolEditorSample()
diff --git a/src/Samples/Toolkit.SampleApp.Maui/Samples/UtilityNetworkTraceToolSample.xaml.cs b/src/Samples/Toolkit.SampleApp.Maui/Samples/UtilityNetworkTraceToolSample.xaml.cs
index 7bb4a25c6..bf3b6c54b 100644
--- a/src/Samples/Toolkit.SampleApp.Maui/Samples/UtilityNetworkTraceToolSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.Maui/Samples/UtilityNetworkTraceToolSample.xaml.cs
@@ -4,7 +4,7 @@
namespace Toolkit.SampleApp.Maui.Samples
{
[XamlCompilation(XamlCompilationOptions.Compile)]
- [SampleInfoAttribute(Category = "UtilityNetworkTraceTool", Description = "UtilityNetworkTraceTool")]
+ [SampleInfo(Category = "UtilityNetworkTraceTool", Description = "UtilityNetworkTraceTool")]
public partial class UtilityNetworkTraceToolSample : ContentPage
{
private const string WebmapURL = "https://www.arcgis.com/home/item.html?id=471eb0bf37074b1fbb972b1da70fb310";
diff --git a/src/Samples/Toolkit.SampleApp.UWP/MainPage.xaml b/src/Samples/Toolkit.SampleApp.UWP/MainPage.xaml
index 832454ab7..388167c49 100644
--- a/src/Samples/Toolkit.SampleApp.UWP/MainPage.xaml
+++ b/src/Samples/Toolkit.SampleApp.UWP/MainPage.xaml
@@ -19,12 +19,12 @@
+ IsRightTapEnabled="False"
+ IsItemClickEnabled="True"
+ IsHoldingEnabled="False"
+ IsDoubleTapEnabled="False"
+ ItemClick="sampleView_ItemClick"
+ ItemsSource="{Binding Samples, Source={StaticResource vm}}" >
@@ -46,6 +46,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ You can get or create an API key from your developer dashboard.
+ More info on API Keys
+
+
+
+
+
diff --git a/src/Samples/Toolkit.SampleApp.UWP/MainPage.xaml.cs b/src/Samples/Toolkit.SampleApp.UWP/MainPage.xaml.cs
index 60df5e7f3..61d700c29 100644
--- a/src/Samples/Toolkit.SampleApp.UWP/MainPage.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.UWP/MainPage.xaml.cs
@@ -4,9 +4,12 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
+using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
+using Windows.Storage;
using Windows.UI.Core;
+using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
@@ -29,8 +32,25 @@ public MainPage()
this.InitializeComponent();
this.Loaded += RootFrame_Loaded;
rootFrame.Navigated += RootFrame_Navigated;
+ //CheckAPIKey();
}
- private void RootFrame_Loaded(object sender, RoutedEventArgs e)
+
+ private async void CheckAPIKey()
+ {
+ ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
+ if(localSettings.Values.ContainsKey("APIKey") && localSettings.Values["APIKey"] is string key)
+ {
+ try
+ {
+ var basemap = new Mapping.Basemap(Mapping.BasemapStyle.ArcGISStreets) { ApiKey = key };
+ await basemap.LoadAsync();
+ ArcGISRuntimeEnvironment.ApiKey = key;
+ }
+ catch { }
+ }
+ }
+
+ private async void RootFrame_Loaded(object sender, RoutedEventArgs e)
{
var currentView = SystemNavigationManager.GetForCurrentView();
currentView.BackRequested += (s, args) =>
@@ -50,6 +70,14 @@ private void RootFrame_Loaded(object sender, RoutedEventArgs e)
}
else
{
+
+ ApiKeyWindow.Visibility = Visibility.Collapsed;
+ ApiKeyTask?.TrySetResult(false);
+ if (sample.ApiKeyRequired && string.IsNullOrEmpty(ArcGISRuntimeEnvironment.ApiKey))
+ {
+ bool ok = await ShowApiKeyWindow();
+ if (!ok) return;
+ }
if (!rootFrame.Navigate(sample.Page))
{
throw new Exception("Failed to create initial page");
@@ -80,9 +108,17 @@ private void sampleView_ItemClick(object sender, ItemClickEventArgs e)
NavigateSample(sample);
}
- public void NavigateSample(Sample sample)
+ public async void NavigateSample(Sample sample)
{
if (sample == null) return;
+
+ ApiKeyWindow.Visibility = Visibility.Collapsed;
+ ApiKeyTask?.TrySetResult(false);
+ if (sample.ApiKeyRequired && string.IsNullOrEmpty(ArcGISRuntimeEnvironment.ApiKey))
+ {
+ bool ok = await ShowApiKeyWindow();
+ if (!ok) return;
+ }
if (!rootFrame.Navigate(sample.Page, null))
{
throw new Exception("Failed to create initial page");
@@ -92,6 +128,46 @@ public Frame SampleFrame
{
get { return rootFrame; }
}
+
+ public ICollectionView Samples => SampleDatasource.Current.CollectionViewSource.View;
+
+ private TaskCompletionSource ApiKeyTask; private Task ShowApiKeyWindow()
+ {
+ ApiKeyTask?.TrySetResult(false);
+ ApiKeyWindow.Visibility = Visibility.Visible;
+ ApiKeyTask = new TaskCompletionSource();
+ return ApiKeyTask.Task;
+ }
+
+ private void CancelApiKey_Click(object sender, RoutedEventArgs e)
+ {
+ ApiKeyWindow.Visibility = Visibility.Collapsed;
+ ApiKeyTask.TrySetResult(false);
+ }
+
+ private async void SaveApiKey_Click(object sender, RoutedEventArgs e)
+ {
+ string key = ApiKeyInput.Text;
+ if (!string.IsNullOrWhiteSpace(key))
+ {
+ // Test API Key
+ try
+ {
+ var basemap = new Mapping.Basemap(Mapping.BasemapStyle.ArcGISStreets) { ApiKey = key };
+ await basemap.LoadAsync();
+ ArcGISRuntimeEnvironment.ApiKey = key;
+ ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
+ localSettings.Values["APIKey"] = key;
+ ApiKeyWindow.Visibility = Visibility.Collapsed;
+ ApiKeyTask.TrySetResult(true);
+ }
+ catch (System.Exception ex)
+ {
+ MessageDialog dialog = new MessageDialog(ex.Message, "Invalid API Key");
+ await dialog.ShowAsync();
+ }
+ };
+ }
}
public class SamplesVM
diff --git a/src/Samples/Toolkit.SampleApp.UWP/SampleDatasource.cs b/src/Samples/Toolkit.SampleApp.UWP/SampleDatasource.cs
index bfd627e12..393870a36 100644
--- a/src/Samples/Toolkit.SampleApp.UWP/SampleDatasource.cs
+++ b/src/Samples/Toolkit.SampleApp.UWP/SampleDatasource.cs
@@ -9,18 +9,19 @@
namespace Esri.ArcGISRuntime.Toolkit.SampleApp
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
- public class SampleInfoAttributeAttribute : Attribute
+ public class SampleInfoAttribute : Attribute
{
- public SampleInfoAttributeAttribute()
+ public SampleInfoAttribute()
{
}
public string Category { get; set; }
public string Description { get; set; }
public string DisplayName { get; set; }
+ public bool ApiKeyRequired { get; set; }
}
[Bindable]
- public class SampleDatasource
+ public class SampleDatasource
{
private SampleDatasource()
{
@@ -29,14 +30,15 @@ where t.GetTypeInfo().IsSubclassOf(typeof(Page)) && t.FullName.Contains(".Sample
select t;
Samples = (from p in pages select new Sample() { Page = p }).ToArray();
- foreach(var sample in Samples)
- {
- var attr = sample.Page.GetTypeInfo().GetCustomAttribute(typeof(SampleInfoAttributeAttribute)) as SampleInfoAttributeAttribute;
+ foreach(var sample in Samples)
+ {
+ var attr = sample.Page.GetTypeInfo().GetCustomAttribute(typeof(SampleInfoAttribute)) as SampleInfoAttribute;
if (attr != null)
{
sample.Category = attr.Category;
sample.Description = attr.Description;
sample.Name = attr.DisplayName;
+ sample.ApiKeyRequired = attr.ApiKeyRequired;
}
if (string.IsNullOrEmpty(sample.Name))
{
@@ -51,7 +53,7 @@ where t.GetTypeInfo().IsSubclassOf(typeof(Page)) && t.FullName.Contains(".Sample
sample.Category = sample.Page.Namespace.Substring(sample.Page.Namespace.IndexOf(".Samples.") + 9);
}
}
- }
+ }
}
public IEnumerable Samples { get; private set; }
@@ -67,49 +69,49 @@ public static SampleDatasource Current
}
}
- public IEnumerable SamplesByCategory
- {
- get
- {
- var groups = (from item in Samples
- orderby item.Category
- group item by item.Category into g
- select new SampleGroup(g) { Key = g.Key ?? "Misc" });
- return groups;
- }
- }
- CollectionViewSource m_CollectionViewSource;
- public CollectionViewSource CollectionViewSource
- {
- get
- {
- if(m_CollectionViewSource == null)
- {
- m_CollectionViewSource = new CollectionViewSource()
- {
- IsSourceGrouped = true,
- Source = SamplesByCategory,
- ItemsPath = new PropertyPath("Items")
- };
- }
- return m_CollectionViewSource;
- }
- }
+ public IEnumerable SamplesByCategory
+ {
+ get
+ {
+ var groups = (from item in Samples
+ orderby item.Category
+ group item by item.Category into g
+ select new SampleGroup(g) { Key = g.Key ?? "Misc" });
+ return groups;
+ }
+ }
+ CollectionViewSource m_CollectionViewSource;
+ public CollectionViewSource CollectionViewSource
+ {
+ get
+ {
+ if(m_CollectionViewSource == null)
+ {
+ m_CollectionViewSource = new CollectionViewSource()
+ {
+ IsSourceGrouped = true,
+ Source = SamplesByCategory,
+ ItemsPath = new PropertyPath("Items")
+ };
+ }
+ return m_CollectionViewSource;
+ }
+ }
}
- [Bindable]
- public class SampleGroup
- {
- public SampleGroup(IEnumerable samples)
- {
- Items = samples;
- }
- public string Key { get; set; }
+ [Bindable]
+ public class SampleGroup
+ {
+ public SampleGroup(IEnumerable samples)
+ {
+ Items = samples;
+ }
+ public string Key { get; set; }
- public IEnumerable Items { get; private set; }
- }
+ public IEnumerable Items { get; private set; }
+ }
- [Bindable]
- public class Sample
+ [Bindable]
+ public class Sample
{
public Type Page { get; set; }
@@ -117,7 +119,7 @@ public class Sample
public string Description { get; set; }
- public string Category { get; set; }
+ public string Category { get; set; }
public double FontSize
{
@@ -128,5 +130,6 @@ public double FontSize
}
}
public int Order { get; set; }
+ public bool ApiKeyRequired { get; set; }
}
}
diff --git a/src/Samples/Toolkit.SampleApp.UWP/Samples/BasemapGallery/BasemapGalleryAppearanceSample.xaml.cs b/src/Samples/Toolkit.SampleApp.UWP/Samples/BasemapGallery/BasemapGalleryAppearanceSample.xaml.cs
index a800a9c44..7d805e8a8 100644
--- a/src/Samples/Toolkit.SampleApp.UWP/Samples/BasemapGallery/BasemapGalleryAppearanceSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.UWP/Samples/BasemapGallery/BasemapGalleryAppearanceSample.xaml.cs
@@ -5,6 +5,7 @@
namespace Esri.ArcGISRuntime.Toolkit.SampleApp.Samples.BasemapGallery
{
+ [SampleInfo(ApiKeyRequired = true)]
public sealed partial class BasemapGalleryAppearanceSample : Page
{
public BasemapGalleryAppearanceSample()
diff --git a/src/Samples/Toolkit.SampleApp.UWP/Samples/BasemapGallery/BasemapGalleryBehaviorSample.xaml.cs b/src/Samples/Toolkit.SampleApp.UWP/Samples/BasemapGallery/BasemapGalleryBehaviorSample.xaml.cs
index d69a410d1..e4e9fd058 100644
--- a/src/Samples/Toolkit.SampleApp.UWP/Samples/BasemapGallery/BasemapGalleryBehaviorSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.UWP/Samples/BasemapGallery/BasemapGalleryBehaviorSample.xaml.cs
@@ -5,6 +5,7 @@
namespace Esri.ArcGISRuntime.Toolkit.SampleApp.Samples.BasemapGallery
{
+ [SampleInfo(ApiKeyRequired = true)]
public sealed partial class BasemapGalleryBehaviorSample : Page
{
public BasemapGalleryBehaviorSample()
diff --git a/src/Samples/Toolkit.SampleApp.UWP/Samples/SearchView/SearchViewCustomizationSample.xaml.cs b/src/Samples/Toolkit.SampleApp.UWP/Samples/SearchView/SearchViewCustomizationSample.xaml.cs
index d7d8404da..4c6d3f53f 100644
--- a/src/Samples/Toolkit.SampleApp.UWP/Samples/SearchView/SearchViewCustomizationSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.UWP/Samples/SearchView/SearchViewCustomizationSample.xaml.cs
@@ -11,6 +11,7 @@
namespace Esri.ArcGISRuntime.Toolkit.SampleApp.Samples.SearchView
{
+ [SampleInfo(ApiKeyRequired = true)]
public sealed partial class SearchViewCustomizationSample : Page
{
public SearchViewCustomizationSample()
diff --git a/src/Samples/Toolkit.SampleApp.UWP/Samples/SearchView/SearchViewMapSample.xaml.cs b/src/Samples/Toolkit.SampleApp.UWP/Samples/SearchView/SearchViewMapSample.xaml.cs
index becc1db4a..5fe66671f 100644
--- a/src/Samples/Toolkit.SampleApp.UWP/Samples/SearchView/SearchViewMapSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.UWP/Samples/SearchView/SearchViewMapSample.xaml.cs
@@ -2,6 +2,7 @@
namespace Esri.ArcGISRuntime.Toolkit.SampleApp.Samples.SearchView
{
+ [SampleInfo(ApiKeyRequired = true)]
public sealed partial class SearchViewMapSample : Page
{
public SearchViewMapSample()
diff --git a/src/Samples/Toolkit.SampleApp.UWP/Samples/SearchView/SearchViewSceneSample.xaml.cs b/src/Samples/Toolkit.SampleApp.UWP/Samples/SearchView/SearchViewSceneSample.xaml.cs
index 06c9a1252..ac6014aec 100644
--- a/src/Samples/Toolkit.SampleApp.UWP/Samples/SearchView/SearchViewSceneSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.UWP/Samples/SearchView/SearchViewSceneSample.xaml.cs
@@ -2,6 +2,7 @@
namespace Esri.ArcGISRuntime.Toolkit.SampleApp.Samples.SearchView
{
+ [SampleInfo(ApiKeyRequired = true)]
public sealed partial class SearchViewSceneSample : Page
{
public SearchViewSceneSample()
diff --git a/src/Samples/Toolkit.SampleApp.WPF/MainWindow.xaml b/src/Samples/Toolkit.SampleApp.WPF/MainWindow.xaml
index 44956aff1..d795a6b3e 100644
--- a/src/Samples/Toolkit.SampleApp.WPF/MainWindow.xaml
+++ b/src/Samples/Toolkit.SampleApp.WPF/MainWindow.xaml
@@ -35,5 +35,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ You can get or create an API key from your developer dashboard.
+ More info on API Keys
+
+
+
+
+
diff --git a/src/Samples/Toolkit.SampleApp.WPF/MainWindow.xaml.cs b/src/Samples/Toolkit.SampleApp.WPF/MainWindow.xaml.cs
index 2f79d7380..74a37a4de 100644
--- a/src/Samples/Toolkit.SampleApp.WPF/MainWindow.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.WPF/MainWindow.xaml.cs
@@ -57,8 +57,15 @@ private void LoadSamples()
}
private MenuItem currentSampleMenuItem;
- private void sampleitem_Click(Sample sample, MenuItem menu)
+ private async void sampleitem_Click(Sample sample, MenuItem menu)
{
+ ApiKeyWindow.Visibility = Visibility.Collapsed;
+ ApiKeyTask?.TrySetResult(false);
+ if (sample.ApiKeyRequired && string.IsNullOrEmpty(ArcGISRuntimeEnvironment.ApiKey))
+ {
+ bool ok = await ShowApiKeyWindow();
+ if (!ok) return;
+ }
var c = sample.Page.GetConstructor(new Type[] { });
var ctrl = c.Invoke(new object[] { }) as UIElement;
SampleContainer.Child = ctrl;
@@ -67,5 +74,47 @@ private void sampleitem_Click(Sample sample, MenuItem menu)
menu.IsChecked = true;
currentSampleMenuItem = menu;
}
+
+ TaskCompletionSource ApiKeyTask;
+ private Task ShowApiKeyWindow()
+ {
+ ApiKeyTask?.TrySetResult(false);
+ ApiKeyWindow.Visibility = Visibility.Visible;
+ ApiKeyTask = new TaskCompletionSource();
+ return ApiKeyTask.Task;
+ }
+
+ private void CancelApiKey_Click(object sender, RoutedEventArgs e)
+ {
+ ApiKeyWindow.Visibility = Visibility.Collapsed;
+ ApiKeyTask.TrySetResult(false);
+ }
+
+ private async void SaveApiKey_Click(object sender, RoutedEventArgs e)
+ {
+ string key = ApiKeyInput.Text;
+ if(!string.IsNullOrWhiteSpace(key))
+ {
+ // Test API Key
+ try
+ {
+ var basemap = new Basemap(BasemapStyle.ArcGISStreets) { ApiKey = key };
+ await basemap.LoadAsync();
+ ArcGISRuntimeEnvironment.ApiKey = key;
+ ApiKeyWindow.Visibility = Visibility.Collapsed;
+ ApiKeyTask.TrySetResult(true);
+ }
+ catch (System.Exception ex)
+ {
+ MessageBox.Show(this, "Invalid API Key: " + ex.Message);
+ }
+ };
+ }
+
+ private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
+ {
+ System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(e.Uri.AbsoluteUri) { UseShellExecute = true });
+ e.Handled = true;
+ }
}
}
diff --git a/src/Samples/Toolkit.SampleApp.WPF/SampleDatasource.cs b/src/Samples/Toolkit.SampleApp.WPF/SampleDatasource.cs
index 780bf1a1e..95f961aa3 100644
--- a/src/Samples/Toolkit.SampleApp.WPF/SampleDatasource.cs
+++ b/src/Samples/Toolkit.SampleApp.WPF/SampleDatasource.cs
@@ -10,14 +10,15 @@
namespace Esri.ArcGISRuntime.Toolkit.Samples
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
- public class SampleInfoAttributeAttribute : Attribute
+ public class SampleInfoAttribute : Attribute
{
- public SampleInfoAttributeAttribute()
+ public SampleInfoAttribute()
{
}
public string Category { get; set; }
public string Description { get; set; }
public string DisplayName { get; set; }
+ public bool ApiKeyRequired { get; set; }
}
public class SampleDatasource
@@ -31,12 +32,13 @@ where t.GetTypeInfo().IsSubclassOf(typeof(UserControl)) && t.FullName.Contains("
Samples = (from p in pages select new Sample() { Page = p }).ToArray();
foreach (var sample in Samples)
{
- var attr = sample.Page.GetTypeInfo().GetCustomAttribute(typeof(SampleInfoAttributeAttribute)) as SampleInfoAttributeAttribute;
+ var attr = sample.Page.GetTypeInfo().GetCustomAttribute(typeof(SampleInfoAttribute)) as SampleInfoAttribute;
if (attr != null)
{
sample.Category = attr.Category;
sample.Description = attr.Description;
sample.Name = attr.DisplayName;
+ sample.ApiKeyRequired = attr.ApiKeyRequired;
}
if (string.IsNullOrEmpty(sample.Name))
{
@@ -68,14 +70,17 @@ public static SampleDatasource Current
}
}
}
+
public class Sample
{
public Type Page { get; set; }
-
+
public string Name { get; set; }
-
+
public string Description { get; set; }
- public string Category { get; set; }
+ public string Category { get; set; }
+
+ public bool ApiKeyRequired { get; set; }
}
}
diff --git a/src/Samples/Toolkit.SampleApp.WPF/Samples/BasemapGallery/BasemapGalleryAppearanceSample.xaml.cs b/src/Samples/Toolkit.SampleApp.WPF/Samples/BasemapGallery/BasemapGalleryAppearanceSample.xaml.cs
index 7685be4a4..ef2ebc984 100644
--- a/src/Samples/Toolkit.SampleApp.WPF/Samples/BasemapGallery/BasemapGalleryAppearanceSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.WPF/Samples/BasemapGallery/BasemapGalleryAppearanceSample.xaml.cs
@@ -7,7 +7,7 @@
namespace Esri.ArcGISRuntime.Toolkit.Samples.BasemapGallery
{
- [SampleInfoAttribute(Category = "BasemapGallery", DisplayName = "BasemapGallery - Appearance", Description = "Sample showing customization options related to appearance")]
+ [SampleInfo(Category = "BasemapGallery", DisplayName = "BasemapGallery - Appearance", Description = "Sample showing customization options related to appearance", ApiKeyRequired = true)]
public partial class BasemapGalleryAppearanceSample : UserControl
{
public BasemapGalleryAppearanceSample()
diff --git a/src/Samples/Toolkit.SampleApp.WPF/Samples/BasemapGallery/BasemapGalleryBehaviorSample.xaml.cs b/src/Samples/Toolkit.SampleApp.WPF/Samples/BasemapGallery/BasemapGalleryBehaviorSample.xaml.cs
index d6006abe8..fc51bff7b 100644
--- a/src/Samples/Toolkit.SampleApp.WPF/Samples/BasemapGallery/BasemapGalleryBehaviorSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.WPF/Samples/BasemapGallery/BasemapGalleryBehaviorSample.xaml.cs
@@ -9,7 +9,7 @@
namespace Esri.ArcGISRuntime.Toolkit.Samples.BasemapGallery
{
- [SampleInfoAttribute(Category = "BasemapGallery", DisplayName = "BasemapGallery - Behavior", Description = "Sample showing behaviors")]
+ [SampleInfo(Category = "BasemapGallery", DisplayName = "BasemapGallery - Behavior", Description = "Sample showing behaviors", ApiKeyRequired = true)]
public partial class BasemapGalleryBehaviorSample : UserControl, INotifyPropertyChanged
{
private GeoView _selectedGeoView;
diff --git a/src/Samples/Toolkit.SampleApp.WPF/Samples/BookmarksView/BookmarksViewSample.xaml.cs b/src/Samples/Toolkit.SampleApp.WPF/Samples/BookmarksView/BookmarksViewSample.xaml.cs
index bc289edf4..a3c95d6ff 100644
--- a/src/Samples/Toolkit.SampleApp.WPF/Samples/BookmarksView/BookmarksViewSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.WPF/Samples/BookmarksView/BookmarksViewSample.xaml.cs
@@ -21,7 +21,7 @@ namespace Esri.ArcGISRuntime.Toolkit.Samples.BookmarksView
///
/// Interaction logic for BookmarksViewSample.xaml
///
- [SampleInfoAttribute(Category = "BookmarksView", DisplayName = "BookmarksView - Comprehensive", Description = "Full BookmarksView scenario")]
+ [SampleInfo(Category = "BookmarksView", DisplayName = "BookmarksView - Comprehensive", Description = "Full BookmarksView scenario")]
public partial class BookmarksViewSample : UserControl
{
private const string webMapOneUrl = "https://arcgisruntime.maps.arcgis.com/home/item.html?id=e50fafe008ac4ce4ad2236de7fd149c3";
diff --git a/src/Samples/Toolkit.SampleApp.WPF/Samples/Compass/MapViewCompassSample.xaml.cs b/src/Samples/Toolkit.SampleApp.WPF/Samples/Compass/MapViewCompassSample.xaml.cs
index e78875487..4b9947686 100644
--- a/src/Samples/Toolkit.SampleApp.WPF/Samples/Compass/MapViewCompassSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.WPF/Samples/Compass/MapViewCompassSample.xaml.cs
@@ -15,7 +15,7 @@
namespace Esri.ArcGISRuntime.Toolkit.Samples.Compass
{
- [SampleInfoAttribute(Category = "Compass", DisplayName = "Compass - MapView", Description = "Compass used with a MapView")]
+ [SampleInfo(Category = "Compass", DisplayName = "Compass - MapView", Description = "Compass used with a MapView")]
public partial class MapViewCompassSample : UserControl
{
public MapViewCompassSample()
diff --git a/src/Samples/Toolkit.SampleApp.WPF/Samples/Compass/SceneViewCompassSample.xaml.cs b/src/Samples/Toolkit.SampleApp.WPF/Samples/Compass/SceneViewCompassSample.xaml.cs
index 5df058773..ed38b63fc 100644
--- a/src/Samples/Toolkit.SampleApp.WPF/Samples/Compass/SceneViewCompassSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.WPF/Samples/Compass/SceneViewCompassSample.xaml.cs
@@ -16,7 +16,7 @@
namespace Esri.ArcGISRuntime.Toolkit.Samples.Compass
{
- [SampleInfoAttribute(Category = "Compass", DisplayName = "Compass - SceneView", Description = "Compass used with a SceneView")]
+ [SampleInfo(Category = "Compass", DisplayName = "Compass - SceneView", Description = "Compass used with a SceneView")]
public partial class SceneViewCompassSample : UserControl
{
public SceneViewCompassSample()
diff --git a/src/Samples/Toolkit.SampleApp.WPF/Samples/Legend/LayerLegendSample.xaml.cs b/src/Samples/Toolkit.SampleApp.WPF/Samples/Legend/LayerLegendSample.xaml.cs
index 306ff0f9f..d4fb58113 100644
--- a/src/Samples/Toolkit.SampleApp.WPF/Samples/Legend/LayerLegendSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.WPF/Samples/Legend/LayerLegendSample.xaml.cs
@@ -2,7 +2,7 @@
namespace Esri.ArcGISRuntime.Toolkit.Samples.Legend
{
- [SampleInfoAttribute(Category = "Legend", DisplayName = "LayerLegend [Obsolete]", Description = "LayerLegend is obsolete. See Legend.")]
+ [SampleInfo(Category = "Legend", DisplayName = "LayerLegend [Obsolete]", Description = "LayerLegend is obsolete. See Legend.")]
public partial class LayerLegendSample : UserControl
{
public LayerLegendSample()
diff --git a/src/Samples/Toolkit.SampleApp.WPF/Samples/OverviewMap/OverviewMapSample.xaml.cs b/src/Samples/Toolkit.SampleApp.WPF/Samples/OverviewMap/OverviewMapSample.xaml.cs
index e9d8cff21..bc4dbf5ed 100644
--- a/src/Samples/Toolkit.SampleApp.WPF/Samples/OverviewMap/OverviewMapSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.WPF/Samples/OverviewMap/OverviewMapSample.xaml.cs
@@ -5,7 +5,7 @@
namespace Esri.ArcGISRuntime.Toolkit.Samples.OverviewMap
{
- [SampleInfoAttribute(Category = "OverviewMap", DisplayName = "OverviewMap", Description = "OverviewMap sample")]
+ [SampleInfo(Category = "OverviewMap", DisplayName = "OverviewMap", Description = "OverviewMap sample", ApiKeyRequired = true)]
public partial class OverviewMapSample : UserControl
{
private bool _mapToggle;
diff --git a/src/Samples/Toolkit.SampleApp.WPF/Samples/SearchView/SearchViewCustomizationSample.xaml.cs b/src/Samples/Toolkit.SampleApp.WPF/Samples/SearchView/SearchViewCustomizationSample.xaml.cs
index d935fc959..f98df7494 100644
--- a/src/Samples/Toolkit.SampleApp.WPF/Samples/SearchView/SearchViewCustomizationSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.WPF/Samples/SearchView/SearchViewCustomizationSample.xaml.cs
@@ -15,6 +15,7 @@
namespace Esri.ArcGISRuntime.Toolkit.Samples.SearchView
{
+ [SampleInfo(ApiKeyRequired = true)]
public partial class SearchViewCustomizationSample : UserControl
{
public SearchViewCustomizationSample()
diff --git a/src/Samples/Toolkit.SampleApp.WPF/Samples/SearchView/SearchViewMapSample.xaml.cs b/src/Samples/Toolkit.SampleApp.WPF/Samples/SearchView/SearchViewMapSample.xaml.cs
index ae58c7ef0..a210c895b 100644
--- a/src/Samples/Toolkit.SampleApp.WPF/Samples/SearchView/SearchViewMapSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.WPF/Samples/SearchView/SearchViewMapSample.xaml.cs
@@ -3,6 +3,7 @@
namespace Esri.ArcGISRuntime.Toolkit.Samples.SearchView
{
+ [SampleInfo(ApiKeyRequired = true)]
public partial class SearchViewMapSample : UserControl
{
public SearchViewMapSample()
diff --git a/src/Samples/Toolkit.SampleApp.WPF/Samples/SearchView/SearchViewSceneSample.xaml.cs b/src/Samples/Toolkit.SampleApp.WPF/Samples/SearchView/SearchViewSceneSample.xaml.cs
index 3df61d704..39ba0a9b1 100644
--- a/src/Samples/Toolkit.SampleApp.WPF/Samples/SearchView/SearchViewSceneSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.WPF/Samples/SearchView/SearchViewSceneSample.xaml.cs
@@ -3,6 +3,7 @@
namespace Esri.ArcGISRuntime.Toolkit.Samples.SearchView
{
+ [SampleInfo(ApiKeyRequired = true)]
public partial class SearchViewSceneSample : UserControl
{
public SearchViewSceneSample()
diff --git a/src/Samples/Toolkit.SampleApp.WinUI/MainWindow.xaml b/src/Samples/Toolkit.SampleApp.WinUI/MainWindow.xaml
index d2ffe9f6c..40df81cca 100644
--- a/src/Samples/Toolkit.SampleApp.WinUI/MainWindow.xaml
+++ b/src/Samples/Toolkit.SampleApp.WinUI/MainWindow.xaml
@@ -40,6 +40,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ You can get or create an API key from your developer dashboard.
+ More info on API Keys
+
+
+
+
+
diff --git a/src/Samples/Toolkit.SampleApp.WinUI/MainWindow.xaml.cs b/src/Samples/Toolkit.SampleApp.WinUI/MainWindow.xaml.cs
index 9da3f7929..0930389df 100644
--- a/src/Samples/Toolkit.SampleApp.WinUI/MainWindow.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.WinUI/MainWindow.xaml.cs
@@ -1,4 +1,5 @@
-using Microsoft.UI.Xaml;
+using Esri.ArcGISRuntime.Mapping;
+using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
@@ -10,8 +11,10 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
+using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
+using Windows.Storage;
using Windows.UI.Core;
namespace Esri.ArcGISRuntime.Toolkit.SampleApp
@@ -28,6 +31,22 @@ public MainWindow()
Microsoft.UI.WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWnd);
appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
appWindow.Title = WindowTitle;
+ CheckAPIKey();
+ }
+
+ private async void CheckAPIKey()
+ {
+ ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
+ if (localSettings.Values.ContainsKey("APIKey") && localSettings.Values["APIKey"] is string key)
+ {
+ try
+ {
+ var basemap = new Mapping.Basemap(Mapping.BasemapStyle.ArcGISStreets) { ApiKey = key };
+ await basemap.LoadAsync();
+ ArcGISRuntimeEnvironment.ApiKey = key;
+ }
+ catch { }
+ }
}
private void sampleView_ItemClick(object sender, ItemClickEventArgs e)
@@ -36,9 +55,17 @@ private void sampleView_ItemClick(object sender, ItemClickEventArgs e)
NavigateSample(sample);
}
- public void NavigateSample(Sample sample)
+ public async void NavigateSample(Sample sample)
{
if (sample == null) return;
+
+ ApiKeyWindow.Visibility = Visibility.Collapsed;
+ ApiKeyTask?.TrySetResult(false);
+ if (sample.ApiKeyRequired && string.IsNullOrEmpty(ArcGISRuntimeEnvironment.ApiKey))
+ {
+ bool ok = await ShowApiKeyWindow();
+ if (!ok) return;
+ }
if (!rootFrame.Navigate(sample.Page))
{
throw new Exception("Failed to create initial page");
@@ -54,5 +81,48 @@ public Frame SampleFrame
}
public ICollectionView Samples => SampleDatasource.Current.CollectionViewSource.View;
+
+ private TaskCompletionSource ApiKeyTask;
+ private Task ShowApiKeyWindow()
+ {
+ ApiKeyTask?.TrySetResult(false);
+ ApiKeyWindow.Visibility = Visibility.Visible;
+ ApiKeyTask = new TaskCompletionSource();
+ return ApiKeyTask.Task;
+ }
+
+ private void CancelApiKey_Click(object sender, RoutedEventArgs e)
+ {
+ ApiKeyWindow.Visibility = Visibility.Collapsed;
+ ApiKeyTask.TrySetResult(false);
+ }
+
+ private async void SaveApiKey_Click(object sender, RoutedEventArgs e)
+ {
+ string key = ApiKeyInput.Text;
+ if (!string.IsNullOrWhiteSpace(key))
+ {
+ // Test API Key
+ try
+ {
+ var basemap = new Basemap(BasemapStyle.ArcGISStreets) { ApiKey = key };
+ await basemap.LoadAsync();
+ ArcGISRuntimeEnvironment.ApiKey = key;
+ ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
+ localSettings.Values["APIKey"] = key;
+ ApiKeyWindow.Visibility = Visibility.Collapsed;
+ ApiKeyTask.TrySetResult(true);
+ }
+ catch (System.Exception ex)
+ {
+ var dialog = new ContentDialog();
+ dialog.Title = "Invalid API Key";
+ dialog.Content = ex.Message;
+ dialog.XamlRoot = Content.XamlRoot;
+ dialog.PrimaryButtonText = "OK";
+ await dialog.ShowAsync();
+ }
+ }
+ }
}
}