mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-03-21 04:35:27 +01:00
Update MapPanel.cs
This commit is contained in:
parent
7a9cd455b2
commit
e1cd5a64b7
|
|
@ -114,18 +114,16 @@ namespace MapControl
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pos = parentMap.LocationToView(location);
|
var position = parentMap.LocationToView(location);
|
||||||
|
|
||||||
if (parentMap.MapProjection.IsNormalCylindrical &&
|
if (parentMap.MapProjection.IsNormalCylindrical && !IsVisible(position))
|
||||||
(pos.X < 0d || pos.X > parentMap.RenderSize.Width ||
|
|
||||||
pos.Y < 0d || pos.Y > parentMap.RenderSize.Height))
|
|
||||||
{
|
{
|
||||||
location = new Location(location.Latitude, parentMap.ConstrainedLongitude(location.Longitude));
|
location = new Location(location.Latitude, parentMap.ConstrainedLongitude(location.Longitude));
|
||||||
|
|
||||||
pos = parentMap.LocationToView(location);
|
position = parentMap.LocationToView(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -142,22 +140,20 @@ namespace MapControl
|
||||||
public ViewRect GetViewRect(Rect rect)
|
public ViewRect GetViewRect(Rect rect)
|
||||||
{
|
{
|
||||||
var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d);
|
var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d);
|
||||||
var pos = parentMap.ViewTransform.MapToView(center);
|
var position = parentMap.ViewTransform.MapToView(center);
|
||||||
|
|
||||||
if (parentMap.MapProjection.IsNormalCylindrical &&
|
if (parentMap.MapProjection.IsNormalCylindrical && !IsVisible(position))
|
||||||
(pos.X < 0d || pos.X > parentMap.RenderSize.Width ||
|
|
||||||
pos.Y < 0d || pos.Y > parentMap.RenderSize.Height))
|
|
||||||
{
|
{
|
||||||
var location = parentMap.MapProjection.MapToLocation(center);
|
var location = parentMap.MapProjection.MapToLocation(center);
|
||||||
location.Longitude = parentMap.ConstrainedLongitude(location.Longitude);
|
location.Longitude = parentMap.ConstrainedLongitude(location.Longitude);
|
||||||
|
|
||||||
pos = parentMap.LocationToView(location);
|
position = parentMap.LocationToView(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
var width = rect.Width * parentMap.ViewTransform.Scale;
|
var width = rect.Width * parentMap.ViewTransform.Scale;
|
||||||
var height = rect.Height * parentMap.ViewTransform.Scale;
|
var height = rect.Height * parentMap.ViewTransform.Scale;
|
||||||
var x = pos.X - width / 2d;
|
var x = position.X - width / 2d;
|
||||||
var y = pos.Y - height / 2d;
|
var y = position.Y - height / 2d;
|
||||||
|
|
||||||
return new ViewRect(x, y, width, height, parentMap.ViewTransform.Rotation);
|
return new ViewRect(x, y, width, height, parentMap.ViewTransform.Rotation);
|
||||||
}
|
}
|
||||||
|
|
@ -213,9 +209,7 @@ namespace MapControl
|
||||||
|
|
||||||
if (GetAutoCollapse(element))
|
if (GetAutoCollapse(element))
|
||||||
{
|
{
|
||||||
if (position.HasValue &&
|
if (position.HasValue && !IsVisible(position.Value))
|
||||||
(position.Value.X < 0d || position.Value.X > parentMap.RenderSize.Width ||
|
|
||||||
position.Value.Y < 0d || position.Value.Y > parentMap.RenderSize.Height))
|
|
||||||
{
|
{
|
||||||
element.SetValue(VisibilityProperty, Visibility.Collapsed);
|
element.SetValue(VisibilityProperty, Visibility.Collapsed);
|
||||||
}
|
}
|
||||||
|
|
@ -248,6 +242,12 @@ namespace MapControl
|
||||||
return finalSize;
|
return finalSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsVisible(Point point)
|
||||||
|
{
|
||||||
|
return point.X >= 0d && point.X <= parentMap.RenderSize.Width
|
||||||
|
&& point.Y >= 0d && point.Y <= parentMap.RenderSize.Height;
|
||||||
|
}
|
||||||
|
|
||||||
private static void ArrangeElement(FrameworkElement element, ViewRect rect)
|
private static void ArrangeElement(FrameworkElement element, ViewRect rect)
|
||||||
{
|
{
|
||||||
element.Width = rect.Width;
|
element.Width = rect.Width;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue