mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Avalonia sample application
This commit is contained in:
parent
f95017bdd3
commit
24b2165d0a
|
|
@ -7,12 +7,15 @@
|
||||||
x:Class="SampleApplication.MainWindow"
|
x:Class="SampleApplication.MainWindow"
|
||||||
Title="MainWindow">
|
Title="MainWindow">
|
||||||
<Grid>
|
<Grid>
|
||||||
|
<Grid.Resources>
|
||||||
|
<local:MapHeadingToVisibilityConverter x:Key="MapHeadingToVisibilityConverter" />
|
||||||
|
</Grid.Resources>
|
||||||
<map:Map x:Name="map"
|
<map:Map x:Name="map"
|
||||||
ZoomLevel="11" MinZoomLevel="3"
|
ZoomLevel="11" MinZoomLevel="3"
|
||||||
Center="53.5,8.2"
|
Center="53.5,8.2"
|
||||||
DoubleTapped="OnMapDoubleTapped">
|
DoubleTapped="OnMapDoubleTapped">
|
||||||
|
|
||||||
<map:MapItemsControl ItemsSource="{Binding Pushpins}">
|
<map:MapItemsControl ItemsSource="{Binding Pushpins}" SelectionMode="Multiple">
|
||||||
<map:MapItemsControl.Styles>
|
<map:MapItemsControl.Styles>
|
||||||
<Style Selector="map|MapItem">
|
<Style Selector="map|MapItem">
|
||||||
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
|
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
|
||||||
|
|
@ -25,7 +28,7 @@
|
||||||
</Setter>
|
</Setter>
|
||||||
</Style>
|
</Style>
|
||||||
<Style Selector="map|MapItem[IsSelected=True]">
|
<Style Selector="map|MapItem[IsSelected=True]">
|
||||||
<Setter Property="Foreground" Value="Red"/>
|
<Setter Property="Foreground" Value="OrangeRed"/>
|
||||||
</Style>
|
</Style>
|
||||||
</map:MapItemsControl.Styles>
|
</map:MapItemsControl.Styles>
|
||||||
</map:MapItemsControl>
|
</map:MapItemsControl>
|
||||||
|
|
@ -155,6 +158,14 @@
|
||||||
Maximum="{Binding MaxZoomLevel, ElementName=map}"
|
Maximum="{Binding MaxZoomLevel, ElementName=map}"
|
||||||
Value="{Binding TargetZoomLevel, ElementName=map}"
|
Value="{Binding TargetZoomLevel, ElementName=map}"
|
||||||
SmallChange="0.1"/>
|
SmallChange="0.1"/>
|
||||||
|
|
||||||
|
<Button Margin="2" Padding="8" ToolTip.Tip="Reset Heading" Click="ResetHeadingButtonClick"
|
||||||
|
FontSize="20" FontFamily="Segoe MDL2 Assets" Content=""
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
HorizontalContentAlignment="Center"
|
||||||
|
IsVisible="{Binding ElementName=map, Path=Heading,
|
||||||
|
Converter={StaticResource MapHeadingToVisibilityConverter}}">
|
||||||
|
</Button>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Data.Converters;
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
using MapControl;
|
using MapControl;
|
||||||
using MapControl.UiTools;
|
using MapControl.UiTools;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace SampleApplication
|
namespace SampleApplication
|
||||||
|
|
@ -70,7 +72,28 @@ namespace SampleApplication
|
||||||
|
|
||||||
private void OnMapDoubleTapped(object sender, TappedEventArgs e)
|
private void OnMapDoubleTapped(object sender, TappedEventArgs e)
|
||||||
{
|
{
|
||||||
map.TargetCenter = map.ViewToLocation(e.GetPosition(map));
|
if (e.Source == map)
|
||||||
|
{
|
||||||
|
map.TargetCenter = map.ViewToLocation(e.GetPosition(map));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResetHeadingButtonClick(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
map.TargetHeading = 0d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MapHeadingToVisibilityConverter : IValueConverter
|
||||||
|
{
|
||||||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
return (double)value != 0d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue