Skip to content

Commit

Permalink
Add support tag combinations cycleway:left and cycleway:right, fixes #…
Browse files Browse the repository at this point in the history
…2969 (#2970)

* Add support tag combinations cycleway:left and cycleway:right, fixes #2969

* Include review comments
  • Loading branch information
ratrun committed Apr 15, 2024
1 parent 115bab2 commit 60405c4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
10 changes: 5 additions & 5 deletions core/src/main/java/com/graphhopper/reader/ReaderElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ public boolean hasTag(List<String> keyList, Object value) {
*
* @return an empty string if nothing found
*/
public String getFirstValue(List<String> restrictions) {
for (String str : restrictions) {
public String getFirstValue(List<String> searchedTags) {
for (String str : searchedTags) {
Object value = properties.get(str);
if (value != null)
return (String) value;
Expand All @@ -178,9 +178,9 @@ public String getFirstValue(List<String> restrictions) {
/**
* @return -1 if not found
*/
public int getFirstIndex(List<String> restrictions) {
for (int i = 0; i < restrictions.size(); i++) {
String str = restrictions.get(i);
public int getFirstIndex(List<String> searchedTags) {
for (int i = 0; i < searchedTags.size(); i++) {
String str = searchedTags.get(i);
Object value = properties.get(str);
if (value != null)
return i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.graphhopper.storage.IntsRef;

import java.util.*;
import java.util.stream.Stream;

import static com.graphhopper.routing.ev.RouteNetwork.*;
import static com.graphhopper.routing.util.PriorityCode.*;
Expand Down Expand Up @@ -183,11 +184,11 @@ void collect(ReaderWay way, double wayTypeSpeed, TreeMap<Double, PriorityCode> w
}
}

String cycleway = way.getFirstValue(Arrays.asList("cycleway", "cycleway:left", "cycleway:right", "cycleway:both"));
if (Arrays.asList("lane", "opposite_track", "shared_lane", "share_busway", "shoulder").contains(cycleway)) {
weightToPrioMap.put(100d, SLIGHT_PREFER);
} else if ("track".equals(cycleway)) {
List<String> cyclewayValues = Stream.of("cycleway", "cycleway:left", "cycleway:both", "cycleway:right").map(key -> way.getTag(key, "")).toList();
if (cyclewayValues.contains("track")) {
weightToPrioMap.put(100d, PREFER);
} else if (Stream.of("lane", "opposite_track", "shared_lane", "share_busway", "shoulder").anyMatch(cyclewayValues::contains)) {
weightToPrioMap.put(100d, SLIGHT_PREFER);
}

if (way.hasTag("bicycle", "use_sidepath")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.graphhopper.reader.ReaderNode;
import com.graphhopper.reader.ReaderRelation;
import com.graphhopper.reader.ReaderWay;
import com.graphhopper.reader.osm.conditional.DateRangeParser;
import com.graphhopper.routing.ev.*;
import com.graphhopper.routing.util.EncodingManager;
import com.graphhopper.routing.util.PriorityCode;
Expand Down Expand Up @@ -335,6 +334,8 @@ public void testCycleway() {
way.setTag("highway", "primary");
way.setTag("cycleway:right", "lane");
assertPriority(SLIGHT_PREFER, way);
way.setTag("cycleway:left", "no");
assertPriority(SLIGHT_PREFER, way);

way.clearTags();
way.setTag("highway", "primary");
Expand Down
4 changes: 2 additions & 2 deletions docs/core/weighting.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Weighting

Instead of creating a new Weighting implementation is is highly recommended to use the CustomWeighting instead, which is explained in
Instead of creating a new Weighting implementation it is highly recommended to use the CustomWeighting instead, which is explained in
the [profiles](profiles.md) and [custom models](custom-models.md) section.

A weighting calculates the "weight" for an edge. The weight of an edge reflects the cost of travelling along this edge.
Expand All @@ -24,4 +24,4 @@ If you only want to change small parts of an existing weighting, it might be a g
a sample can be found in the [AvoidEdgesWeighting](https://github.com/graphhopper/graphhopper/blob/master/core/src/main/java/com/graphhopper/routing/weighting/AvoidEdgesWeighting.java).
If your weights change on a per-request base you cannot use the 'speed mode', but have to use the 'hybrid mode' or 'flexible mode' (more details [here](https://github.com/graphhopper/graphhopper#technical-overview)).
If you haven't disabled the 'speed mode' in your config, you have to disable it for the requests by appending `ch.disable=true`
in the request url.
in the request url.

0 comments on commit 60405c4

Please sign in to comment.