Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traversal permissions debug layer #6114

Merged
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opentripplanner.apis.vectortiles;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -10,7 +11,9 @@
import org.opentripplanner.apis.vectortiles.model.VectorSourceLayer;
import org.opentripplanner.apis.vectortiles.model.ZoomDependentNumber;
import org.opentripplanner.apis.vectortiles.model.ZoomDependentNumber.ZoomStop;
import org.opentripplanner.framework.collection.ListUtils;
import org.opentripplanner.service.vehiclerental.street.StreetVehicleRentalLink;
import org.opentripplanner.street.model.StreetTraversalPermission;
import org.opentripplanner.street.model.edge.AreaEdge;
import org.opentripplanner.street.model.edge.BoardingLocationToStopLink;
import org.opentripplanner.street.model.edge.Edge;
Expand Down Expand Up @@ -44,17 +47,15 @@ public class DebugStyleSpec {
private static final String DARK_GREEN = "#136b04";
private static final String PURPLE = "#BC55F2";
private static final String BLACK = "#140d0e";

private static final int MAX_ZOOM = 23;
private static final ZoomDependentNumber LINE_WIDTH = new ZoomDependentNumber(
1.3f,
List.of(new ZoomStop(13, 0.5f), new ZoomStop(MAX_ZOOM, 10))
);
private static final ZoomDependentNumber LINE_OFFSET = new ZoomDependentNumber(
1.3f,
List.of(new ZoomStop(13, 0.3f), new ZoomStop(MAX_ZOOM, 6))
);
private static final ZoomDependentNumber LINE_WIDTH = new ZoomDependentNumber(
List.of(new ZoomStop(13, 0.2f), new ZoomStop(MAX_ZOOM, 8))
);
private static final ZoomDependentNumber CIRCLE_STROKE = new ZoomDependentNumber(
1,
List.of(new ZoomStop(15, 0.2f), new ZoomStop(MAX_ZOOM, 3))
);
private static final Class<Edge>[] EDGES_TO_DISPLAY = new Class[] {
Expand All @@ -66,6 +67,10 @@ public class DebugStyleSpec {
TemporaryPartialStreetEdge.class,
TemporaryFreeEdge.class,
};
private static final String EDGES_GROUP = "Edges";
private static final String STOPS_GROUP = "Stops";
private static final String VERTICES_GROUP = "Vertices";
private static final String TRAVERSAL_PERMISSIONS_GROUP = "Traversal permissions";

static StyleSpec build(
VectorSourceLayer regularStops,
Expand All @@ -83,104 +88,178 @@ static StyleSpec build(
return new StyleSpec(
"OTP Debug Tiles",
allSources,
List.of(
StyleBuilder.ofId("background").typeRaster().source(BACKGROUND_SOURCE).minZoom(0),
StyleBuilder
.ofId("edge")
.typeLine()
.vectorSourceLayer(edges)
.lineColor(MAGENTA)
.edgeFilter(EDGES_TO_DISPLAY)
.lineWidth(LINE_WIDTH)
.lineOffset(LINE_OFFSET)
.minZoom(6)
.maxZoom(MAX_ZOOM)
.intiallyHidden(),
ListUtils.combine(
List.of(StyleBuilder.ofId("background").typeRaster().source(BACKGROUND_SOURCE).minZoom(0)),
traversalPermissions(edges),
edges(edges),
vertices(vertices),
stops(regularStops, areaStops, groupStops)
)
);
}

private static List<StyleBuilder> stops(
VectorSourceLayer regularStops,
VectorSourceLayer areaStops,
VectorSourceLayer groupStops
) {
return List.of(
StyleBuilder
.ofId("area-stop")
.group(STOPS_GROUP)
.typeFill()
.vectorSourceLayer(areaStops)
.fillColor(BRIGHT_GREEN)
.fillOpacity(0.5f)
.fillOutlineColor(BLACK)
.minZoom(6)
.maxZoom(MAX_ZOOM),
StyleBuilder
.ofId("group-stop")
.group(STOPS_GROUP)
.typeFill()
.vectorSourceLayer(groupStops)
.fillColor(BRIGHT_GREEN)
.fillOpacity(0.5f)
.fillOutlineColor(BLACK)
.minZoom(6)
.maxZoom(MAX_ZOOM),
StyleBuilder
.ofId("regular-stop")
.group(STOPS_GROUP)
.typeCircle()
.vectorSourceLayer(regularStops)
.circleStroke(
BLACK,
new ZoomDependentNumber(List.of(new ZoomStop(11, 0.5f), new ZoomStop(MAX_ZOOM, 5)))
)
.circleRadius(
new ZoomDependentNumber(List.of(new ZoomStop(11, 0.5f), new ZoomStop(MAX_ZOOM, 10)))
)
.circleColor("#fcf9fa")
.minZoom(10)
.maxZoom(MAX_ZOOM)
);
}

private static List<StyleBuilder> vertices(VectorSourceLayer vertices) {
return List.of(
StyleBuilder
.ofId("vertex")
.group(VERTICES_GROUP)
.typeCircle()
.vectorSourceLayer(vertices)
.circleStroke(BLACK, CIRCLE_STROKE)
.circleRadius(
new ZoomDependentNumber(List.of(new ZoomStop(15, 1), new ZoomStop(MAX_ZOOM, 7)))
)
.circleColor(PURPLE)
.minZoom(15)
.maxZoom(MAX_ZOOM)
.intiallyHidden(),
StyleBuilder
.ofId("parking-vertex")
.group(VERTICES_GROUP)
.typeCircle()
.vectorSourceLayer(vertices)
.vertexFilter(VehicleParkingEntranceVertex.class)
.circleStroke(BLACK, CIRCLE_STROKE)
.circleRadius(
new ZoomDependentNumber(List.of(new ZoomStop(13, 1.4f), new ZoomStop(MAX_ZOOM, 10)))
)
.circleColor(DARK_GREEN)
.minZoom(13)
.maxZoom(MAX_ZOOM)
.intiallyHidden()
);
}

private static List<StyleBuilder> edges(VectorSourceLayer edges) {
return List.of(
StyleBuilder
.ofId("edge")
.group(EDGES_GROUP)
.typeLine()
.vectorSourceLayer(edges)
.lineColor(MAGENTA)
.edgeFilter(EDGES_TO_DISPLAY)
.lineWidth(LINE_WIDTH)
.lineOffset(LINE_OFFSET)
.minZoom(6)
.maxZoom(MAX_ZOOM)
.intiallyHidden(),
StyleBuilder
.ofId("edge-name")
.group(EDGES_GROUP)
.typeSymbol()
.lineText("name")
.vectorSourceLayer(edges)
.edgeFilter(EDGES_TO_DISPLAY)
.minZoom(17)
.maxZoom(MAX_ZOOM)
.intiallyHidden(),
StyleBuilder
.ofId("link")
.group(EDGES_GROUP)
.typeLine()
.vectorSourceLayer(edges)
.lineColor(BRIGHT_GREEN)
.edgeFilter(
StreetTransitStopLink.class,
StreetTransitEntranceLink.class,
BoardingLocationToStopLink.class,
StreetVehicleRentalLink.class,
StreetVehicleParkingLink.class,
StreetStationCentroidLink.class
)
.lineWidth(LINE_WIDTH)
.lineOffset(LINE_OFFSET)
.minZoom(13)
.maxZoom(MAX_ZOOM)
.intiallyHidden()
);
}

private static List<StyleBuilder> traversalPermissions(VectorSourceLayer edges) {
var permissionStyles = Arrays
.stream(StreetTraversalPermission.values())
.map(p ->
StyleBuilder
.ofId("edge-name")
.typeSymbol()
.lineText("name")
.ofId(p.name())
.vectorSourceLayer(edges)
.edgeFilter(EDGES_TO_DISPLAY)
.minZoom(17)
.maxZoom(MAX_ZOOM)
.intiallyHidden(),
StyleBuilder
.ofId("link")
.group(TRAVERSAL_PERMISSIONS_GROUP)
.typeLine()
.vectorSourceLayer(edges)
.lineColor(BRIGHT_GREEN)
.edgeFilter(
StreetTransitStopLink.class,
StreetTransitEntranceLink.class,
BoardingLocationToStopLink.class,
StreetVehicleRentalLink.class,
StreetVehicleParkingLink.class,
StreetStationCentroidLink.class
)
.lineColor(permissionColor(p))
.permissionsFilter(p)
.lineWidth(LINE_WIDTH)
.lineOffset(LINE_OFFSET)
.minZoom(13)
.maxZoom(MAX_ZOOM)
.intiallyHidden(),
StyleBuilder
.ofId("vertex")
.typeCircle()
.vectorSourceLayer(vertices)
.circleStroke(BLACK, CIRCLE_STROKE)
.circleRadius(
new ZoomDependentNumber(1, List.of(new ZoomStop(15, 1), new ZoomStop(MAX_ZOOM, 7)))
)
.circleColor(PURPLE)
.minZoom(15)
.maxZoom(MAX_ZOOM)
.intiallyHidden(),
StyleBuilder
.ofId("parking-vertex")
.typeCircle()
.vectorSourceLayer(vertices)
.vertexFilter(VehicleParkingEntranceVertex.class)
.circleStroke(BLACK, CIRCLE_STROKE)
.circleRadius(
new ZoomDependentNumber(1, List.of(new ZoomStop(13, 1.4f), new ZoomStop(MAX_ZOOM, 10)))
)
.circleColor(DARK_GREEN)
.minZoom(13)
.maxZoom(MAX_ZOOM)
.intiallyHidden(),
StyleBuilder
.ofId("area-stop")
.typeFill()
.vectorSourceLayer(areaStops)
.fillColor(BRIGHT_GREEN)
.fillOpacity(0.5f)
.fillOutlineColor(BLACK)
.minZoom(6)
.maxZoom(MAX_ZOOM),
StyleBuilder
.ofId("group-stop")
.typeFill()
.vectorSourceLayer(groupStops)
.fillColor(BRIGHT_GREEN)
.fillOpacity(0.5f)
.fillOutlineColor(BLACK)
.minZoom(6)
.maxZoom(MAX_ZOOM),
StyleBuilder
.ofId("regular-stop")
.typeCircle()
.vectorSourceLayer(regularStops)
.circleStroke(
BLACK,
new ZoomDependentNumber(1, List.of(new ZoomStop(11, 0.5f), new ZoomStop(MAX_ZOOM, 5)))
)
.circleRadius(
new ZoomDependentNumber(1, List.of(new ZoomStop(11, 0.5f), new ZoomStop(MAX_ZOOM, 10)))
)
.circleColor("#fcf9fa")
.minZoom(10)
.maxZoom(MAX_ZOOM)
.intiallyHidden()
)
);
.toList();
var textStyle = StyleBuilder
.ofId("permission-text")
.vectorSourceLayer(edges)
.group(TRAVERSAL_PERMISSIONS_GROUP)
.typeSymbol()
.lineText("permission")
.textOffset(1)
.edgeFilter(EDGES_TO_DISPLAY)
.minZoom(17)
.maxZoom(MAX_ZOOM)
.intiallyHidden();
return ListUtils.combine(permissionStyles, List.of(textStyle));
}

private static String permissionColor(StreetTraversalPermission p) {
return switch (p) {
case NONE -> "#000";
case PEDESTRIAN -> "#2ba812";
case BICYCLE, PEDESTRIAN_AND_BICYCLE -> "#10d3b6";
case CAR -> "#f92e13";
case BICYCLE_AND_CAR, PEDESTRIAN_AND_CAR -> "#e25f8f";
case ALL -> "#adb2b0";
};
}
}
Loading
Loading