mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 06:26:41 +00:00
Added MapControl.UiTools.MapLayerInfo
This commit is contained in:
parent
c31780a298
commit
d23bc99f3d
16 changed files with 332 additions and 161 deletions
|
|
@ -17,10 +17,6 @@
|
|||
<Compile Include="..\Shared\*.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="..\Shared\HyperlinkText.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\Shared\etna.kml" Link="etna.kml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
|
|
@ -37,7 +33,6 @@
|
|||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.6" />
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.6" />
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.3.6" />
|
||||
<PackageReference Include="Markdown.Avalonia.Tight" Version="11.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.9" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:md="clr-namespace:Markdown.Avalonia;assembly=Markdown.Avalonia"
|
||||
xmlns:map="clr-namespace:MapControl;assembly=MapControl.Avalonia"
|
||||
xmlns:tools="clr-namespace:MapControl.UiTools;assembly=MapUiTools.Avalonia"
|
||||
xmlns:local="clr-namespace:SampleApplication"
|
||||
|
|
@ -12,10 +11,6 @@
|
|||
</Window.DataContext>
|
||||
|
||||
<Grid>
|
||||
<Grid.Resources>
|
||||
<local:MapHeadingToVisibilityConverter x:Key="MapHeadingToVisibilityConverter" />
|
||||
</Grid.Resources>
|
||||
|
||||
<map:Map x:Name="map"
|
||||
ZoomLevel="11" MinZoomLevel="3"
|
||||
Center="53.5,8.2"
|
||||
|
|
@ -117,25 +112,8 @@
|
|||
</TextBlock.Background>
|
||||
</TextBlock>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#7FFFFFFF"
|
||||
DataContext="{Binding MapLayer, ElementName=map}">
|
||||
<ProgressBar Width="100" Height="8" Margin="4,2" VerticalAlignment="Center"
|
||||
Maximum="1" Value="{Binding LoadingProgress}">
|
||||
<ProgressBar.Styles>
|
||||
<Style Selector="ProgressBar[Value=1]">
|
||||
<Setter Property="IsVisible" Value="False"/>
|
||||
</Style>
|
||||
</ProgressBar.Styles>
|
||||
</ProgressBar>
|
||||
|
||||
<LayoutTransformControl Margin="4,2">
|
||||
<LayoutTransformControl.LayoutTransform>
|
||||
<ScaleTransform ScaleX="0.7" ScaleY="0.7"/>
|
||||
</LayoutTransformControl.LayoutTransform>
|
||||
<md:MarkdownScrollViewer Markdown="{Binding Description}"/>
|
||||
</LayoutTransformControl>
|
||||
</StackPanel>
|
||||
|
||||
<tools:MapLayerInfo MapLayer="{Binding MapLayer, ElementName=map}" Background="#AFFFFFFF"/>
|
||||
|
||||
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="6" Background="#7FFFFFFF">
|
||||
<tools:MenuButton x:Name="mapLayersMenuButton"
|
||||
Icon="" Margin="2" ToolTip.Tip="Map Layers and Overlays" Map="{Binding ElementName=map}">
|
||||
|
|
@ -223,9 +201,14 @@
|
|||
<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}}">
|
||||
HorizontalContentAlignment="Center">
|
||||
<Button.IsVisible>
|
||||
<Binding Path="Heading" ElementName="map">
|
||||
<Binding.Converter>
|
||||
<local:MapHeadingToVisibilityConverter/>
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</Button.IsVisible>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
|
|
|||
|
|
@ -1,110 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
#if WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Documents;
|
||||
#elif UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Documents;
|
||||
#else
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
#endif
|
||||
|
||||
namespace SampleApplication
|
||||
{
|
||||
public static class HyperlinkText
|
||||
{
|
||||
private static readonly Regex regex = new Regex(@"\[([^\]]+)\]\(([^\)]+)\)");
|
||||
|
||||
/// <summary>
|
||||
/// Converts text containing hyperlinks in markdown syntax [text](url)
|
||||
/// to a collection of Run and Hyperlink inlines.
|
||||
/// </summary>
|
||||
public static IEnumerable<Inline> TextToInlines(this string text)
|
||||
{
|
||||
var inlines = new List<Inline>();
|
||||
|
||||
while (!string.IsNullOrEmpty(text))
|
||||
{
|
||||
var match = regex.Match(text);
|
||||
|
||||
if (match.Success &&
|
||||
match.Groups.Count == 3 &&
|
||||
Uri.TryCreate(match.Groups[2].Value, UriKind.Absolute, out Uri uri))
|
||||
{
|
||||
inlines.Add(new Run { Text = text.Substring(0, match.Index) });
|
||||
text = text.Substring(match.Index + match.Length);
|
||||
|
||||
var link = new Hyperlink { NavigateUri = uri };
|
||||
link.Inlines.Add(new Run { Text = match.Groups[1].Value });
|
||||
#if !WINUI && !UWP
|
||||
link.ToolTip = uri.ToString();
|
||||
|
||||
link.RequestNavigate += (s, e) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(e.Uri.ToString()) { UseShellExecute = true });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{e.Uri}: {ex}");
|
||||
}
|
||||
};
|
||||
#endif
|
||||
inlines.Add(link);
|
||||
}
|
||||
else
|
||||
{
|
||||
inlines.Add(new Run { Text = text });
|
||||
text = null;
|
||||
}
|
||||
}
|
||||
|
||||
return inlines;
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty InlinesSourceProperty = DependencyProperty.RegisterAttached(
|
||||
"InlinesSource", typeof(string), typeof(HyperlinkText), new PropertyMetadata(null, InlinesSourcePropertyChanged));
|
||||
|
||||
public static string GetInlinesSource(DependencyObject element)
|
||||
{
|
||||
return (string)element.GetValue(InlinesSourceProperty);
|
||||
}
|
||||
|
||||
public static void SetInlinesSource(DependencyObject element, string value)
|
||||
{
|
||||
element.SetValue(InlinesSourceProperty, value);
|
||||
}
|
||||
|
||||
private static void InlinesSourcePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
InlineCollection inlines = null;
|
||||
|
||||
if (obj is TextBlock block)
|
||||
{
|
||||
inlines = block.Inlines;
|
||||
}
|
||||
else if (obj is Paragraph paragraph)
|
||||
{
|
||||
inlines = paragraph.Inlines;
|
||||
}
|
||||
|
||||
if (inlines != null)
|
||||
{
|
||||
inlines.Clear();
|
||||
|
||||
foreach (var inline in TextToInlines((string)e.NewValue))
|
||||
{
|
||||
inlines.Add(inline);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
44
SampleApps/Shared/MapHeadingToVisibilityConverter.cs
Normal file
44
SampleApps/Shared/MapHeadingToVisibilityConverter.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
#if WPF
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
#elif UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Data;
|
||||
#elif WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
#else
|
||||
using Avalonia.Data.Converters;
|
||||
#endif
|
||||
|
||||
namespace SampleApplication
|
||||
{
|
||||
public class MapHeadingToVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
#if AVALONIA
|
||||
return (double)value != 0d;
|
||||
#else
|
||||
return (double)value != 0d ? Visibility.Visible : Visibility.Collapsed;
|
||||
#endif
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return Convert(value, targetType, parameter, culture.ToString());
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return ConvertBack(value, targetType, parameter, culture.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
#if WINUI
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
#elif UWP
|
||||
using Windows.UI.Xaml.Data;
|
||||
#elif AVALONIA
|
||||
using Avalonia.Data.Converters;
|
||||
#endif
|
||||
|
||||
namespace SampleApplication
|
||||
{
|
||||
public class DoubleTriggerConverter : IValueConverter
|
||||
{
|
||||
public double Trigger { get; set; }
|
||||
public object TriggerValue { get; set; }
|
||||
public object DefaultValue { get; set; }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
var converter = TypeDescriptor.GetConverter(targetType);
|
||||
|
||||
return (double)value == Trigger ? converter.ConvertFrom(TriggerValue) : converter.ConvertFrom(DefaultValue);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return Convert(value, targetType, parameter, "");
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return ConvertBack(value, targetType, parameter, "");
|
||||
}
|
||||
}
|
||||
|
||||
public class MapHeadingToVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
return (double)value != 0d;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return Convert(value, targetType, parameter, "");
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return ConvertBack(value, targetType, parameter, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -168,21 +168,7 @@
|
|||
FontFamily="Consolas" Margin="4,2" Visibility="Collapsed"/>
|
||||
</Border>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#AFFFFFFF"
|
||||
DataContext="{Binding MapLayer, ElementName=map}">
|
||||
<ProgressBar Width="100" Height="8" Margin="4,2" VerticalAlignment="Center"
|
||||
Maximum="1" Value="{Binding LoadingProgress}">
|
||||
<ProgressBar.Visibility>
|
||||
<Binding Path="Value" RelativeSource="{RelativeSource Self}">
|
||||
<Binding.Converter>
|
||||
<local:DoubleTriggerConverter Trigger="1" TriggerValue="Collapsed" DefaultValue="Visible"/>
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</ProgressBar.Visibility>
|
||||
</ProgressBar>
|
||||
|
||||
<TextBlock Margin="4,2" FontSize="10" local:HyperlinkText.InlinesSource="{Binding Description}"/>
|
||||
</StackPanel>
|
||||
<tools:MapLayerInfo MapLayer="{Binding MapLayer, ElementName=map}" Background="#AFFFFFFF"/>
|
||||
|
||||
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="6" Background="#7FFFFFFF">
|
||||
<tools:MenuButton x:Name="mapLayersMenuButton"
|
||||
|
|
@ -271,7 +257,7 @@
|
|||
<Button.Visibility>
|
||||
<Binding Path="Heading" ElementName="map">
|
||||
<Binding.Converter>
|
||||
<local:DoubleTriggerConverter Trigger="0" TriggerValue="Collapsed" DefaultValue="Visible"/>
|
||||
<local:MapHeadingToVisibilityConverter/>
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</Button.Visibility>
|
||||
|
|
|
|||
|
|
@ -193,21 +193,7 @@
|
|||
FontFamily="Consolas" Margin="4,2" Visibility="Collapsed"/>
|
||||
</Border>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#AFFFFFFF"
|
||||
DataContext="{Binding MapLayer, ElementName=map}">
|
||||
<ProgressBar Width="100" Height="8" Margin="4,2" VerticalAlignment="Center"
|
||||
Maximum="1" Value="{Binding LoadingProgress}">
|
||||
<ProgressBar.Visibility>
|
||||
<Binding Path="Value" RelativeSource="{RelativeSource Self}">
|
||||
<Binding.Converter>
|
||||
<local:DoubleTriggerConverter Trigger="1" TriggerValue="Collapsed" DefaultValue="Visible"/>
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</ProgressBar.Visibility>
|
||||
</ProgressBar>
|
||||
|
||||
<TextBlock Margin="4,1,4,3" FontSize="10" local:HyperlinkText.InlinesSource="{Binding Description}"/>
|
||||
</StackPanel>
|
||||
<tools:MapLayerInfo MapLayer="{Binding MapLayer, ElementName=map}" Background="#AFFFFFFF"/>
|
||||
|
||||
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="6">
|
||||
<tools:MenuButton x:Name="mapLayersMenuButton"
|
||||
|
|
@ -296,7 +282,7 @@
|
|||
<Button.Visibility>
|
||||
<Binding Path="Heading" ElementName="map">
|
||||
<Binding.Converter>
|
||||
<local:DoubleTriggerConverter Trigger="0" TriggerValue="Collapsed" DefaultValue="Visible"/>
|
||||
<local:MapHeadingToVisibilityConverter/>
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</Button.Visibility>
|
||||
|
|
|
|||
|
|
@ -170,23 +170,7 @@
|
|||
</TextBlock.Background>
|
||||
</TextBlock>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#AFFFFFFF"
|
||||
DataContext="{Binding MapLayer, ElementName=map}">
|
||||
<ProgressBar Width="100" Height="8" Margin="4,2" VerticalAlignment="Center"
|
||||
Maximum="1" Value="{Binding LoadingProgress}">
|
||||
<ProgressBar.Style>
|
||||
<Style TargetType="ProgressBar">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="Value" Value="1">
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ProgressBar.Style>
|
||||
</ProgressBar>
|
||||
|
||||
<TextBlock Margin="4,2" FontSize="10" local:HyperlinkText.InlinesSource="{Binding Description}"/>
|
||||
</StackPanel>
|
||||
<tools:MapLayerInfo MapLayer="{Binding MapLayer, ElementName=map}" Background="#AFFFFFFF"/>
|
||||
|
||||
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="6">
|
||||
<tools:MenuButton x:Name="mapLayersMenuButton"
|
||||
|
|
@ -275,15 +259,13 @@
|
|||
|
||||
<Button Margin="2" Padding="8" ToolTip="Reset Heading" Click="ResetHeadingButtonClick"
|
||||
FontSize="20" FontFamily="Segoe MDL2 Assets" Content="">
|
||||
<Button.Style>
|
||||
<Style TargetType="Button">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Heading, ElementName=map}" Value="0">
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
<Button.Visibility>
|
||||
<Binding Path="Heading" ElementName="map">
|
||||
<Binding.Converter>
|
||||
<local:MapHeadingToVisibilityConverter/>
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</Button.Visibility>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
|
|
|||
|
|
@ -12,10 +12,6 @@
|
|||
<Compile Include="..\Shared\*.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="..\Shared\ValueConverters.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\Shared\10_535_330.jpg" Link="10_535_330.jpg">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue