[gnome-maps] Mapview: Add support for showing routes
- From: Mattias Bengtsson <mattiasb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] Mapview: Add support for showing routes
- Date: Fri, 20 Jun 2014 03:02:24 +0000 (UTC)
commit d90af211b6c87d2b53f2369c024e493b7d746b12
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 | 33 +++++++++++++++++++++++++++++++++
1 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/src/mapView.js b/src/mapView.js
index 3ca3a50..19a6f39 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) {
@@ -187,6 +198,28 @@ const MapView = new Lang.Class({
mapLocation.goTo(true);
},
+ showRoute: function(route) {
+ this._routeLayer.remove_all();
+
+ route.path.forEach(this._routeLayer.add_node.bind(this._routeLayer));
+
+ // Animate to the center of the route bounding box
+ // goto() is currently implemented on mapLocation, so we need to go
+ // through some hoops here.
+ let [lat, lon] = route.bbox.get_center();
+ let place = new Geocode.Place({
+ location : new Geocode.Location({ latitude : lat,
+ longitude : lon }),
+ bounding_box : new Geocode.BoundingBox({ top : route.bbox.top,
+ bottom : route.bbox.bottom,
+ left : route.bbox.left,
+ right : route.bbox.right })
+ });
+ let mapLocation = new MapLocation.MapLocation(place, this);
+
+ mapLocation.goTo(true);
+ },
+
_onViewMoved: function() {
this.emit('view-moved');
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]