Key Features
You can try out leafmap by using the cloud-computing platforms below without having to install anything on your computer:

Install leafmap
| # !pip install leafmap geopandas pycrs osmnx
|
Use ipyleaflet plotting backend
Create an interactive map
| m = leafmap.Map(center=(40, -100), zoom=4)
m
|
Customize map height
| m = leafmap.Map(height="400px", width="800px")
m
|
Set control visibility
| m = leafmap.Map(
draw_control=False,
measure_control=False,
fullscreen_control=False,
attribution_control=True,
)
m
|
Change basemaps
| m = leafmap.Map()
m.add_basemap("OpenTopoMap")
m
|
Add XYZ tile layer
| m = leafmap.Map()
m.add_tile_layer(
url="https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}",
name="Google Satellite",
attribution="Google",
)
m
|
Add WMS tile layer
1
2
3
4
5
6
7
8
9
10
11
12 | m = leafmap.Map(center=[40, -100], zoom=4)
naip_url = "https://www.mrlc.gov/geoserver/mrlc_display/NLCD_2019_Land_Cover_L48/wms?"
m.add_wms_layer(
url=naip_url,
layers="NLCD_2019_Land_Cover_L48",
name="NLCD 2019",
attribution="MRLC",
format="image/png",
shown=True,
)
m.add_legend(title="NLCD Land Cover Type", builtin_legend="NLCD")
m
|
Add COG layer
| m = leafmap.Map()
url = "https://github.com/opengeos/data/releases/download/raster/Libya-2023-07-01.tif"
m.add_cog_layer(url, name="Fire (pre-event)")
m
|
Add STAC layer
| m = leafmap.Map()
url = "https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot5_orthoimages/S5_2007/S5_11055_6057_20070622/S5_11055_6057_20070622.json"
m.add_stac_layer(url, bands=["B3", "B2", "B1"], name="False color")
m
|
Add legend
| m = leafmap.Map()
url = "https://www.mrlc.gov/geoserver/mrlc_display/NLCD_2016_Land_Cover_L48/wms?"
m.add_wms_layer(
url,
layers="NLCD_2016_Land_Cover_L48",
name="NLCD 2016 CONUS Land Cover",
format="image/png",
transparent=True,
)
m.add_legend(builtin_legend="NLCD")
m
|
Add colorbar
| m = leafmap.Map()
m.add_basemap("USGS 3DEP Elevation")
colors = ["006633", "E5FFCC", "662A00", "D8D8D8", "F5F5F5"]
vmin = 0
vmax = 4000
m.add_colorbar(colors=colors, vmin=vmin, vmax=vmax)
m
|
Add GeoJSON
| m = leafmap.Map(center=[0, 0], zoom=2)
in_geojson = (
"https://github.com/opengeos/datasets/releases/download/vector/cables.geojson"
)
m.add_geojson(in_geojson, layer_name="Cable lines")
m
|
| # Add a GeoJSON with random filled color to the map.
m = leafmap.Map(center=[0, 0], zoom=2)
url = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/countries.geojson"
style = {"fillOpacity": 0.5}
m.add_geojson(
url,
layer_name="Countries",
style=style,
fill_colors=["red", "yellow", "green", "orange"],
)
m
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 | # Use custom style and hover_style functions.
m = leafmap.Map(center=[0, 0], zoom=2)
url = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/countries.geojson"
style = {
"stroke": True,
"color": "#0000ff",
"weight": 2,
"opacity": 1,
"fill": True,
"fillColor": "#0000ff",
"fillOpacity": 0.1,
}
hover_style = {"fillOpacity": 0.7}
m.add_geojson(url, layer_name="Countries", style=style, hover_style=hover_style)
m
|
Add shapefile
| m = leafmap.Map(center=[0, 0], zoom=2)
in_shp = "https://github.com/opengeos/leafmap/raw/master/examples/data/countries.zip"
m.add_shp(in_shp, layer_name="Countries")
m
|
Add KML
| try:
import geopandas
except ImportError:
print("Installing geopandas ...")
subprocess.check_call(["python", "-m", "pip", "install", "geopandas"])
|
| m = leafmap.Map()
in_kml = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/us_states.kml"
m.add_kml(in_kml, layer_name="US States KML")
m
|
Add GeoDataFrame
| import geopandas as gpd
m = leafmap.Map()
gdf = gpd.read_file(
"https://github.com/opengeos/datasets/releases/download/vector/cables.geojson"
)
m.add_gdf(gdf, layer_name="Cable lines")
m
|
Create heat map
| m = leafmap.Map()
in_csv = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/world_cities.csv"
m.add_heatmap(
in_csv,
latitude="latitude",
longitude="longitude",
value="pop_max",
name="Heat map",
radius=20,
)
|
| colors = ["blue", "lime", "red"]
vmin = 0
vmax = 10000
m.add_colorbar(colors=colors, vmin=vmin, vmax=vmax)
m.add_title("World Population Heat Map", font_size="20px", align="center")
m
|
Save map to HTML
| m = leafmap.Map()
m.add_basemap("Esri.NatGeoWorldMap")
m
|
Add Planet imagery
| os.environ["PLANET_API_KEY"] = "your-api-key"
|
| m = leafmap.Map()
m.add_planet_by_month(year=2020, month=8)
m.add_planet_by_quarter(year=2019, quarter=2)
m
|