1

I need 3 layers: OSM, Google and Yandex. My view, OSM and Google layer in EPSG:3857 projection, but Yandex layer seems to be in EPSG:3395, so it was displayed not correctly. I've defined the new projection via proj4js and the layer has moved significantly, but it still doesn't match the other layers.

My code is:

proj4.defs('EPSG:3395', '+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs');

map = new ol.Map({
  target: 'olmap',
  layers: [
    new ol.layer.Tile({
      title: 'Yandex',
      source: new ol.source.XYZ({
        url: '...',
        projection: 'EPSG:3395'
      })
    }),
    new ol.layer.Tile({
      title: 'Google',
      source: new ol.source.XYZ({
        url: '...'
      })
    }),
    new ol.layer.Tile({
      title: 'OSM',
      source: new ol.source.XYZ({
        url: '...'
      })
    })
  ],
  view: new ol.View({
    projection: 'EPSG:3857',
    extent: ol.proj.transformExtent([-180, -80, 180, 80], 'EPSG:4326', 'EPSG:3857')
  })
});

The definition of EPSG:3395 I took from here: https://epsg.io/3395 .

OSM layer: OSM

Yandex.Maps layer: Yandex

Where is my mistake?

  • I believe that the problem can be found in the remarks section in the definition of 3857, which says: "Uses spherical development of ellipsoidal coordinates. Relative to WGS 84 / World Mercator (CRS code 3395) errors of 0.7 percent in scale and differences in northing of up to 43km in the map (equivalent to 21km on the ground) may arise". Consequently, you will probably not be able to get them to align perfectly, because the scale in the north-south direction differs between the two projections. – John Powell Mar 29 '16 at 14:32
  • I just changed k value from '1' to '0.99888' and now it seems to work well. But I still don't know why. – mike_grinin Apr 1 '16 at 7:52
  • Because 3857 uses a spherical earth assumption and 3395 uses an ellipsoid, so you have scale distortion in the north-south direction, which will increase the closer you get to the pole. 0.99888 may work for NYC, but will be inaccurate in Anchorage or Accra. Thanks for bringing 3395 to my attention, I hadn't heard of it before. – John Powell Apr 1 '16 at 7:56
  • @mike_grinin. Can you, please, share how a full definition of Google layer looks like? I managed to add a Yandex map and it works good. Now I want to do the same with the Google layer. Thanks! – Jacobian Dec 14 '16 at 10:29
  • @Jacobian It looks exectly like in my description. For url I use mt1.google.com/vt/lyrs=m@129&hl=en&x={x}&y={y}&z={z} and for projection - EPSG:3857 – mike_grinin Dec 15 '16 at 12:02
2

To configure the Yandex tile layer correctly, you need to customize the tile grid to match the extent Yandex uses for the world, which is [-20037508.342789244, -20037508.342789244, 20037508.342789244, 20037508.342789244]. So your Yandex tile layer configuration would look like this:

new ol.layer.Tile({
  source: new ol.source.XYZ({
    url: 'http://vec0{1-4}.maps.yandex.net/tiles?l=map&x={x}&y={y}&z={z}',
    projection: 'EPSG:3395',
    tileGrid: ol.tilegrid.createXYZ({
      extent: [-20037508.342789244, -20037508.342789244, 20037508.342789244, 20037508.342789244]
    })
  })
})

If you want to use EPSG:3395 as view projection, it makes sense to configure the projection extent for EPSG:3395:

proj4.defs('EPSG:3395', '+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs');
ol.proj.get('EPSG:3395').setExtent([-20037508.342789244, -20037508.342789244, 20037508.342789244, 20037508.342789244]);

If you have done so, you can omit the tileGrid option for the Yandex source.

  • Thanks for sharing! But don't you know how to create a Google tile layer? – Jacobian Dec 14 '16 at 10:31
  • There is no legal way to create a Google tile layer. – ahocevar Dec 14 '16 at 13:29
  • And as for teaching purposes? I'm just interested to know if it is possible to create a Google layer as easily as we do it with a Yandex layer. – Jacobian Dec 14 '16 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.