Centering the view on a given coordinate

Nov 14, 2011 at 4:30 PM

Hello, I'm trying to center the view on a point given his latitude and longitude; I'm using the SphericalMercator that I've found in another topic for the coordinate conversion. What I'm doing is simply this:

public void MoveTo(double lon, double lat)
var pos = SphericalMercator.FromLonLat(lon, lat);
view.Center = view.WorldToView(pos.X, pos.Y); 

OnViewChanged(false, true); 

but it doesn't work; notice  that the opposite approach is working, if for example I want to show longitude and latitude of the mouse position:

var pos = e.GetPosition(this);
var wpos = view.ViewToWorld(pos.X, pos.Y);
var lonlat = SphericalMercator.ToLonLat(wpos.X, wpos.Y);
var mappos = e.GetPosition(this);

What am I missing?

Many thanks in advance,


Nov 15, 2011 at 10:54 AM

Ok I figured out that WorldToView just outputs coordinates relative to the screen; so at this point I guess that simply assigning view.Center = pos should work, but it doesn't, the point is not centered correctly, can anyone help me here?

Nov 21, 2011 at 5:35 PM

Could it be you are centering on the top left iso of the center of the point symbol?