OpenLayers and Yandex.Maps (Яндекс.Карты)

15 May 2009

FIXED version is available

Hello all! At last i have uploaded the fixed version of Yandex maps for openlayers. Look here: Yandex maps for OpenLayers (in sandbox). This fix removes latitude distortion because of ellipsoid globe model used in YandexMaps in contrast to spheroid in Google and Bing. I can't make these changes in simple version (beneath)— i have no idea about projection (EPSG) used in this webmap. If you have — send me description (see Spatialreference).

There are 2 files Yandex.html and OL_Yandex.js

OpenLayers is splendid opensource javascript framework for webmapping. "Yandex.Maps" (russian:Яндекс.Карты) - russian webmapping service (like Google Maps or VirtualEarth)

This is example map (up) and here is the code (down):

<script type="text/javascript" src="http://www.openlayers.org/api/OpenLayers.js"></script>
<div id="map" style="border: 1px solid lightgray; margin: 0pt 0pt 30px; padding: 0pt; width: 350px; height: 256px;"/>
<script type="text/javascript">
function yandex_getTileURL(bounds){
  var res = this.map.getResolution();
  var maxExtent = (this.maxExtent) ? this.maxExtent : yandexBounds;
  var tileW = (this.tileSize)?this.tileSize.w:256;
  var tileH = (this.tileSize)?this.tileSize.h:256;
  var x = Math.round((bounds.left - maxExtent.left)/(res * tileW));
  var y = Math.round((maxExtent.top - bounds.top)/(res * tileH));
  var z = this.map.getZoom();var limit = Math.pow(2, z);
  if (y <0>= limit) {
    return OpenLayers.Util.getImagesLocation() + "404.png";
  }else {
    x = ((x % limit) + limit) % limit;
    url = (this.url)?this.url:"http://vec02.maps.yandex.net/";
    return url+"tiles?l=map&v=2.2.3&x="+x+"&y="+y+"&z="+z;
  }
};

var yandexBounds = new OpenLayers.Bounds(-20037508,-20002151,20037508,20072865);

var map = new OpenLayers.Map('map', {
  projection: new OpenLayers.Projection("EPSG:900913"),
  displayProjection: new OpenLayers.Projection("EPSG:4326"),
  units: "m",
  maxResolution: 156543.0339,
  maxExtent:new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508.34)
});

var yandexMaps =
  new OpenLayers.Layer.TMS("Yandex","http://vec02.maps.yandex.net/",
  {
    maxExtent:yandexBounds,
    type:"png",
    getURL:yandex_getTileURL,
    numZoomLevels:18,
    attribution:'<a href="http://beta-maps.yandex.ru/">Яндекс.Карты</a>',
    transitionEffect:'resize'
  });
map.addLayers([yandexMaps]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomTo(4);
</script>

7 comments:

  1. That would be so but on the contrary!
    (For example both http://webmaps.t35.com/mymap.html But the coordinates do not match! I do not know what to do, may have a solution?)

    ReplyDelete
  2. Anonymous31/3/09 13:46

    Просто реально нужно! help

    ReplyDelete
  3. Oops.. really coordinates mismatch. This is because Yandex.Maps are "shorter" from North to South - uses another GLOBE model (not like Google or MS). There is more complicated solution - i will upload it tomorrow.

    ReplyDelete
  4. Let's wait the decision..

    ReplyDelete
  5. still waiting for solution

    ReplyDelete
  6. У нас, как и у всех, используется проекция EPSG:4326
    http://clubs.ya.ru/mapsapi/replies.xml?item_no=8089#coord-3

    ReplyDelete
  7. I have the problem
    OpenLayers with Yandex layer position issue

    can you please help me

    http://jsfiddle.net/mozkan/4c20jjph/9/

    ReplyDelete