mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Version 2.9.0: Added WmsImageLayer, enabled optional setting of MapPanel.Location on MapPath elements
This commit is contained in:
parent
de5576447d
commit
2b66e89696
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2016 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("2.8.0")]
|
||||
[assembly: AssemblyFileVersion("2.8.0")]
|
||||
[assembly: AssemblyVersion("2.9.0")]
|
||||
[assembly: AssemblyFileVersion("2.9.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2016 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("2.8.0")]
|
||||
[assembly: AssemblyFileVersion("2.8.0")]
|
||||
[assembly: AssemblyVersion("2.9.0")]
|
||||
[assembly: AssemblyFileVersion("2.9.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2016 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("2.8.0")]
|
||||
[assembly: AssemblyFileVersion("2.8.0")]
|
||||
[assembly: AssemblyVersion("2.9.0")]
|
||||
[assembly: AssemblyFileVersion("2.9.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2016 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("2.8.0")]
|
||||
[assembly: AssemblyFileVersion("2.8.0")]
|
||||
[assembly: AssemblyVersion("2.9.0")]
|
||||
[assembly: AssemblyFileVersion("2.9.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -8,4 +8,9 @@ namespace MapControl
|
|||
{
|
||||
MapBase ParentMap { get; set; }
|
||||
}
|
||||
|
||||
public interface IMapShape : IMapElement
|
||||
{
|
||||
void LocationChanged(Location oldValue, Location newValue);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,6 +74,9 @@ namespace MapControl
|
|||
double.Parse(pair[1], NumberStyles.Float, CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalizes a longitude to a value in the interval [-180..180].
|
||||
/// </summary>
|
||||
public static double NormalizeLongitude(double longitude)
|
||||
{
|
||||
if (longitude < -180d)
|
||||
|
|
@ -87,5 +90,21 @@ namespace MapControl
|
|||
|
||||
return longitude;
|
||||
}
|
||||
|
||||
internal static double NearestLongitude(double longitude, double referenceLongitude)
|
||||
{
|
||||
longitude = NormalizeLongitude(longitude);
|
||||
|
||||
if (longitude > referenceLongitude + 180d)
|
||||
{
|
||||
longitude -= 360d;
|
||||
}
|
||||
else if (longitude < referenceLongitude - 180d)
|
||||
{
|
||||
longitude += 360d;
|
||||
}
|
||||
|
||||
return longitude;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -618,8 +618,9 @@ namespace MapControl
|
|||
// animate private CenterPoint property by PointAnimation
|
||||
centerAnimation = new PointAnimation
|
||||
{
|
||||
From = mapTransform.Transform(Center),
|
||||
To = mapTransform.Transform(targetCenter, Center.Longitude),
|
||||
To = mapTransform.Transform(new Location(
|
||||
targetCenter.Latitude,
|
||||
Location.NearestLongitude(targetCenter.Longitude, Center.Longitude))),
|
||||
Duration = AnimationDuration,
|
||||
EasingFunction = AnimationEasingFunction
|
||||
};
|
||||
|
|
|
|||
|
|
@ -98,6 +98,8 @@
|
|||
<Compile Include="TileLayerCollection.cs" />
|
||||
<Compile Include="TileSource.cs" />
|
||||
<Compile Include="TileSourceConverter.cs" />
|
||||
<Compile Include="WmsImageLayer.cs" />
|
||||
<Compile Include="WmsImageLayer.WPF.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="Themes\Generic.xaml">
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ namespace MapControl
|
|||
{
|
||||
foreach (UIElement element in Children)
|
||||
{
|
||||
var location = GetLocation(element);
|
||||
Location location;
|
||||
|
||||
if (location != null)
|
||||
if (!(element is IMapShape) && (location = GetLocation(element)) != null)
|
||||
{
|
||||
ArrangeElementWithLocation(element);
|
||||
SetViewportPosition(element, parentMap, location);
|
||||
|
|
@ -82,9 +82,9 @@ namespace MapControl
|
|||
{
|
||||
foreach (UIElement element in Children)
|
||||
{
|
||||
var location = GetLocation(element);
|
||||
Location location;
|
||||
|
||||
if (location != null)
|
||||
if (!(element is IMapShape) && (location = GetLocation(element)) != null)
|
||||
{
|
||||
SetViewportPosition(element, parentMap, location);
|
||||
}
|
||||
|
|
@ -108,22 +108,25 @@ namespace MapControl
|
|||
|
||||
private static void LocationPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var element = obj as UIElement;
|
||||
var element = (UIElement)obj;
|
||||
var mapShape = element as IMapShape;
|
||||
|
||||
if (element != null)
|
||||
if (mapShape != null)
|
||||
{
|
||||
var location = e.NewValue as Location;
|
||||
|
||||
if (location == null)
|
||||
mapShape.LocationChanged((Location)e.OldValue, (Location)e.NewValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (e.NewValue == null)
|
||||
{
|
||||
ArrangeElementWithoutLocation(element, Size.Empty);
|
||||
}
|
||||
else if (e.OldValue == null)
|
||||
{
|
||||
ArrangeElementWithLocation(element); // arrange element when Location was null before
|
||||
ArrangeElementWithLocation(element);
|
||||
}
|
||||
|
||||
SetViewportPosition(element, GetParentMap(element), location);
|
||||
SetViewportPosition(element, GetParentMap(element), (Location)e.NewValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -133,9 +136,9 @@ namespace MapControl
|
|||
|
||||
if (parentMap != null && location != null)
|
||||
{
|
||||
var mapPosition = parentMap.MapTransform.Transform(location, parentMap.Center.Longitude); // nearest to center longitude
|
||||
|
||||
viewportPosition = parentMap.ViewportTransform.Transform(mapPosition);
|
||||
viewportPosition = parentMap.LocationToViewportPoint(new Location(
|
||||
location.Latitude,
|
||||
Location.NearestLongitude(location.Longitude, parentMap.Center.Longitude)));
|
||||
|
||||
if ((bool)element.GetValue(FrameworkElement.UseLayoutRoundingProperty))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace MapControl
|
|||
public static readonly DependencyProperty DataProperty = DependencyProperty.Register(
|
||||
"Data", typeof(Geometry), typeof(MapPath), new FrameworkPropertyMetadata(
|
||||
null, FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(o, e) => ((MapPath)o).UpdateData(), CoerceDataProperty));
|
||||
DataPropertyChanged, CoerceDataProperty));
|
||||
|
||||
static MapPath()
|
||||
{
|
||||
|
|
@ -38,10 +38,18 @@ namespace MapControl
|
|||
return new Size(1, 1);
|
||||
}
|
||||
|
||||
private static void DataPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (!object.ReferenceEquals(e.OldValue, e.NewValue))
|
||||
{
|
||||
((MapPath)obj).UpdateData();
|
||||
}
|
||||
}
|
||||
|
||||
private static object CoerceDataProperty(DependencyObject obj, object value)
|
||||
{
|
||||
var data = (Geometry)value;
|
||||
return data != null && data.IsFrozen ? data.CloneCurrentValue() : data;
|
||||
return (data != null && data.IsFrozen) ? data.CloneCurrentValue() : data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,12 @@
|
|||
// © 2016 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
#if NETFX_CORE
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
#endif
|
||||
|
||||
|
|
@ -14,17 +17,46 @@ namespace MapControl
|
|||
/// Base class for map shapes. The shape geometry is given by the Data property,
|
||||
/// which must contain a Geometry defined in cartesian (projected) map coordinates.
|
||||
/// The Stretch property is meaningless for MapPath, it will be reset to None.
|
||||
/// Optionally, the MapPanel.Location property can by set to move the viewport position
|
||||
/// to a longitude with minimal distance to the longitude of the current map center.
|
||||
/// </summary>
|
||||
public partial class MapPath : IMapElement
|
||||
public partial class MapPath : IMapShape
|
||||
{
|
||||
private readonly TransformGroup viewportTransform = new TransformGroup();
|
||||
private MapBase parentMap;
|
||||
|
||||
public TransformGroup ViewportTransform
|
||||
{
|
||||
get { return viewportTransform; }
|
||||
}
|
||||
|
||||
public MapBase ParentMap
|
||||
{
|
||||
get { return parentMap; }
|
||||
set
|
||||
{
|
||||
var location = MapPanel.GetLocation(this);
|
||||
|
||||
if (parentMap != null && location != null)
|
||||
{
|
||||
parentMap.ViewportChanged -= OnViewportChanged;
|
||||
}
|
||||
|
||||
viewportTransform.Children.Clear();
|
||||
parentMap = value;
|
||||
|
||||
if (parentMap != null)
|
||||
{
|
||||
viewportTransform.Children.Add(parentMap.ViewportTransform);
|
||||
|
||||
if (location != null)
|
||||
{
|
||||
viewportTransform.Children.Insert(0, new TranslateTransform());
|
||||
parentMap.ViewportChanged += OnViewportChanged;
|
||||
OnViewportChanged(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateData();
|
||||
}
|
||||
}
|
||||
|
|
@ -33,15 +65,34 @@ namespace MapControl
|
|||
{
|
||||
if (Data != null)
|
||||
{
|
||||
if (parentMap != null)
|
||||
Data.Transform = viewportTransform;
|
||||
}
|
||||
}
|
||||
|
||||
void IMapShape.LocationChanged(Location oldValue, Location newValue)
|
||||
{
|
||||
if (parentMap != null)
|
||||
{
|
||||
if (newValue == null)
|
||||
{
|
||||
Data.Transform = ParentMap.ViewportTransform;
|
||||
parentMap.ViewportChanged -= OnViewportChanged;
|
||||
viewportTransform.Children.RemoveAt(0);
|
||||
}
|
||||
else
|
||||
else if (oldValue == null)
|
||||
{
|
||||
Data.ClearValue(Geometry.TransformProperty);
|
||||
viewportTransform.Children.Insert(0, new TranslateTransform());
|
||||
parentMap.ViewportChanged += OnViewportChanged;
|
||||
OnViewportChanged(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnViewportChanged(object sender, EventArgs e)
|
||||
{
|
||||
var longitude = Location.NormalizeLongitude(MapPanel.GetLocation(this).Longitude);
|
||||
|
||||
((TranslateTransform)viewportTransform.Children[0]).X =
|
||||
Location.NearestLongitude(longitude, parentMap.Center.Longitude) - longitude;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace MapControl
|
|||
|
||||
public MapPolyline()
|
||||
{
|
||||
Data = new PathGeometry();
|
||||
Data = new PathGeometry { Transform = ViewportTransform };
|
||||
}
|
||||
|
||||
protected override void UpdateData()
|
||||
|
|
@ -49,11 +49,6 @@ namespace MapControl
|
|||
|
||||
figure.Segments.Add(segment);
|
||||
geometry.Figures.Add(figure);
|
||||
geometry.Transform = ParentMap.ViewportTransform;
|
||||
}
|
||||
else
|
||||
{
|
||||
geometry.ClearValue(Geometry.TransformProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace MapControl
|
|||
|
||||
public MapPolyline()
|
||||
{
|
||||
Data = new StreamGeometry();
|
||||
Data = new StreamGeometry { Transform = ViewportTransform };
|
||||
}
|
||||
|
||||
protected override void UpdateData()
|
||||
|
|
@ -32,13 +32,10 @@ namespace MapControl
|
|||
context.BeginFigure(points.First(), IsClosed, IsClosed);
|
||||
context.PolyLineTo(points.Skip(1).ToList(), true, false);
|
||||
}
|
||||
|
||||
geometry.Transform = ParentMap.ViewportTransform;
|
||||
}
|
||||
else
|
||||
{
|
||||
geometry.Clear();
|
||||
geometry.ClearValue(Geometry.TransformProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ namespace MapControl
|
|||
{
|
||||
var rect = new Rect(ParentMap.MapTransform.Transform(new Location(South, West)),
|
||||
ParentMap.MapTransform.Transform(new Location(North, East)));
|
||||
Transform transform = ParentMap.ViewportTransform;
|
||||
Transform transform = ViewportTransform;
|
||||
|
||||
ScaleRect(ref rect, ref transform);
|
||||
|
||||
|
|
|
|||
|
|
@ -41,28 +41,6 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public abstract Location Transform(Point point);
|
||||
|
||||
/// <summary>
|
||||
/// Transforms a geographic location to a cartesian coordinate point
|
||||
/// with minumum distance to the specified reference longitude value.
|
||||
/// </summary>
|
||||
public Point Transform(Location location, double referenceLongitude)
|
||||
{
|
||||
var p = Transform(location);
|
||||
|
||||
p.X = Location.NormalizeLongitude(p.X);
|
||||
|
||||
if (p.X > referenceLongitude + 180d)
|
||||
{
|
||||
p.X -= 360d;
|
||||
}
|
||||
else if (p.X < referenceLongitude - 180d)
|
||||
{
|
||||
p.X += 360d;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms a geographic location by the specified translation in viewport coordinates.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@ namespace MapControl
|
|||
return matrix;
|
||||
}
|
||||
|
||||
public static Matrix TranslatePrepend(this Matrix matrix, double offsetX, double offsetY)
|
||||
{
|
||||
return new Matrix(1d, 0d, 0d, 1d, offsetX, offsetY).Multiply(matrix);
|
||||
}
|
||||
|
||||
public static Matrix Scale(this Matrix matrix, double scaleX, double scaleY)
|
||||
{
|
||||
return Multiply(matrix, new Matrix(scaleX, 0d, 0d, scaleY, 0d, 0d));
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ using System.Windows;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2016 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("2.8.0")]
|
||||
[assembly: AssemblyFileVersion("2.8.0")]
|
||||
[assembly: AssemblyVersion("2.9.0")]
|
||||
[assembly: AssemblyFileVersion("2.9.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -238,14 +238,14 @@ namespace MapControl
|
|||
{
|
||||
if (parentMap != null)
|
||||
{
|
||||
parentMap.ViewportChanged -= ViewportChanged;
|
||||
parentMap.ViewportChanged -= OnViewportChanged;
|
||||
}
|
||||
|
||||
parentMap = value;
|
||||
|
||||
if (parentMap != null)
|
||||
{
|
||||
parentMap.ViewportChanged += ViewportChanged;
|
||||
parentMap.ViewportChanged += OnViewportChanged;
|
||||
mapOriginX = parentMap.MapOrigin.X;
|
||||
}
|
||||
|
||||
|
|
@ -253,7 +253,7 @@ namespace MapControl
|
|||
}
|
||||
}
|
||||
|
||||
private void ViewportChanged(object sender, EventArgs e)
|
||||
private void OnViewportChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (TileGrid == null || Math.Abs(parentMap.MapOrigin.X - mapOriginX) > 180d)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -162,6 +162,12 @@
|
|||
<Compile Include="..\TileSource.cs">
|
||||
<Link>TileSource.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\WmsImageLayer.cs">
|
||||
<Link>WmsImageLayer.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\WmsImageLayer.WinRT.cs">
|
||||
<Link>WmsImageLayer.WinRT.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2016 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("2.8.0")]
|
||||
[assembly: AssemblyFileVersion("2.8.0")]
|
||||
[assembly: AssemblyVersion("2.9.0")]
|
||||
[assembly: AssemblyFileVersion("2.9.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
19
MapControl/WmsImageLayer.WPF.cs
Normal file
19
MapControl/WmsImageLayer.WPF.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
||||
// © 2016 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class WmsImageLayer
|
||||
{
|
||||
private static async Task<XmlDocument> LoadDocument(string requestUri)
|
||||
{
|
||||
var document = new XmlDocument();
|
||||
await Task.Run(() => document.Load(requestUri));
|
||||
return document;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
MapControl/WmsImageLayer.WinRT.cs
Normal file
18
MapControl/WmsImageLayer.WinRT.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
||||
// © 2016 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Data.Xml.Dom;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class WmsImageLayer
|
||||
{
|
||||
private static async Task<XmlDocument> LoadDocument(string requestUri)
|
||||
{
|
||||
return await XmlDocument.LoadFromUriAsync(new Uri(requestUri));
|
||||
}
|
||||
}
|
||||
}
|
||||
152
MapControl/WmsImageLayer.cs
Normal file
152
MapControl/WmsImageLayer.cs
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
||||
// © 2016 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
#if NETFX_CORE
|
||||
using Windows.Data.Xml.Dom;
|
||||
using Windows.UI.Xaml;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Xml;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class WmsImageLayer : MapImageLayer
|
||||
{
|
||||
public static readonly DependencyProperty BaseUriProperty = DependencyProperty.Register(
|
||||
"ServerUri", typeof(string), typeof(WmsImageLayer),
|
||||
new PropertyMetadata(null, async (o, e) => await ((WmsImageLayer)o).UpdateUriFormat(true)));
|
||||
|
||||
public static readonly DependencyProperty LayersProperty = DependencyProperty.Register(
|
||||
"Layers", typeof(string), typeof(WmsImageLayer),
|
||||
new PropertyMetadata(null, async (o, e) => await ((WmsImageLayer)o).UpdateUriFormat()));
|
||||
|
||||
public static readonly DependencyProperty ParametersProperty = DependencyProperty.Register(
|
||||
"Parameters", typeof(string), typeof(WmsImageLayer),
|
||||
new PropertyMetadata(null, async (o, e) => await ((WmsImageLayer)o).UpdateUriFormat()));
|
||||
|
||||
public static readonly DependencyProperty TransparentProperty = DependencyProperty.Register(
|
||||
"Transparent", typeof(bool), typeof(WmsImageLayer),
|
||||
new PropertyMetadata(false, async (o, e) => await ((WmsImageLayer)o).UpdateUriFormat()));
|
||||
|
||||
public string ServerUri
|
||||
{
|
||||
get { return (string)GetValue(BaseUriProperty); }
|
||||
set { SetValue(BaseUriProperty, value); }
|
||||
}
|
||||
|
||||
public string Layers
|
||||
{
|
||||
get { return (string)GetValue(LayersProperty); }
|
||||
set { SetValue(LayersProperty, value); }
|
||||
}
|
||||
|
||||
public string Parameters
|
||||
{
|
||||
get { return (string)GetValue(ParametersProperty); }
|
||||
set { SetValue(ParametersProperty, value); }
|
||||
}
|
||||
|
||||
public bool Transparent
|
||||
{
|
||||
get { return (bool)GetValue(TransparentProperty); }
|
||||
set { SetValue(TransparentProperty, value); }
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetAllLayers()
|
||||
{
|
||||
var layers = new List<string>();
|
||||
|
||||
if (!string.IsNullOrEmpty(ServerUri))
|
||||
{
|
||||
try
|
||||
{
|
||||
var document = await LoadDocument(ServerUri
|
||||
+ "?SERVICE=WMS"
|
||||
+ "&VERSION=1.3.0"
|
||||
+ "&REQUEST=GetCapabilities");
|
||||
|
||||
var capability = FirstChild(document.DocumentElement, "Capability");
|
||||
if (capability != null)
|
||||
{
|
||||
var rootLayer = FirstChild(capability, "Layer");
|
||||
if (rootLayer != null)
|
||||
{
|
||||
foreach (var layer in ChildElements(rootLayer, "Layer"))
|
||||
{
|
||||
var name = FirstChild(layer, "Name");
|
||||
if (name != null)
|
||||
{
|
||||
layers.Add(name.InnerText);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return layers;
|
||||
}
|
||||
|
||||
private string allLayers;
|
||||
|
||||
private async Task UpdateUriFormat(bool baseUriChanged = false)
|
||||
{
|
||||
if (baseUriChanged)
|
||||
{
|
||||
allLayers = null;
|
||||
}
|
||||
|
||||
string uriFormat = null;
|
||||
var layers = Layers;
|
||||
|
||||
if (!string.IsNullOrEmpty(ServerUri) && !string.IsNullOrEmpty(layers))
|
||||
{
|
||||
if (layers == "*")
|
||||
{
|
||||
layers = allLayers ?? (allLayers = string.Join(",", await GetAllLayers()));
|
||||
}
|
||||
|
||||
uriFormat = ServerUri
|
||||
+ "?SERVICE=WMS"
|
||||
+ "&VERSION=1.3.0"
|
||||
+ "&REQUEST=GetMap"
|
||||
+ "&LAYERS=" + layers.Replace(" ", "%20")
|
||||
+ "&STYLES="
|
||||
+ "&CRS=EPSG:3857"
|
||||
+ "&BBOX={W},{S},{E},{N}"
|
||||
+ "&WIDTH={X}"
|
||||
+ "&HEIGHT={Y}"
|
||||
+ "&FORMAT=image/png"
|
||||
+ "&TRANSPARENT=" + (Transparent ? "TRUE" : "FALSE");
|
||||
|
||||
if (!string.IsNullOrEmpty(Parameters))
|
||||
{
|
||||
uriFormat += "&" + Parameters;
|
||||
}
|
||||
}
|
||||
|
||||
UriFormat = uriFormat;
|
||||
}
|
||||
|
||||
private static IEnumerable<XmlElement> ChildElements(XmlElement element, string name)
|
||||
{
|
||||
return element.ChildNodes.OfType<XmlElement>().Where(e => (string)e.LocalName == name);
|
||||
}
|
||||
|
||||
private static XmlElement FirstChild(XmlElement element, string name)
|
||||
{
|
||||
return element.ChildNodes.OfType<XmlElement>().FirstOrDefault(e => (string)e.LocalName == name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2016 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("2.8.0")]
|
||||
[assembly: AssemblyFileVersion("2.8.0")]
|
||||
[assembly: AssemblyVersion("2.9.0")]
|
||||
[assembly: AssemblyFileVersion("2.9.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2016 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("2.8.0")]
|
||||
[assembly: AssemblyFileVersion("2.8.0")]
|
||||
[assembly: AssemblyVersion("2.9.0")]
|
||||
[assembly: AssemblyFileVersion("2.9.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2016 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("2.8.0")]
|
||||
[assembly: AssemblyFileVersion("2.8.0")]
|
||||
[assembly: AssemblyVersion("2.9.0")]
|
||||
[assembly: AssemblyFileVersion("2.9.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCopyright("© 2015 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyVersion("2.8.0")]
|
||||
[assembly: AssemblyFileVersion("2.8.0")]
|
||||
[assembly: AssemblyVersion("2.9.0")]
|
||||
[assembly: AssemblyFileVersion("2.9.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -211,10 +211,12 @@
|
|||
</map:MapPanel.Location>
|
||||
</map:Pushpin>
|
||||
</map:Map>
|
||||
|
||||
<Border HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#BFFFFFFF">
|
||||
<TextBlock Margin="2" FontSize="10" Foreground="Black"
|
||||
map:HyperlinkText.InlinesSource="{Binding TileLayer.Description, ElementName=map}"/>
|
||||
</Border>
|
||||
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCopyright("© 2016 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyVersion("2.8.0")]
|
||||
[assembly: AssemblyFileVersion("2.8.0")]
|
||||
[assembly: AssemblyVersion("2.9.0")]
|
||||
[assembly: AssemblyFileVersion("2.9.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -194,10 +194,8 @@
|
|||
ManipulationInertiaStarting="MapManipulationInertiaStarting">
|
||||
|
||||
<!-- experimental WMS map layers -->
|
||||
<!--<map:MapImageLayer
|
||||
UriFormat="http://129.206.228.72/cached/osm?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=osm_auto:all&STYLES=&SRS=EPSG:900913&BBOX={W},{S},{E},{N}&WIDTH={X}&HEIGHT={Y}&FORMAT=image/png"/>-->
|
||||
<!--<map:MapImageLayer
|
||||
UriFormat="http://ows.terrestris.de/osm/service?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=OSM-WMS&STYLES=&SRS=EPSG:900913&BBOX={W},{S},{E},{N}&WIDTH={X}&HEIGHT={Y}&FORMAT=image/png"/>-->
|
||||
<!--<map:WmsImageLayer ServerUri="http://129.206.228.72/cached/osm" Layers="osm_auto:all"/>-->
|
||||
<!--<map:WmsImageLayer ServerUri="http://ows.terrestris.de/osm/service" Layers="OSM-WMS"/>-->
|
||||
|
||||
<map:MapImage x:Name="mapImage" South="53.54031" North="53.74871" West="8.08594" East="8.43750"
|
||||
Source="10_535_330.jpg" Opacity="0.5"/>
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2016 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("2.8.0")]
|
||||
[assembly: AssemblyFileVersion("2.8.0")]
|
||||
[assembly: AssemblyVersion("2.9.0")]
|
||||
[assembly: AssemblyFileVersion("2.9.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue