[gnome-maps/wip/routing2: 10/11] Mapview: Add support for showing routes
- From: Mattias Bengtsson <mattiasb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/routing2: 10/11] Mapview: Add support for showing routes
- Date: Mon, 28 Apr 2014 17:13:38 +0000 (UTC)
commit 63e82eb445b6e7d9a57163a49963b8f6f44e5c3c
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/mainWindow.js | 3 ++-
src/mapView.js | 20 +++++++++++++++++++-
2 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 3e3d99d..2847d73 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -64,7 +64,6 @@ const MainWindow = new Lang.Class({
this._overlay = overlay;
ui.appWindow.add(this._overlay);
- this.mapView = new MapView.MapView();
// NOTE: Maybe call these *model?
let routeQuery = new Route.Query();
@@ -86,6 +85,8 @@ const MainWindow = new Lang.Class({
routeModel.reset();
}
}).bind(this));
+
+ this.mapView = new MapView.MapView(routeModel);
overlay.add(this.mapView);
this.mapView.gotoUserLocation(false);
diff --git a/src/mapView.js b/src/mapView.js
index 32f3bfe..287b8b4 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,12 @@ const MapView = new Lang.Class({
this._updateUserLocation();
this.geoclue.connect("location-changed",
this._updateUserLocation.bind(this));
+
+ routeModel.connect('update', (function() {
+ this.showRoute(routeModel);
+ }).bind(this));
+ routeModel.connect('reset',
+ this._routeLayer.remove_all.bind(this._routeLayer));
},
setMapType: function(mapType) {
@@ -185,6 +195,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]