mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
MapLayer/MapLayerItemsSource
This commit is contained in:
parent
bb47829cd3
commit
21ac686843
|
|
@ -1,6 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace MapControl
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class MapPanel
|
||||
{
|
||||
|
|
@ -13,18 +11,6 @@ namespace MapControl
|
|||
public static readonly AttachedProperty<BoundingBox> BoundingBoxProperty =
|
||||
DependencyPropertyHelper.RegisterAttached<BoundingBox>("BoundingBox", typeof(MapPanel));
|
||||
|
||||
protected Controls ChildElements => Children;
|
||||
|
||||
protected FrameworkElement GetChildElement(int index) => index < Children.Count ? Children[index] : null;
|
||||
|
||||
protected void InsertChildElement(int index, FrameworkElement element) => Children.Insert(index, element);
|
||||
|
||||
protected void InsertChildElements(int index, IEnumerable<FrameworkElement> elements) => Children.InsertRange(index, elements);
|
||||
|
||||
protected void RemoveChildElement(int index) => Children.RemoveAt(index);
|
||||
|
||||
protected void RemoveChildElements(int index, int count) => Children.RemoveRange(index, count);
|
||||
|
||||
static MapPanel()
|
||||
{
|
||||
AffectsParentArrange<MapPanel>(LocationProperty, BoundingBoxProperty);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
|
|
@ -54,14 +55,14 @@ namespace MapControl
|
|||
|
||||
private void MapLayerPropertyChanged(object oldLayer, object newLayer)
|
||||
{
|
||||
var firstChild = GetChildElement(0);
|
||||
var firstChild = Children.Cast<FrameworkElement>().FirstOrDefault();
|
||||
|
||||
if (oldLayer != null)
|
||||
{
|
||||
if (firstChild != null &&
|
||||
(firstChild == oldLayer as FrameworkElement || firstChild.DataContext == oldLayer))
|
||||
{
|
||||
RemoveChildElement(0);
|
||||
Children.RemoveAt(0);
|
||||
}
|
||||
|
||||
if (hasMapLayerBackground)
|
||||
|
|
@ -83,10 +84,10 @@ namespace MapControl
|
|||
if (firstChild == null ||
|
||||
firstChild != newLayer as FrameworkElement && firstChild.DataContext != newLayer)
|
||||
{
|
||||
InsertChildElement(0, GetMapLayer(newLayer));
|
||||
Children.Insert(0, GetMapLayer(newLayer));
|
||||
}
|
||||
|
||||
if (GetChildElement(0) is IMapLayer mapLayer)
|
||||
if (Children.Cast<FrameworkElement>().FirstOrDefault() is IMapLayer mapLayer)
|
||||
{
|
||||
if (mapLayer.MapBackground != null)
|
||||
{
|
||||
|
|
@ -168,17 +169,23 @@ namespace MapControl
|
|||
|
||||
private void AddMapLayers(List<FrameworkElement> mapLayers, int index)
|
||||
{
|
||||
InsertChildElements(index, mapLayers);
|
||||
foreach (var mapLayer in mapLayers)
|
||||
{
|
||||
Children.Insert(index, mapLayer);
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
MapLayer = mapLayers[0];
|
||||
MapLayer = mapLayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveMapLayers(IEnumerable items, int index)
|
||||
{
|
||||
RemoveChildElements(index, items.Cast<object>().Count());
|
||||
foreach (var _ in items)
|
||||
{
|
||||
Children.RemoveAt(index);
|
||||
}
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#if WPF
|
||||
using System.Linq;
|
||||
#if WPF
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
|
@ -172,7 +173,7 @@ namespace MapControl
|
|||
{
|
||||
availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
|
||||
|
||||
foreach (var element in ChildElements)
|
||||
foreach (var element in Children.Cast<FrameworkElement>())
|
||||
{
|
||||
element.Measure(availableSize);
|
||||
}
|
||||
|
|
@ -184,7 +185,7 @@ namespace MapControl
|
|||
{
|
||||
if (parentMap != null)
|
||||
{
|
||||
foreach (var element in ChildElements)
|
||||
foreach (var element in Children.Cast<FrameworkElement>())
|
||||
{
|
||||
ArrangeChildElement(element, finalSize);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace MapControl
|
||||
|
|
@ -18,24 +16,6 @@ namespace MapControl
|
|||
DependencyPropertyHelper.RegisterAttached<BoundingBox>("BoundingBox", typeof(MapPanel), null,
|
||||
FrameworkPropertyMetadataOptions.AffectsParentArrange);
|
||||
|
||||
protected IEnumerable<FrameworkElement> ChildElements => Children.OfType<FrameworkElement>();
|
||||
|
||||
protected FrameworkElement GetChildElement(int index) => index < Children.Count ? (FrameworkElement)Children[index] : null;
|
||||
|
||||
protected void InsertChildElement(int index, FrameworkElement element) => Children.Insert(index, element);
|
||||
|
||||
protected void InsertChildElements(int index, IEnumerable<FrameworkElement> elements)
|
||||
{
|
||||
foreach (var element in elements)
|
||||
{
|
||||
Children.Insert(index++, element);
|
||||
}
|
||||
}
|
||||
|
||||
protected void RemoveChildElement(int index) => Children.RemoveAt(index);
|
||||
|
||||
protected void RemoveChildElements(int index, int count) => Children.RemoveRange(index, count);
|
||||
|
||||
public static MapBase GetParentMap(FrameworkElement element)
|
||||
{
|
||||
return (MapBase)element.GetValue(ParentMapProperty);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
#if UWP
|
||||
#if UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
#else
|
||||
|
|
@ -25,30 +21,6 @@ namespace MapControl
|
|||
DependencyPropertyHelper.RegisterAttached<BoundingBox>("BoundingBox", typeof(MapPanel), null,
|
||||
(element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange());
|
||||
|
||||
protected IEnumerable<FrameworkElement> ChildElements => Children.OfType<FrameworkElement>();
|
||||
|
||||
protected FrameworkElement GetChildElement(int index) => index < Children.Count ? (FrameworkElement)Children[index] : null;
|
||||
|
||||
protected void InsertChildElement(int index, FrameworkElement element) => Children.Insert(index, element);
|
||||
|
||||
protected void InsertChildElements(int index, IEnumerable<FrameworkElement> elements)
|
||||
{
|
||||
foreach (var element in elements)
|
||||
{
|
||||
Children.Insert(index++, element);
|
||||
}
|
||||
}
|
||||
|
||||
protected void RemoveChildElement(int index) => Children.RemoveAt(index);
|
||||
|
||||
protected void RemoveChildElements(int index, int count)
|
||||
{
|
||||
while (--count >= 0)
|
||||
{
|
||||
RemoveChildElement(index);
|
||||
}
|
||||
}
|
||||
|
||||
public static void InitMapElement(FrameworkElement element)
|
||||
{
|
||||
// Workaround for missing property value inheritance.
|
||||
|
|
|
|||
Loading…
Reference in a new issue