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)
|
|
|
|
|
|
|
2014-11-19 21:11:14 +01:00
|
|
|
|
using System;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class MapBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public static readonly DependencyProperty ForegroundProperty =
|
2014-11-19 21:11:14 +01:00
|
|
|
|
Control.ForegroundProperty.AddOwner(typeof(MapBase));
|
2012-11-22 21:42:29 +01:00
|
|
|
|
|
2013-12-05 17:56:04 +01:00
|
|
|
|
public static readonly DependencyProperty CenterProperty = DependencyProperty.Register(
|
|
|
|
|
|
"Center", typeof(Location), typeof(MapBase), new FrameworkPropertyMetadata(
|
|
|
|
|
|
new Location(), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
|
|
|
|
|
(o, e) => ((MapBase)o).CenterPropertyChanged((Location)e.NewValue)));
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty TargetCenterProperty = DependencyProperty.Register(
|
|
|
|
|
|
"TargetCenter", typeof(Location), typeof(MapBase), new FrameworkPropertyMetadata(
|
|
|
|
|
|
new Location(), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
|
|
|
|
|
(o, e) => ((MapBase)o).TargetCenterPropertyChanged((Location)e.NewValue)));
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty ZoomLevelProperty = DependencyProperty.Register(
|
|
|
|
|
|
"ZoomLevel", typeof(double), typeof(MapBase), new FrameworkPropertyMetadata(
|
|
|
|
|
|
1d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
|
|
|
|
|
(o, e) => ((MapBase)o).ZoomLevelPropertyChanged((double)e.NewValue)));
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty TargetZoomLevelProperty = DependencyProperty.Register(
|
|
|
|
|
|
"TargetZoomLevel", typeof(double), typeof(MapBase), new FrameworkPropertyMetadata(
|
|
|
|
|
|
1d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
|
|
|
|
|
(o, e) => ((MapBase)o).TargetZoomLevelPropertyChanged((double)e.NewValue)));
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty HeadingProperty = DependencyProperty.Register(
|
|
|
|
|
|
"Heading", typeof(double), typeof(MapBase), new FrameworkPropertyMetadata(
|
|
|
|
|
|
0d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
|
|
|
|
|
(o, e) => ((MapBase)o).HeadingPropertyChanged((double)e.NewValue)));
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty TargetHeadingProperty = DependencyProperty.Register(
|
|
|
|
|
|
"TargetHeading", typeof(double), typeof(MapBase), new FrameworkPropertyMetadata(
|
|
|
|
|
|
0d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
|
|
|
|
|
(o, e) => ((MapBase)o).TargetHeadingPropertyChanged((double)e.NewValue)));
|
|
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
static MapBase()
|
|
|
|
|
|
{
|
|
|
|
|
|
UIElement.ClipToBoundsProperty.OverrideMetadata(
|
|
|
|
|
|
typeof(MapBase), new FrameworkPropertyMetadata(true));
|
|
|
|
|
|
|
|
|
|
|
|
Panel.BackgroundProperty.OverrideMetadata(
|
|
|
|
|
|
typeof(MapBase), new FrameworkPropertyMetadata(Brushes.Transparent));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-30 18:23:13 +01:00
|
|
|
|
partial void RemoveAnimation(DependencyProperty property)
|
|
|
|
|
|
{
|
|
|
|
|
|
BeginAnimation(property, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-04-04 18:01:13 +02:00
|
|
|
|
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2013-04-04 18:01:13 +02:00
|
|
|
|
base.OnRenderSizeChanged(sizeInfo);
|
2012-11-22 21:42:29 +01:00
|
|
|
|
ResetTransformOrigin();
|
|
|
|
|
|
UpdateTransform();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-11-19 21:11:14 +01:00
|
|
|
|
private void SetViewportTransform(Point mapOrigin)
|
|
|
|
|
|
{
|
|
|
|
|
|
var transform = Matrix.Identity;
|
|
|
|
|
|
transform.Translate(-mapOrigin.X, -mapOrigin.Y);
|
|
|
|
|
|
transform.Scale(ViewportScale, -ViewportScale);
|
|
|
|
|
|
transform.Rotate(Heading);
|
|
|
|
|
|
transform.Translate(viewportOrigin.X, viewportOrigin.Y);
|
|
|
|
|
|
|
|
|
|
|
|
viewportTransform.Matrix = transform;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SetTileLayerTransform()
|
|
|
|
|
|
{
|
|
|
|
|
|
var scale = Math.Pow(2d, ZoomLevel - TileZoomLevel);
|
|
|
|
|
|
var transform = Matrix.Identity;
|
|
|
|
|
|
transform.Translate(TileGrid.X * TileSource.TileSize, TileGrid.Y * TileSource.TileSize);
|
|
|
|
|
|
transform.Scale(scale, scale);
|
|
|
|
|
|
transform.Translate(tileLayerOffset.X, tileLayerOffset.Y);
|
|
|
|
|
|
transform.RotateAt(Heading, viewportOrigin.X, viewportOrigin.Y);
|
|
|
|
|
|
|
|
|
|
|
|
tileLayerTransform.Matrix = transform;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-12-20 17:05:10 +01:00
|
|
|
|
private void SetTransformMatrixes()
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2014-11-19 21:11:14 +01:00
|
|
|
|
var rotateMatrix = Matrix.Identity;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
rotateMatrix.Rotate(Heading);
|
|
|
|
|
|
rotateTransform.Matrix = rotateMatrix;
|
2014-11-19 21:11:14 +01:00
|
|
|
|
|
|
|
|
|
|
var scaleMatrix = Matrix.Identity;
|
|
|
|
|
|
scaleMatrix.Scale(CenterScale, CenterScale);
|
|
|
|
|
|
scaleTransform.Matrix = scaleMatrix;
|
|
|
|
|
|
|
|
|
|
|
|
scaleRotateTransform.Matrix = scaleMatrix * rotateMatrix;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Matrix GetTileIndexMatrix(double scale)
|
|
|
|
|
|
{
|
|
|
|
|
|
var transform = viewportTransform.Matrix;
|
|
|
|
|
|
transform.Invert(); // view to map coordinates
|
|
|
|
|
|
transform.Translate(180d, -180d);
|
|
|
|
|
|
transform.Scale(scale, -scale); // map coordinates to tile indices
|
|
|
|
|
|
|
|
|
|
|
|
return transform;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|