Skip to content

Commit

Permalink
Merge pull request opentripplanner#42 from ibi-group/transitive-no-in…
Browse files Browse the repository at this point in the history
…termediate-stops

Get transitive utility to tolerate itineraries without intermediate stops
  • Loading branch information
fpurcell authored Jan 24, 2020
2 parents b65a456 + caaef4b commit 7e767ed
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
35 changes: 21 additions & 14 deletions packages/core-utils/src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ export function itineraryToTransitive(itin, companies) {
}
if (isTransit(leg.mode)) {
// determine if we have valid inter-stop geometry
const hasInterStopGeometry =
leg.interStopGeometry &&
const hasInterStopGeometry = !!leg.interStopGeometry;
const hasIntermediateStopGeomerty =
hasInterStopGeometry &&
leg.intermediateStops &&
leg.interStopGeometry.length === leg.intermediateStops.length + 1;

// create leg-specific pattern
Expand All @@ -184,18 +186,21 @@ export function itineraryToTransitive(itin, companies) {
pattern.stops.push({ stop_id: leg.from.stopId });

// add intermediate stops to stops dictionary and pattern object
leg.intermediateStops.forEach((stop, i) => {
stops[stop.stopId] = {
stop_id: stop.stopId,
stop_name: stop.name,
stop_lat: stop.lat,
stop_lon: stop.lon
};
pattern.stops.push({
stop_id: stop.stopId,
geometry: hasInterStopGeometry && leg.interStopGeometry[i].points
if (leg.intermediateStops) {
leg.intermediateStops.forEach((stop, i) => {
stops[stop.stopId] = {
stop_id: stop.stopId,
stop_name: stop.name,
stop_lat: stop.lat,
stop_lon: stop.lon
};
pattern.stops.push({
stop_id: stop.stopId,
geometry:
hasIntermediateStopGeomerty && leg.interStopGeometry[i].points
});
});
});
}

// add 'to' stop to stops dictionary and pattern object
stops[leg.to.stopId] = {
Expand Down Expand Up @@ -231,7 +236,9 @@ export function itineraryToTransitive(itin, companies) {
{
pattern_id: ptnId,
from_stop_index: 0,
to_stop_index: leg.intermediateStops.length + 2 - 1
to_stop_index: leg.intermediateStops
? leg.intermediateStops.length + 2 - 1
: 1
}
]
});
Expand Down
5 changes: 3 additions & 2 deletions packages/transitive-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
},
"homepage": "https://github.com/opentripplanner/otp-ui#readme",
"dependencies": {
"@opentripplanner/base-map": "^0.0.11",
"@opentripplanner/core-utils": "^0.0.11",
"@opentripplanner/icons": "^0.0.11",
"@opentripplanner/base-map": "^0.0.11",
"lodash.isequal": "^4.5.0",
"react-leaflet": "^2.6.1",
"transitive-js": "^0.13.0"
Expand All @@ -29,6 +29,7 @@
},
"devDependencies": {
"@opentripplanner/endpoints-overlay": "^0.0.11",
"@opentripplanner/itinerary-body": "^0.0.11"
"@opentripplanner/itinerary-body": "^0.0.11",
"lodash.clonedeep": "^4.5.0"
}
}
31 changes: 31 additions & 0 deletions packages/transitive-overlay/src/TransitiveOverlay.story.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import clone from "lodash.clonedeep";
import BaseMap from "@opentripplanner/base-map";
import { itineraryToTransitive } from "@opentripplanner/core-utils/lib/map";
import EndpointsOverlay from "@opentripplanner/endpoints-overlay";
Expand Down Expand Up @@ -25,6 +26,12 @@ const walkOnlyItinerary = require("@opentripplanner/itinerary-body/src/__mocks__
const walkTransitWalkItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-transit-walk.json");
const walkTransitWalkTransitWalkItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-transit-walk-transit-walk.json");

const walkInterlinedTransitItineraryNoIntermediateStops = clone(
walkInterlinedTransitItinerary
);
delete walkInterlinedTransitItineraryNoIntermediateStops.legs[1]
.intermediateStops;

const companies = [
{
id: "RAZOR",
Expand Down Expand Up @@ -130,6 +137,30 @@ storiesOf("TransitiveOverlay", module)
/>
</BaseMap>
))
.add(
"TransitiveOverlay with walk-interlined-transit itinerary with no intermediate stops",
() => (
<BaseMap center={[45.511841, -122.679302]} zoom={14}>
<EndpointsOverlay
fromLocation={getFromLocation(
walkInterlinedTransitItineraryNoIntermediateStops
)}
setLocation={setLocation}
toLocation={getToLocation(
walkInterlinedTransitItineraryNoIntermediateStops
)}
visible
/>
<TransitiveOverlay
transitiveData={itineraryToTransitive(
walkInterlinedTransitItineraryNoIntermediateStops,
companies
)}
visible
/>
</BaseMap>
)
)
.add("TransitiveOverlay with walk-transit-transfer itinerary", () => (
<BaseMap center={[45.505841, -122.631302]} zoom={14}>
<EndpointsOverlay
Expand Down

0 comments on commit 7e767ed

Please sign in to comment.