forked from opentripplanner/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/dev-2.x' into upstream-merge-2…
…024-03-04
- Loading branch information
Showing
9 changed files
with
268 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...java/org/opentripplanner/ext/vectortiles/layers/areastops/AreaStopPropertyMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.opentripplanner.ext.vectortiles.layers.areastops; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.opentripplanner.inspector.vector.KeyValue.kv; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentripplanner._support.geometry.Polygons; | ||
import org.opentripplanner.transit.model._data.TransitModelForTest; | ||
import org.opentripplanner.transit.model.network.Route; | ||
import org.opentripplanner.transit.model.site.AreaStop; | ||
import org.opentripplanner.transit.service.StopModel; | ||
|
||
class AreaStopPropertyMapperTest { | ||
|
||
private static final TransitModelForTest MODEL = new TransitModelForTest(StopModel.of()); | ||
private static final AreaStop STOP = MODEL.areaStopForTest("123", Polygons.BERLIN); | ||
private static final Route ROUTE_WITH_COLOR = TransitModelForTest | ||
.route("123") | ||
.withColor("ffffff") | ||
.build(); | ||
private static final Route ROUTE_WITHOUT_COLOR = TransitModelForTest.route("456").build(); | ||
|
||
@Test | ||
void map() { | ||
var mapper = new AreaStopPropertyMapper( | ||
ignored -> List.of(ROUTE_WITH_COLOR, ROUTE_WITHOUT_COLOR), | ||
Locale.ENGLISH | ||
); | ||
|
||
var kv = mapper.map(STOP); | ||
|
||
assertEquals( | ||
List.of( | ||
kv("gtfsId", "F:123"), | ||
kv("name", "123"), | ||
kv("code", null), | ||
kv("routeColors", "ffffff") | ||
), | ||
kv | ||
); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
.../java/org/opentripplanner/ext/vectortiles/layers/areastops/AreaStopsLayerBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.opentripplanner.ext.vectortiles.layers.areastops; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.opentripplanner.standalone.config.framework.json.JsonSupport.newNodeAdapterForTest; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentripplanner._support.geometry.Polygons; | ||
import org.opentripplanner.ext.vectortiles.VectorTilesResource; | ||
import org.opentripplanner.framework.i18n.I18NString; | ||
import org.opentripplanner.inspector.vector.LayerParameters; | ||
import org.opentripplanner.standalone.config.routerconfig.VectorTileConfig; | ||
import org.opentripplanner.transit.model.framework.Deduplicator; | ||
import org.opentripplanner.transit.model.framework.FeedScopedId; | ||
import org.opentripplanner.transit.model.site.AreaStop; | ||
import org.opentripplanner.transit.service.DefaultTransitService; | ||
import org.opentripplanner.transit.service.StopModel; | ||
import org.opentripplanner.transit.service.StopModelBuilder; | ||
import org.opentripplanner.transit.service.TransitModel; | ||
|
||
class AreaStopsLayerBuilderTest { | ||
|
||
private static final FeedScopedId ID = new FeedScopedId("FEED", "ID"); | ||
private static final I18NString NAME = I18NString.of("Test stop"); | ||
private static final String CONFIG = | ||
""" | ||
{ | ||
"vectorTiles": { | ||
"layers" : [ | ||
{ | ||
"name": "areaStops", | ||
"type": "AreaStop", | ||
"mapper": "OTPRR", | ||
"maxZoom": 20, | ||
"minZoom": 14, | ||
"cacheMaxSeconds": 60, | ||
"expansionFactor": 0 | ||
} | ||
] | ||
} | ||
} | ||
"""; | ||
private static final LayerParameters<VectorTilesResource.LayerType> LAYER_CONFIG = VectorTileConfig | ||
.mapVectorTilesParameters(newNodeAdapterForTest(CONFIG), "vectorTiles") | ||
.layers() | ||
.getFirst(); | ||
|
||
private final StopModelBuilder stopModelBuilder = StopModel.of(); | ||
|
||
private final AreaStop AREA_STOP = stopModelBuilder | ||
.areaStop(ID) | ||
.withName(NAME) | ||
.withGeometry(Polygons.BERLIN) | ||
.build(); | ||
|
||
private final TransitModel transitModel = new TransitModel( | ||
stopModelBuilder.withAreaStop(AREA_STOP).build(), | ||
new Deduplicator() | ||
); | ||
|
||
@Test | ||
void getAreaStops() { | ||
transitModel.index(); | ||
|
||
var subject = new AreaStopsLayerBuilder( | ||
new DefaultTransitService(transitModel), | ||
LAYER_CONFIG, | ||
Locale.ENGLISH | ||
); | ||
var geometries = subject.getGeometries(AREA_STOP.getGeometry().getEnvelopeInternal()); | ||
assertEquals(List.of(Polygons.BERLIN), geometries); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ext/java/org/opentripplanner/ext/vectortiles/layers/areastops/AreaStopPropertyMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.opentripplanner.ext.vectortiles.layers.areastops; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Objects; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import org.opentripplanner.apis.support.mapping.PropertyMapper; | ||
import org.opentripplanner.framework.i18n.I18NStringMapper; | ||
import org.opentripplanner.inspector.vector.KeyValue; | ||
import org.opentripplanner.transit.model.network.Route; | ||
import org.opentripplanner.transit.model.site.AreaStop; | ||
import org.opentripplanner.transit.model.site.StopLocation; | ||
import org.opentripplanner.transit.service.TransitService; | ||
|
||
public class AreaStopPropertyMapper extends PropertyMapper<AreaStop> { | ||
|
||
private final Function<StopLocation, Collection<Route>> getRoutesForStop; | ||
private final I18NStringMapper i18NStringMapper; | ||
|
||
protected AreaStopPropertyMapper( | ||
Function<StopLocation, Collection<Route>> getRoutesForStop, | ||
Locale locale | ||
) { | ||
this.getRoutesForStop = getRoutesForStop; | ||
this.i18NStringMapper = new I18NStringMapper(locale); | ||
} | ||
|
||
protected static AreaStopPropertyMapper create(TransitService transitService, Locale locale) { | ||
return new AreaStopPropertyMapper(transitService::getRoutesForStop, locale); | ||
} | ||
|
||
@Override | ||
protected Collection<KeyValue> map(AreaStop stop) { | ||
var routeColors = getRoutesForStop | ||
.apply(stop) | ||
.stream() | ||
.map(Route::getColor) | ||
.filter(Objects::nonNull) | ||
.distinct() | ||
// the MVT spec explicitly doesn't cover how to encode arrays | ||
// https://docs.mapbox.com/data/tilesets/guides/vector-tiles-standards/#what-the-spec-doesnt-cover | ||
.collect(Collectors.joining(",")); | ||
return List.of( | ||
new KeyValue("gtfsId", stop.getId().toString()), | ||
new KeyValue("name", i18NStringMapper.mapNonnullToApi(stop.getName())), | ||
new KeyValue("code", stop.getCode()), | ||
new KeyValue("routeColors", routeColors) | ||
); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/ext/java/org/opentripplanner/ext/vectortiles/layers/areastops/AreaStopsLayerBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.opentripplanner.ext.vectortiles.layers.areastops; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.function.BiFunction; | ||
import org.locationtech.jts.geom.Envelope; | ||
import org.locationtech.jts.geom.Geometry; | ||
import org.opentripplanner.apis.support.mapping.PropertyMapper; | ||
import org.opentripplanner.ext.vectortiles.VectorTilesResource; | ||
import org.opentripplanner.inspector.vector.LayerBuilder; | ||
import org.opentripplanner.inspector.vector.LayerParameters; | ||
import org.opentripplanner.transit.model.site.AreaStop; | ||
import org.opentripplanner.transit.service.TransitService; | ||
|
||
public class AreaStopsLayerBuilder extends LayerBuilder<AreaStop> { | ||
|
||
static Map<MapperType, BiFunction<TransitService, Locale, PropertyMapper<AreaStop>>> mappers = Map.of( | ||
MapperType.OTPRR, | ||
AreaStopPropertyMapper::create | ||
); | ||
private final TransitService transitService; | ||
|
||
public AreaStopsLayerBuilder( | ||
TransitService transitService, | ||
LayerParameters<VectorTilesResource.LayerType> layerParameters, | ||
Locale locale | ||
) { | ||
super( | ||
mappers.get(MapperType.valueOf(layerParameters.mapper())).apply(transitService, locale), | ||
layerParameters.name(), | ||
layerParameters.expansionFactor() | ||
); | ||
this.transitService = transitService; | ||
} | ||
|
||
protected List<Geometry> getGeometries(Envelope query) { | ||
return transitService | ||
.findAreaStops(query) | ||
.stream() | ||
.filter(g -> g.getGeometry() != null) | ||
.map(stop -> { | ||
Geometry point = stop.getGeometry().copy(); | ||
point.setUserData(stop); | ||
return point; | ||
}) | ||
.toList(); | ||
} | ||
|
||
enum MapperType { | ||
OTPRR, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters