15
15
import static com .graphhopper .routing .util .parsers .AbstractAccessParser .INTENDED ;
16
16
17
17
public abstract class BikeCommonPriorityParser implements TagParser {
18
-
19
18
// Bicycle tracks subject to compulsory use in Germany and Poland (https://wiki.openstreetmap.org/wiki/DE:Key:cycleway)
20
19
private static final List <String > CYCLEWAY_BICYCLE_KEYS = List .of ("cycleway:bicycle" , "cycleway:both:bicycle" , "cycleway:left:bicycle" , "cycleway:right:bicycle" );
21
20
@@ -85,6 +84,7 @@ protected BikeCommonPriorityParser(DecimalEncodedValue priorityEnc, DecimalEncod
85
84
public void handleWayTags (int edgeId , EdgeIntAccess edgeIntAccess , ReaderWay way , IntsRef relationFlags ) {
86
85
String highwayValue = way .getTag ("highway" );
87
86
Integer priorityFromRelation = routeMap .get (bikeRouteEnc .getEnum (false , edgeId , edgeIntAccess ));
87
+ RouteNetwork bikeNetork = this .bikeRouteEnc .getEnum (false , edgeId , edgeIntAccess );
88
88
if (highwayValue == null ) {
89
89
if (FerrySpeedCalculator .isFerry (way )) {
90
90
priorityFromRelation = SLIGHT_AVOID .getValue ();
@@ -94,7 +94,7 @@ public void handleWayTags(int edgeId, EdgeIntAccess edgeIntAccess, ReaderWay way
94
94
}
95
95
96
96
double maxSpeed = Math .max (avgSpeedEnc .getDecimal (false , edgeId , edgeIntAccess ), avgSpeedEnc .getDecimal (true , edgeId , edgeIntAccess ));
97
- priorityEnc .setDecimal (false , edgeId , edgeIntAccess , PriorityCode .getValue (handlePriority (way , maxSpeed , priorityFromRelation )));
97
+ priorityEnc .setDecimal (false , edgeId , edgeIntAccess , PriorityCode .getValue (handlePriority (way , maxSpeed , priorityFromRelation , bikeNetork )));
98
98
}
99
99
100
100
/**
@@ -103,14 +103,14 @@ public void handleWayTags(int edgeId, EdgeIntAccess edgeIntAccess, ReaderWay way
103
103
*
104
104
* @return new priority based on priorityFromRelation and on the tags in ReaderWay.
105
105
*/
106
- int handlePriority (ReaderWay way , double wayTypeSpeed , Integer priorityFromRelation ) {
106
+ int handlePriority (ReaderWay way , double wayTypeSpeed , Integer priorityFromRelation , RouteNetwork bikeNetork ) {
107
107
TreeMap <Double , PriorityCode > weightToPrioMap = new TreeMap <>();
108
108
if (priorityFromRelation == null )
109
109
weightToPrioMap .put (0d , UNCHANGED );
110
110
else
111
111
weightToPrioMap .put (110d , PriorityCode .valueOf (priorityFromRelation ));
112
112
113
- collect (way , wayTypeSpeed , weightToPrioMap );
113
+ collect (way , wayTypeSpeed , weightToPrioMap , bikeNetork );
114
114
115
115
// pick priority with biggest order value
116
116
return weightToPrioMap .lastEntry ().getValue ().getValue ();
@@ -147,8 +147,9 @@ private PriorityCode convertClassValueToPriority(String tagvalue) {
147
147
* @param weightToPrioMap associate a weight with every priority. This sorted map allows
148
148
* subclasses to 'insert' more important priorities as well as overwrite determined priorities.
149
149
*/
150
- void collect (ReaderWay way , double wayTypeSpeed , TreeMap <Double , PriorityCode > weightToPrioMap ) {
150
+ void collect (ReaderWay way , double wayTypeSpeed , TreeMap <Double , PriorityCode > weightToPrioMap , RouteNetwork bikeNetork ) {
151
151
String highway = way .getTag ("highway" );
152
+
152
153
if (isDesignated (way )) {
153
154
boolean isGoodSurface = way .getTag ("tracktype" , "" ).equals ("grade1" ) || goodSurface .contains (way .getTag ("surface" ,"" ));
154
155
if ("path" .equals (highway ) || "track" .equals (highway ) && isGoodSurface )
@@ -174,7 +175,15 @@ void collect(ReaderWay way, double wayTypeSpeed, TreeMap<Double, PriorityCode> w
174
175
} else if (avoidHighwayTags .containsKey (highway )
175
176
|| (maxSpeed != MaxSpeed .MAXSPEED_MISSING && maxSpeed >= avoidSpeedLimit && !"track" .equals (highway ))) {
176
177
PriorityCode priorityCode = avoidHighwayTags .get (highway );
177
- weightToPrioMap .put (50d , priorityCode == null ? AVOID : priorityCode );
178
+
179
+
180
+ if (bikeNetork != RouteNetwork .MISSING ) {
181
+ // If there's a bike network on an avoided highway, give it a better priority than REACH_DESTINATION
182
+ weightToPrioMap .put (50d , AVOID );
183
+ } else {
184
+ weightToPrioMap .put (50d , priorityCode == null ? AVOID : priorityCode );
185
+ }
186
+
178
187
if (way .hasTag ("tunnel" , INTENDED )) {
179
188
PriorityCode worse = priorityCode == null ? BAD : priorityCode .worse ().worse ();
180
189
weightToPrioMap .put (50d , worse == EXCLUDE ? REACH_DESTINATION : worse );
0 commit comments