forked from Esri/arcgis-maps-sdk-dotnet-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplayDeviceLocation.xaml.cs
114 lines (94 loc) · 4.62 KB
/
DisplayDeviceLocation.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
110
111
112
113
114
// Copyright 2016 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.Location;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.UI;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace ArcGISRuntime.UWP.Samples.DisplayDeviceLocation
{
[ArcGISRuntime.Samples.Shared.Attributes.Sample(
"Display device location",
"Location",
"This sample demonstrates how you can enable location services and switch between different types of auto pan modes.",
"")]
public partial class DisplayDeviceLocation
{
// String array to store the different device location options.
private string[] _navigationTypes = new string[]
{
"On",
"Re-Center",
"Navigation",
"Compass"
};
public DisplayDeviceLocation()
{
InitializeComponent();
// Setup the control references and execute initialization
Initialize();
}
private void Initialize()
{
// Create new Map with basemap
Map myMap = new Map(Basemap.CreateTopographic());
// Assign the map to the MapView
MyMapView.Map = myMap;
// Set titles as a items source
locationModes.ItemsSource = _navigationTypes;
}
private void OnStopClicked(object sender, RoutedEventArgs e)
{
//TODO Remove this IsStarted check https://github.com/Esri/arcgis-runtime-samples-xamarin/issues/182
if (MyMapView.LocationDisplay.IsEnabled)
MyMapView.LocationDisplay.IsEnabled = false;
locationModes.SelectedItem = null;
}
private void OnLocationModesSelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Selection cleared, don't do anything.
if (!e.AddedItems.Any()) return;
var selectedBasemap = e.AddedItems[0].ToString();
// Get index that is used to get the selected url
var selectedIndex = _navigationTypes.ToList().IndexOf(locationModes.SelectedValue.ToString());
switch (selectedIndex)
{
case 0:
// Starts location display with auto pan mode set to Off
MyMapView.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.Off;
//TODO Remove this IsStarted check https://github.com/Esri/arcgis-runtime-samples-xamarin/issues/182
if (!MyMapView.LocationDisplay.IsEnabled)
MyMapView.LocationDisplay.IsEnabled = true;
break;
case 1:
// Starts location display with auto pan mode set to Re-center
MyMapView.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.Recenter;
//TODO Remove this IsStarted check https://github.com/Esri/arcgis-runtime-samples-xamarin/issues/182
if (!MyMapView.LocationDisplay.IsEnabled)
MyMapView.LocationDisplay.IsEnabled = true;
break;
case 2:
// Starts location display with auto pan mode set to Navigation
MyMapView.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.Navigation;
//TODO Remove this IsStarted check https://github.com/Esri/arcgis-runtime-samples-xamarin/issues/182
if (!MyMapView.LocationDisplay.IsEnabled)
MyMapView.LocationDisplay.IsEnabled = true;
break;
case 3:
// Starts location display with auto pan mode set to Compass Navigation
MyMapView.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.CompassNavigation;
//TODO Remove this IsStarted check https://github.com/Esri/arcgis-runtime-samples-xamarin/issues/182
if (!MyMapView.LocationDisplay.IsEnabled)
MyMapView.LocationDisplay.IsEnabled = true;
break;
}
}
}
}