1
votes

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 * 2^level 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 (as needed in the sample in the article). But also with a whole number ZoomLevel of i.e. 4.0 (int --> 4) the formula doesn't work.

Now, I 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

1

1 Answers

1
votes

The article you are referencing was written years ago and is the basis to the map tiling system in all of the Bing Maps controls. However, this is for the tiling system and not necessarily the displayed map. The UWP control modifies how it renders to align with the pixel density of your screen so that it is nice and clear. This is why you are seeing discrepancies between the expected map pixel size when using the GetOffsetFromLocation. I believe the UWP controls base pixel density used for calculations is 128. The Surface Pro 3 has a pixel density of 216.33. So with a bit of math and taking into consideration 1.5 scaling, we see that (128*1.5)/216.33*4096 = 3635 which is a lot closer to the values you are calculating using your method. With this in mind, I would estimate that the pixel density of your external screen is 4096/3274*128 = 160.

As for:

map width = map height = 256 * 2^zoom;

This works with doubles too. The old Bing Maps Silverlight control allowed double zoom levels as well and this worked fine when doing pixel calculations.