Documentation
¶
Overview ¶
Package chargers serves the chargers.pmtiles archive from the rivolt API: the entire ~10 MB file is fetched once at startup (or first request), parsed in-memory, and queries against it run fully server-side. This replaces the SPA's per-tile fan-out over the same archive — for long corridors that was ~hundreds of HTTPS range requests per planner re-render, saturating the browser's per-origin socket pool and feeling sluggish even after the upstream tile server moved to tmpfs.
Wire path: tiles nginx pod serves /chargers.pmtiles → rivolt fetches it once via the in-cluster Service → keeps a *[]byte in memory → answers /api/maps/chargers-along with a flat JSON list.
Index ¶
- type Archive
- func (a *Archive) LoadedAt() time.Time
- func (a *Archive) Nearest(lat, lon, maxM float64, filter Filter) (POI, bool, error)
- func (a *Archive) QueryCorridor(path [][2]float64, filter Filter, opts QueryCorridorOptions) ([]POI, error)
- func (a *Archive) Reload(ctx context.Context) error
- func (a *Archive) Within(lat, lon, maxM float64, filter Filter) ([]NearPOI, error)
- type Filter
- type NearPOI
- type POI
- type QueryCorridorOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Archive ¶
type Archive struct {
// contains filtered or unexported fields
}
Archive holds the entire chargers PMTiles file in memory plus a decoded root directory. Leaf directories are decoded lazily and cached in leafDirs. Safe for concurrent readers; the only writer is Reload.
func New ¶
New returns an empty archive; the caller drives Reload to populate it (so startup wiring can defer the fetch until the URL is known).
func (*Archive) LoadedAt ¶
LoadedAt returns the timestamp of the last successful Reload, or the zero Time if the archive has not yet been loaded.
func (*Archive) Nearest ¶ added in v0.32.0
Nearest returns the closest charger passing filter within maxM meters of (lat, lon). Used to attribute a recorded charging session to the station (and network) it happened at. Searches the point's tile and its eight neighbours, so maxM must stay well under a z14 tile (~2.4 km at the equator). Concurrent-safe.
func (*Archive) QueryCorridor ¶
func (a *Archive) QueryCorridor(path [][2]float64, filter Filter, opts QueryCorridorOptions) ([]POI, error)
QueryCorridor returns all chargers passing `filter` within `corridorKm` of any non-endpoint point on `path`. Concurrent-safe.
func (*Archive) Reload ¶
Reload fetches the .pmtiles file from a.url, parses the header and root directory, and atomically swaps the live state. Existing in-flight queries continue to read the previous bytes via their captured RLock; the next query sees the new state.
func (*Archive) Within ¶ added in v0.33.0
Within returns every charger passing filter within maxM meters of (lat, lon), nearest first: the whole site, so a caller can tell a co-located one (a Supercharger beside RAN) from a single network. Same tile search and maxM limit as Nearest. Concurrent-safe.
type POI ¶
type POI struct {
Lat float64 `json:"lat"`
Lon float64 `json:"lon"`
Name string `json:"name,omitempty"`
IsDCFC bool `json:"isDCFC"`
IsL2 bool `json:"isL2"`
MaxPowerKW float64 `json:"maxPowerKW,omitempty"`
FacilityType string `json:"facilityType,omitempty"`
EVNetwork string `json:"evNetwork,omitempty"`
EVPricing string `json:"evPricing,omitempty"`
EntityID string `json:"entityID,omitempty"`
DCFCCount int `json:"dcfcCount,omitempty"`
L2Count int `json:"l2Count,omitempty"`
SocketTesla bool `json:"socketTeslaSupercharger,omitempty"`
SocketCCS1 bool `json:"socketType1Combo,omitempty"`
SocketChademo bool `json:"socketChademo,omitempty"`
}
POI is one charging-station feature as the SPA expects it. Fields mirror the SPA's POI type in web/src/lib/poi.ts so the renderer code is unchanged. Names are camelCase on the JSON wire to match the existing TS type.
type QueryCorridorOptions ¶
type QueryCorridorOptions struct {
CorridorKm float64
EndpointTrimMeter float64
MinPowerKW float64
// If true, includes destinations that project onto the route's
// endpoint segment. Off by default (matches SPA behaviour).
IncludeEndpoints bool
}
QueryCorridorOptions tunes the corridor scan; zero values pick the SPA defaults.