How our Neighbors made friends with Yandex.Maps

    What country do we live in? That's right - in Russia.
    So why bind yourself to foreign maps from Google?
    We live in Russia, and for her there are cards. Relatives. These are Maps from Yandex.


    Now eNeighbors are friends with Yandex.Maps. Having visited the site, you can see your house or cottage on them, and if you wish, compare with Google maps.

    The transition to Yandex.Maps was made not only for patriotic reasons :)
    In some cases, Google’s coverage in Russia is far from ideal. At the same time, it cannot be said that Yandex.Maps are definitely better. But they sometimes show what is missing on Google maps. Here is a curious example of an almost mirror image of quality sites:
    image image

    Read about how to use Yandex on your site if you already have Google.


    Differences between Yandex and Google

    1. GLatLng and YMaps.GeoPoint are used in G and Z, respectively.
    the transition from one system to another is simple: 2. Yandex uses a different projection standard, a little narrower epsg: 3395 ( details ) 3. Some functions are simply called differently, some work a little differently.
    function G2YA(a){return new YMaps.GeoPoint(a.lng(),a.lat())}
    function YA2G(a){return new GLatLng(a.getLat(),a.getLng());}






    How to connect Yandex and Google maps?

    Option - use a proxy ( description of the proxy in the club )
    The bottom line is simple - we wrap both Google and Yandex with an interface.
    In our case, it was a little easier - we had a centralized call to the coordinates, SET was in one place, we still let GET through the proxy.
    It turned out something similar to: The map shift event in Google is set as in Yandex in a different way - you have to hang on two events: Markers and e- Neighbors do not use, but they use overlays that allow you to display anything on the map. If you are interested in learning how to do this, kashey can describe it in more detail, but in a different topic.

    map.getPane=function(a){return 0;}
    map.checkResize=function(){this.redraw(true);}
    map.disableScrollWheelZoom=function(){this.disableScrollZoom();}
    map.enableScrollWheelZoom=function(){this.enableScrollZoom();}
    map.fromLatLngToDivPixel=function(a){ YA=G2YA(a);return this.converter.coordinatesToMapPixels(YA);}
    map.fromContainerPixelToLatLng=function(a){ return YA2G(geo_map.converter.localPixelsToCoordinates(GP2YA(a)));}
    map.getMapCenter=function(){return YA2G(this.getCenter());}
    map.setMapType=function(a)
    {
    if(a==G_NORMAL_MAP )this.setType(YMaps.MapType.MAP);
    if(a==G_HYBRID_MAP )this.setType(YMaps.MapType.HYBRID);
    if(a==G_PHYSICAL_MAP )this.setType(YMaps.MapType.SATELLITE );
    }

    map.getCurrentMapType=function()
    {
    a=this.getType();
    if(a==YMaps.MapType.MAP )return G_NORMAL_MAP;
    if(a==YMaps.MapType.HYBRID )return G_HYBRID_MAP;
    if(a==YMaps.MapType.SATELLITE)return G_PHYSICAL_MAP;
    }

    YMaps.GeoBounds.prototype.getSouthWest=function(){ return YA2G(this.getLeftBottom());}
    YMaps.GeoBounds.prototype.getNorthEast=function(){ return YA2G(this.getRightTop());}



    GEvent.addListener(geo_map, "moveend", map_moveend_event );



    YMaps.Events.observe(map, map.Events.Update,map_moveend_event);
    YMaps.Events.observe(map, map.Events.MoveEnd,map_moveend_event);





    How to make friends with overlays G and I?

    Again, everything is very simple. The onAddToMap function creates a div (_div) into which you can put any data. In the case of G cards, its addition to the map is performed in the initialize function with the command; in the case of G cards , this command simply will not work. In principle, GMarker can be downloaded in a similar way, and it will “just work”, or write an inverse function. Then beautiful Yandex.Balunas will earn on G cards ... We had enough of the described patches to launch a new version of the cards. Perhaps we did not take into account something, but for a week of testing glitches did not come out.

    GOverlay.prototype.onAddToMap = function(map,to)
    {
    this.initialize(map);
    to.appendChild(this.div_);
    this.onMapUpdate(map);
    return obj;
    }

    GOverlay.prototype.onRemoveFromMap = function(map)
    {
    return this.remove();
    }

    GOverlay.prototype.onMapUpdate = function(map)
    {
    this.redraw(true);
    }




    if(GetMap().getPane(defmappane))
    GetMap().getPane(defmappane).appendChild(div);





    Also popular now: