Skip to content

Commit

Permalink
cycleway: fix bug in setting the the sidewalk value (fixes #740)
Browse files Browse the repository at this point in the history
When the user selected "cyclists may use sidewalk" for one side and "cyclists must use sidewalk" for the other, the application crashed.
  • Loading branch information
westnordost committed Jan 3, 2018
1 parent 58124c3 commit 4443f06
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,32 @@ public class AddCycleway implements OsmElementQuestType
}
}

applySidewalkAnswerTo(cyclewayLeft, cyclewayRight, changes);

if(answer.getBoolean(AddCyclewayForm.IS_ONEWAY_NOT_FOR_CYCLISTS))
{
changes.addOrModify("oneway:bicycle", "no");
}
}

private void applySidewalkAnswerTo(Cycleway cyclewayLeft, Cycleway cyclewayRight,
StringMapChangesBuilder changes)
{
boolean hasSidewalkLeft = cyclewayLeft != null && cyclewayLeft.isOnSidewalk();
boolean hasSidewalkRight = cyclewayRight != null && cyclewayRight.isOnSidewalk();

Side side;
if(hasSidewalkLeft && hasSidewalkRight) side = Side.BOTH;
else if(hasSidewalkLeft) side = Side.LEFT;
else if(hasSidewalkRight) side = Side.RIGHT;
else side = null;

if(side != null)
{
changes.addOrModify("sidewalk", side.value);
}
}

private enum Side
{
LEFT("left"), RIGHT("right"), BOTH("both");
Expand Down Expand Up @@ -109,12 +129,10 @@ private void applyCyclewayAnswerTo(Cycleway cycleway, Side side, int dir, String
// https://wiki.openstreetmap.org/wiki/File:Z240GemeinsamerGehundRadweg.jpeg
changes.add(cyclewayKey, "track");
changes.add(cyclewayKey + ":segregated", "no");
changes.addOrModify("sidewalk", side.value);
break;
case SIDEWALK_OK:
// https://wiki.openstreetmap.org/wiki/File:Z239Z1022-10GehwegRadfahrerFrei.jpeg
changes.add(cyclewayKey, "no");
changes.addOrModify("sidewalk", side.value);
changes.add("sidewalk:" + side.value + ":bicycle", "yes");
break;
case SHARED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ public int getIconResId(boolean isLeftHandTraffic)
{
return isLeftHandTraffic ? iconResIdLeft : iconResId;
}

public boolean isOnSidewalk()
{
return this == SIDEWALK || this == SIDEWALK_OK;
}
}

0 comments on commit 4443f06

Please sign in to comment.