2014-07-09 21:27:28 +02:00
|
|
|
|
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
2015-01-20 17:52:02 +01:00
|
|
|
|
// © 2015 Clemens Fischer
|
2014-07-09 21:27:28 +02:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
2015-08-09 20:04:44 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
#if NETFX_CORE
|
2015-11-11 19:48:50 +01:00
|
|
|
|
using Windows.Foundation;
|
2015-08-09 20:04:44 +02:00
|
|
|
|
using Windows.UI.Xaml.Media;
|
|
|
|
|
|
#else
|
2015-11-11 19:48:50 +01:00
|
|
|
|
using System.Windows;
|
2015-08-09 20:04:44 +02:00
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2014-07-09 21:27:28 +02:00
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2014-11-19 21:11:14 +01:00
|
|
|
|
public partial class TileLayer
|
2014-07-09 21:27:28 +02:00
|
|
|
|
{
|
2014-11-19 21:11:14 +01:00
|
|
|
|
partial void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
IsHitTestVisible = false;
|
2015-08-09 20:04:44 +02:00
|
|
|
|
|
2014-11-19 21:11:14 +01:00
|
|
|
|
MapPanel.AddParentMapHandlers(this);
|
|
|
|
|
|
}
|
2015-08-09 20:04:44 +02:00
|
|
|
|
|
2015-11-11 19:48:50 +01:00
|
|
|
|
private Rect GetTileIndexBounds(int zoomLevel)
|
2015-08-09 20:04:44 +02:00
|
|
|
|
{
|
|
|
|
|
|
var scale = (double)(1 << zoomLevel) / 360d;
|
2015-11-11 19:48:50 +01:00
|
|
|
|
var transform = new MatrixTransform
|
|
|
|
|
|
{
|
|
|
|
|
|
Matrix = parentMap.ViewportTransform.Matrix
|
|
|
|
|
|
.Invert() // view to map coordinates
|
|
|
|
|
|
.Translate(180d, -180d)
|
|
|
|
|
|
.Scale(scale, -scale) // map coordinates to tile indices
|
|
|
|
|
|
};
|
2015-08-09 20:04:44 +02:00
|
|
|
|
|
2015-11-11 19:48:50 +01:00
|
|
|
|
return transform.TransformBounds(new Rect(new Point(), parentMap.RenderSize));
|
2015-08-09 20:04:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SetRenderTransform()
|
|
|
|
|
|
{
|
2015-11-11 19:48:50 +01:00
|
|
|
|
var scale = Math.Pow(2d, parentMap.ZoomLevel - TileGrid.ZoomLevel);
|
2015-08-09 20:04:44 +02:00
|
|
|
|
var offsetX = parentMap.ViewportOrigin.X - (180d + parentMap.MapOrigin.X) * parentMap.ViewportScale;
|
|
|
|
|
|
var offsetY = parentMap.ViewportOrigin.Y - (180d - parentMap.MapOrigin.Y) * parentMap.ViewportScale;
|
|
|
|
|
|
|
|
|
|
|
|
((MatrixTransform)RenderTransform).Matrix =
|
2015-11-11 19:48:50 +01:00
|
|
|
|
new Matrix(1d, 0d, 0d, 1d, TileSource.TileSize * TileGrid.XMin, TileSource.TileSize * TileGrid.YMin)
|
2015-08-09 20:04:44 +02:00
|
|
|
|
.Scale(scale, scale)
|
|
|
|
|
|
.Translate(offsetX, offsetY)
|
2016-01-30 11:50:53 +01:00
|
|
|
|
.RotateAt(parentMap.Heading, parentMap.ViewportOrigin.X, parentMap.ViewportOrigin.Y);
|
2015-08-09 20:04:44 +02:00
|
|
|
|
}
|
2014-07-09 21:27:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|