4

There is a working example in leaflet site for adding WMS Layer in leaflet map at : http://leafletjs.com/reference.html#tilelayer-wms. But I don't see methods to provide the filter for bounding box.

Is there a way to provide bounding box filters for Leaflet WMS ?

MPelletier
  • 16,256
  • 15
  • 86
  • 137
Prabhash Jha
  • 330
  • 2
  • 12

3 Answers3

2

Just add bbox: [-180,-90,180,90] to the L.tileLayer.wms options.

Example:

var layer_SOEST_SurfaceTemp = L.tileLayer.wms("http://...............", {
    layers: 'tmpsfc',                                                
    format: 'image/png',
    transparent: true,
    opacity: 0.5,
    crs: L.CRS.EPSG4326,
    bbox: [-180,-90,180,90],
    styles: 'boxfill/alg',
    attribution: "SOEST Hawaii",
    time : forecast_datetime,
    version : '1.3.0'
});
Robin Ellerkmann
  • 2,083
  • 4
  • 29
  • 34
0

Just add the desired parameters to your L.tileLayer.wms options even if not shown in the API... Thoses parameters will be passed anyway to your map server and if this server support bbox or any others parameters provided it will return you the correct tiles...

Etienne Desgagné
  • 3,102
  • 1
  • 29
  • 36
0

You can use the option bounds to filter.

If set, tiles will only be loaded inside the set LatLngBounds.

L.TileLayer and L.TileLayer.WMS are both extending L.GridLayer, so the same options can used: https://leafletjs.com/reference-1.7.1.html#gridlayer-bounds

var nexrad = L.tileLayer.wms("URL.COM", {
    layers: 'LAYER_NAME',
    format: 'image/png',
    transparent: true,
    attribution: "Weather data © 2012 IEM Nexrad",
    bounds: L.latLngBounds([[1,0],[0,1]])
});
Falke Design
  • 10,635
  • 3
  • 15
  • 30