Google maps api 3 WMS作为Google Maps v3中的单个平铺图像
我在下面的代码中使用API v3将WMS作为图像覆盖在Google地图上。上面链接的js代码如下Google maps api 3 WMS作为Google Maps v3中的单个平铺图像,google-maps-api-3,wms,Google Maps Api 3,Wms,我在下面的代码中使用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
"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个平铺。没什么奇怪的,因为这是我的要求。然而,在讨论之后,似乎我最好从mapserver请求一个未绑定的(单个)图像。这将减少服务器的负担。在任何情况下,我都想尝试使用单个图像,但我无法正确地构造一个请求
具体来说,我把瓷砖的尺寸改大了;例如,我尝试了1024x1024个瓷砖。我确实得到了更少的瓷砖,但返回的图像与谷歌地图的基本层边界不匹配
我想要的是根本不指定瓷砖大小。相反,我应该动态计算出平铺大小,比如说,比当前地图大小大256像素。这样,无论地图大小如何,都将返回单个图像。此外,在地图边缘额外的256px的帮助下,将实现无缝平移
建议?1)它对我来说很有效——512和1024也适用。您只需在所有适当的位置进行更改(角坐标计算、平铺大小设置、WMS参数宽度和高度设置)。只要在代码中的所有位置正确处理,任何平铺设置都应该是可能的
2) 我认为您试图在错误的地方进行优化。建立256x256瓷砖是有原因的。请记住,google正在缓存分幅,因此使用较大的分幅,整个解决方案可能会慢得多。此外,地图将为用户加载得更快
3) 瓷砖的概念是正确的,应该保留下来。像接收整个地图这样的事情是行不通的——想象一下当时的地图平移。不要试图重新发明轮子和坚持当前的谷歌瓷砖概念-它是为这种类型的应用程序优化。如果您需要以单个图像的形式接收地图,您可以使用静态google maps api。请参阅我刚才为其他人回答的问题。这很可能是你的预测。EPSG:4326不是谷歌地图的正确投影。更改投影意味着您需要更改坐标的计算和引用方式。您是否找到了解决方案?据了解,Weather Underground的好人使用这种方法绘制地图:。也许他们中的一个会看到这一点并跳进去:)