Skip to content

Using hovering callback on GeoJSON features? #397

Answered by giswqs
deeplook asked this question in Q&A
Discussion options

You must be logged in to vote

Would this be acceptable?

import requests
from ipyleaflet import GeoJSON
from leafmap import Map

def handle_geojson_hover(event=None, id=None, properties=None, **kwargs):
    print(properties)

url = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/countries.geojson"
data = requests.get(url).json()
m = Map(center=(0, 0), zoom=2)
gj_layer = GeoJSON(data=data, hover_style={"color": "red", "fillColor": "red"})
gj_layer.on_hover(handle_geojson_hover)
m += gj_layer
m

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@deeplook
Comment options

deeplook Mar 23, 2023
Collaborator Author

Answer selected by deeplook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants