facett-map 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- facett_map/__init__.py +126 -0
- facett_map/_buildinfo.py +3 -0
- facett_map/assets/bundles.json +22 -0
- facett_map/assets/facet_wrapped_group.js +2861 -0
- facett_map/assets/facet_wrapped_group_bg.wasm +0 -0
- facett_map/assets/index.html +443 -0
- facett_map/assets/manifest.json +20 -0
- facett_map-0.3.0.dist-info/METADATA +53 -0
- facett_map-0.3.0.dist-info/RECORD +13 -0
- facett_map-0.3.0.dist-info/WHEEL +5 -0
- facett_map-0.3.0.dist-info/licenses/LICENSE +21 -0
- facett_map-0.3.0.dist-info/licenses/NOTICE +5 -0
- facett_map-0.3.0.dist-info/top_level.txt +1 -0
facett_map/__init__.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""facett-map — the facett map viewer alone, as a Streamlit component.
|
|
2
|
+
|
|
3
|
+
The 2D map (facett-map) and the 3D city (facett-map3d), compiled from Rust to one
|
|
4
|
+
small wasm bundle and drawn on WebGPU. The wasm fetches the map itself from a korp
|
|
5
|
+
map server (map-wire v1, Arrow IPC over HTTP); Python only names the server, the
|
|
6
|
+
region and the mode, so no geometry passes through Python::
|
|
7
|
+
|
|
8
|
+
pip install facett-map
|
|
9
|
+
|
|
10
|
+
import facett_map
|
|
11
|
+
facett_map.map(server="http://host:8765", region="sweden", mode="3d") # or "2d"
|
|
12
|
+
|
|
13
|
+
The map server must allow the page's origin (CORS). WebGPU needs a secure context in
|
|
14
|
+
every ancestor frame: serve Streamlit on localhost or on https.
|
|
15
|
+
|
|
16
|
+
The loader page and the bundle are facett's own (`facet-wrapped-group --features
|
|
17
|
+
map`); `facett` the full components wheel is not needed and not installed.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import json
|
|
23
|
+
from importlib import metadata as _metadata
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
from typing import Any, Sequence
|
|
26
|
+
|
|
27
|
+
__all__ = ["__version__", "MODES", "assets_dir", "manifest", "build_info", "payload", "map"]
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
__version__ = _metadata.version("facett-map")
|
|
31
|
+
except _metadata.PackageNotFoundError: # pragma: no cover - source checkout only
|
|
32
|
+
__version__ = "0+unknown"
|
|
33
|
+
|
|
34
|
+
_ASSETS = Path(__file__).parent / "assets"
|
|
35
|
+
|
|
36
|
+
#: mode -> the bundle's component name.
|
|
37
|
+
MODES = {"2d": "osm2d", "3d": "osm3d"}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def assets_dir() -> Path:
|
|
41
|
+
"""Directory holding the loader page, the wasm, its JS glue and `manifest.json`."""
|
|
42
|
+
return _ASSETS
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def manifest() -> list[dict[str, Any]]:
|
|
46
|
+
"""The bundle's component manifest (osm2d and osm3d). Empty in a source checkout
|
|
47
|
+
without a built bundle."""
|
|
48
|
+
mf = _ASSETS / "manifest.json"
|
|
49
|
+
return json.loads(mf.read_text()) if mf.exists() else []
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def build_info() -> dict[str, Any]:
|
|
53
|
+
"""Identity of the shipped artifact: version, the commit it was built from, wasm size."""
|
|
54
|
+
try:
|
|
55
|
+
from facett_map._buildinfo import GIT_HASH
|
|
56
|
+
except ImportError: # source checkout: the stamp is written by `cargo ops publish-pip`
|
|
57
|
+
GIT_HASH = "unknown"
|
|
58
|
+
wasm = _ASSETS / "facet_wrapped_group_bg.wasm"
|
|
59
|
+
return {
|
|
60
|
+
"version": __version__,
|
|
61
|
+
"git_hash": GIT_HASH,
|
|
62
|
+
"wasm_present": wasm.exists(),
|
|
63
|
+
"wasm_bytes": wasm.stat().st_size if wasm.exists() else 0,
|
|
64
|
+
"components": [c.get("name") for c in manifest()],
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def payload(
|
|
69
|
+
server: str,
|
|
70
|
+
region: str = "sweden",
|
|
71
|
+
*,
|
|
72
|
+
bbox: Sequence[float] | None = None,
|
|
73
|
+
title: str | None = None,
|
|
74
|
+
max: int | None = None, # noqa: A002 - the wire's own field name
|
|
75
|
+
) -> dict[str, Any]:
|
|
76
|
+
"""The map-server payload the wasm reads: `{"server", "region"}` plus the optional
|
|
77
|
+
`bbox` to open on (`[minlon, minlat, maxlon, maxlat]`), `title` and `max`."""
|
|
78
|
+
if not server or not str(server).strip():
|
|
79
|
+
raise ValueError("facett_map: name the map server, e.g. server='http://host:8765'")
|
|
80
|
+
d: dict[str, Any] = {"server": str(server).rstrip("/"), "region": region}
|
|
81
|
+
if bbox is not None:
|
|
82
|
+
b = [float(x) for x in bbox]
|
|
83
|
+
if len(b) != 4:
|
|
84
|
+
raise ValueError(f"facett_map: bbox is [minlon, minlat, maxlon, maxlat], got {list(bbox)!r}")
|
|
85
|
+
d["bbox"] = b
|
|
86
|
+
if title:
|
|
87
|
+
d["title"] = title
|
|
88
|
+
if max is not None:
|
|
89
|
+
d["max"] = int(max)
|
|
90
|
+
return d
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
_impl: Any = None
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _component() -> Any:
|
|
97
|
+
global _impl
|
|
98
|
+
if _impl is None:
|
|
99
|
+
import streamlit.components.v1 as components
|
|
100
|
+
|
|
101
|
+
_impl = components.declare_component("facett_map", path=str(_ASSETS))
|
|
102
|
+
return _impl
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def map( # noqa: A001 - the package's one verb
|
|
106
|
+
server: str,
|
|
107
|
+
region: str = "sweden",
|
|
108
|
+
mode: str = "3d",
|
|
109
|
+
*,
|
|
110
|
+
bbox: Sequence[float] | None = None,
|
|
111
|
+
title: str | None = None,
|
|
112
|
+
max: int | None = None, # noqa: A002
|
|
113
|
+
height: int = 520,
|
|
114
|
+
key: str | None = None,
|
|
115
|
+
) -> None:
|
|
116
|
+
"""Mount the map in a Streamlit app: `mode="2d"` (pan/zoom/tilt) or `"3d"` (the
|
|
117
|
+
orbit city). The wasm fetches every viewport from `server` itself.
|
|
118
|
+
|
|
119
|
+
The viewer sends no value back to Python, so this returns None.
|
|
120
|
+
"""
|
|
121
|
+
m = str(mode).lower()
|
|
122
|
+
if m not in MODES:
|
|
123
|
+
raise ValueError(f"facett_map: mode is one of {sorted(MODES)}, got {mode!r}")
|
|
124
|
+
data = payload(server, region, bbox=bbox, title=title, max=max)
|
|
125
|
+
_component()(component=MODES[m], data=data, height=height, key=key, dev=False, nav="labels", default=None)
|
|
126
|
+
return None
|
facett_map/_buildinfo.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_": "EMITTED by facett-build-thing (MAP_GROUP) — do not edit; re-run `cargo run -p facett-build-thing -- emit`",
|
|
3
|
+
"default": "map",
|
|
4
|
+
"groups": [
|
|
5
|
+
{
|
|
6
|
+
"dir": "",
|
|
7
|
+
"entries": [
|
|
8
|
+
"osm2d",
|
|
9
|
+
"osm3d"
|
|
10
|
+
],
|
|
11
|
+
"features": [
|
|
12
|
+
"map"
|
|
13
|
+
],
|
|
14
|
+
"js": "facet_wrapped_group.js",
|
|
15
|
+
"manifest": "manifest.json",
|
|
16
|
+
"name": "map",
|
|
17
|
+
"v": "29aae11b243b7f8e",
|
|
18
|
+
"wasm": "facet_wrapped_group_bg.wasm"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"schema": 2
|
|
22
|
+
}
|