From f9ef568899a79dd0d319156ef9a96564911f6c0e Mon Sep 17 00:00:00 2001 From: Evan Siroky Date: Thu, 23 Jan 2020 16:19:02 -0800 Subject: [PATCH] Properly translate transitive itineraries with no intermediate stops Fixes https://github.com/opentripplanner/otp-ui/issues/36 --- packages/core-utils/src/map.js | 35 +++++++++++-------- packages/transitive-overlay/package.json | 5 +-- .../src/TransitiveOverlay.story.js | 31 ++++++++++++++++ 3 files changed, 55 insertions(+), 16 deletions(-) diff --git a/packages/core-utils/src/map.js b/packages/core-utils/src/map.js index 60de31504..a7276e47c 100644 --- a/packages/core-utils/src/map.js +++ b/packages/core-utils/src/map.js @@ -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 @@ -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] = { @@ -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 } ] }); diff --git a/packages/transitive-overlay/package.json b/packages/transitive-overlay/package.json index 786b4b1df..d21f7c07f 100644 --- a/packages/transitive-overlay/package.json +++ b/packages/transitive-overlay/package.json @@ -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" @@ -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" } } diff --git a/packages/transitive-overlay/src/TransitiveOverlay.story.js b/packages/transitive-overlay/src/TransitiveOverlay.story.js index 3db2bd01f..0c51972b5 100644 --- a/packages/transitive-overlay/src/TransitiveOverlay.story.js +++ b/packages/transitive-overlay/src/TransitiveOverlay.story.js @@ -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"; @@ -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", @@ -130,6 +137,30 @@ storiesOf("TransitiveOverlay", module) /> )) + .add( + "TransitiveOverlay with walk-interlined-transit itinerary with no intermediate stops", + () => ( + + + + + ) + ) .add("TransitiveOverlay with walk-transit-transfer itinerary", () => (