WMS 作为 Google Maps v3 中的单个平铺图像

Posted

技术标签:

【中文标题】WMS 作为 Google Maps v3 中的单个平铺图像【英文标题】:WMS as a single tile image in Google Maps v3 【发布时间】:2011-06-21 12:42:12 【问题描述】:

我正在按照http://www.gisdoctor.com/v3/mapserver.html 的代码使用 API v3 将 WMS 作为图像覆盖在 Google 地图上。上面链接的js代码如下

"WMSGetTileUrl" : function(tile, zoom) 
    var projection = map.getProjection();
    var zpow = Math.pow(2, zoom);
    var ul = new google.maps.Point(
        tile.x * 256.0 / zpow, 
        (tile.y + 1) * 256.0 / zpow
    );
    var lr = new google.maps.Point(
        (tile.x + 1) * 256.0 / zpow, 
        tile.y * 256.0 / zpow
    );
    var ulw = projection.fromPointToLatLng(ul);
    var lrw = projection.fromPointToLatLng(lr);

    var bbox = ulw.lng() + "," + ulw.lat() + "," + lrw.lng() + "," + lrw.lat();

    return url = "http://url/to/mapserver?" + 
        "version=1.1.1&" + 
        "request=GetMap&" + 
        "Styles=default&" + 
        "SRS=EPSG:4326&" + 
        "Layers=wmsLayers&" + 
        "BBOX=" + bbox + "&" + 
        "width=256&" + 
        "height=256&" + 
        "format=image/png&" + 
        "TRANSPARENT=TRUE";
,

"addWmsLayer" : function() 

    /*
    Creating the WMS layer options. This code creates the Google 
    imagemaptype options for each wms layer. In the options the function 
    that calls the individual wms layer is set 
    */
    var wmsOptions = 
        alt: "MapServer Layers",
        getTileUrl: WMSGetTileUrl,
        isPng: false,
        maxZoom: 17,
        minZoom: 1,
        name: "MapServer Layer",
        tileSize: new google.maps.Size(256, 256)
    ;

    /*
    Creating the object to create the ImageMapType that will call the WMS 
    Layer Options. 
    */
    wmsMapType = new google.maps.ImageMapType(wmsOptions);
    map.overlayMapTypes.insertAt(0, wmsMapType);
,

一切正常,但是,当然,WMS 返回为 256 x 256 瓦片。毫不奇怪,因为这是我要求的。但是,在http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/c22837333f9a1812/d410a2a453025b38 的讨论之后,似乎我最好从地图服务器请求一个未处理的(单个)图像。这会减少我的服务器的负担。无论如何,我想尝试使用单个图像,但我无法正确构造一个请求。

具体来说,我将图块的大小更改为较大;例如,我尝试了 1024 x 1024 的瓷砖。我确实得到了较少的图块,但返回的图像与 Google 地图基础层边界不匹配。

我想要的是根本不指定图块大小。相反,我应该动态计算出图块大小比当前地图大小大 256 像素。这样,无论地图大小如何,都将返回单个图像。此外,将借助沿地图边缘的额外 256px 实现无缝平移。

建议?

【问题讨论】:

您找到解决方案了吗?它看到 Weather Underground 的好人使用这种方法进行映射:wunderground.com/wundermap。也许他们中的一个会看到这个并跳进去:) 【参考方案1】:

1) 它适用于我 - 也适用于 512 和 1024。您只需在所有适当的地方进行更改(角坐标计算、tileSize 设置、WMS 参数宽度和高度设置)。如果您只是在代码中的所有位置正确处理它,则任何平铺设置都应该是可能的。

2)我认为您正在尝试在错误的地方进行优化。建立 256x256 瓷砖是有原因的。请记住,谷歌正在缓存瓷砖,因此使用较大的瓷砖,整个解决方案可能会慢得多。此外,地图将为用户加载得更快。

3) 平铺概念是正确的,应该保留。像接收整个地图这样的事情是行不通的——想象一下地图平移。不要试图重新发明***并坚持当前的 google tile 概念 - 它已针对此类应用程序进行了优化。如果您需要将地图作为单个图像接收,您可以使用 静态 google maps api

【讨论】:

【参考方案2】:

看到这个same question我只是替别人回答。这很可能是你的预测。 EPSG:4326 不是谷歌地图的正确投影。更改投影意味着您需要更改计算和引用坐标的方式。

【讨论】:

以上是关于WMS 作为 Google Maps v3 中的单个平铺图像的主要内容,如果未能解决你的问题,请参考以下文章

Google Maps API V3 中的 API 密钥是啥?

Google Maps API v3 中的 Javascript 错误 (RefererDeniedMapError)

Google Maps v3 AutoComplete 获取建议

关闭 Google Maps API v3 中的所有信息窗口

在 google maps api v3 中隐藏方向服务中的标记

如何更改 Google Maps API V3 中的图标颜色?