引用ol.js开发包,加载如下代码:
var layers = [
new ol.layer.Tile({
source: new ol.source.TileWMS({
url: 'http://localhost:8080/geowebcache/service/wms',
params: {
'LAYERS': 'MyMapService',
'FORMAT': 'image/jpeg',
'SRS': 'EPSG:4326',
'VERSION': '1.1.1'
},
tileGrid: new ol.tilegrid.TileGrid({
//resolution和conf.xml中保持一致
resolutions: [0.05948652514575701, 0.00951784402332112, 0.00475892201166056, 0.00237946100583028, 0.00118973050291514],
tileSize: [256, 256],
origin: [-400, 399.99999999999977]
})
})
})
];
var map = new ol.Map({
controls: [],
layers: layers,
target: 'map',
view: new ol.View({
projection: 'EPSG:4326',
center: [108.942566, 34.271469],
zoom: 4
})
});