-
Notifications
You must be signed in to change notification settings - Fork 520
/
ConfigureBasemapStyleParameters.xaml.cs
98 lines (83 loc) · 4.81 KB
/
ConfigureBasemapStyleParameters.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
// 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.Geometry;
using Esri.ArcGISRuntime.Mapping;
using System.Globalization;
namespace ArcGIS.Samples.ConfigureBasemapStyleParameters
{
[ArcGIS.Samples.Shared.Attributes.Sample(
name: "Configure basemap style parameters",
category: "Map",
description: "Apply basemap style parameters customization for a basemap, such as displaying all labels in a specific language or displaying every label in their corresponding local language.",
instructions: "This sample showcases the workflow of configuring basemap style parameters by displaying a basemap with labels in different languages and launches with a `Viewpoint` set over Bulgaria, Greece and Turkey, as they use three different alphabets: Cyrillic, Greek, and Latin, respectively. By default, the `BasemapStyleLanguageStrategy` is set to `Local` which displays all labels in their corresponding local language. This can be changed to `Global`, which displays all labels in English. The `SpecificLanguage` setting sets all labels to a selected language and overrides the `BasemapStyleLanguageStrategy` settings.",
tags: new[] { "basemap style", "language", "language strategy", "map", "point", "viewpoint" })]
[ArcGIS.Samples.Shared.Attributes.OfflineData()]
public partial class ConfigureBasemapStyleParameters
{
/// <summary>
/// Get the selected language from the language picker.
/// </summary>
private string SelectedLanguage
{
get => LanguagePicker.SelectedItem as string;
}
public ConfigureBasemapStyleParameters()
{
InitializeComponent();
Initialize();
}
private void Initialize()
{
MyMapView.Map = new Map();
LanguagePicker.SelectedItem = "None";
SetNewBasemap();
// Focus the viewpoint on an area where the different languages are best showcased: Bulgaria / Greece / Turkey
// as they use three different alphabets: Cyrillic, Greek, and Latin, respectively.
// Thus, showcasing the different functionalities in the most obvious way:
// all English, all Greek, all Bulgarian, all Turkish, or each their own.
MyMapView.SetViewpoint(new Viewpoint(new MapPoint(3144804, 4904598, SpatialReferences.WebMercator), 10000000));
// Ensure parameter changes are reflected on the basemap.
GlobalRadioButton.CheckedChanged += StrategyRadioButton_Checked;
LanguagePicker.SelectedIndexChanged += LanguagePicker_SelectionChanged;
}
private void SetNewBasemap()
{
BasemapStyleParameters basemapStyleParameters = new BasemapStyleParameters();
basemapStyleParameters.LanguageStrategy = (bool)GlobalRadioButton.IsChecked ? BasemapStyleLanguageStrategy.Global : BasemapStyleLanguageStrategy.Local;
switch (SelectedLanguage)
{
// A SpecificLanguage setting overrides the BasemapStyleLanguageStrategy settings when
// the BasemapStyleParameters.SpecificLanguage is a non-empty string.
// Setting the specific language back to an empty string allows the strategy to be used.
case "None":
basemapStyleParameters.SpecificLanguage = new CultureInfo("");
break;
case "Bulgarian":
basemapStyleParameters.SpecificLanguage = new CultureInfo("bg");
break;
case "Greek":
basemapStyleParameters.SpecificLanguage = new CultureInfo("el");
break;
case "Turkish":
basemapStyleParameters.SpecificLanguage = new CultureInfo("tr");
break;
}
MyMapView.Map.Basemap = new Basemap(BasemapStyle.OSMLightGray, basemapStyleParameters);
}
private void LanguagePicker_SelectionChanged(object sender, EventArgs e)
{
GlobalRadioButton.IsEnabled = LocalRadioButton.IsEnabled = SelectedLanguage == "None";
SetNewBasemap();
}
private void StrategyRadioButton_Checked(object sender, CheckedChangedEventArgs e)
{
SetNewBasemap();
}
}
}