Click on a GeoJson layer feature shown on Python Folium map

孤街醉人 提交于 2020-12-06 05:04:44

问题


I have the following code to display a geojson file on a Folium map in python.

import folium
import json 

with open("roadway.geojson") as f:
    data = json.load(f)

m = folium.Map(location=[39.945559, -86.503854], zoom_start=10)
folium.GeoJson(
    data= data, 
    name="Network", 
    show=False,
    style_function=lambda x: {"weight":2, 'color':'black','fillColor': 'lightblue',},
    highlight_function=lambda x: {'weight':3, 'color':'black'},
    smooth_factor=2.0,
    tooltip=folium.features.GeoJsonTooltip(
        fields=['DLY_TOT_VO'],
        aliases=['Daily Volume:'], 
        labels=True, 
        sticky=True,
        toLocaleString=True
    )
).add_to(m)

m

What I get from this is a map with the geojson overlay that has lines displayed in black and then if I hover over each line, I can see the value read from DLY_TOT_VO in the geojson file as shown below

I am including this map in my application using PyQt5. What I'd like to do is to actually be able to click on a line and save the value of DLY_TOT_VO for that line in a variable. I will then do some further calculations with that value.

Is there a way I can do that? Maybe a click event listener or something like that? Also, roadway.geojson can be downloaded from here

来源:https://stackoverflow.com/questions/64576899/click-on-a-geojson-layer-feature-shown-on-python-folium-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!