feat: Implement synthetic edges city↔airport (Task 10)

- Add TransferTime constants (AirportToCity, CityToStation, StationToStation)
- Update Edge struct with Synthetic field
- Enhance addSyntheticEdgesForNode to use constants and mark synthetic edges
- Update BuildGraphFromStations to set Synthetic field
- Mark synthetic edges in GeoJSON output as dashed lines
- Write TestSyntheticAirportCityEdges and TestRouteWithSyntheticAirportCityEdges tests
This commit is contained in:
2026-08-16 16:05:50 +03:00
parent d93445ad55
commit 06730fe05c
4 changed files with 218 additions and 13 deletions

View File

@@ -40,7 +40,9 @@ type routeSearchResponse struct {
// routeGeoJSONResponse represents the response for route GeoJSON.
type routeGeoJSONResponse struct {
Type string `json:"type"`
Type string `json:"type"`
Features []map[string]interface{} `json:"features"`
SyntheticEdgeStyle map[string]string `json:"synthetic_edge_style,omitempty"`
}
// CityAutocomplete handles GET /v1/cities?query=.
@@ -100,9 +102,69 @@ func RouteGeoJSON(hc *HandlerContext, w http.ResponseWriter, r *http.Request) {
http.Error(w, "invalid route ID", http.StatusBadRequest)
return
}
// In a full implementation, would convert route to GeoJSON
// For now, return a simple JSON response
resp := routeGeoJSONResponse{Type: "FeatureCollection"}
// Generate GeoJSON from the graph's edges, distinguishing synthetic vs real
// Synthetic edges (e.g., city↔airport transfers) are marked with dashed lines
// Real edges (actual scheduled trips) are solid lines
features := make([]map[string]interface{}, 0)
for _, edge := range hc.Router.Edges() {
// Determine line style based on edge type
strokeColor := "#1976d2" // default blue for train
strokeDasharray := "" // solid for real edges
if edge.Synthetic {
strokeDasharray = "5, 5" // dashed line for synthetic edges
}
// Color by transport type
switch edge.TransportType {
case routing.TransportTypePlane:
strokeColor = "#ff9800" // orange for plane
case routing.TransportTypeBus:
strokeColor = "#cddc39" // lime for bus
case routing.TransportTypeTrain:
strokeColor = "#1976d2" // blue for train (default)
}
// Create LineString geometry
// Use edge endpoints as coordinate placeholders
fromCoord := []float64{0, 0} // placeholder
toCoord := []float64{0, 0} // placeholder
// In a full implementation, would use actual node coordinates from PostGIS
// For now, use fixed placeholder coordinates
geoJsonLine := map[string]interface{}{
"type": "LineString",
"coordinates": []interface{}{
fromCoord, toCoord,
},
"properties": map[string]interface{}{
"transport": edge.Transport,
"transport_type": string(edge.TransportType),
"kind": "real",
"synthetic": edge.Synthetic,
"duration": edge.Duration,
"cost": edge.Cost,
"is_transfer": edge.IsTransfer,
"stroke_color": strokeColor,
"stroke_width": 2,
"stroke_dasharray": strokeDasharray,
},
}
features = append(features, map[string]interface{}{
"type": "Feature",
"geometry": geoJsonLine,
"properties": map[string]interface{}{},
})
}
resp := routeGeoJSONResponse{
Type: "FeatureCollection",
Features: features,
SyntheticEdgeStyle: map[string]string{"stroke_dasharray": "5, 5", "stroke_color": "#ff9800"},
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(resp)
}