我可以创建一个带有maxExtent和restrictedExtent属性的OpenLayers地图。我也已经尝试过WMS图层及其maxExtent属性,但问题在于使用WMS图层中的singleTile时。 我想要的是只从服务器获取一张图片的WMS图层,但限制在我想要的范围内。因此,我使用了singleTile=true,ratio=1和maxExtend=my_desired_extent。但它总是请求整个地图视图。 有什么好的想法吗? 谢谢提前。 下面的代码显示了一个带有基础层和海岸线层的地图,我想在单瓦片模式下使用,并限制它们对WMS的请求区域。
<script type="text/javascript" src="http://openlayers.org/api/2.11/OpenLayers.js"></script>
<div id="map" style="width: 700px; height: 500px;"></div>
<script type="text/javascript">
var map = new OpenLayers.Map("map");
var wms = new OpenLayers.Layer.WMS("OpenLayers WMS Basic", "http://labs.metacarta.com/wms/vmap0",
{
layers: 'basic'
});
map.addLayer(wms);
var restricted = new OpenLayers.Layer.WMS("Coast Line", "http://labs.metacarta.com/wms/vmap0",
{
layers: 'coastline_01,coastline_02'
},
{
opacity: 0.6,
singleTile: true,
ratio: 1,
isBaseLayer: false,
maxExtent: OpenLayers.Bounds.fromString("-10,-90,30,90")
});
map.addLayer(restricted);
map.setCenter(new OpenLayers.LonLat(0,40), 3);
</script>
我正在查看OpenLayers源代码,似乎我需要的功能没有被实现,所以我需要创建一些WMS子类或重新定义一些WMS图层方法。
如果有帮助,我将不胜感激。
谢谢。