[gnome-maps/wip/mlundblad/transit-routing: 6/17] routeService: WIP, Enable querying GraphHopper externally



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

    routeService: WIP, 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.

 src/routeService.js |   43 ++++++++++++++++++++++++++++++-------------
 1 files changed, 30 insertions(+), 13 deletions(-)
---
diff --git a/src/routeService.js b/src/routeService.js
index d887c31..385c9c9 100644
--- a/src/routeService.js
+++ b/src/routeService.js
@@ -79,39 +79,56 @@ 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, callback);
+    },
+
     _buildURL: function(points, transportation) {
         let locations = points.map(function(point) {
             return [point.place.location.latitude, point.place.location.longitude].join(',');


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