Implement popup option in folium.TopoJson layer
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python
- Lĩnh vực
- data-visualization
Hướng nghiên cứu
Start by comparing the folium.TopoJson and folium.GeoJson entry points, focusing on how tooltip and popup options are handled in the examples. Trace how feature properties reach generated map output, then determine what equivalent dynamic popup behavior would require for TopoJson. Done means each polygon can display popup content from its own properties while existing styling and tooltip behavior continue to work.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I am making a map with different colors and popups for each group of polygons.
I did it using folium.GeoJson and it worked. The problem is slow to render.
I tested using folium.TopoJson and the rendering is much better!! However, I can't put a dynamic popup, using the properties of json, as I do like folium.GeoJson.
I have tried iteration (for), adding in a FeatureGroup... also without sucess.
Is there any way to insert a dynamic popup using folium.TopoJson?
If not, I leave the suggestion to include ...
:)
TopoJson renders faster. I would like to make the popup because I am inserting the map in a Django project.
Code using folium.GeoJson. Slow, but works!
import folium
import geopandas as gpd
from folium import plugins
# Read
gdf = gpd.read_file('https://raw.githubusercontent.com/michelmetran/sp_bombeiro/main/data/shps/sp_bombeiros.geojson')
# Dict
color_polygon = {
'1º Grupamento de Bombeiros': '#ffff99',
'5º Grupamento de Bombeiros': '#a6cee3',
'6º Grupamento de Bombeiros': '#1f78b4',
'7º Grupamento de Bombeiros': '#b2df8a',
'8º Grupamento de Bombeiros': '#33a02c',
'9º Grupamento de Bombeiros': '#fb9a99',
'10º Grupamento de Bombeiros': '#a6cee3',
'11º Grupamento de Bombeiros': '#1f78b4',
'12º Grupamento de Bombeiros': '#b2df8a',
'13º Grupamento de Bombeiros': '#33a02c',
'14º Grupamento de Bombeiros': '#fb9a99',
'15º Grupamento de Bombeiros': '#e31a1c',
'16º Grupamento de Bombeiros': '#fdbf6f',
'17º Grupamento de Bombeiros': '#ff7f00',
'18º Grupamento de Bombeiros': '#cab2d6',
'19º Grupamento de Bombeiros': '#6a3d9a',
'20º Grupamento de Bombeiros': '#b15928'
}
# Map
m = folium.Map([-23, -47], zoom_start=6)
# Layer
folium.GeoJson(
gdf,
name='Bombeiros',
smooth_factor=1.0,
#zoom_on_click=True,
embed=False,
style_function=lambda x: {
'fillColor': color_polygon[x['properties']['gb_nome']],
'color': color_polygon[x['properties']['gb_nome']],
'weight': 1,
'fillOpacity': 0.3,
},
highlight_function=lambda x: {'weight': 3},
tooltip=folium.features.GeoJsonTooltip(
fields=['municipio_nome', 'gb_sigla'],
aliases=['Munícipio', 'Grupamento'],
sticky=True,
opacity=0.9,
direction='right',
),
popup=folium.GeoJsonPopup(
['popup'],
parse_html=False,
max_width='300',
show=False,
labels=False,
sticky=True,
)
).add_to(m)
# Plugins
m.fit_bounds(m.get_bounds())
plugins.Fullscreen(
position='topleft',
title='Clique para Maximizar',
title_cancel='Mininizar',
).add_to(m)
m
Code using folium.TopoJson. Faster. Without dinamic popups...
import folium
import requests
# Url Data
url = 'https://raw.githubusercontent.com/michelmetran/sp_bombeiro/main/data/shps/sp_bombeiros.json'
# Map
m = folium.Map([-23, -47], zoom_start=6)
# Dict
color_polygon = {
'1º Grupamento de Bombeiros': '#ffff99',
'5º Grupamento de Bombeiros': '#a6cee3',
'6º Grupamento de Bombeiros': '#1f78b4',
'7º Grupamento de Bombeiros': '#b2df8a',
'8º Grupamento de Bombeiros': '#33a02c',
'9º Grupamento de Bombeiros': '#fb9a99',
'10º Grupamento de Bombeiros': '#a6cee3',
'11º Grupamento de Bombeiros': '#1f78b4',
'12º Grupamento de Bombeiros': '#b2df8a',
'13º Grupamento de Bombeiros': '#33a02c',
'14º Grupamento de Bombeiros': '#fb9a99',
'15º Grupamento de Bombeiros': '#e31a1c',
'16º Grupamento de Bombeiros': '#fdbf6f',
'17º Grupamento de Bombeiros': '#ff7f00',
'18º Grupamento de Bombeiros': '#cab2d6',
'19º Grupamento de Bombeiros': '#6a3d9a',
'20º Grupamento de Bombeiros': '#b15928'
}
# Layer
lyr = folium.TopoJson(
#open(os.path.join('data', 'shps', 'sp_bombeiros.json')), # Local File
requests.get(url).json(),
object_path='objects.data',
name='São Paulo',
style_function=lambda x: {
'fillColor': color_polygon[x['properties']['gb_nome']],
'color': color_polygon[x['properties']['gb_nome']],
'weight': 1,
'fillOpacity': 0.3,
},
tooltip=folium.features.GeoJsonTooltip(
fields=['municipio_nome', 'gb_sigla'],
aliases=['Munícipio', 'Grupamento'],
sticky=True,
opacity=0.9,
direction='right',
),
#popup='test', # Doesnt Work! ERROR!
)
lyr.add_child(
folium.Popup(
#'test', # Doesnt Work, static text...
#['popup'], # Doesnt Work, blank
gdf['popup'][0], # Doesnt Work STATIC INFOS, NOT DYNAMIC!
#lambda x: x['properties']['popup'], # Doesnt Work
#sticky=False,
#localize=True,
#parse_html=False,
max_width=400
)
)
# Add Layer to Map
lyr.add_to(m)
# Apresenta o mapa
m.fit_bounds(m.get_bounds())
plugins.Fullscreen(
position='topleft',
title='Clique para Maximizar',
title_cancel='Mininizar',
).add_to(m)
m
- Ngôn ngữ chính
- Python
- Star
- 7.4k
- Fork
- 2.3k
- Merge trung bình
- 17 giờ 22 phút
- Pull request đã merge (30 ngày)
- 11
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python-visualization/folium
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
python-visualization/folium#2092 · 5 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 67/100
python-visualization/folium#2278 · 1 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
python-visualization/folium#2259 ·
-
Map output from OSM returns blocked tiles, due to defective request or not following referer-policy Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
python-visualization/folium#2236 · 5 bình luận · 1 reaction ·
-
Touch Screen often fails Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
python-visualization/folium#2219 · 2 bình luận ·
Tất cả issue của python-visualization/folium
Issue tương tự
-
essnmx good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
-
[Feature] 奇物选择添加优先级 Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
syfoud/Simulated_Scepter#174 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Giskard-AI/giskard-oss#2840 · 1 bình luận ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Đang mởarea: repo bug perceived difficulty: 2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
yeti-platform/yeti#1380 ·