-
Notifications
You must be signed in to change notification settings - Fork 521
/
CreateDynamicBasemapGallery.xaml.cs
109 lines (89 loc) · 5.12 KB
/
CreateDynamicBasemapGallery.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2024 Esri.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.
using Esri.ArcGISRuntime.Mapping;
namespace ArcGIS.Samples.CreateDynamicBasemapGallery
{
[ArcGIS.Samples.Shared.Attributes.Sample(
name: "Create dynamic basemap gallery",
category: "Map",
description: "Implement a basemap gallery that automatically retrieves the latest customization options from the basemap styles service.",
instructions: "When launched, this sample displays a map containing a button that, when pressed, displays a gallery of all styles available in the basemap styles service. Selecting a style results in the drop-down menus at the base of the gallery becoming enabled or disabled. A disabled menu indicates that the customization cannot be applied to the selected style. Once a style and any desired customizations have been selected, pressing `Load` will update the basemap in the map view.",
tags: new[] { "basemap", "languages", "service", "style" })]
[ArcGIS.Samples.Shared.Attributes.OfflineData()]
public partial class CreateDynamicBasemapGallery
{
public CreateDynamicBasemapGallery()
{
InitializeComponent();
_ = Initialize();
}
private async Task Initialize()
{
// Create a new map with the ArcGIS Navigation basemap style.
MyMapView.Map = new Map(BasemapStyle.ArcGISNavigation);
// Create a new basemap styles service, pulling in the available styles and their information.
BasemapStylesServiceInfo service = await BasemapStylesServiceInfo.CreateAsync();
// Populate the basemap style gallery.
BasemapStyleGallery.ItemsSource = service.StylesInfo;
// Listen for basemap style selection events.
BasemapStyleGallery.SelectionChanged += BasemapStyleGallery_SelectionChanged;
}
private void BasemapStyleGallery_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Get the selected basemap style info.
var styleInfo = (BasemapStyleInfo)BasemapStyleGallery.SelectedItem;
// Set the pickers to the available options for the selected basemap.
StrategyPicker.ItemsSource = styleInfo.LanguageStrategies.ToList();
LanguagePicker.ItemsSource = styleInfo.Languages.ToList();
WorldviewPicker.ItemsSource = styleInfo.Worldviews.ToList();
// Disable any pickers that have no items.
LanguagePicker.IsEnabled = styleInfo.Languages.Any();
WorldviewPicker.IsEnabled = styleInfo.Worldviews.Any();
StrategyPicker.IsEnabled = styleInfo.LanguageStrategies.Any();
}
private void LoadButton_Click(object sender, EventArgs e)
{
// Return if no basemap style is selected.
if (BasemapStyleGallery.SelectedItem == null) return;
// Create a new basemap style parameters object.
var basemapStyleParameters = new BasemapStyleParameters();
// Set the language to the selected language.
if (LanguagePicker.SelectedItem != null)
basemapStyleParameters.SpecificLanguage = (LanguagePicker.SelectedItem as BasemapStyleLanguageInfo).CultureInfo;
// Set the worldview to the selected worldview.
if (WorldviewPicker.SelectedItem != null)
basemapStyleParameters.Worldview = (WorldviewPicker.SelectedItem as Worldview);
// Set the strategy to the selected strategy.
if (StrategyPicker.SelectedItem != null)
basemapStyleParameters.LanguageStrategy = (BasemapStyleLanguageStrategy)StrategyPicker.SelectedItem;
// Determine the basemap style of the currently selected basemap.
BasemapStyle selectedBasemapStyle = ((BasemapStyleInfo)BasemapStyleGallery.SelectedItem).Style;
// Update the map's basemap.
MyMapView.Map.Basemap = new Basemap(selectedBasemapStyle, basemapStyleParameters);
// Hide the gallery.
HideGallery();
}
private void ShowGallery_Clicked(object sender, EventArgs e)
{
DynamicBasemapStyleGallery.IsVisible = true;
TransparentBackground.IsVisible = true;
ShowGalleryButton.IsEnabled = false;
}
private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
{
HideGallery();
}
private void HideGallery()
{
DynamicBasemapStyleGallery.IsVisible = false;
TransparentBackground.IsVisible = false;
ShowGalleryButton.IsEnabled = true;
}
}
}