This project is read-only.

Zoom and Move to position

Jul 9, 2008 at 2:04 PM
Hi, First of all congrats on the project its awesome.

I want to zoom directly to a latlon position.
It works, but if i call it once the wrong position comes up.
so i call it in a loop, and its very slow....

Is there a better alternative?

Code snippet:
Msi.MoveTo(Location, ViewportWidth);

p = MapHelper.LatLongToPoint(ll, MSI);
Point zoomCenter = MSI.ElementToLogicalPoint(p);
zoomCenter.X = zoomCenter.X - ((MSI.ViewportWidth/10) * 5);
zoomCenter.Y = zoomCenter.Y - ((MSI.ViewportWidth/10) * 4);
MSI.ViewportOrigin = zoomCenter;
MSI.ViewportWidth = ViewportWidth;}



Jul 10, 2008 at 1:46 AM
Edited Jul 10, 2008 at 1:48 AM
Well spotted - the public method we have exposed is "SetView" on the map object eg to Move to Brisbane, Australia:


new Point {X = 153.03, Y = -27.47}, 14);



But you're right it looks like when it hits the right zoom level it no longer pans to the right spot, we need to fix the code in Map.cs function:


public void SetView(Point center, int zoomLevel)
IZoomLevelProvider zoomProvider = ZoomLevelProvider; 
if (zoomProvider != null && msi != null)
zoomLevel = zoomProvider.ValidateZoomLevel(zoomLevel);
Point pixel = Projection.ToDisplay(center, this, MapWidth);
pixel = TransformToVisual(msi).Transform(pixel);
Point logicalPoint = msi.ElementToLogicalPoint(pixel); 
Size mapSize = zoomProvider.GetMapSizeAtZoomLevel(zoomLevel); 
double ratio = msi.ActualWidth/mapSize.Width; 
double zoomFactor = msi.ViewportWidth/ratio;
msi.ZoomAboutLogicalPoint(zoomFactor, logicalPoint.X, logicalPoint.Y);

Aug 29, 2008 at 5:52 PM
Has the SetView function (in Jul 9 post by soulsolutions) been fixed yet???   Thanks.
Aug 30, 2008 at 12:56 AM
Edited Aug 30, 2008 at 12:58 AM
if you look in the post called "SetView end up on a blury map"

you will see a fix for "SetView" there

"Set UseSprings=false"

but then the map just goes directly to the new location and does not do all the fancy zooming stuff...

also if you read a few other posts you will see the guys are pretty busy doing there real life stuff and plan on making some updates in a couple weeks... ;)