Smooth zooming in WPF

Topics: WPF
Nov 2, 2011 at 11:59 AM

If you need smooth zooming in WPF control, then you can replace commented code in RenderMapWPF(...) method with this one:

else // testing smooth zooming
{
	int zoomOffset = 0;
	Tile parentTile = Tile.Empty;
	int Ix = 0;

	while (parentTile == Tile.Empty && (Core.Zoom - zoomOffset) >= 1 && zoomOffset <= LevelsKeepInMemmory)
	{
		Ix = (int)Math.Pow(2, ++zoomOffset);
		parentTile = Core.Matrix.GetTileWithNoLock(Core.Zoom - zoomOffset, new GMap.NET.GPoint((int)(tilePoint.X / Ix), (int)(tilePoint.Y / Ix)));
	}

	if (parentTile != Tile.Empty)
	{
		int Xoff = Math.Abs(tilePoint.X - (parentTile.Pos.X * Ix));
		int Yoff = Math.Abs(tilePoint.Y - (parentTile.Pos.Y * Ix));

		var geometry = new RectangleGeometry(new Rect(Core.tileRect.X + 0.6, Core.tileRect.Y + 0.6, Core.tileRect.Width + 0.6, Core.tileRect.Height + 0.6));
		var parentImgRect = new Rect(Core.tileRect.X - Core.tileRect.Width * Xoff + 0.6, Core.tileRect.Y - Core.tileRect.Height * Yoff + 0.6, Core.tileRect.Width * Ix + 0.6, Core.tileRect.Height * Ix + 0.6);

		// render tile 
		lock (parentTile.Overlays)
		{
			foreach (WindowsPresentationImage img in parentTile.Overlays)
			{
				if (img != null && img.Img != null)
				{
					if (!found)
						found = true;

					g.PushClip(geometry);

					g.DrawImage(img.Img, parentImgRect);

					g.DrawRectangle(LessDetailedLevelTileMask, null, geometry.Bounds);

					g.Pop();
				}
			}
		}
	}
}

Coordinator
Nov 24, 2011 at 1:56 PM

thanks, sorry for delay ;}

Dec 1, 2011 at 2:33 PM
Edited Dec 1, 2011 at 9:27 PM

Hi, I took your updated code, but you have added checking for MercatorProjection. Now it's not working with maps.lt provider (because it uses LKS94Projection). What is the reason for this?

Dec 1, 2011 at 2:35 PM

If not all projections could solve position in same way, then it might be done in projection class, or it somehow be modified... I could try to do that, but I don't know the difference between projections :)

Coordinator
Dec 1, 2011 at 5:50 PM

not the projection itself, but level resolution in maps.lt is not consistent, so i disabled it until correct solution arrive

Mar 27, 2013 at 8:36 PM
Lashas wrote:
If not all projections could solve position in same way, then it might be done in projection class, or it somehow be modified... I could try to do that, but I don't know the difference between projections :)
Have you found a solution for WPF smooth zooming?