LatLongToPoint bug?

Feb 4, 2010 at 12:01 AM

Hi:

Great work on the library. I though I should mention an issue I'm having though.

LatLongToPoint and PointToLatLong both seem to return rubbish.

For example:

Point? pt=MyMap.LatLongToPoint(MyMap.VELatLong)  would, I expect,return the value of the point at the center of the map.  It returns NULL.  If I put a PushPin in at MyMap.VELatLong it's nicely in the center of the screen.

PointToLatLong() is just as bad. It seems to return almost random values.  Typically the coordinates are up and left by about 1/4 the screen width, but they can be in any direction.  If my map is large then PointToLatLong() return null unless the coordinates are between 8.0 and 12.0.

This is just a test app, consisting of a Window, with a map inside it.  Here is the entire source code.

 

       public Window1()
        {
            InitializeComponent();
            
            MyMap.Altitude = 3000;
            MyMap.LatLong = new Point(51, 114f);
            MyMap.MapStyle = VEMapStyle.Aerial;
        }

        private void MyMap_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Point? ptTest=MyMap.LatLongToPoint(MyMap.VELatLong);
            VELatLong latTest=MyMap.PointToLatLong(ptTest);
        }

 

 

Any ideas?

 

Taco

 

     //       Microsoft.Maps.MapControl.Map m = new Microsoft.Maps.MapControl.Map();
            MyMap.Altitude = 3000;
            MyMap.LatLong = new Point(51, 114f);
            MyMap.MapStyle = VEMapStyle.Aerial;
        }

 

 

 

Feb 4, 2010 at 1:27 AM

FYI:  I downloaded the source code.  Looks like the bug is in the way the coords are being mapped.

Inside LatLongToPoint it calls MathHelper.MapValue  with TargetImage.ActualHeight/Width.  IF I substitute ActualHeight/Width it works fine.  I notice from the comment that it USED to be correct, so I'm not sure why it was changed.

Taco

 

Coordinator
Feb 4, 2010 at 5:04 AM

I'm taking a look at this, thanks for reporting.

The comment doesn't represent the immediate previous version. It's been like that for a long time.

The core issue is the addition of the Stretch="UniformToFill" to the Viewbox causes a wrinkle in transforming points from inside the viewbox context to outside because the aspect ratio can change.