[gnome-maps/wip/mlundblad/transit-routing: 5/5] mapView: WIP, implement showing transit routes



commit 17dc5b3c5936a7deff9c6771b76563bd6b54a243
Author: Marcus Lundblad <ml update uu se>
Date:   Tue Mar 29 23:10:22 2016 +0200

    mapView: WIP, implement showing transit routes

 src/mapView.js |   37 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)
---
diff --git a/src/mapView.js b/src/mapView.js
index e8db3bb..5760616 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -39,6 +39,7 @@ const Maps = imports.gi.GnomeMaps;
 const MapWalker = imports.mapWalker;
 const Place = imports.place;
 const PlaceMarker = imports.placeMarker;
+const RouteQuery = imports.routeQuery;
 const ShapeLayer = imports.shapeLayer;
 const StoredRoute = imports.storedRoute;
 const TurnPointMarker = imports.turnPointMarker;
@@ -93,6 +94,10 @@ const MapView = new Lang.Class({
 
         this._routeLayer.visible = value && isValid;
         this._instructionMarkerLayer.visible = value && isValid;
+        if (Application.routeQuery.transportation === RouteQuery.Transportation.TRANSIT)
+            this._walkingRouteLayer.visible = value && isValid;
+        else
+            this._walkingRouteLayer.visible = false;
         this.notify('routeVisible');
     },
 
@@ -171,7 +176,10 @@ const MapView = new Lang.Class({
         this._routeLayer = new Champlain.PathLayer({ stroke_width: 5.0,
                                                      stroke_color: strokeColor });
         this.view.add_layer(this._routeLayer);
-
+        this._walkingRouteLayer = new Champlain.PathLayer({ stroke_width: 5.0,
+                                                            stroke_color: strokeColor});
+        this._walkingRouteLayer.set_dash([5, 5]);
+        this.view.add_layer(this._walkingRouteLayer);
 
         this._placeLayer = new Champlain.MarkerLayer({ selection_mode: mode });
         this.view.add_layer(this._placeLayer);
@@ -189,6 +197,7 @@ const MapView = new Lang.Class({
 
     _connectRouteSignals: function() {
         let route = Application.routeService.route;
+        let transitPlan = Application.openTripPlanner.plan;
         let query = Application.routeQuery;
 
         route.connect('update', this.showRoute.bind(this, route));
@@ -196,6 +205,11 @@ const MapView = new Lang.Class({
             this._routeLayer.remove_all();
             this._instructionMarkerLayer.remove_all();
         }).bind(this));
+        transitPlan.connect('update', this.showTransitPlan.bind(this, transitPlan));
+        transitPlan.connect('reset', (function() {
+            this._routeLayer.remove_all();
+            this._instructionMarkerLayer.remove_all();
+        }).bind(this));
 
         query.connect('notify', (function() {
                 this.routeVisible = query.isValid();
@@ -481,6 +495,27 @@ const MapView = new Lang.Class({
         }, this);
     },
 
+    showTransitPlan: function(plan) {
+        this._routeLayer.remove_all();
+        this._walkingRouteLayer.remove_all();
+        this._placeLayer.remove_all();
+        this._instructionMarkerLayer.remove_all();
+
+        this.routeVisible = true;
+        Utils.debug('showing transit plan…');
+
+        /* TODO: for now always show the first itinerary */
+        let itinerary = plan.itineraries[0];
+        itinerary.legs.forEach((function(leg) {
+            if (leg.transit)
+                leg.polyline.forEach(this._routeLayer.add_node.bind(this._routeLayer));
+            else
+                leg.polyline.forEach(this._walkingRouteLayer.add_node.bind(this._walkingRouteLayer));
+        }).bind(this));
+
+        this.gotoBBox(plan.bbox);
+    },
+
     _onViewMoved: function() {
         this.emit('view-moved');
         if (this._storeId !== 0)


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