3

I'm developing Windows Phone 8.1 application and I want to display Yandex Maps instead of Bing Maps in MapControl. I've set a new tile datasource with yandex url. It works, but tiles are displayed with a small vertical offset.

The offset only is not a problem, but it affects on placemarks - they are displayed in wrong position on yandex tiles, but correct in bing tiles.

The problem is not in coordinates because I pick them from original yandex maps in browser.

In example below, colored tiles are provided by yandex and gray shape is from bing maps.

Tile offset example

Setting yandex tiles 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've tried to intercept MapControl's tile request and decrement the value of y coordinate but the result was completely wrong.

Result of intercepting request and modifying value of y

enter image description here

MSDN: MapControl tile overlay

opewix
  • 4,993
  • 1
  • 20
  • 42
  • 1
    Yandex has different projection than google and bing. visit [http://gis.stackexchange.com/questions/69287/openlayers-with-yandex-layer-position-issue] – Fatih Pazarbaş Aug 19 '15 at 11:24

2 Answers2

3
    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);
    }

Example of usage:

    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 });
reflex
  • 31
  • 1
  • 3
1

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

Ishan
  • 130
  • 6