Fix Wereldexport world map loading and tiles.
Self-host Leaflet locally, proxy map tiles through cockpit, set explicit map height, and invalidate size after init.
This commit is contained in:
@@ -6,7 +6,7 @@ from typing import Any, Optional
|
||||
|
||||
import httpx
|
||||
from fastapi import APIRouter, Query, Request
|
||||
from fastapi.responses import RedirectResponse, StreamingResponse
|
||||
from fastapi.responses import RedirectResponse, Response, StreamingResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from pathlib import Path
|
||||
|
||||
@@ -157,6 +157,26 @@ async def api_gov_sources(country: Optional[str] = None):
|
||||
return await _proxy("GET", "/gov-sources", params=params)
|
||||
|
||||
|
||||
|
||||
|
||||
@router.get("/api/map/tiles/{z}/{x}/{y}.png")
|
||||
async def map_tile_proxy(z: int, x: int, y: int) -> Response:
|
||||
"""Proxy Carto dark basemap tiles via cockpit (no client internet needed)."""
|
||||
host = ("a", "b", "c", "d")[(x + y) % 4]
|
||||
url = f"https://{host}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png"
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=20.0, follow_redirects=True) as client:
|
||||
r = await client.get(url)
|
||||
if r.status_code != 200:
|
||||
return Response(status_code=502, content=b"")
|
||||
return Response(
|
||||
content=r.content,
|
||||
media_type="image/png",
|
||||
headers={"Cache-Control": "public, max-age=604800"},
|
||||
)
|
||||
except Exception:
|
||||
return Response(status_code=502, content=b"")
|
||||
|
||||
@router.get("/api/export-intel/map/bundle")
|
||||
async def api_map_bundle(
|
||||
country: Optional[str] = None,
|
||||
|
||||
Reference in New Issue
Block a user