[gnome-maps/wip/mlundblad/transit-routing: 2/26] routeService: Enable querying GraphHopper externally



commit b19a7c60a5c9239fbdd0f12405080f4a2c3ab4f1
Author: Marcus Lundblad <ml update uu se>
Date:   Tue Apr 5 22:00:38 2016 +0200

    routeService: Enable querying GraphHopper externally
    
    Add a way to do a route query without triggering route signals.
    This will be used by the OpenTripPlanner module to use the existing
    GraphHopper services to calculate walking (and maybe
    pontentially in the future car and bike park-and-ride) segments
    in an intinerary.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=755808

 src/routeService.js |   51 ++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 38 insertions(+), 13 deletions(-)
---
diff --git a/src/routeService.js b/src/routeService.js
index 3b0289f..56c6cf0 100644
--- a/src/routeService.js
+++ b/src/routeService.js
@@ -65,35 +65,60 @@ const GraphHopper = new Lang.Class({
         }).bind(this));
     },
 
+    _queryGraphHopper: function(points, transportationType, callback) {
+        let url = this._buildURL(points, transportationType);
+        let msg = Soup.Message.new('GET', url);
+        this._session.queue_message(msg, (function(session, message) {
+            try {
+                let result = this._parseMessage(message);
+                if (!result)
+                    callback(null, null);
+                else
+                    callback(result, null);
+            } catch (e) {
+                callback(null, e);
+            }
+        }).bind(this));
+    },
+
     fetchRoute: function(points, transportationType) {
         if (this.storedRoute) {
             this._updateFromStored();
             return;
         }
 
-        let url = this._buildURL(points, transportationType);
-        let msg = Soup.Message.new('GET', url);
-        this._session.queue_message(msg, (function(session, message) {
-            try {
-                let result = this._parseMessage(message);
+        this._queryGraphHopper(points, transportationType,
+                               (function(result, exception) {
+            if (exception) {
+                Application.notificationManager.showMessage(_("Route request failed."));
+                Utils.debug(e);
+                if (this._query.latest)
+                    this._query.latest.place = null;
+                else
+                    this.route.reset();
+            } else {
                 if (!result) {
                     Application.notificationManager.showMessage(_("No route found."));
                     if (this._query.latest)
                         this._query.latest.place = null;
                     else
                         this.route.reset();
-
                 } else {
                     let route = this._createRoute(result.paths[0]);
                     this.route.update(route);
                 }
-            } catch(e) {
-                Application.notificationManager.showMessage(_("Route request failed."));
-                Utils.debug(e);
-                if (this._query.latest)
-                    this._query.latest.place = null;
-                else
-                    this.route.reset();
+            }
+        }).bind(this));
+    },
+
+    fetchRouteAsync: function(points, transportationType, callback) {
+        this._queryGraphHopper(points, transportationType,
+                               (function(result, exception) {
+            if (result) {
+                let route = this._createRoute(result.paths[0]);
+                callback(route, exception);
+            } else {
+                callback(null, exception);
             }
         }).bind(this));
     },


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