var ip = 127.0.0.1:8080 //geoserver 服务地址
var layer =相应图层名 //geoserver 服务图层
url = `http://${ip}/geoserver/wms?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:3857&transparent=true&width=256&height=256&layers=${layer}`
const ip = '127.0.0.1:8080'
const layer = 'test'
map.on('load', () => {
map.addSource('geoserver-source', {
type: 'raster',
tiles: [
`http://${ip}/geoserver/wms?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:3857&transparent=true&width=256&height=256&layers=${layer}`,
],
tileSize: 256,
})
map.addLayer({
id: 'geoserver-layer',
type: 'raster',
source: 'geoserver-source',
paint: {},
})
})