Google maps api 3 在Google Maps v3中使用Yandex地图分幅

Google maps api 3 在Google Maps v3中使用Yandex地图分幅,google-maps-api-3,Google Maps Api 3,我在Google Maps API v2中使用了Yandex map tiles(俄语),但在Google Maps API v3中有些东西不起作用,请参见以下JSFIDLE: 请注意,在谷歌路线图和Yandex瓷砖之间切换时,它们没有对齐&标记位置错误 对于Maps v2,我制作了一个等效的JSFIDLE,但由于它需要一个API密钥,所以它被破坏了: 您可以在此处看到类似的代码,但您必须手动导航到莫斯科,因为Yandex在俄罗斯以外没有任何像样的数据: 我不记得我从哪里得到了v3代码,但常量似

我在Google Maps API v2中使用了Yandex map tiles(俄语),但在Google Maps API v3中有些东西不起作用,请参见以下JSFIDLE:

请注意,在谷歌路线图和Yandex瓷砖之间切换时,它们没有对齐&标记位置错误

对于Maps v2,我制作了一个等效的JSFIDLE,但由于它需要一个API密钥,所以它被破坏了:

您可以在此处看到类似的代码,但您必须手动导航到莫斯科,因为Yandex在俄罗斯以外没有任何像样的数据:

我不记得我从哪里得到了v3代码,但常量似乎大致对应于v2版本。除此之外,我不明白投影在做什么,所以我被卡住了

有什么想法吗

JSFIDLE中的代码如下所示:

var center = new google.maps.LatLng(55.75, 37.62);
var mapOptions = {
    zoom: 10,
    center: center,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), mapOptions);

new google.maps.Marker({map: map, position: center});

map.mapTypes.set("Yandex",
                 new google.maps.ImageMapType(
                     {getTileUrl: function(coord, zoom) {
                         return "http://vec0"+((coord.x+coord.y)%5)+".maps.yandex.net/tiles?l=map&v=2.16.0&x=" + 
                             coord.x + "&y=" + coord.y + "&z=" + zoom + "";
                     },
                      tileSize: new google.maps.Size(256, 256),
                      isPng: true,
                      alt: "Yandex",
                      name: "Yandex",
                      projection: new YandexProjection(),
                      maxZoom: 17}));

map.setOptions({mapTypeControlOptions: {mapTypeIds: [google.maps.MapTypeId.ROADMAP, "Yandex"]} });

function YandexProjection() {
    this.pixelOrigin_ = new google.maps.Point(128,128);
    var MERCATOR_RANGE = 256;
    this.pixelsPerLonDegree_ = MERCATOR_RANGE / 360;
    this.pixelsPerLonRadian_ = MERCATOR_RANGE / (2 * Math.PI);

    this.fromLatLngToPoint = function(latLng) {
        function atanh(x) {
            return 0.5*Math.log((1+x)/(1-x));
        }
        function degreesToRadians(deg) {
            return deg * (Math.PI / 180);
        }
        function bound(value, opt_min, opt_max) {
            if (opt_min != null) value = Math.max(value, opt_min);
            if (opt_max != null) value = Math.min(value, opt_max);
            return value;
        }

        var origin = this.pixelOrigin_;
        var exct = 0.0818197;
        var z = Math.sin(latLng.lat()/180*Math.PI);
        return new google.maps.Point(origin.x + latLng.lng() *this.pixelsPerLonDegree_,
                                     Math.abs(origin.y - this.pixelsPerLonRadian_*(atanh(z)-exct*atanh(exct*z))));
    };

    this.fromPointToLatLng = function(point) {
        var origin = this.pixelOrigin_;
        var lng = (point.x - origin.x) / this.pixelsPerLonDegree_;
        var latRadians = (point.y - origin.y) / -this.pixelsPerLonRadian_;
        var lat = Math.abs((2*Math.atan(Math.exp(latRadians))-Math.PI/2)*180/Math.PI);
        var Zu = lat/(180/Math.PI);
        var Zum1 = Zu+1;
        var exct = 0.0818197;
        var yy = -Math.abs(((point.y)-128));
        while (Math.abs(Zum1-Zu)>0.0000001){
        Zum1 = Zu;
        Zu = Math.asin(1-((1+Math.sin(Zum1))*Math.pow(1-exct*Math.sin(Zum1),exct))
                       / (Math.exp((2*yy)/-(256/(2*Math.PI)))*Math.pow(1+exct*Math.sin(Zum1),exct)));
        }
        if (point.y>256/2) {
            lat=-Zu*180/Math.PI;
        } else {
            lat=Zu*180/Math.PI;
        }
        return new google.maps.LatLng(lat, lng);
    };

    return this;
}

事实证明,
projection
属性不能通过
ImageMapTypeOptions
进行设置,必须在构建
ImageMapType
后进行分配,此JSFIDLE现在可以工作:


事实证明,
projection
属性不能通过
ImageMapTypeOptions
进行设置,必须在构建
ImageMapType
后进行分配,此JSFIDLE现在可以工作:

当然,没有yandex api,您无法使用yandex贴图。传单中不能使用yandex瓷砖

您需要包装yandex api或使用

或者自己写一个包装器

范例

没有yandex api,您无法使用yandex地图。传单中不能使用yandex瓷砖

您需要包装yandex api或使用

或者自己写一个包装器

范例

var yandexMapType = new google.maps.ImageMapType(
                     {getTileUrl: function(coord, zoom) {
                         return "http://vec0"+((coord.x+coord.y)%5)+".maps.yandex.net/tiles?l=map&v=2.16.0&x=" + 
                             coord.x + "&y=" + coord.y + "&z=" + zoom + "";
                     },
                      tileSize: new google.maps.Size(256, 256),
                      isPng: true,
                      alt: "Yandex",
                      name: "Yandex",
                      maxZoom: 17});
// projection is ignored if passed to MapTypeOptions
yandexMapType.projection = new YandexProjection();
map.mapTypes.set("Yandex", yandexMapType);