A Python package for geospatial analysis and interactive mapping in a Jupyter environment.
54
Evaluation — 54%
↓ 0.80xAgent success when using this tile
Extensive basemap collection with 100+ predefined providers supporting XYZ tiles, WMS services, and custom tile sources with backend-specific optimizations and QuickMapServices integration.
Access and manage basemaps from various providers with automatic backend-specific formatting and optimization.
def get_xyz_dict(free_only=True, france=False):
"""
Get dictionary of available XYZ basemap providers.
Args:
free_only (bool): Return only free basemap providers
france (bool): Include France-specific providers
Returns:
dict: Dictionary of basemap providers with metadata
"""
def xyz_to_leaflet():
"""
Convert XYZ basemap definition to ipyleaflet format.
Returns:
ipyleaflet.TileLayer: Formatted basemap layer
"""
def xyz_to_folium(xyz):
"""
Convert XYZ basemap definition to folium format.
Args:
xyz (dict): XYZ basemap definition
Returns:
folium.TileLayer: Formatted basemap layer
"""
def xyz_to_plotly(xyz):
"""
Convert XYZ basemap definition to plotly format.
Args:
xyz (dict): XYZ basemap definition
Returns:
dict: Plotly basemap configuration
"""
def xyz_to_bokeh(xyz):
"""
Convert XYZ basemap definition to bokeh format.
Args:
xyz (dict): XYZ basemap definition
Returns:
bokeh.models.WMTSTileSource: Bokeh tile source
"""
def xyz_to_pydeck(xyz):
"""
Convert XYZ basemap definition to pydeck format.
Args:
xyz (dict): XYZ basemap definition
Returns:
dict: Pydeck basemap configuration
"""Search and access basemaps from QuickMapServices (QMS) repository with thousands of additional providers.
def search_qms(keyword):
"""
Search QuickMapServices for basemaps matching keyword.
Args:
keyword (str): Search term for basemap names/descriptions
Returns:
list: List of matching QMS basemap definitions
"""
def get_qms(qms_id):
"""
Get specific QuickMapServices basemap by ID.
Args:
qms_id (int): QMS basemap ID
Returns:
dict: QMS basemap definition with tile URL and metadata
"""
def qms_to_leaflet(qms_id):
"""
Convert QMS basemap to ipyleaflet format.
Args:
qms_id (int): QMS basemap ID
Returns:
ipyleaflet.TileLayer: Leaflet basemap layer
"""
def qms_to_folium(qms_id):
"""
Convert QMS basemap to folium format.
Args:
qms_id (int): QMS basemap ID
Returns:
folium.TileLayer: Folium basemap layer
"""Add and manage basemaps directly on map instances with automatic styling and layer control integration.
def add_basemap(self, basemap='OpenStreetMap', show=True, **kwargs):
"""
Add basemap to the map.
Args:
basemap (str or dict): Basemap name or custom definition
show (bool): Whether to show the basemap immediately
**kwargs: Basemap options (opacity, attribution, etc.)
"""
def change_basemap(self, basemap):
"""
Change the current basemap.
Args:
basemap (str): New basemap name
"""
def add_xyz_service(self, provider, **kwargs):
"""
Add XYZ tile service as basemap.
Args:
provider (str): XYZ provider name or URL template
**kwargs: Service options (attribution, max_zoom, etc.)
"""
def add_wms_layer(self, url, layers, **kwargs):
"""
Add WMS service as basemap layer.
Args:
url (str): WMS service URL
layers (str): Comma-separated layer names
**kwargs: WMS options (format, transparent, version, etc.)
"""The package includes access to 100+ basemap providers through built-in XYZ_TILES and integration with xyzservices:
XYZ_TILES: dict # Dictionary of 100+ basemap provider definitions
# Core XYZ tile providers dictionary structure:
XYZ_TILES = {
'OpenStreetMap': {...},
'ROADMAP': {...}, # Google Roads
'SATELLITE': {...}, # Google Satellite
'TERRAIN': {...}, # Google Terrain
'HYBRID': {...}, # Google Hybrid
'Esri WorldImagery': {...},
'CartoDB positron': {...},
'CartoDB dark_matter': {...},
'OpenTopoMap': {...},
'Stamen Terrain': {...},
'Stamen Toner': {...},
'Stamen Watercolor': {...},
# ... 80+ additional providers
}
# WMS service definitions
WMS_TILES: dict # Dictionary of WMS service providers
# basemaps object with accessor methods
basemaps = Box(XYZ_TILES) # Box object providing dot notation access
# Key basemap categories:
# - OpenStreetMap variants
# - Satellite imagery (Google, Esri, etc.)
# - Topographic maps
# - Terrain and elevation
# - Specialized themes (dark, light, etc.)
# - Historical and vintage maps'OpenStreetMap': Standard OSM'OpenTopoMap': Topographic styling'Stamen Terrain': Terrain visualization'Stamen Toner': High contrast black and white'Stamen Watercolor': Artistic watercolor style'SATELLITE': Google Satellite'ROADMAP': Google Roads'TERRAIN': Google Terrain'HYBRID': Google Hybrid'Esri WorldImagery': Esri satellite imagery'Esri NatGeoWorldMap': National Geographic styling'CartoDB positron': Light theme'CartoDB dark_matter': Dark theme'OpenRailwayMap': Railway infrastructure'OpenFireMap': Fire station and hydrant dataAccess to Web Map Services for specialized data layers:
WMS_TILES: dict # WMS service definitions
# Available WMS services include:
# - National weather services
# - Geological surveys
# - Land cover datasets
# - Administrative boundariesimport leafmap
# Create map with specific basemap
m = leafmap.Map(center=[40, -100], zoom=4, basemap='OpenTopoMap')
# Add additional basemap
m.add_basemap('SATELLITE', show=False)
# Add layer control to toggle basemaps
m.add_layer_control()
mimport leafmap
# Define custom XYZ basemap
custom_basemap = {
'url': 'https://your-tile-server.com/{z}/{x}/{y}.png',
'attribution': 'Your Attribution',
'name': 'Custom Basemap',
'max_zoom': 18
}
# Create map and add custom basemap
m = leafmap.Map()
m.add_xyz_service(custom_basemap)
mimport leafmap
# Search for specific basemap type
results = leafmap.search_qms('satellite')
print(f"Found {len(results)} satellite basemaps")
# Use specific QMS basemap
m = leafmap.Map()
if results:
qms_layer = leafmap.qms_to_leaflet(results[0]['id'])
m.add_layer(qms_layer)
m# Get basemap dictionary
xyz_dict = leafmap.get_xyz_dict()
# Convert for different backends
import leafmap.foliumap as folium_map
import leafmap.plotlymap as plotly_map
# Folium backend
folium_basemap = leafmap.xyz_to_folium(xyz_dict['OpenStreetMap'])
# Plotly backend
plotly_basemap = leafmap.xyz_to_plotly(xyz_dict['OpenStreetMap'])import leafmap
# Add WMS weather layer
m = leafmap.Map()
m.add_wms_layer(
url='https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi',
layers='nexrad-n0r-900913',
name='Weather Radar',
format='image/png',
transparent=True,
opacity=0.6
)
mbasemap_options = {
'opacity': 1.0, # Layer opacity (0-1)
'attribution': 'Custom', # Attribution text
'max_zoom': 18, # Maximum zoom level
'min_zoom': 0, # Minimum zoom level
'tms': False, # TMS tile ordering
'show': True # Initially visible
}advanced_options = {
'subdomains': ['a', 'b', 'c'], # Tile server subdomains
'format': 'png', # Tile format
'tile_size': 256, # Tile size in pixels
'zoomOffset': 0, # Zoom level offset
'detectRetina': True, # High DPI display support
'crossOrigin': False # CORS settings
}wms_options = {
'layers': 'layer_name', # WMS layer names
'styles': '', # WMS styles
'format': 'image/png', # Image format
'transparent': True, # Background transparency
'version': '1.1.1', # WMS version
'crs': 'EPSG:3857', # Coordinate reference system
'uppercase': False # Parameter case sensitivity
}All basemap providers have specific attribution requirements. Leafmap automatically includes proper attribution for built-in providers:
Different providers have varying usage policies:
Install with Tessl CLI
npx tessl i tessl/pypi-leafmapdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10