2012-11-22 21:42:29 +01:00
|
|
|
|
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
2014-01-10 20:11:39 +01:00
|
|
|
|
// Copyright © 2014 Clemens Fischer
|
2012-11-22 21:42:29 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
2013-05-13 23:49:48 +02:00
|
|
|
|
using System;
|
2014-07-01 18:57:44 +02:00
|
|
|
|
#if WINDOWS_RUNTIME
|
2012-11-22 21:42:29 +01:00
|
|
|
|
using Windows.UI.Xaml.Media;
|
|
|
|
|
|
#else
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2014-07-01 18:57:44 +02:00
|
|
|
|
internal partial class TileContainer
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2014-10-19 21:50:23 +02:00
|
|
|
|
private Matrix GetTileIndexMatrix(double scale)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
|
|
|
|
|
return ViewportTransform.Matrix
|
|
|
|
|
|
.Invert() // view to map coordinates
|
|
|
|
|
|
.Translate(180d, -180d)
|
2013-05-13 23:49:48 +02:00
|
|
|
|
.Scale(scale, -scale); // map coordinates to tile indices
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-09 21:27:28 +02:00
|
|
|
|
private void UpdateViewportTransform(double scale, double offsetX, double offsetY)
|
|
|
|
|
|
{
|
|
|
|
|
|
ViewportTransform.Matrix =
|
|
|
|
|
|
new Matrix(scale, 0d, 0d, -scale, offsetX, offsetY)
|
|
|
|
|
|
.RotateAt(rotation, viewportOrigin.X, viewportOrigin.Y);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-01 18:57:44 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets a RenderTransform with origin at tileGrid.X and tileGrid.Y to minimize rounding errors.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void UpdateRenderTransform()
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2014-07-01 18:57:44 +02:00
|
|
|
|
var scale = Math.Pow(2d, zoomLevel - tileZoomLevel);
|
2012-11-22 21:42:29 +01:00
|
|
|
|
|
2014-07-01 18:57:44 +02:00
|
|
|
|
((MatrixTransform)RenderTransform).Matrix =
|
|
|
|
|
|
new Matrix(1d, 0d, 0d, 1d, tileGrid.X * TileSource.TileSize, tileGrid.Y * TileSource.TileSize)
|
|
|
|
|
|
.Scale(scale, scale)
|
|
|
|
|
|
.Translate(tileLayerOffset.X, tileLayerOffset.Y)
|
|
|
|
|
|
.RotateAt(rotation, viewportOrigin.X, viewportOrigin.Y);
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|