-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a MapControl page in the Media section (#1466)
## Description Adds a MapControl page to the app ## Motivation and Context MapControl was in introduced in WinAppSDK 1.5 and this page demonstrates how to use the control. ## How Has This Been Tested? Ad-hoc testing running app locally. ## Screenshots (if appropriate): ![image](https://github.com/microsoft/WinUI-Gallery/assets/7658216/6595954f-7639-4546-bcc8-24f31b0cfb47) Co-authored-by: bkudiess <barbara.kudiess@microsoft.com> Co-authored-by: Niels Laute <niels.laute@live.nl> Co-authored-by: Karen Lai <biilai@microsoft.com>
- Loading branch information
1 parent
0797527
commit b9d1ad8
Showing
8 changed files
with
176 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<!-- | ||
//********************************************************* | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF | ||
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY | ||
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR | ||
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. | ||
// | ||
//********************************************************* | ||
--> | ||
<Page | ||
x:Class="WinUIGallery.ControlPages.MapControlPage" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:controls="using:Microsoft.UI.Xaml.Controls" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="using:WinUIGallery" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
<StackPanel> | ||
<TextBlock Margin="0,0,0,12" TextWrapping="Wrap"> | ||
<Span xml:space="preserve"><Run>Follow instructions </Run><Hyperlink NavigateUri="https://learn.microsoft.com/en-us/azure/azure-maps/how-to-manage-account-keys">here</Hyperlink><Run> to obtain your MapServiceToken.</Run></Span> | ||
|
||
</TextBlock> | ||
<Image | ||
Height="320" | ||
HorizontalAlignment="Left" | ||
Source="/Assets/SampleMedia/MapExample.png" /> | ||
<local:ControlExample | ||
HorizontalAlignment="Stretch" | ||
HorizontalContentAlignment="Stretch" | ||
CSharpSource="MapControl\MapControlSample_cs.txt" | ||
HeaderText="Showing a pin on the map"> | ||
<local:ControlExample.Example> | ||
<StackPanel Spacing="12"> | ||
<StackPanel Orientation="Horizontal" Spacing="8"> | ||
<PasswordBox | ||
x:Name="MapToken" | ||
Width="200" | ||
KeyDown="MapToken_KeyDown" | ||
PlaceholderText="Map service token" /> | ||
<Button Click="Button_Click" Content="Set token" /> | ||
</StackPanel> | ||
<controls:MapControl | ||
x:Name="map1" | ||
Height="400" | ||
HorizontalAlignment="Stretch" /> | ||
</StackPanel> | ||
</local:ControlExample.Example> | ||
|
||
<local:ControlExample.Xaml> | ||
<x:String xml:space="preserve"> | ||
<controls:MapControl x:Name="map1" MapServiceToken="MapServiceToken" Height="600"/> | ||
</x:String> | ||
</local:ControlExample.Xaml> | ||
</local:ControlExample> | ||
</StackPanel> | ||
</Page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//********************************************************* | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF | ||
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY | ||
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR | ||
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. | ||
// | ||
//********************************************************* | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Windows.Devices.Geolocation; | ||
|
||
namespace WinUIGallery.ControlPages | ||
{ | ||
public sealed partial class MapControlPage : Page | ||
{ | ||
public MapControlPage() | ||
{ | ||
this.InitializeComponent(); | ||
|
||
this.Loaded += MapControlPage_Loaded; | ||
} | ||
|
||
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; | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
WinUIGallery/ControlPagesSampleCode/MapControl/MapControlSample_cs.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
BasicGeoposition centerPosition = new BasicGeoposition { Latitude = 0, Longitude = 0 }; | ||
Geopoint centerPoint = new Geopoint(centerPosition); | ||
|
||
map1.Center = centerPoint; | ||
map1.ZoomLevel = 1; | ||
|
||
var myLandmarks = new List<MapElement>(); | ||
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters