WMS Layer#

Example#

from ipyleaflet import Map, WMSLayer, basemaps

wms = WMSLayer(
    url='http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi',
    layers='nexrad-n0r-900913',
    format='image/png',
    transparent=True,
    attribution='Weather data © 2012 IEM Nexrad'
)

m = Map(basemap=basemaps.CartoDB.Positron, center=(38.491, -95.712), zoom=4)

m.add(wms)

m

Usage#

By default, options like layers, format, transparent are passed in the request URL. If your tiles provider needs any extra parameter, you can define your own WMSLayer class which adds new parameters. For example, the following code adds a time parameter to the request by defining a custom TimeWMSLayer:

from traitlets import Unicode


class TimeWMSLayer(WMSLayer):

    time = Unicode('').tag(sync=True, o=True)


time_wms = TimeWMSLayer(
    url='https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r-t.cgi?',
    layers='nexrad-n0r-wmst',
    time='2005-08-29T13:00:00Z',
    format='image/png',
    transparent=True,
    attribution='Weather data © 2012 IEM Nexrad'
)

m2 = Map(basemap=basemaps.CartoDB.Positron, center=(30.661, -88.645), zoom=5)

m2.add(time_wms)

m2

Because it is a widget, you can dynamically update WMS parameters from Python manually:

# This will redraw the layer dynamically
time_wms.time = '2005-08-29T14:00'

Or from another widget like a slider: (Note that this example will not work in the documentation as there is no live Python kernel, but it will work in a Jupyter Notebook)

from ipywidgets import SelectionSlider

time_options = [
    '13:00', '13:30',
    '14:00', '14:30',
    '15:00', '15:30',
    '16:00', '16:30'
]

slider = SelectionSlider(description='Time:', options=time_options)

def update_wms(change):
    time_wms.time = '2005-08-29T{}'.format(slider.value)

slider.observe(update_wms, 'value')

slider

Attributes#

class ipyleaflet.leaflet.WMSLayer(**kwargs: Any)[source]#

WMSLayer class, with TileLayer as a parent class.

layers#

Comma-separated list of WMS layers to show.

Type:

string, default “”

styles#

Comma-separated list of WMS styles

Type:

string, default “”

format#

WMS image format (use ‘image/png’ for layers with transparency).

Type:

string, default “image/jpeg”

transparent#

If true, the WMS service will return images with transparency.

Type:

boolean, default False

crs#

Projection used for this WMS service.

Type:

dict, default ipyleaflet.projections.EPSG3857