这是代码:它可以工作,但返回时带有定义为矩形的BBOX
function createLayer () {
var e = 20037508.34;
var tileGrid = new ol.tilegrid.TileGrid({
origin: [-e, -e],
extent: [-e, -e, e, e],
resolutions: [168e3, 84e3, 42e3, 21e3, 14e3, 5600, 2800, 1400, 560, 280, 140, 70, 28, 14, 7, 5.6, 4.2, 2.8, 1.4, .56, .42, .28],
});
var layers = [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
new ol.layer.Image({
source: new ol.source.ImageWMS({
url: 'hidelink',
params: {
'LAYERS': 'pianificazione:v_ps_timewms_vinc_archeologico_vigente',
'SRS':'EPSG:900913',
'FORMAT': 'image/png; mode=8bit',
'VERSION': '1.1.0',
'WIDTH': '256',
'HEIGHT': '256'
},
tileGrid: tileGrid
})
})
];
return layers;
}
我需要这个rest调用返回一个正方形BBOX中的图像。我该怎么办?
ImageWMS将设置BBOX以填充视口,TileWMS将BBOX设置为填充平铺,在这两种情况下,您指定的任何宽度width和HEIGHT都将被覆盖。既然你已经建立了瓷砖网格,我怀疑你想要瓷砖
new ol.layer.Tile({
source: new ol.source.TileWMS({
url: 'hidelink',
params: {
'LAYERS': 'pianificazione:v_ps_timewms_vinc_archeologico_vigente',
'SRS':'EPSG:900913',
'FORMAT': 'image/png; mode=8bit',
'VERSION': '1.1.0'
},
tileGrid: tileGrid
})
什么不起作用?有了这个图层参数,我想你使用的是意大利的市政服务。我为Firenze找到了这个,这个代码为我返回了256 x 256瓷砖
<!DOCTYPE html>
<html>
<head>
<title>WMS Test</title>
<link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" type="text/css">
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
</head>
<body>
<div id="map" class="map"></div>
<script>
function createLayer () {
var e = 20037508.34;
var tileGrid = new ol.tilegrid.TileGrid({
origin: [-e, -e],
extent: [-e, -e, e, e],
resolutions: [168e3, 84e3, 42e3, 21e3, 14e3, 5600, 2800, 1400, 560, 280, 140, 70, 28, 14, 7, 5.6, 4.2, 2.8, 1.4, .56, .42, .28],
});
var layers = [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
new ol.layer.Tile({
source: new ol.source.TileWMS({
url: 'http://tms.comune.fi.it/geowebcache/service/wms',
params: {
'LAYERS': 'pianificazione:v_ps_timewms_vinc_archeologico_vigente',
'SRS':'EPSG:900913',
'FORMAT': 'image/png; mode=8bit',
'VERSION': '1.1.0'
},
tileGrid: tileGrid
})
})
];
return layers;
}
var map = new ol.Map({
layers: createLayer (),
target: "map",
view: new ol.View({
center: ol.proj.fromLonLat([11.23, 43.77]),
zoom: 12
})
});
</script>
</body>
</html>