App 2.39.1, server 2.8.0: map roads from OpenFreeMap, on demand
The public Overpass answered 429/502 and needs ~40 s a tile while the car gives up after 8 s, so the server cancelled its queries and the car's retries added load. Now the server fetches only the tiles a car asks for, as OpenStreetMap vector tiles from OpenFreeMap (MAP_TILES_URL), decodes the transportation layer with a small reader of its own, and keeps each tile 30 days on a volume (MAP_CACHE_DIR). A fetch finishes even after the car has stopped waiting; the car hears 503 with Retry-After and gets the tile on its next try. App: OpenFreeMap/OpenMapTiles attribution on the map, retry after 15 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
This commit is contained in:
+19
-11
@@ -34,7 +34,8 @@ type config struct {
|
||||
forgeURL string
|
||||
forgeRepo string
|
||||
forgeToken string
|
||||
overpassURL string
|
||||
mapTilesURL string
|
||||
mapCacheDir string
|
||||
}
|
||||
|
||||
// loadConfig reads the environment and fails closed: a missing InfluxDB setting or a
|
||||
@@ -52,7 +53,8 @@ func loadConfig(getenv func(string) string) (config, error) {
|
||||
forgeURL: getenv("FORGE_URL"),
|
||||
forgeRepo: getenv("FORGE_REPO"),
|
||||
forgeToken: getenv("FORGE_TOKEN"),
|
||||
overpassURL: getenv("OVERPASS_URL"),
|
||||
mapTilesURL: getenv("MAP_TILES_URL"),
|
||||
mapCacheDir: getenv("MAP_CACHE_DIR"),
|
||||
}
|
||||
if c.listenAddr == "" {
|
||||
c.listenAddr = ":8080"
|
||||
@@ -75,16 +77,16 @@ func loadConfig(getenv func(string) string) (config, error) {
|
||||
if c.forgeURL != "" && !strings.HasPrefix(c.forgeURL, "https://") {
|
||||
return config{}, errors.New("FORGE_URL must be an https URL")
|
||||
}
|
||||
// The map's roads come from an Overpass API: the public one unless another is named, none
|
||||
// with "off". Only https, like the forge.
|
||||
switch c.overpassURL {
|
||||
// The map's roads come from vector tiles named by a TileJSON: OpenFreeMap unless another is
|
||||
// named, none with "off". Only https, like the forge.
|
||||
switch c.mapTilesURL {
|
||||
case "":
|
||||
c.overpassURL = DefaultOverpassURL
|
||||
c.mapTilesURL = DefaultMapTilesURL
|
||||
case "off":
|
||||
c.overpassURL = ""
|
||||
c.mapTilesURL = ""
|
||||
default:
|
||||
if !strings.HasPrefix(c.overpassURL, "https://") {
|
||||
return config{}, errors.New("OVERPASS_URL must be an https URL or \"off\"")
|
||||
if !strings.HasPrefix(c.mapTilesURL, "https://") {
|
||||
return config{}, errors.New("MAP_TILES_URL must be an https URL or \"off\"")
|
||||
}
|
||||
}
|
||||
if c.approvalPass != "" && len(c.approvalPass) < minApprovalPasswordLength {
|
||||
@@ -116,8 +118,14 @@ func main() {
|
||||
releases := &Releases{ForgeURL: cfg.forgeURL, Repo: cfg.forgeRepo, Token: cfg.forgeToken}
|
||||
api := &API{Store: store, IngestToken: cfg.ingestToken, Pairing: pairing, Handoff: NewHandoff(),
|
||||
Releases: releases, PublicURL: cfg.publicURL}
|
||||
if cfg.overpassURL != "" {
|
||||
api.Maps = NewMaps(cfg.overpassURL, mapUserAgent)
|
||||
if cfg.mapTilesURL != "" {
|
||||
if cfg.mapCacheDir != "" {
|
||||
if err := os.MkdirAll(cfg.mapCacheDir, 0o700); err != nil {
|
||||
slog.Error("map cache directory not usable", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
api.Maps = NewMaps(cfg.mapTilesURL, cfg.mapCacheDir, mapUserAgent)
|
||||
}
|
||||
|
||||
srv := &http.Server{
|
||||
|
||||
Reference in New Issue
Block a user