Files
Antoine fb892ea9f2 Translate the whole project to English and fix outdated comments and help
Comments, docstrings, logs, CLI help, map UI, legends, PDF sheet, scripts,
compose files and AGENTS.md are now English. Data keys stay unchanged
(relief_oriente, densite_sol, visualisations/, API JSON keys, link params).
Wrong comments and help defaults found along the way are corrected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 23:16:45 +02:00

53 lines
1.6 KiB
Python

"""XYZ tile map interface (served by mapserve, in both images).
The HTML, CSS and JS live in `web/` (real files, read at import time);
`write_map_assets()` bakes them into the image at build time. The page is a
minimal shell: all state comes from `/api/map/meta`, the layers are standard
`L.tileLayer`s — the browser handles LOD, caching and animation.
"""
import hashlib
from pathlib import Path
ASSETS_DIRNAME = "mapserve_assets"
WEB_DIR = Path(__file__).resolve().parent / "web"
def _read_web(name):
"""Interface file (HTML/CSS/JS), read once at import time."""
return (WEB_DIR / name).read_text(encoding="utf-8")
_MAP_HTML = _read_web("map.html")
_MAP_CSS = _read_web("map.css")
_MAP_JS = _read_web("map.js")
def ui_version():
"""Short hash of CSS+JS: used as the version in asset URLs."""
return hashlib.sha1((_MAP_CSS + _MAP_JS).encode("utf-8")).hexdigest()[:10]
def write_map_assets(assets_dir):
"""Writes app.css / app.js (+ vendored Leaflet) into `assets_dir`."""
import shutil
assets_dir = Path(assets_dir)
assets_dir.mkdir(parents=True, exist_ok=True)
(assets_dir / "app.css").write_text(_MAP_CSS, encoding="utf-8")
(assets_dir / "app.js").write_text(
_MAP_JS.replace("__UI_VERSION__", ui_version()), encoding="utf-8")
src_vendor = Path(__file__).parent / "assets" / "vendor"
dst_vendor = assets_dir / "vendor"
if src_vendor.is_dir():
shutil.rmtree(dst_vendor, ignore_errors=True)
shutil.copytree(src_vendor, dst_vendor)
return assets_dir
def render_html():
"""HTML shell (data loaded from /api/map/meta)."""
return _MAP_HTML.replace("__ASSETS_V__", ui_version())