| import streamlit as st |
| import pydeck as pdk |
|
|
| |
| geojson_data = { |
| "type": "FeatureCollection", |
| "features": [ |
| { |
| "type": "Feature", |
| "geometry": { |
| "type": "Point", |
| "coordinates": [15.8277, -0.2280] |
| }, |
| "properties": { |
| "name": "Republic of Congo" |
| } |
| } |
| ] |
| } |
|
|
| |
| line_geojson_data = { |
| "type": "FeatureCollection", |
| "features": [ |
| { |
| "type": "Feature", |
| "geometry": { |
| "type": "LineString", |
| "coordinates": [ |
| [8.7811, -0.7193], |
| [15.8277, -0.2280] |
| ] |
| } |
| } |
| ] |
| } |
|
|
| |
| polygon_geojson_data = { |
| "type": "FeatureCollection", |
| "features": [ |
| { |
| "type": "Feature", |
| "geometry": { |
| "type": "Polygon", |
| "coordinates": [ |
| [ |
| [16.0315, -0.3797], |
| [16.0315, -0.4515], |
| [15.9199, -0.4515], |
| [15.9199, -0.3797], |
| [16.0315, -0.3797] |
| ] |
| ] |
| }, |
| "properties": { |
| "name": "Population: 200,000" |
| } |
| } |
| ] |
| } |
|
|
|
|
| |
| layer = pdk.Layer( |
| "GeoJsonLayer", |
| data=geojson_data, |
| get_position="geometry.coordinates", |
| get_radius=100000, |
| get_fill_color=[255, 0, 0], |
| pickable=True |
| ) |
|
|
| |
| line_layer = pdk.Layer( |
| "GeoJsonLayer", |
| data=line_geojson_data, |
| get_source_position="geometry.coordinates", |
| get_target_position=lambda feature: feature["geometry"]["coordinates"][-1], |
| get_color=[255, 165, 0], |
| get_width=30000, |
| pickable=True |
| ) |
|
|
| |
| polygon_layer = pdk.Layer( |
| "GeoJsonLayer", |
| data=polygon_geojson_data, |
| get_fill_color=[0, 255, 255, 128], |
| get_line_color=[0, 0, 0], |
| get_line_width=3, |
| get_polygon="geometry.coordinates", |
| get_text="properties.name", |
| get_text_anchor="middle", |
| get_text_offset=[0, 20], |
| get_text_color=[255, 255, 255], |
| pickable=True |
| ) |
|
|
| |
| view_state = pdk.ViewState( |
| latitude=geojson_data['features'][0]['geometry']['coordinates'][1], |
| longitude=geojson_data['features'][0]['geometry']['coordinates'][0], |
| zoom=5 |
| ) |
|
|
| |
| pdk.settings.api_key = "pk.eyJ1IjoiYWFyb253YWNrZXIiLCJhIjoiY2xlOGV2enN3MGV0YzN2bzZjMm96eXhyOSJ9.SqZugs5uIpIBvMM_Hioyvg" |
|
|
| |
| deck = pdk.Deck( |
| layers=[layer], |
| initial_view_state=view_state, |
| map_style="mapbox://styles/mapbox/light-v9" |
| ) |
|
|
| |
| st.pydeck_chart(deck) |