[gnome-maps/wip/mlundblad/transit-service-discovery: 3/3] WIP: Add transit router



commit eead440cf66bfa5d77409f2e6d86ac5c19259e4d
Author: Marcus Lundblad <ml update uu se>
Date:   Tue Aug 20 22:07:58 2019 +0200

    WIP: Add transit router
    
    Dispatches routing requests to matching
    transit provider.

 src/mapView.js                        |  2 +-
 src/org.gnome.Maps.src.gresource.xml  |  1 +
 src/routingDelegator.js               | 16 +++++++--------
 src/sidebar.js                        | 16 +++++++--------
 src/transitRouter.js                  | 37 +++++++++++++++++++++++++++++++++++
 src/transitplugins/openTripPlanner.js |  3 +--
 6 files changed, 55 insertions(+), 20 deletions(-)
---
diff --git a/src/mapView.js b/src/mapView.js
index 80fdeda..a84eacc 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -262,7 +262,7 @@ var MapView = GObject.registerClass({
 
     _connectRouteSignals() {
         let route = Application.routingDelegator.graphHopper.route;
-        let transitPlan = Application.routingDelegator.openTripPlanner.plan;
+        let transitPlan = Application.routingDelegator.transitRouter.plan;
         let query = Application.routeQuery;
 
         route.connect('update', () => {
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index 0ca0fc2..94e5099 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -90,6 +90,7 @@
     <file>transitOptionsPanel.js</file>
     <file>transitPlan.js</file>
     <file>transitPrintLayout.js</file>
+    <file>transitRouter.js</file>
     <file>transitRouteLabel.js</file>
     <file>transitStopRow.js</file>
     <file>transitWalkMarker.js</file>
diff --git a/src/routingDelegator.js b/src/routingDelegator.js
index 57e956f..37728c7 100644
--- a/src/routingDelegator.js
+++ b/src/routingDelegator.js
@@ -20,7 +20,7 @@
  */
 
 const GraphHopper = imports.graphHopper;
-const OpenTripPlanner = imports.transitplugins.openTripPlanner;
+const TransitRouter = imports.transitRouter;
 const RouteQuery = imports.routeQuery;
 
 const _FALLBACK_TRANSPORTATION = RouteQuery.Transportation.PEDESTRIAN;
@@ -32,16 +32,14 @@ var RoutingDelegator = class RoutingDelegator {
 
         this._transitRouting = false;
         this._graphHopper = new GraphHopper.GraphHopper({ query: this._query });
-        this._openTripPlanner =
-            new OpenTripPlanner.OpenTripPlanner({ query: this._query,
-                                                  graphHopper: this._graphHopper });
+        this._transitRouter = new TransitRouter.TransitRouter({ query: this._query });
         this._query.connect('notify::points', this._onQueryChanged.bind(this));
 
         /* if the query is set to transit mode when it's not available, revert
          * to a fallback mode
          */
         if (this._query.transportation === RouteQuery.Transportation.TRANSIT &&
-            !this._openTripPlanner.enabled) {
+            !this._transitRouter.enabled) {
             this._query.transportation = _FALLBACK_TRANSPORTATION;
         }
     }
@@ -50,8 +48,8 @@ var RoutingDelegator = class RoutingDelegator {
         return this._graphHopper;
     }
 
-    get openTripPlanner() {
-        return this._openTripPlanner;
+    get transitRouter() {
+        return this._transitRouter;
     }
 
     set useTransit(useTransit) {
@@ -60,7 +58,7 @@ var RoutingDelegator = class RoutingDelegator {
 
     reset() {
         if (this._transitRouting)
-            this._openTripPlanner.plan.reset();
+            this._transitRouter.plan.reset();
         else
             this._graphHopper.route.reset();
     }
@@ -68,7 +66,7 @@ var RoutingDelegator = class RoutingDelegator {
     _onQueryChanged() {
         if (this._query.isValid()) {
             if (this._transitRouting) {
-                this._openTripPlanner.fetchFirstResults();
+                this._transitRouter.fetchFirstResults();
             } else {
                 this._graphHopper.fetchRoute(this._query.filledPoints,
                                              this._query.transportation);
diff --git a/src/sidebar.js b/src/sidebar.js
index 1b546a2..1ab1acf 100644
--- a/src/sidebar.js
+++ b/src/sidebar.js
@@ -95,13 +95,13 @@ var Sidebar = GObject.registerClass({
         this._query.addPoint(1);
         this._switchRoutingMode(Application.routeQuery.transportation);
         /* Enable/disable transit mode switch based on the presence of
-         * OpenTripPlanner.
+         * public transit providers.
          * For some reason, setting visible to false in the UI file and
          * dynamically setting visible false here doesn't work, maybe because
          * it's part of a radio group? As a workaround, just remove the button
          * instead.
          */
-        if (!Application.routingDelegator.openTripPlanner.enabled)
+        if (!Application.routingDelegator.transitRouter.enabled)
             this._modeTransitToggle.destroy();
     }
 
@@ -154,7 +154,7 @@ var Sidebar = GObject.registerClass({
             Application.routingDelegator.useTransit = false;
             this._linkButtonStack.visible_child_name = 'graphHopper';
             this._transitRevealer.reveal_child = false;
-            Application.routingDelegator.openTripPlanner.plan.deselectItinerary();
+            Application.routingDelegator.transitRouter.plan.deselectItinerary();
         }
         this._clearInstructions();
     }
@@ -214,7 +214,7 @@ var Sidebar = GObject.registerClass({
 
     _initInstructionList() {
         let route = Application.routingDelegator.graphHopper.route;
-        let transitPlan = Application.routingDelegator.openTripPlanner.plan;
+        let transitPlan = Application.routingDelegator.transitRouter.plan;
 
         route.connect('reset', () => {
             this._clearInstructions();
@@ -341,7 +341,7 @@ var Sidebar = GObject.registerClass({
     }
 
     _showTransitOverview() {
-        let plan = Application.routingDelegator.openTripPlanner.plan;
+        let plan = Application.routingDelegator.transitRouter.plan;
 
         this._transitListStack.visible_child_name = 'overview';
         this._transitHeader.visible_child_name = 'options';
@@ -354,7 +354,7 @@ var Sidebar = GObject.registerClass({
     }
 
     _populateTransitItineraryOverview() {
-        let plan = Application.routingDelegator.openTripPlanner.plan;
+        let plan = Application.routingDelegator.transitRouter.plan;
 
         plan.itineraries.forEach((itinerary) => {
             let row =
@@ -371,7 +371,7 @@ var Sidebar = GObject.registerClass({
     }
 
     _onItineraryActivated(itinerary) {
-        let plan = Application.routingDelegator.openTripPlanner.plan;
+        let plan = Application.routingDelegator.transitRouter.plan;
 
         this._populateTransitItinerary(itinerary);
         this._showTransitItineraryView();
@@ -380,7 +380,7 @@ var Sidebar = GObject.registerClass({
 
     _onMoreActivated(row) {
         row.startLoading();
-        Application.routingDelegator.openTripPlanner.fetchMoreResults();
+        Application.routingDelegator.transitRouter.fetchMoreResults();
     }
 
     _onItineraryOverviewRowActivated(listBox, row) {
diff --git a/src/transitRouter.js b/src/transitRouter.js
new file mode 100644
index 0000000..1cd1a3e
--- /dev/null
+++ b/src/transitRouter.js
@@ -0,0 +1,37 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2019 Marcus Lundblad
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Marcus Lundblad <ml update uu se>
+ */
+
+const TransitPlan = imports.transitPlan;
+
+var TransitRouter = class TransitRoute {
+    constructor() {
+        this._plan = new TransitPlan.Plan();
+    }
+
+    get enabled() {
+        // TODO: should check availablity of transit providers in the service def
+        return true;
+    }
+
+    get plan() {
+        return this._plan;
+    }
+};
diff --git a/src/transitplugins/openTripPlanner.js b/src/transitplugins/openTripPlanner.js
index 7303eb3..b03d819 100644
--- a/src/transitplugins/openTripPlanner.js
+++ b/src/transitplugins/openTripPlanner.js
@@ -30,7 +30,6 @@ const Location = imports.location;
 const Place = imports.place;
 const RouteQuery = imports.routeQuery;
 const Service = imports.service;
-const TransitPlan = imports.transitPlan;
 const Utils = imports.utils;
 
 /**
@@ -128,8 +127,8 @@ var OpenTripPlanner = class OpenTripPlanner {
          * a download when first request
          */
         this._routersUpdatedTimestamp = 0;
+        this._plan = Application.routingDelegator.transitRouter.plan;
         this._query = params.query;
-        this._plan = new TransitPlan.Plan();
         this._baseUrl = this._getBaseUrl();
         this._walkingRoutes = [];
         this._extendPrevious = false;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]