none
MapControl TrySetViewBoundsAsync() Not Working Correctly RRS feed

  • Question

  • I am creating a UWP app on the Xbox. I have a MapControl with a height of 370 and width of 960. I have two locations that I show pins for on the map and then want to zoom the map so that those two pins are fully visible.

    I use the GeoboundingBox.TryCompute() method and pass in my two BasicGeopositions which are...

    Latitude: 51.503449
    Longitude: -0.081991

    Latitude: 51.51366
    Longitude: -0.0719299

    This generates a bounding box with the following values...

    Centre
    Latitude: 51.5085545
    Longitude: -0.07696045

    NorthwestCorner
    Latitude: 51.51366
    Longitude: -0.081991

    SoutheastCorner
    Latitude: 51.503449
    Longitude: -0.0719299

    When I then use the above generated bounding box in the method TrySetViewBoundsAsync()

    Then the map moves the two pins into the top left quarter of the map and the maps centre is given as...

    Altitude: 50.780917732045054
    Latitude: 51.503402517711919
    Longitude: -0.049609963467326011

    As you can see this is way off the centre of the bounding box

    Friday, October 20, 2017 10:08 AM

Answers

  • The bug has already been fixed and will be available in a future servicing release. There's no fixed ETA for which servicing release yet.
    Friday, October 27, 2017 5:42 PM
    Moderator

All replies

  • When I call:

                GeoboundingBox box = new GeoboundingBox(new BasicGeoposition { Latitude = 51.503449, Longitude = -0.081991 }, new BasicGeoposition { Latitude = 51.503449, Longitude = -0.0719299 });
                mainPageMapControl.TrySetViewBoundsAsync(box, null, MapAnimationKind.None);

    It appears to set the view correctly. Are you calling the TrySetViewBounds before the control has fully initialized? Generally you should wait for the first loaded event before calling any set view as some API's (like TrySetViewBounds) need at least some map data loaded in order to properly calculate the view. Also, are you waiting on the async event to return before checking the center? The center property won't be fully set until any animation is complete.

    By the way the scenario you describe (setting the view for a set of pins) is best handled by the TrySetScene API using MapScene.CreateFromLocations

    https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.maps.mapscene

    It was designed exactly for this so the app doesn't have to worry about creating a bounding box.

    Friday, October 20, 2017 4:17 PM
    Moderator
  • One other possibility - is this a high DPI device? There's a known bug where the view may be calculated incorrectly on some high DPI systems where the scaling is set to > 100%
    Friday, October 20, 2017 4:18 PM
    Moderator
  • No I'm calling TrySetViewBounds after the map has loaded.

    If I use TrySetScene with the exact same bounding box then it works much better and at least puts everything in the centre correctly but doesn't zoom in enough. This is on an Xbox as stated in my original post and Xbox runs at 200% scale so it looks like this is a bug as you mentioned above. When is the known issue going to be fixed?

    The issue now is that TrySetScene doesn't zoom in enough and zooming in more after is difficult because I need to know that it won't cut the pins off screen. I rotate the map so that the two pins are always in a horizontal line.



    • Edited by luk8ja Friday, October 27, 2017 1:13 PM
    Friday, October 27, 2017 1:09 PM
  • The bug has already been fixed and will be available in a future servicing release. There's no fixed ETA for which servicing release yet.
    Friday, October 27, 2017 5:42 PM
    Moderator