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



commit 04fb7f5a247b0176a4a1335e3e9852eeb41f20b1
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/mapView.js |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
---
diff --git a/src/mapView.js b/src/mapView.js
index 32f3bfe..0a6f6ec 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,10 @@ const MapView = new Lang.Class({
         this._updateUserLocation();
         this.geoclue.connect("location-changed",
                              this._updateUserLocation.bind(this));
+
+        routeModel.connect('update', this.showRoute.bind(this));
+        routeModel.connect('reset',
+                           this._routeLayer.remove_all.bind(this._routeLayer));
     },
 
     setMapType: function(mapType) {
@@ -185,6 +193,14 @@ const MapView = new Lang.Class({
         mapLocation.goTo(true);
     },
 
+    showRoute: function(route) {
+        this._routeLayer.remove_all();
+        route.coordinates.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]