[gnome-maps/wip/routing2: 9/10] Mapview: Add support for showing routes



commit 89489dba91f1dc34b8af2a6bd1049f1e2ffe4df1
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Tue Apr 22 04:58:38 2014 +0200

    Mapview: Add support for showing routes
    
    Connect to the route model and when it changes also update the map.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=728695

 src/mapView.js |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/src/mapView.js b/src/mapView.js
index 32f3bfe..d4569e1 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -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,13 @@ const MapView = new Lang.Class({
         this._updateUserLocation();
         this.geoclue.connect("location-changed",
                              this._updateUserLocation.bind(this));
+
+        this._connectRouteSignals(Application.routeService.route);
+    },
+
+    _connectRouteSignals: function(route) {
+        route.connect('update', this.showRoute.bind(this, route));
+        route.connect('reset', this._routeLayer.remove_all.bind(this._routeLayer));
     },
 
     setMapType: function(mapType) {
@@ -185,6 +196,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]