|
| 1 | +import json |
| 2 | + |
| 3 | +import streamlit as st |
| 4 | +from streamlit_folium import st_folium |
| 5 | + |
| 6 | +import folium |
| 7 | + |
| 8 | +st.set_page_config(layout="wide") |
| 9 | + |
| 10 | +geojson = """ |
| 11 | +{"type": "FeatureCollection", |
| 12 | + "features": [ |
| 13 | + {"id": "0", "type": "Feature", "properties": {"foo": 0}, |
| 14 | + "geometry": {"type": "Point", "coordinates": [0.0, 0.0]} |
| 15 | + }, |
| 16 | + {"id": "1", "type": "Feature", "properties": {"foo": 1}, |
| 17 | + "geometry": {"type": "MultiPoint", "coordinates": [[1.0, 1.0]]}}, |
| 18 | + {"id": "2", "type": "Feature", |
| 19 | + "properties": {"foo": 2}, "geometry": {"type": "MultiPoint", "coordinates": |
| 20 | + [[2.0, 2.0]]}}, {"id": "3", "type": "Feature", "properties": {"foo": 3}, |
| 21 | + "geometry": {"type": "MultiPoint", "coordinates": [[3.0, 3.0]]}}, {"id": "4", |
| 22 | + "type": "Feature", "properties": {"foo": 4}, "geometry": {"type": |
| 23 | + "MultiPoint", "coordinates": [[4.0, 4.0]]}}]}""" |
| 24 | + |
| 25 | +geojson = json.loads(geojson) |
| 26 | + |
| 27 | +on_each_feature = folium.JsCode( |
| 28 | + """ |
| 29 | + (feature, layer) => { |
| 30 | + layer.bindPopup("hello world"); |
| 31 | + } |
| 32 | +""" |
| 33 | +) |
| 34 | +m = folium.Map( |
| 35 | + zoom_start=5, |
| 36 | + location=(0, 0), |
| 37 | +) |
| 38 | +folium.GeoJson( |
| 39 | + geojson, on_each_feature=on_each_feature, marker=folium.CircleMarker(radius=20) |
| 40 | +).add_to(m) |
| 41 | + |
| 42 | +st_folium(m, width=700, height=500) |
| 43 | +# st_folium(m, width=700, height=500, returned_objects=[]) |
| 44 | + |
| 45 | +html = m.get_root().render() |
| 46 | +st.code(html) |
0 commit comments