diff --git a/maps/generate_offline.go b/maps/generate_offline.go index 19d37a3..d2c29c1 100644 --- a/maps/generate_offline.go +++ b/maps/generate_offline.go @@ -7,6 +7,7 @@ import ( "math" "os" "runtime" + "slices" "strconv" "strings" @@ -160,7 +161,6 @@ func GenerateOffline(s OfflineSettings) { MaxSpeedBackward: ParseMaxSpeed(tags["maxspeed:backward"]), MaxSpeedAdvisory: ParseMaxSpeed(tags["maxspeed:advisory"]), Lanes: uint8(lanes), - OneWay: tags["oneway"] == "yes", Id: int64(way.ID), HighwayClass: HighwayClassFromTag(tags["highway"]), @@ -190,6 +190,17 @@ func GenerateOffline(s OfflineSettings) { tmpWay.Nodes[i].Latitude = n.Lat tmpWay.Nodes[i].Longitude = n.Lon } + switch tags["oneway"] { + case "yes", "1": + tmpWay.OneWay = true + case "-1": + tmpWay.OneWay = true + slices.Reverse(tmpWay.Nodes) + tmpWay.MaxSpeedForward, tmpWay.MaxSpeedBackward = tmpWay.MaxSpeedBackward, tmpWay.MaxSpeedForward + tmpWay.MaxSpeedForwardConditional, tmpWay.MaxSpeedBackwardConditional = tmpWay.MaxSpeedBackwardConditional, tmpWay.MaxSpeedForwardConditional + case "": + tmpWay.OneWay = tags["junction"] == "roundabout" || tags["highway"] == "motorway" + } tmpWay.Box.MinPos = m.NewPosition(minLat, minLon) tmpWay.Box.MaxPos = m.NewPosition(maxLat, maxLon) if minLat < allMinLat { diff --git a/maps/way.go b/maps/way.go index d920c99..3c923b6 100644 --- a/maps/way.go +++ b/maps/way.go @@ -150,7 +150,11 @@ func (w *Way) IsForwardFrom(matchNode m.Position) bool { } lastNode := w.Nodes.At(w.Nodes.Len()-1) - return !lastNode.Equals(matchNode) + if lastNode.Equals(matchNode) { + // A closed one-way can be entered at its repeated endpoint in stored order. + return w.OneWay() && matchNode.Equals(w.Nodes.At(0)) + } + return true } func IsForward(lineStart m.Position, lineEnd m.Position, bearing float64) bool {