[gnome-maps/wip/routing3: 9/9] MapView: add support for showing routes



commit 78bfa1d7e6553f2b42862dfa4c8828a2fc2e5766
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Fri Aug 30 03:02:30 2013 +0200

    MapView: add support for showing routes
    
    WIP! Add:
      * clearing of routes

 src/mainWindow.js |   17 ++++++++++++++---
 src/mapView.js    |   20 +++++++++++++++++++-
 2 files changed, 33 insertions(+), 4 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index d53d784..cd66fac 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -73,10 +73,11 @@ const MainWindow = new Lang.Class({
                 Application.routeService.getRoute([routeQuery.from, routeQuery.to],
                                                   routeQuery.transportation,
                                                   (function(err, result) {
-                                                      if(!err)
+                                                      if(!err) {
                                                           routeModel.update(result);
-                                                      else
-                                                          log("Couldn't do route'");
+                                                      } else {
+                                                          log(err);
+                                                      }
                                                   }));
             } else {
                 // TODO: implement
@@ -100,6 +101,16 @@ const MainWindow = new Lang.Class({
 
         this._overlay.add_overlay(new ZoomControl.ZoomControl(this.mapView));
         this._overlay.show_all();
+
+        const Geocode = imports.gi.GeocodeGlib;
+        let berlin = new Geocode.Location({ latitude: 52.536273, longitude: 13.007813 });
+        let kiev = new Geocode.Location({ latitude:50.289339, longitude: 30.761719 });
+        let other = new Geocode.Location({ latitude:51.289339, longitude: 31.761719 });
+
+        routeQuery.setMany({ from: berlin, to: kiev });
+        Mainloop.timeout_add(10000, (function() {
+            routeQuery.setMany({ from: kiev, to: other });
+        }));
     },
 
     _initSearchWidgets: function() {
diff --git a/src/mapView.js b/src/mapView.js
index 32f3bfe..287b8b4 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -55,7 +55,7 @@ const MapView = new Lang.Class({
     Name: 'MapView',
     Extends: GtkChamplain.Embed,
 
-    _init: function() {
+    _init: function(routeModel) {
         this.parent();
 
         this.actor = this.get_view();
@@ -72,6 +72,10 @@ const MapView = new Lang.Class({
         // Don't show sidebar until it has something in it
         //this.view.add_child(this._sidebar.actor);
 
+        this._routeLayer = new Champlain.PathLayer();
+        this._routeLayer.set_stroke_width(2.0);
+        this.view.add_layer(this._routeLayer);
+
         this._markerLayer = new Champlain.MarkerLayer();
         this._markerLayer.set_selection_mode(Champlain.SelectionMode.SINGLE);
         this.view.add_layer(this._markerLayer);
@@ -95,6 +99,12 @@ const MapView = new Lang.Class({
         this._updateUserLocation();
         this.geoclue.connect("location-changed",
                              this._updateUserLocation.bind(this));
+
+        routeModel.connect('update', (function() {
+            this.showRoute(routeModel);
+        }).bind(this));
+        routeModel.connect('reset',
+                           this._routeLayer.remove_all.bind(this._routeLayer));
     },
 
     setMapType: function(mapType) {
@@ -185,6 +195,14 @@ const MapView = new Lang.Class({
         mapLocation.goTo(true);
     },
 
+    showRoute: function(route) {
+        this._routeLayer.remove_all();
+        route.path.forEach(function(coordinate) {
+            this._routeLayer.add_node(coordinate);
+        }, this);
+        this.view.ensure_visible(route.bbox, true);
+    },
+
     _onViewMoved: function() {
         this.emit('view-moved');
     }


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