WMS作为Google Maps v3中的单个平铺图片 [英] WMS as a single tile image in Google Maps v3
问题描述
我遵循 http://www.gisdoctor.com/v3/mapserver上的代码。 HTML 将WMS作为图像叠加在使用API v3的Google地图上。上面链接的js代码如下所示:
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 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? +
版本= 1.1.1& +
request = GetMap& +
样式=默认值& +
SRS = EPSG:4326& +
图层= wmsLayers& +
BBOX =+ bbox +& +
width = 256& +
height = 256& +
format = image / png& +
TRANSPARENT = TRUE;
},
addWmsLayer:function(){
/ *
创建WMS图层选项。此代码为每个wms图层创建Google
imagemaptype选项。在选项中,调用单个wms层的函数
被设置为
* /
var wmsOptions = {
alt:MapServer Layers,
getTileUrl:WMSGetTileUrl,
isPng:false,
maxZoom:17,
minZoom:1,
name:MapServer Layer,
tileSize:new google.maps.Size(256, 256)
};
/ *
创建对象以创建将调用WMS
图层选项的ImageMapType。
* /
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 ,似乎我可能会更好地向mapserver请求一个不带色的(单个)图像。这会减少我的服务器。无论如何,我想尝试一个单一的图像,但我无法正确构建一个请求。
具体来说,我改变了瓷砖的大小到一些大的东西;例如,我尝试了1024 x 1024的图块。我确实获得了较少的图块,但返回的图像与Google Maps基本图层边界不匹配。
我想要的是根本不指定图块大小。相反,我应该动态地确定图块的大小,例如比当前地图大小大256个像素。这样,无论地图大小如何,都会返回单个图像。此外,在地图边缘的额外256像素的帮助下,可以实现无缝平移。
建议?
请参阅同样的问题我刚刚为其他人回答。这很可能是你的预测。 EPSG:4326不是Google地图的正确投影。改变投影意味着你需要改变坐标计算和引用的方式。
I am following the code at http://www.gisdoctor.com/v3/mapserver.html to overlay a WMS as an image on Google Maps using API v3. The js code at the above link is as follows
"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);
},
Everything works fine, but, of course, the WMS is returned as 256 x 256 tiles. No surprises, because that is what I requested. However, following the discussion at http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/c22837333f9a1812/d410a2a453025b38 it seems that I might be better off requesting an untiled (single) image from mapserver. This would tax my server less. In any case, I would like to experiment with a single image, but I am unable to construct a request for one properly.
Specifically, I changed the size of the tile to something large; for example, I tried 1024 x 1024 tiles. I did get fewer tiles, but the returned images didn't match the Google Maps base layer boundaries.
What I would like is to not specify the tile size at all. Instead, I should dynamically figure out the tile size to be, say, 256 pixels bigger than the current map size. That way, a single image would be returned, no matter what the map size. Also, a seamless pan would be implemented with the help of the extra 256px along the map edges.
Suggestions?
See this same question I just answered for someone else. It's likely to be your projection. EPSG:4326 is not the correct projection for Google Maps. Changing the projection means you need to change the way coordinates are calculated and referenced.
这篇关于WMS作为Google Maps v3中的单个平铺图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!