Skip to content

Commit

Permalink
Merge pull request #497 from ibi-group/vector-flex-arcing
Browse files Browse the repository at this point in the history
Restore arc rendering for flex segments
  • Loading branch information
miles-grant-ibigroup authored Dec 16, 2022
2 parents dcc81e6 + e8d736a commit 240cc1c
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 16 deletions.
3 changes: 2 additions & 1 deletion packages/transit-vehicle-overlay/i18n/ko.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
otpUi:
TransitVehicleOverlay:
defaultTooltip: "{route}: {duration} 전"
durationWithSeconds: "{hours, plural, =0 {} other {# 시간 }}{minutes, plural, =0\
durationWithSeconds:
"{hours, plural, =0 {} other {# 시간 }}{minutes, plural, =0\
\ {{seconds, plural, =0 {# 분} other {}}} other {# 분}}{seconds, plural, =0 {}\
\ other { # 초}}"
transitLine:
11 changes: 8 additions & 3 deletions packages/transitive-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@
"dependencies": {
"@mapbox/polyline": "^1.1.1",
"@opentripplanner/base-map": "^3.0.6",
"@opentripplanner/itinerary-body": "^4.1.3",
"@opentripplanner/core-utils": "^7.0.5",
"lodash.isequal": "^4.5.0",
"@turf/bbox": "^6.5.0"
"@opentripplanner/itinerary-body": "^4.1.3",
"@turf/bbox": "^6.5.0",
"@turf/bearing": "^6.5.0",
"@turf/destination": "^6.5.0",
"@turf/line-arc": "^6.5.0",
"@turf/line-distance": "^4.7.3",
"@turf/midpoint": "^6.5.0",
"lodash.isequal": "^4.5.0"
},
"devDependencies": {
"@opentripplanner/endpoints-overlay": "^2.0.4",
Expand Down
62 changes: 53 additions & 9 deletions packages/transitive-overlay/src/route-layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import polyline from "@mapbox/polyline";
import { SymbolLayout } from "mapbox-gl";
import { TransitivePattern, TransitiveRoute } from "@opentripplanner/types";

import lineArc from "@turf/line-arc";
import lineDistance from "@turf/line-distance";
import midpoint from "@turf/midpoint";
import destination from "@turf/destination";
import bearing from "@turf/bearing";
import distance from "@turf/distance";

/**
* Create a labeled-line feature for the given transit route pattern.
*/
Expand Down Expand Up @@ -32,16 +39,53 @@ export function patternToRouteFeature(
.replace(/\s/g, "!")
.replace(/[+-0124679FHJLPTVXYZ]/g, "E");

const properties = {
color: `#${route.route_color || "000080"}`,
name: routeName,
nameUpper: routeNameUpper,
routeType: route.route_type,
textColor: `#${route.route_text_color || "eee"}`,
type: "route"
};

const isFlex = pattern.stops[pattern.stops.length - 1].stop_id.endsWith(
"flexed_to"
);
const straight = polyline.toGeoJSON(polyline.encode(concatenatedLines));

// TODO: add a second condition for TNC routes to also be drawn as arcs
if (isFlex) {
// Create clone of plain route that only includes first and last point
straight.coordinates = [
straight.coordinates[0],
straight.coordinates[straight.coordinates.length - 1]
];
const orig = straight.coordinates[0];
const dest = straight.coordinates[1];

// Adapted from https://github.com/Turfjs/turf/issues/1218#issuecomment-592421977
const length = lineDistance(straight, "kilometers");
const mp = midpoint(orig, dest);
const center = destination(mp, length, bearing(orig, dest) - 90);

const arc = lineArc(
center,
distance(center, orig),
bearing(center, dest),
bearing(center, orig),
{ steps: 500 }
).geometry;

return {
geometry: arc,
properties,
type: "Feature"
};
}

return {
geometry: polyline.toGeoJSON(polyline.encode(concatenatedLines)),
properties: {
color: `#${route.route_color || "000080"}`,
name: routeName,
nameUpper: routeNameUpper,
routeType: route.route_type,
textColor: `#${route.route_text_color || "eee"}`,
type: "route"
},
geometry: straight,
properties,
type: "Feature"
};
}
Expand Down
65 changes: 62 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4217,49 +4217,108 @@
"@turf/helpers" "^6.5.0"
"@turf/meta" "^6.5.0"

"@turf/bearing@^6.3.0":
"@turf/bearing@^6.3.0", "@turf/bearing@^6.5.0":
version "6.5.0"
resolved "https://registry.yarnpkg.com/@turf/bearing/-/bearing-6.5.0.tgz#462a053c6c644434bdb636b39f8f43fb0cd857b0"
integrity sha512-dxINYhIEMzgDOztyMZc20I7ssYVNEpSv04VbMo5YPQsqa80KO3TFvbuCahMsCAW5z8Tncc8dwBlEFrmRjJG33A==
dependencies:
"@turf/helpers" "^6.5.0"
"@turf/invariant" "^6.5.0"

"@turf/destination@^6.3.0":
"@turf/circle@^6.5.0":
version "6.5.0"
resolved "https://registry.yarnpkg.com/@turf/circle/-/circle-6.5.0.tgz#dc017d8c0131d1d212b7c06f76510c22bbeb093c"
integrity sha512-oU1+Kq9DgRnoSbWFHKnnUdTmtcRUMmHoV9DjTXu9vOLNV5OWtAAh1VZ+mzsioGGzoDNT/V5igbFOkMfBQc0B6A==
dependencies:
"@turf/destination" "^6.5.0"
"@turf/helpers" "^6.5.0"

"@turf/destination@^6.3.0", "@turf/destination@^6.5.0":
version "6.5.0"
resolved "https://registry.yarnpkg.com/@turf/destination/-/destination-6.5.0.tgz#30a84702f9677d076130e0440d3223ae503fdae1"
integrity sha512-4cnWQlNC8d1tItOz9B4pmJdWpXqS0vEvv65bI/Pj/genJnsL7evI0/Xw42RvEGROS481MPiU80xzvwxEvhQiMQ==
dependencies:
"@turf/helpers" "^6.5.0"
"@turf/invariant" "^6.5.0"

"@turf/distance@^6.3.0":
"@turf/distance@^4.7.3":
version "4.7.3"
resolved "https://registry.yarnpkg.com/@turf/distance/-/distance-4.7.3.tgz#b5ab48a09a642706d65c39b919433d5d2cc571b1"
integrity sha512-nluvFy7qjZFq4B6E+KAlKdwdg9fbgJMIe/5O7jveg56gcXZ5Bvgx3lFUxAY016+l907OeX9lIZCNr/Y96FMyEA==
dependencies:
"@turf/helpers" "^4.7.3"
"@turf/invariant" "^4.7.3"

"@turf/distance@^6.3.0", "@turf/distance@^6.5.0":
version "6.5.0"
resolved "https://registry.yarnpkg.com/@turf/distance/-/distance-6.5.0.tgz#21f04d5f86e864d54e2abde16f35c15b4f36149a"
integrity sha512-xzykSLfoURec5qvQJcfifw/1mJa+5UwByZZ5TZ8iaqjGYN0vomhV9aiSLeYdUGtYRESZ+DYC/OzY+4RclZYgMg==
dependencies:
"@turf/helpers" "^6.5.0"
"@turf/invariant" "^6.5.0"

"@turf/helpers@^4.7.3":
version "4.7.3"
resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-4.7.3.tgz#bc312ac43cab3c532a483151c4c382c5649429e9"
integrity sha512-hk5ANVazb80zK6tjJYAG76oCRTWMQo6SAFu5E1dVnlb2kT3FHLoPcOB9P11duwDafMwywz24KZ+FUorB5e728w==

"@turf/helpers@^6.3.0", "@turf/helpers@^6.5.0":
version "6.5.0"
resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-6.5.0.tgz#f79af094bd6b8ce7ed2bd3e089a8493ee6cae82e"
integrity sha512-VbI1dV5bLFzohYYdgqwikdMVpe7pJ9X3E+dlr425wa2/sMJqYDhTO++ec38/pcPvPE6oD9WEEeU3Xu3gza+VPw==

"@turf/invariant@^4.7.3":
version "4.7.3"
resolved "https://registry.yarnpkg.com/@turf/invariant/-/invariant-4.7.3.tgz#538f367d23c113fc849d70c9a524b8563874601d"
integrity sha512-MtlIn9aPC4gZsflLEnfBl/o/SJjZU/yuvj+fo9qRXUOI8wBiKaUcZIT4x1jdLW0NGvU7wMPWJSFJanLCQ9eU1w==

"@turf/invariant@^6.3.0", "@turf/invariant@^6.5.0":
version "6.5.0"
resolved "https://registry.yarnpkg.com/@turf/invariant/-/invariant-6.5.0.tgz#970afc988023e39c7ccab2341bd06979ddc7463f"
integrity sha512-Wv8PRNCtPD31UVbdJE/KVAWKe7l6US+lJItRR/HOEW3eh+U/JwRCSUl/KZ7bmjM/C+zLNoreM2TU6OoLACs4eg==
dependencies:
"@turf/helpers" "^6.5.0"

"@turf/line-arc@^6.5.0":
version "6.5.0"
resolved "https://registry.yarnpkg.com/@turf/line-arc/-/line-arc-6.5.0.tgz#5ca35516ccf1f3a01149889d9facb39a77b07431"
integrity sha512-I6c+V6mIyEwbtg9P9zSFF89T7QPe1DPTG3MJJ6Cm1MrAY0MdejwQKOpsvNl8LDU2ekHOlz2kHpPVR7VJsoMllA==
dependencies:
"@turf/circle" "^6.5.0"
"@turf/destination" "^6.5.0"
"@turf/helpers" "^6.5.0"

"@turf/line-distance@^4.7.3":
version "4.7.3"
resolved "https://registry.yarnpkg.com/@turf/line-distance/-/line-distance-4.7.3.tgz#00a33000e088ee5e3a8d92b7b96bb332af373006"
integrity sha512-U6sFReqpMJq/LhOoDna4w1Vs2gliJUhFa1g94WrZrVz7l4IHldy7Q0Va0CyQ00qN5n3f09/vf4F+q2+ThHbL4g==
dependencies:
"@turf/distance" "^4.7.3"
"@turf/helpers" "^4.7.3"
"@turf/meta" "^4.7.3"

"@turf/meta@^4.7.3":
version "4.7.4"
resolved "https://registry.yarnpkg.com/@turf/meta/-/meta-4.7.4.tgz#6de2f1e9890b8f64b669e4b47c09b20893063977"
integrity sha512-cvwz4EI9BjrgRHxmJ3Z3HKxq6k/fj/V95kwNZ8uWNLncCvrb7x1jUBDkQUo1tShnYdZ8eBgA+a2bvJmAM+MJ0A==

"@turf/meta@^6.5.0":
version "6.5.0"
resolved "https://registry.yarnpkg.com/@turf/meta/-/meta-6.5.0.tgz#b725c3653c9f432133eaa04d3421f7e51e0418ca"
integrity sha512-RrArvtsV0vdsCBegoBtOalgdSOfkBrTJ07VkpiCnq/491W67hnMWmDu7e6Ztw0C3WldRYTXkg3SumfdzZxLBHA==
dependencies:
"@turf/helpers" "^6.5.0"

"@turf/midpoint@^6.5.0":
version "6.5.0"
resolved "https://registry.yarnpkg.com/@turf/midpoint/-/midpoint-6.5.0.tgz#5f9428959309feccaf3f55873a8de70d4121bdce"
integrity sha512-MyTzV44IwmVI6ec9fB2OgZ53JGNlgOpaYl9ArKoF49rXpL84F9rNATndbe0+MQIhdkw8IlzA6xVP4lZzfMNVCw==
dependencies:
"@turf/bearing" "^6.5.0"
"@turf/destination" "^6.5.0"
"@turf/distance" "^6.5.0"
"@turf/helpers" "^6.5.0"

"@types/babel__core@^7.1.0":
version "7.1.14"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.14.tgz#faaeefc4185ec71c389f4501ee5ec84b170cc402"
Expand Down

0 comments on commit 240cc1c

Please sign in to comment.