opengeos/leafmap

Add a GeoPandas GeoDataFrame to the map with MapLibre

AuHoh opened this issue · 5 comments

Environment Information

  • leafmap version:0.34.1
  • Python version:3.10.14
  • Operating System:macOS-14.3

Description

I was trying to add a GeoDataFrame following this tutorial https://leafmap.org/maplibre/geopandas/ when a strange error appeared: telling me that the add_gdf command doesn't exist

What I Did

import os
import geopandas as gpd
import leafmap.maplibregl as leafmap

MAPTILER_KEY = leafmap.get_api_key("MAPTILER_KEY")
style = f"https://api.maptiler.com/maps/streets/style.json?key={MAPTILER_KEY}"

m = leafmap.Map(center=[-100, 40], zoom=3, style=style)
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
Capture d’écran 2024-06-25 à 16 57 27

Make sure you update it to the latest version.

pip install -U "leafmap[maplibre]"

You are using v0.34.1. The latest version is v0.34.6

I didn't understand, because I started my notebook by this command: pip install "leafmap[maplibre]"

Note the -U in the command. Otherwise, it will not update it to the latest version if you have installed it before.

pip install -U "leafmap[maplibre]"

Thank you Dr Wu, it is now working after an update and a reboot of my environment.