opengeos / leafmap

A Python package for interactive mapping and geospatial analysis with minimal coding in a Jupyter environment
https://leafmap.org
MIT License
3.22k stars 387 forks source link

Add a GeoPandas GeoDataFrame to the map with MapLibre #791

Closed AuHoh closed 4 months ago

AuHoh commented 4 months ago

Environment Information

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
giswqs commented 4 months ago

Make sure you update it to the latest version.

pip install -U "leafmap[maplibre]"
giswqs commented 4 months ago

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

AuHoh commented 4 months ago

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

giswqs commented 4 months ago

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]"
AuHoh commented 4 months ago

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