File size: 2,910 Bytes
adce761
c8a522d
 
b73c3d8
c8a522d
adce761
c8a522d
 
adce761
c8a522d
 
 
 
 
 
 
 
 
 
 
 
 
adce761
c8a522d
 
 
 
 
 
 
 
 
 
 
 
 
adce761
c8a522d
 
 
 
 
adce761
c8a522d
 
 
adce761
c8a522d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b0e8dc8
c8a522d
 
 
 
 
 
 
 
 
 
 
 
 
 
adce761
f231198
c8a522d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import streamlit as st
import altair as alt
from vega_datasets import data
import pandas as pd
import pydeck as pdk

# Define the data source for the map
iceland_geojson = "https://raw.githubusercontent.com/deldersveld/topojson/master/countries/iceland/iceland-counties.json"

# Define the mythological cities with their respective latitude and longitude
cities = {
    "Asgard": [64.7938, -17.3413],
    "Helheim": [63.8278, -21.1865],
    "Jotunheim": [64.8441, -19.1669],
    "Midgard": [63.9863, -22.6210],
    "Muspellheim": [65.3201, -16.4235],
    "Nidavellir": [64.9011, -18.0580],
    "Svartalfheim": [64.0114, -21.4504],
    "Valhalla": [63.7267, -19.6133],
    "Vanaheim": [64.7381, -17.4497],
    "Yggdrasil": [64.8999, -19.0044]
}

# Define the colors to use for each city marker
colors = {
    "Asgard": [255, 0, 0],
    "Helheim": [255, 255, 0],
    "Jotunheim": [0, 0, 255],
    "Midgard": [0, 255, 0],
    "Muspellheim": [255, 153, 0],
    "Nidavellir": [153, 0, 255],
    "Svartalfheim": [0, 255, 255],
    "Valhalla": [255, 0, 255],
    "Vanaheim": [153, 255, 0],
    "Yggdrasil": [255, 255, 255]
}

# Define the Streamlit app layout
st.set_page_config(layout="wide")
st.title("Mythological Cities in Iceland")
st.sidebar.title("Select a City to View the Northern Lights From")
selected_city = st.sidebar.selectbox("", sorted(cities.keys()))

# Load the Icelandic county boundaries and prepare the data for the 3D map
iceland_data = alt.topo_feature(iceland_geojson, "iceland-counties")
iceland_df = pd.DataFrame(iceland_data["features"])

# Create the 3D map with Deck.gl and Altair
view_state = pdk.ViewState(latitude=64.9, longitude=-18.5, zoom=5, pitch=40)
layers = [
    pdk.Layer(
        "PolygonLayer",
        data=iceland_data,
        get_polygon="coordinates",
        filled=True,
        extruded=True,
        get_elevation="properties.avg_elevation",
        elevation_scale=1000,
        get_fill_color=[200, 200, 200, 200]
    ),
    pdk.Layer(
        "ScatterplotLayer",
        data=pd.DataFrame({"latitude": [cities[selected_city][0]], "longitude": [cities[selected_city][1]]}),
        get_position="[longitude, latitude]",
        get_color=colors[selected_city],
        get_radius=20000
    )
]

r = pdk.Deck(layers=layers, initial_view_state=view_state)
altair_chart = alt.Chart(iceland_df).mark_geoshape(
stroke="black",
strokeWidth=0.5
    ).encode(
        color=alt.Color("properties.avg_elevation:Q", scale=alt.Scale(scheme="viridis")),
        tooltip=[alt.Tooltip("properties.name", title="County"), alt.Tooltip("properties.avg_elevation:Q", title="Elevation (m)")]
    ).transform_lookup(
    lookup="id",
    from_=alt.LookupData(iceland_data, "id", ["properties.avg_elevation", "properties.name"])
    ).properties(
    width=900,
    height=600
).interactive()

# Display the 3D map and the Altair chart
st.pydeck_chart(r)
st.altair_chart(altair_chart)