[gnome-maps/wip/routing2: 7/9] RouteService: hook up with models



commit 5a4b5fb61a84c0fd536567e7c7f87287ba8c3391
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Sun Apr 20 03:51:45 2014 +0200

    RouteService: hook up with models
    
    Make the route service a global service and hook it up with the query-
    and result models.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=728695

 src/application.js |    3 +++
 src/mainWindow.js  |   24 +++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index ae00dda..a78fc78 100644
--- a/src/application.js
+++ b/src/application.js
@@ -40,12 +40,14 @@ const Utils = imports.utils;
 const Path = imports.path;
 const Settings = imports.settings;
 const PlaceStore = imports.placeStore;
+const RouteService = imports.routeService;
 
 // used globally
 let application = null;
 let settings = null;
 let placeStore = null;
 let notificationManager = null;
+let routeService = null;
 
 const Application = new Lang.Class({
     Name: 'Application',
@@ -93,6 +95,7 @@ const Application = new Lang.Class({
 
         application = this;
         settings = new Settings.Settings('org.gnome.maps');
+        routeService = new RouteService.GraphHopper();
 
         Utils.initActions(this, [{
             properties: { name: 'quit' },
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 01d37b5..3e3d99d 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -38,6 +38,8 @@ const PlaceStore = imports.placeStore;
 const Utils = imports.utils;
 const Config = imports.config;
 const ZoomControl = imports.zoomControl;
+const RouteService = imports.routeService;
+const Route = imports.route;
 
 const _ = imports.gettext.gettext;
 
@@ -62,8 +64,28 @@ const MainWindow = new Lang.Class({
         this._overlay = overlay;
 
         ui.appWindow.add(this._overlay);
-
         this.mapView = new MapView.MapView();
+
+        // NOTE: Maybe call these *model?
+        let routeQuery = new Route.Query();
+        let routeModel = new Route.Route();
+        routeQuery.connect('change', (function() {
+            if(routeQuery.from && routeQuery.to) {
+                Application.routeService.getRoute([routeQuery.from, routeQuery.to],
+                                                  routeQuery.transportation,
+                                                  (function(err, result) {
+                                                      if(!err) {
+                                                          routeModel.update(result);
+                                                      } else {
+                                                          log(err);
+                                                      }
+                                                  }));
+            } else {
+                // TODO: implement
+                // NOTE: think about whether we should reset here
+                routeModel.reset();
+            }
+        }).bind(this));
         overlay.add(this.mapView);
 
         this.mapView.gotoUserLocation(false);


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