summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Lundblad <ml@update.uu.se>2019-09-23 21:21:15 +0200
committerMarcus Lundblad <ml@update.uu.se>2019-09-23 21:22:11 +0200
commitcbcf63f034ce94062f173ce64d68bd253d2ca2fe (patch)
tree30b7f9f15d94046c02a532ea605935829a839fa4
parentafcc207aa9d413bfb027e8924283de7c9eb9e07b (diff)
downloadgnome-maps-wip/mlundblad/otp-fixed-router.tar.gz
transitRouter: Fix provider matching algorithmwip/mlundblad/otp-fixed-router
Fix matching algorithm in the multiple-areas for a router case. Fixes #208
-rw-r--r--src/transitRouter.js74
1 files changed, 49 insertions, 25 deletions
diff --git a/src/transitRouter.js b/src/transitRouter.js
index 30e73405..adf3b231 100644
--- a/src/transitRouter.js
+++ b/src/transitRouter.js
@@ -105,21 +105,9 @@ var TransitRouter = class TransitRoute {
return null;
}
- /**
- * Get the most preferred provider for a given query.
- * Return: an array with the provider definition and the plugin instance,
- * or null if no matching provider was found.
- */
- _getBestProviderForQuery() {
- let startLocation = this._query.filledPoints[0].place.location;
- let endLocation =
- this._query.filledPoints[this._query.points.length - 1].place.location;
- let startCountry =
- Utils.getCountryCodeForCoordinates(startLocation.latitude,
- startLocation.longitude);
- let endCountry =
- Utils.getCountryCodeForCoordinates(endLocation.latitude,
- endLocation.longitude);
+ _getMatchingProvidersForLocation(location) {
+ let country = Utils.getCountryCodeForCoordinates(location.latitude,
+ location.longitude);
let matchingProviders = [];
@@ -144,9 +132,8 @@ var TransitRouter = class TransitRoute {
let countries = area.countries;
if (countries) {
- if (countries.includes(startCountry) &&
- countries.includes(endCountry)) {
- matchingProviders.push(provider);
+ if (countries.includes(country)) {
+ matchingProviders[provider.name] = provider;
return;
}
}
@@ -165,19 +152,56 @@ var TransitRouter = class TransitRoute {
top: x2,
right: y2 });
- if (cbbox.covers(startLocation.latitude,
- startLocation.longitude) &&
- cbbox.covers(endLocation.latitude,
- endLocation.longitude)) {
- matchingProviders.push(provider);
+ if (cbbox.covers(location.latitude,
+ location.longitude)) {
+ matchingProviders[provider.name] = provider;
return;
}
}
});
});
- if (matchingProviders.length === 0)
- return null;
+ Utils.debug('returning matching providers: ' + matchingProviders.length);
+ return matchingProviders;
+ }
+
+ /**
+ * Get the most preferred provider for a given query.
+ * Return: an array with the provider definition and the plugin instance,
+ * or null if no matching provider was found.
+ */
+ _getBestProviderForQuery() {
+ let startLocation = this._query.filledPoints[0].place.location;
+ let endLocation =
+ this._query.filledPoints[this._query.points.length - 1].place.location;
+
+ let matchingProvidersForStart =
+ this._getMatchingProvidersForLocation(startLocation);
+ let matchingProvidersForEnd =
+ this._getMatchingProvidersForLocation(endLocation);
+
+ let matchingProviders = [];
+
+ // check all candidate providers matching on the start location
+ for (let name in matchingProvidersForStart) {
+ let providerAtStart = matchingProvidersForStart[name];
+ let providerAtEnd = matchingProvidersForEnd[name];
+
+ /* if the provider also matches on the end location, consider it
+ * as a potential candidate
+ */
+ if (providerAtEnd) {
+ let order = this._sortProviders(providerAtStart, providerAtEnd);
+
+ /* add the provider at it lowest priority to favor higher
+ * priority providers in "fringe cases"
+ */
+ if (order < 0)
+ matchingProviders.push(providerAtStart);
+ else
+ matchingProviders.push(providerAtEnd);
+ }
+ }
matchingProviders.sort(this._sortProviders);