MapControl displays Yandex maps Maps with offset

I am developing a Windows Phone 8.1 application and I want to display Yandex Maps

instead Bing Maps

in a MapControl. I have set up a new datasource tile with yandex url. It works, but the tiles are displayed with a slight vertical offset.

Offset is not a problem, but it does affect the tags - they are displayed in the wrong position on yandex feeds, but are corrected in bing fragments.

The problem is not the coordinates, because I am fetching them from the original yandex maps in the browser.

In the example below, the colored tiles are provided by yandex and the gray form is from bing cards.

Tile offset example

Installing yandex slabs in MapControl:

HttpMapTileDataSource dataSource = new HttpMapTileDataSource("http://vec02.maps.yandex.net/tiles?l=map&x={x}&y={y}&z={zoomlevel}");
MapTileSource tileSource = new MapTileSource(dataSource);
MyMapControl.TileSources.Add(tileSource);

      

I tried to intercept the MapControl mosaic request and decrease the coordinate value y

, but the result was completely wrong.

The result of a request to intercept and change the value y

enter image description here

MSDN: MapControl Overlay Overlay

+3


source to share


2 answers


This is because Yandex Maps and Bing Maps have slightly different map projections. However I am not an expert on projections, you can see the difference in MercatorProjection (implemented for Bing Map) and MercatorProjectionYandex (implemented for Yandex Maps) implemented for Great Maps for Windows Forms and Presentation .



+1


source


    public static Point WGS84ToBing(Point coordinate)
    {
        double d = coordinate.X * Math.PI / 180, m = coordinate.Y * Math.PI / 180, l = 6378137, k = 0.0818191908426, f = k * Math.Sin(m);
        double h = Math.Tan(Math.PI / 4 + m / 2), j = Math.Pow(Math.Tan(Math.PI / 4 + Math.Asin(f) / 2), k), i = h / j;

        return new Point(l * d, l * Math.Log(i));
    }

    public static Point BingtoWGS84Mercator(Point point)
    {
        double lon = (point.X / 20037508.34) * 180;
        double lat = (point.Y / 20037508.34) * 180;

        lat = 180 / Math.PI * (2 * Math.Atan(Math.Exp(lat * Math.PI / 180)) - Math.PI / 2);

        return new Point(lon, lat);
    }

      

Usage example:



    HttpMapTileDataSource dataSource = new HttpMapTileDataSource("http://vec02.maps.yandex.net/tiles?l=map&v=2.2.3&x={x}&y={y}&z={zoomlevel}");

    MapTileSource tileSource = new MapTileSource(dataSource)
    {
        Layer = MapTileLayer.BackgroundReplacement
    };

    map.Style = MapStyle.None;
    map.TileSources.Add(tileSource);

    Point bingPoint = WGS84ToBing(new Point(47.245252, 56.139498));
    Point yandexCoordinates = BingtoWGS84Mercator(new Point(bingPoint.X, bingPoint.Y));

    map.Center = new Geopoint(new BasicGeoposition() { Longitude = yandexCoordinates.X, Latitude = yandexCoordinates.Y });

      

+1


source







All Articles