Sverigekartan
Live: https://karta.gunnar.rs/
A one-page Streamlit demo of the korp-map server's Sweden map: the facett-map viewer (2D map or 3D city), address search and nearest-address lookup through korp-map-client.
python -m venv venv && venv/bin/pip install -r requirements.txt
SVERIGEKARTAN_MAP_SERVER=https://karta.gunnar.rs venv/bin/streamlit run app.py
| env | default | used by |
SVERIGEKARTAN_MAP_SERVER |
unset: the page's own https origin | the browser: the map viewer fetches every viewport from it. Unset, the page opened as https://<name>/ with <name> in SVERIGEKARTAN_PUBLIC_HOSTS fetches from https://<name> (the front routes /v1 to the map server); any other host gets the first public name (origin.py) |
SVERIGEKARTAN_PUBLIC_HOSTS |
karta.gunnar.rs,sverigekartan.gunnar.rs,83-190-65-118.sslip.io |
the public names the page answers under |
SVERIGEKARTAN_MAP_SERVER_INTERNAL |
http://127.0.0.1:8765 |
Python on the app host: address search, nearest address, data_version; its contract (/openapi.json: 1.2 or 3.0) picks the examples (lod or res) |
SVERIGEKARTAN_ADDRESS_FALLBACK |
unset | Python: where address search and nearest address go while the map server's cut has no address index (korp-map-116); unset, nowhere else |
SVERIGEKARTAN_ADDRESS_FALLBACK_PUBLIC |
https://karta.gunnar.rs |
the fallback's public name, used by the address examples while the fallback is in use |
| SVERIGEKARTAN_FILES_INDEX | $SVERIGEKARTAN_MAP_SERVER_INTERNAL/v1/files/sweden/ | Python: the file index the Data section lists; its links point at $SVERIGEKARTAN_MAP_SERVER/v1/files/sweden/ |
The Data section lists the Sweden Parquet files from the server's file index (a JSON list of {name, format, size, sha256, url}; format "geoparquet-2.0" or "geoparquet-1.1-native" picks the set; a v3 server lists v3/<layer>.parquet as "korp-map-v3.0"), GeoParquet 2.0 points/lines/areas and the native files the map draws (or the v3 layers), with sizes and download links, and three copy-paste snippets (DuckDB, korp-map-client, GeoPandas) that query areas in central Stockholm in place. Until the server answers its file index, the section says the files are coming soon. data_files.py reads the index (JSON or an HTML listing).
sverigekartan.service is an example systemd user unit (Streamlit on 0.0.0.0:8501). The 2D view opens on all of Sweden; the 3D city opens on Stockholm the first time (from a country-wide view). The map (facett-map 0.3.2) reports its view and clicks: switching 2D <-> 3D opens the other mode where the first one was, and a click on the map shows the nearest address under it.
Tests (AppTest, against the live server named by SVERIGEKARTAN_MAP_SERVER_INTERNAL):
venv/bin/pip install pytest && venv/bin/python -m pytest test_app.py
Against a v3 server (korp-map-client >= 0.3), addresses from a v1.2 server meanwhile:
SVERIGEKARTAN_MAP_SERVER_INTERNAL=http://127.0.0.1:8769 \
SVERIGEKARTAN_ADDRESS_FALLBACK=http://127.0.0.1:8765 venv/bin/python -m pytest test_app.py
WebGPU, https and the front
The map draws with WebGPU, which browsers expose only in a secure context: a page served over https://, or from localhost. Opened as plain http://<ip>:8501 the page works but the map frame shows facett's refusal ("not a secure context").
So the public deployment is one https origin per public name, https://karta.gunnar.rs/ (aliases https://sverigekartan.gunnar.rs/ and https://83-190-65-118.sslip.io/), each with its own certificate, served by rpxy (pure-Rust reverse proxy, rustls, Let's Encrypt via TLS-ALPN-01):
router TCP 443 -> <host>:443 -> 127.0.0.1:8443 (rpxy)
/v1, /openapi.json -> korp-map-server http://127.0.0.1:8765
everything else -> Streamlit http://127.0.0.1:8501 (WebSocket /_stcore/stream)
The page and the map data share the origin, so the browser needs no CORS and sees no mixed content. Files: rpxy.toml (config; start with the staging dir_url, switch to production once a staging cert is served; the certificate cache lives in registry_path, so restarts do not re-issue) and rpxy.service (example user unit).
rpxy 0.14.1 is built from its git tag (it is not on crates.io; needs rustc 1.100) with --no-default-features --features rustls-backend,acme; no OpenSSL, but its rustls provider is aws-lc-rs, which no feature turns off. rpxy-empty-contact.patch makes it send no ACME contact address when email = "". rpxy-coop-coep.patch adds the route option cross_origin_isolated: every response of that app then carries Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp (cross-origin isolation, needed for wasm threads). Streamlit and the facett-map viewer work under both headers.
git clone https://github.com/junkurihara/rust-rpxy && cd rust-rpxy && git checkout 0.14.1
git submodule update --init --recursive && git apply .../rpxy-empty-contact.patch
git apply .../rpxy-coop-coep.patch
cargo +1.100.0 update -p url --precise 2.5.9 # the tag's lock has url 2.5.8 (RUSTSEC-2026-0592)
cargo +1.100.0 install --locked --path rpxy-bin --no-default-features --features rustls-backend,acme
Streamlit's WebSocket origin check compares Origin with Host: keep keep_original_host on the Streamlit route and serve the public origin on port 443.
Map data © OpenStreetMap contributors, ODbL.