This project has moved. For the latest updates, please go here.

Map center after zoom

Oct 24, 2014 at 9:28 AM
I would like to know where the map center will be located at the end of a mouse wheel-initiated zoom. As I understand, the map center will be changed according to where the mouse is positioned when the user zooms using the mouse wheel. Can this location be calculated beforehand? Thanks in advance.
Oct 29, 2014 at 8:45 AM
Edited Oct 29, 2014 at 8:45 AM
You could reproduce the calculation that happens in the private MapBase.UpdateTransform method:
var viewportOrigin = e.GetPosition(map);
var mapOrigin = map.ViewportTransform.Inverse.Transform(viewportOrigin);
var targetScale = Math.Pow(2d, map.TargetZoomLevel) * TileSource.TileSize / 360d;

var viewportTransform = new Matrix();
viewportTransform.Translate(-mapOrigin.X, -mapOrigin.Y);
viewportTransform.Scale(targetScale, -targetScale);
viewportTransform.Translate(viewportOrigin.X, viewportOrigin.Y);

var viewportCenter = new Point(map.ActualWidth / 2d, map.ActualHeight / 2d);
var targetCenter = map.MapTransform.Transform(
where e is a MouseEventArgs and map an instance of the Map control.