Added plz map

This commit is contained in:
2022-08-28 19:42:57 +02:00
parent 98523f60c7
commit ad245ee780
4 changed files with 59 additions and 0 deletions

5
map/README.md Normal file
View File

@@ -0,0 +1,5 @@
# PLZ Karte Deutschland
_tbd_
[Link](https://checksch.de/pa-pyscript/map/map.html)

1
map/data.json Normal file

File diff suppressed because one or more lines are too long

21
map/map.html Normal file
View File

@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/x-icon" href="../assets/favicon.png" />
<link rel="stylesheet" href="../assets/pyscript.css" />
<script defer src="../assets/pyscript.js"></script>
<title>PLZ Karte Deutschland</title>
<!-- prettier-ignore -->
<py-env>
- folium
- pandas
</py-env>
</head>
<body>
<div id="folium" style="width: 100%; height: 100%"></div>
<py-script output="folium" src="script.py"></py-script>
</body>
</html>

32
map/script.py Normal file
View File

@@ -0,0 +1,32 @@
import pandas as pd
import folium
import json
import random
from pyodide.http import open_url
data = "./data.json"
geo_json = json.loads(open_url(data).read())
m = folium.Map(location=[50.4, 9.6], zoom_start=6)
def style(x):
match (x["properties"]["plz"]):
case "0": return {"color": "yellow"}
case "1": return {"color": "orange"}
case "2": return {"color": "tomato"}
case "3": return {"color": "violet"}
case "4": return {"color": "dodgerblue"}
case "5": return {"color": "blue"}
case "6": return {"color": "gold"}
case "7": return {"color": "green"}
case "8": return {"color": "mediumseagreen"}
case "9": return {"color": "slateblue"}
return {"color": "black"}
folium.GeoJson(geo_json, name="Postleitzahl", style_function=lambda x: style(x)).add_to(
m
)
m