Add a WMS source
This source code of this example is adapted from the MapLibre GL JS example - Add a WMS source.
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# %pip install "leafmap[maplibre]"
# %pip install "leafmap[maplibre]"
In [2]:
Copied!
import leafmap.maplibregl as leafmap
import leafmap.maplibregl as leafmap
In [3]:
Copied!
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
In [4]:
Copied!
m = leafmap.Map(center=[-74.5447, 40.6892], zoom=8, style="streets")
source = {
"type": "raster",
"tiles": [
"https://img.nj.gov/imagerywms/Natural2015?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=Natural2015"
],
"tileSize": 256,
}
layer = {
"id": "wms-test-layer",
"type": "raster",
"source": "wms-test-source",
"paint": {},
}
m.add_source("wms-test-source", source)
m.add_layer(layer, before_id="aeroway_fill")
m
m = leafmap.Map(center=[-74.5447, 40.6892], zoom=8, style="streets")
source = {
"type": "raster",
"tiles": [
"https://img.nj.gov/imagerywms/Natural2015?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=Natural2015"
],
"tileSize": 256,
}
layer = {
"id": "wms-test-layer",
"type": "raster",
"source": "wms-test-source",
"paint": {},
}
m.add_source("wms-test-source", source)
m.add_layer(layer, before_id="aeroway_fill")
m
Failed to retrieve the MapTiler style. Defaulting to 'dark-matter' style.