none
MapControl map size (pixels) RRS feed

  • Question

  • Hello,

    This article describes how to get the total map size in pixels depending on the actual zoom level.

    The formula should be: map width = map height = 256 * 2level pixels

    Unfortunately this doesn't seem to work for the MapControl for universal apps. First thing is, the ZoomLevel property is of type double not integer. But also with a whole number ZoomLevel of i.e. 4.0 (int --> 4) the formula doesn't work.

    I now tried to get the map size in pixel with help of the MapControl.GetOffsetFromLocation method:

            private double GetMapSize()
            {
                Point pW, pE;
    
                myMap.GetOffsetFromLocation(new Geopoint(new BasicGeoposition()
                    { Longitude = -90, Latitude = 0 }), out pW);
                myMap.GetOffsetFromLocation(new Geopoint(new BasicGeoposition()
                    { Longitude = 90, Latitude = 0 }), out pE);
    
                return (pE.X - pW.X) * 2;
            }

    This works with a discrepancy of some pixels, but this issue is actually not important.

    I get on my Surface Pro 3 the following results (ZoomLevel is 4.0):

    Surface screen (scale 1.5): 3654px
    Surface external screen (scale 1.0): 3274px

    None of these results is 4096px like described in the article. The results are correct and I can work with that. But for me it's just a workaround and also if the ZoomLevel is higher than approx 13 the GetOffsetFromLocation method returns -1 for pE.X and pW.X (for -90 and 90). For nearer longitudes to the actual center it works. It seems that GetOffsetFromLocation has a maximum of distance. So I would need to use nearer longitude values when having a higher ZoomLevel.

    That all is not really a clear solution. So my question is: Is there a save method to get the exact map size in pixels for the UWP MapControl?

    Thanks!

    Maas

    Monday, July 25, 2016 12:26 PM

Answers

  • I'm not sure what you're trying to do here, but that article is about the web-based Raster map control where there are discrete levels of detail rendered as raster bitmaps.

    The UWP map control is a vector-based control where there aren't any discrete levels of detail. Zoom level is kind of arbitrary and meaningless - it was just kept for compatibility reasons. You can have a map view at any altitude or scale and there's no pre-rasterized total bitmap size. The map control will also try to adjust for screen DPI and other factors to maintain the best readability.

    In general you should avoid trying to use OffsetFromLocation to try to reverse engineer map views as most apps that do this don't consider rotated or tilted views and get the math wrong. There should be API's available to set views for all the common cases using the TrySetScene API's. MapElements are the best way of adding map content which will do all the work to keep content in sync. You should definitely avoid trying to position XAML yourself that matches map pixel coordinates as this will be pretty much impossible to do in all scenarios.

    • Proposed as answer by Ricky_Brundritt Monday, July 25, 2016 5:33 PM
    • Marked as answer by MaasOne Monday, July 25, 2016 5:47 PM
    Monday, July 25, 2016 5:02 PM
    Moderator

All replies

  • I'm not sure what you're trying to do here, but that article is about the web-based Raster map control where there are discrete levels of detail rendered as raster bitmaps.

    The UWP map control is a vector-based control where there aren't any discrete levels of detail. Zoom level is kind of arbitrary and meaningless - it was just kept for compatibility reasons. You can have a map view at any altitude or scale and there's no pre-rasterized total bitmap size. The map control will also try to adjust for screen DPI and other factors to maintain the best readability.

    In general you should avoid trying to use OffsetFromLocation to try to reverse engineer map views as most apps that do this don't consider rotated or tilted views and get the math wrong. There should be API's available to set views for all the common cases using the TrySetScene API's. MapElements are the best way of adding map content which will do all the work to keep content in sync. You should definitely avoid trying to position XAML yourself that matches map pixel coordinates as this will be pretty much impossible to do in all scenarios.

    • Proposed as answer by Ricky_Brundritt Monday, July 25, 2016 5:33 PM
    • Marked as answer by MaasOne Monday, July 25, 2016 5:47 PM
    Monday, July 25, 2016 5:02 PM
    Moderator
  • Thanks for your answer!

    I had the same thoughts. And yes it's a kind of XAML positioning relative to the map. It's not really possible for all scenarios or at least very hard to implement, that's right, but it's not necessary for me. For the most common cases the integrated possibilities of MapControl are OK. But in my case it's not enough. So, I know that GetOffsetFromLocation is not perfect. That's why I'm asking. ^^

    I can't give more details about my project, but I can tell you that I've tried everything with the integrated functions of MapControl. The performance is just too slow/bad for my purposes (fast/dynamic shape changes). In the Win8 map control there was an extra shape layer for that which was very perfomant (as I remember). But unfortunately this doesn't exist anymore in UWP MapControl. :-(

    Monday, July 25, 2016 5:31 PM