【问题标题】:How to stretch tiles for certain zoom levels in custom ImageMapType implementation?如何在自定义 ImageMapType 实现中为某些缩放级别拉伸图块?
【发布时间】:2012-05-04 00:15:21
【问题描述】:

我已经实现了一个自定义 ImageMapType,它根据给定的坐标和 getTileUrl() 的缩放级别返回有效的磁贴 URL。

new google.maps.ImageMapType({
    name: 'Satellite',
    getTileUrl: function(coord, zoom) {
        var p_type = "satellite",
            z = zoom - 11,
            corr = Math.pow(2, zoom) - Math.pow(2, z),
            p_x = coord.x - corr,
            p_y = coord.y - corr,
            maxCoord = Math.pow(2, (z+1)) - 1;

        if (p_x > maxCoord || p_y > maxCoord || p_x < 0 || p_y < 0) {
            return 'http://maps.gstatic.com/intl/en_us/mapfiles/transparent.png';
        }

        p_x = (p_x < 16 ? '0' : '') + p_x.toString(16);
        p_y = (p_y < 16 ? '0' : '') + p_y.toString(16);

        return 'http://map.example.com/' + p_type + '/' + (z + 1) + '/tile_' + p_y + p_x + '.jpg';
    },
    tileSize: new google.maps.Size(128, 128),
    isPng: false,
    minZoom: 11,
    maxZoom: 16
});

对于缩放级别 11 到 16,我有 128x128 个图块。通过将 ImageMapTypeOptions 对象的 maxZoom 属性增加到 16 以上,可以缩放到有图块的位置(但当然不会出现图块,但是标记和折线确实有效)。在这种情况下,我希望从上一个缩放层拉伸图块(与更改缩放级别时的过渡效果相同)。

有可能吗?如果有,怎么做?

【问题讨论】:

    标签: javascript google-maps google-maps-api-3


    【解决方案1】:

    非常好的问题。这在理论上应该可以在客户端上做,但是作为getTileUrl 的方法 google.maps.ImageMapType对象必须返回URL,使用该对象时必须在服务器端进行。

    另一种可能性是使用更通用的google.maps.MapType 对象并定义您自己的getTile 方法。然后你可能会返回你自己的拉伸&lt;img&gt; 元素。

    【讨论】:

    • TMS 的答案之一正是我的想法。遇到类似的事情,并通过在不同的地方生成图像+ URL(在我的情况下:REST api)并在那里应用我的逻辑为我修复了它。不幸的是,getTileUrl 方法没有太多空间可以使用,并且只接受 URL。
    猜你喜欢
    • 1970-01-01
    • 2014-09-10
    • 2020-01-08
    • 1970-01-01
    • 2015-12-07
    • 1970-01-01
    • 2018-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多