[gnome-maps/wip/osrm-routing] WIP! List directions



commit d273c7e2a5096059eb19c169bf60a5f969a5c0b4
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Fri Jul 19 18:49:20 2013 +0200

    WIP! List directions

 src/mapView.js |    8 ++++++++
 src/sidebar.js |   45 +++++++++++++++++++++++++++++++++++++++------
 src/sidebar.ui |   28 ++++++++++++++--------------
 3 files changed, 61 insertions(+), 20 deletions(-)
---
diff --git a/src/mapView.js b/src/mapView.js
index e9c4597..0c88d21 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -66,6 +66,8 @@ const MapView = new Lang.Class({
         this.view.connect('notify::longitude', Lang.bind(this, this._onViewMoved));
 
         this._sidebar = new Sidebar.Sidebar();
+        this._sidebar.connect('click-instruction',
+                              this._gotoRouteNode.bind(this));
         this.view.add_child(this._sidebar.actor);
 
         this._markerLayer = new Champlain.MarkerLayer();
@@ -98,6 +100,11 @@ const MapView = new Lang.Class({
         this._sidebar.conceal();
     },
 
+    _gotoRouteNode: function(_, instruction) {
+        log(JSON.stringify(instruction));
+        this.view.go_to(instruction.point.lat,
+                        instruction.point.lng);
+    },
     _routeRequest: function(toLocation) {
         let fromLocation = this._userLocation;
         let router = new osrm.Router();
@@ -149,6 +156,7 @@ const MapView = new Lang.Class({
         }));
     },
 
+    
     setMapType: function(mapType) {
         let source = this._factory.create_cached_source(mapType);
         this.view.set_map_source(source);
diff --git a/src/sidebar.js b/src/sidebar.js
index 13dc9ac..69eb4ed 100644
--- a/src/sidebar.js
+++ b/src/sidebar.js
@@ -31,6 +31,7 @@ const MapView = imports.mapView;
 
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
+const Signals = imports.signals;
 
 const Utils = imports.utils;
 const _ = imports.gettext.gettext;
@@ -45,7 +46,10 @@ const Sidebar = new Lang.Class({
                                                  'reveal-button']);
         this._ui.revealButton.connect('clicked', this.toggle.bind(this));
         this._ui.revealer.show_all();
-
+        this._ui.instructionsList.connect('row-activated', (function(box, row) {
+            this.emit('click-instruction', row.instruction);
+        }).bind(this));
+        
         this.actor = this._createActor();
         this.actor.hide();
         this.conceal();
@@ -78,12 +82,9 @@ const Sidebar = new Lang.Class({
     },
 
     addInstruction: function(instruction) {
-        this._ui.instructionsList.add(new Gtk.ListBoxRow({
-            child: new Gtk.Label({
-                label: instruction.toString()
-            })
+        this._ui.instructionsList.add(new InstructionRow(instruction, {
+            visible: true
         }));
-        log(" * " + instruction.toString());
     },
 
     reveal: function() {
@@ -107,3 +108,35 @@ const Sidebar = new Lang.Class({
         return this._ui.revealer.reveal_child;
     }
 });
+Signals.addSignalMethods(Sidebar.prototype);
+
+const InstructionRow = new Lang.Class({
+    Name: "InstructionRow",
+    Extends: Gtk.ListBoxRow,
+
+    _init: function(instruction, props) {
+        this.parent();
+        
+        this.instruction = instruction;
+
+        for(let key in props) 
+            this[key] = props[key];
+        
+        let box = new Gtk.Box({
+            visible: true,
+            can_focus: false
+        });
+        box.add(new Gtk.Image({
+            stock: "gtk-cdrom",
+            visible: true,
+            can_focus: false
+        }));
+        box.add(new Gtk.Label({
+            visible: true,
+            can_focus: false,
+            label: instruction.toString()
+        }));
+        this.add(box);
+    }
+});
+
diff --git a/src/sidebar.ui b/src/sidebar.ui
index 6d76265..6a35893 100644
--- a/src/sidebar.ui
+++ b/src/sidebar.ui
@@ -1,6 +1,19 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <!-- interface-requires gtk+ 3.6 -->
+  <!-- interface-requires gtk+ 3.10 -->
+  <object class="GtkImage" id="closeImage">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="stock">gtk-close</property>
+  </object>
+  <object class="GdHeaderSimpleButton" id="reveal-button">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="valign">center</property>
+       <style>
+         <class name="osd"/>
+       </style>
+  </object>
   <object class="GdRevealer" id="revealer">
     <property name="orientation">vertical</property>
     <child>
@@ -164,17 +177,4 @@
          </object>
        </child>
   </object>
-  <object class="GtkImage" id="closeImage">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="stock">gtk-close</property>
-  </object>
-  <object class="GdHeaderSimpleButton" id="reveal-button">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="valign">center</property>
-       <style>
-         <class name="osd" />
-       </style>
-  </object>
 </interface>


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