我正在按照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 的瓷砖。我确实得到了更少的图块,但返回的图像与谷歌地图的基础层边界不匹配。
我想要的是根本不指定瓷砖大小。相反,我应该动态计算出图块大小比当前地图大小大 256 像素。这样,无论地图大小如何,都将返回单个图像。此外,将借助沿地图边缘的额外 256px 实现无缝平移。
建议?