Add a GeoPandas GeoDataFrame to the map
The following notebook demonstrates how to add a GeoPandas GeoDataFrame to the map.
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# %pip install "leafmap[maplibre]"
# %pip install "leafmap[maplibre]"
In [2]:
Copied!
import geopandas as gpd
import leafmap.maplibregl as leafmap
import geopandas as gpd
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=[-100, 40], zoom=3, style="streets")
url = "https://github.com/opengeos/datasets/releases/download/us/us_states.geojson"
gdf = gpd.read_file(url)
paint = {
"fill-color": "#3388ff",
"fill-opacity": 0.8,
"fill-outline-color": "#ffffff",
}
m.add_gdf(gdf, layer_type="fill", name="States", paint=paint)
m
m = leafmap.Map(center=[-100, 40], zoom=3, style="streets")
url = "https://github.com/opengeos/datasets/releases/download/us/us_states.geojson"
gdf = gpd.read_file(url)
paint = {
"fill-color": "#3388ff",
"fill-opacity": 0.8,
"fill-outline-color": "#ffffff",
}
m.add_gdf(gdf, layer_type="fill", name="States", paint=paint)
m
Failed to retrieve the MapTiler style. Defaulting to 'dark-matter' style.