Skip to content

Commit

Permalink
Merge pull request #74 from ibi-group/transitive-improvements
Browse files Browse the repository at this point in the history
Transitive improvements
  • Loading branch information
fpurcell authored Mar 4, 2020
2 parents 41a06ee + bd9dda4 commit 0c7ce21
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
20 changes: 19 additions & 1 deletion packages/core-utils/src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function itineraryToTransitive(itin, companies) {
place_lon: itin.legs[itin.legs.length - 1].to.lon
});

itin.legs.forEach(leg => {
itin.legs.forEach((leg, idx) => {
if (
leg.mode === "WALK" ||
leg.mode === "BICYCLE" ||
Expand All @@ -114,6 +114,13 @@ export function itineraryToTransitive(itin, companies) {
fromPlaceId = `bicycle_rent_station_${leg.from.bikeShareId}`;
} else if (leg.from.vertexType === "VEHICLERENTAL") {
fromPlaceId = `escooter_rent_station_${leg.from.name}`;
} else if (
leg.mode === "CAR" &&
idx > 0 &&
itin.legs[idx - 1].mode === "WALK"
) {
// create a special place ID for car legs preceeded by walking legs
fromPlaceId = `itin_car_${streetEdgeId}_from`;
} else {
fromPlaceId = `itin_street_${streetEdgeId}_from`;
}
Expand All @@ -123,6 +130,13 @@ export function itineraryToTransitive(itin, companies) {
toPlaceId = `bicycle_rent_station_${leg.to.bikeShareId}`;
} else if (leg.to.vertexType === "VEHICLERENTAL") {
toPlaceId = `escooter_rent_station_${leg.to.name}`;
} else if (
leg.mode === "CAR" &&
idx < itin.legs.length - 1 &&
itin.legs[idx + 1].mode === "WALK"
) {
// create a special place ID for car legs followed by walking legs
toPlaceId = `itin_car_${streetEdgeId}_to`;
} else {
toPlaceId = `itin_street_${streetEdgeId}_to`;
}
Expand Down Expand Up @@ -268,6 +282,10 @@ export function isEScooterStation(place) {
return place.place_id.lastIndexOf("escooter_rent_station") !== -1;
}

export function isCarWalkTransition(place) {
return place.place_id.lastIndexOf("itin_car_") !== -1;
}

export function isValidLat(lat) {
return Number.isFinite(lat) && lat >= -90 && lat <= 90;
}
Expand Down
7 changes: 4 additions & 3 deletions packages/transitive-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
"dependencies": {
"@opentripplanner/base-map": "^0.0.16",
"@opentripplanner/core-utils": "^0.0.16",
"@opentripplanner/endpoints-overlay": "^0.0.16",
"@opentripplanner/icons": "^0.0.16",
"@opentripplanner/itinerary-body": "^0.0.16",
"lodash.isequal": "^4.5.0",
"react-leaflet": "^2.6.1",
"transitive-js": "^0.13.0"
},
"devDependencies": {
"@opentripplanner/endpoints-overlay": "^0.0.16",
"@opentripplanner/itinerary-body": "^0.0.16"
},
"peerDependencies": {
"react": "^16.8.6"
}
Expand Down
10 changes: 9 additions & 1 deletion packages/transitive-overlay/src/transitive-styles.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
isBikeshareStation,
isCarWalkTransition,
isEScooterStation
} from "@opentripplanner/core-utils/lib/map";

Expand All @@ -17,11 +18,18 @@ const STYLES = {};
*/
STYLES.places = {
display: (display, place) =>
isBikeshareStation(place) || isEScooterStation(place) ? true : "none",
isBikeshareStation(place) ||
isEScooterStation(place) ||
isCarWalkTransition(place)
? true
: "none",
fill: (display, place) => {
if (isBikeshareStation(place)) {
return "#f00";
}
if (isCarWalkTransition(place)) {
return "#888";
}
if (isEScooterStation(place)) {
return "#f5a729";
}
Expand Down

0 comments on commit 0c7ce21

Please sign in to comment.