I have many tile layers in a map.So when I zoom or move the map,all layers will send wms request to the server.How can I reduce HTTP requests when zoom the map by merging different layer's request to a single request?
If all your WMS layers come from the same server, you can combine them into a single ol.layer.Layer
object, more precisely in one source object by definining each layer in a comma separated list (under the 'LAYERS'
parameter):
new ol.layer.Image({
extent: [-13884991, 2870341, -7455066, 6338219],
source: new ol.source.ImageWMS({
url: 'https://ahocevar.com/geoserver/wms',
params: {'LAYERS': 'topp:states,topp:population'}, // <---
ratio: 1,
serverType: 'geoserver'
})
})
There are other things you could try to reduce the number of requests / to enhance the overall performance: