diff --git a/MapControl/Avalonia/MapBase.Avalonia.cs b/MapControl/Avalonia/MapBase.Avalonia.cs index dfb32a09..8d7066f4 100644 --- a/MapControl/Avalonia/MapBase.Avalonia.cs +++ b/MapControl/Avalonia/MapBase.Avalonia.cs @@ -16,13 +16,13 @@ global using Avalonia.Media.Imaging; global using Avalonia.Platform; global using Avalonia.Styling; global using Avalonia.Threading; -global using Brush = Avalonia.Media.IBrush; -global using ImageSource = Avalonia.Media.IImage; global using DependencyObject = Avalonia.AvaloniaObject; global using DependencyProperty = Avalonia.AvaloniaProperty; global using FrameworkElement = Avalonia.Controls.Control; global using HorizontalAlignment = Avalonia.Layout.HorizontalAlignment; global using VerticalAlignment = Avalonia.Layout.VerticalAlignment; +global using Brush = Avalonia.Media.IBrush; +global using ImageSource = Avalonia.Media.IImage; global using PathFigureCollection = Avalonia.Media.PathFigures; global using PointCollection = System.Collections.Generic.List; global using PropertyPath = System.String; diff --git a/MapControl/Avalonia/MapControl.Avalonia.csproj b/MapControl/Avalonia/MapControl.Avalonia.csproj index cfda3ddd..70dacd37 100644 --- a/MapControl/Avalonia/MapControl.Avalonia.csproj +++ b/MapControl/Avalonia/MapControl.Avalonia.csproj @@ -24,8 +24,6 @@ - - diff --git a/MapControl/Avalonia/MapItem.Avalonia.cs b/MapControl/Avalonia/MapItem.Avalonia.cs new file mode 100644 index 00000000..1104fd90 --- /dev/null +++ b/MapControl/Avalonia/MapItem.Avalonia.cs @@ -0,0 +1,24 @@ +// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control +// Copyright © 2024 Clemens Fischer +// Licensed under the Microsoft Public License (Ms-PL) + +namespace MapControl +{ + public partial class MapItem + { + public static readonly StyledProperty AutoCollapseProperty = + DependencyPropertyHelper.AddOwner(MapPanel.AutoCollapseProperty); + + public static readonly StyledProperty LocationProperty = + DependencyPropertyHelper.AddOwner(MapPanel.LocationProperty, null, + (item, oldValue, newValue) => item.UpdateMapTransform(newValue)); + + protected override void OnPointerPressed(PointerPressedEventArgs e) + { + base.OnPointerPressed(e); + + (ItemsControl.ItemsControlFromItemContainer(this) as MapItemsControl)?.OnItemClicked( + this, e.KeyModifiers.HasFlag(KeyModifiers.Control), e.KeyModifiers.HasFlag(KeyModifiers.Shift)); + } + } +} diff --git a/MapControl/Avalonia/MapItemsControl.Avalonia.cs b/MapControl/Avalonia/MapItemsControl.Avalonia.cs new file mode 100644 index 00000000..b779e248 --- /dev/null +++ b/MapControl/Avalonia/MapItemsControl.Avalonia.cs @@ -0,0 +1,64 @@ +// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control +// Copyright © 2024 Clemens Fischer +// Licensed under the Microsoft Public License (Ms-PL) + +using Avalonia.Controls.Presenters; +using Avalonia.Controls.Templates; + +namespace MapControl +{ + public partial class MapItemsControl + { + static MapItemsControl() + { + TemplateProperty.OverrideDefaultValue( + new FuncControlTemplate( + (itemsControl, namescope) => new ItemsPresenter { ItemsPanel = itemsControl.ItemsPanel })); + + ItemsPanelProperty.OverrideDefaultValue( + new FuncTemplate(() => new MapPanel())); + } + + public void SelectItemsInGeometry(Geometry geometry) + { + SelectItemsByPosition(p => geometry.FillContains(p)); + } + + protected override bool NeedsContainerOverride(object item, int index, out object recycleKey) + { + recycleKey = null; + + return item is not MapItem; + } + + protected override Control CreateContainerForItemOverride(object item, int index, object recycleKey) + { + return new MapItem(); + } + + protected override void PrepareContainerForItemOverride(Control container, object item, int index) + { + base.PrepareContainerForItemOverride(container, item, index); + + if (LocationMemberPath != null && container is MapItem mapItem) + { + mapItem.SetBinding(MapItem.LocationProperty, + new Binding + { + Path = new PropertyPath(LocationMemberPath), + Source = item + }); + } + } + + protected override void ClearContainerForItemOverride(Control container) + { + base.ClearContainerForItemOverride(container); + + if (LocationMemberPath != null && container is MapItem mapItem) + { + mapItem.ClearValue(MapItem.LocationProperty); + } + } + } +} diff --git a/MapControl/Avalonia/Themes/Generic.axaml b/MapControl/Avalonia/Themes/Generic.axaml index 308630cc..3282c254 100644 --- a/MapControl/Avalonia/Themes/Generic.axaml +++ b/MapControl/Avalonia/Themes/Generic.axaml @@ -2,6 +2,24 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:map="clr-namespace:MapControl"> + + + - - - - - - - + + +