-
Notifications
You must be signed in to change notification settings - Fork 722
Expand file tree
/
Copy pathMapControlPage.xaml.cs
More file actions
84 lines (68 loc) · 2.52 KB
/
MapControlPage.xaml.cs
File metadata and controls
84 lines (68 loc) · 2.52 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System.Collections.Generic;
using Windows.Devices.Geolocation;
namespace WinUIGallery.ControlPages;
public sealed partial class MapControlPage : Page
{
public MapControlPage()
{
this.InitializeComponent();
this.Loaded += MapControlPage_Loaded;
this.Unloaded += MapControlPage_Unloaded;
}
private void MapControlPage_Unloaded(object sender, RoutedEventArgs e)
{
// MapControl is internally backed by a WebView2 hosting Azure Maps.
// When the page is navigated away from, the WebView2's UIA tree
// (a Pane containing a Chromium RootWebArea with a long
// data:text/html;base64 Name) can outlive the page and contaminate
// subsequent Axe.Windows accessibility scans across the process.
// Explicitly tearing down the MapControl on Unloaded forces the
// framework to dispose the embedded WebView2 and remove its UIA
// subtree from the process tree.
this.Loaded -= MapControlPage_Loaded;
this.Unloaded -= MapControlPage_Unloaded;
if (map1 is not null)
{
map1.Layers.Clear();
if (map1.Parent is Panel parent)
{
parent.Children.Remove(map1);
}
}
}
private void MapControlPage_Loaded(object sender, RoutedEventArgs e)
{
var myLandmarks = new List<MapElement>();
BasicGeoposition centerPosition = new BasicGeoposition { Latitude = 0, Longitude = 0 };
Geopoint centerPoint = new Geopoint(centerPosition);
map1.Center = centerPoint;
map1.ZoomLevel = 1;
BasicGeoposition position = new BasicGeoposition { Latitude = -30.034647, Longitude = -51.217659 };
Geopoint point = new Geopoint(position);
var icon = new MapIcon
{
Location = point,
};
myLandmarks.Add(icon);
var LandmarksLayer = new MapElementsLayer
{
MapElements = myLandmarks
};
map1.Layers.Add(LandmarksLayer);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
map1.MapServiceToken = MapToken.Password;
}
private void MapToken_KeyDown(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{
map1.MapServiceToken = MapToken.Password;
}
}
}