[gnome-maps] routing: New markers for turnpoint
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] routing: New markers for turnpoint
- Date: Tue, 2 Sep 2014 15:47:05 +0000 (UTC)
commit aa60ff6772d55350b6b2dde879977c3cb4e37f36
Author: Dario Di Nucci <linkin88mail gmail com>
Date: Tue Jul 29 16:03:16 2014 +0200
routing: New markers for turnpoint
These markers are shown if a turnpoint is a stop.
The markers are draggable and after drag is finished a
new route is calculated and shown.
https://bugzilla.gnome.org/show_bug.cgi?id=731068
src/gnome-maps.data.gresource.xml | 1 +
src/gnome-maps.js.gresource.xml | 2 +
src/mapView.js | 36 +++++++++++-
src/route.js | 10 ++-
src/turn-point-bubble.ui | 49 +++++++++++++++
src/turnPointBubble.js | 57 +++++++++++++++++
src/turnPointMarker.js | 122 +++++++++++++++++++++++++++++++++++++
7 files changed, 272 insertions(+), 5 deletions(-)
---
diff --git a/src/gnome-maps.data.gresource.xml b/src/gnome-maps.data.gresource.xml
index 6add0c0..b9beff2 100644
--- a/src/gnome-maps.data.gresource.xml
+++ b/src/gnome-maps.data.gresource.xml
@@ -12,6 +12,7 @@
<file preprocess="xml-stripblanks">notification.ui</file>
<file preprocess="xml-stripblanks">route-via-row.ui</file>
<file preprocess="xml-stripblanks">search-result-bubble.ui</file>
+ <file preprocess="xml-stripblanks">turn-point-bubble.ui</file>
<file preprocess="xml-stripblanks">user-location-bubble.ui</file>
<file alias="application.css">../data/gnome-maps.css</file>
<file alias="zoom-in.png">../data/media/zoom-in.png</file>
diff --git a/src/gnome-maps.js.gresource.xml b/src/gnome-maps.js.gresource.xml
index 9343fee..5e8ef6d 100644
--- a/src/gnome-maps.js.gresource.xml
+++ b/src/gnome-maps.js.gresource.xml
@@ -26,6 +26,8 @@
<file>searchPopup.js</file>
<file>searchResultBubble.js</file>
<file>searchResultMarker.js</file>
+ <file>turnPointBubble.js</file>
+ <file>turnPointMarker.js</file>
<file>settings.js</file>
<file>sidebar.js</file>
<file>userLocationMarker.js</file>
diff --git a/src/mapView.js b/src/mapView.js
index e760aac..7504e44 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -38,6 +38,7 @@ const Utils = imports.utils;
const Path = imports.path;
const MapWalker = imports.mapWalker;
const SearchResultMarker = imports.searchResultMarker;
+const TurnPointMarker = imports.turnPointMarker;
const UserLocationMarker = imports.userLocationMarker;
const _ = imports.gettext.gettext;
@@ -102,13 +103,20 @@ const MapView = new Lang.Class({
this._searchResultLayer = new Champlain.MarkerLayer({ selection_mode: mode });
this.view.add_layer(this._searchResultLayer);
+ this._instructionMarkerLayer = new Champlain.MarkerLayer({ selection_mode: mode });
+ this.view.add_layer(this._instructionMarkerLayer);
+
this._userLocationLayer = new Champlain.MarkerLayer({ selection_mode: mode });
this.view.add_layer(this._userLocationLayer);
},
_connectRouteSignals: function(route) {
route.connect('update', this.showRoute.bind(this, route));
- route.connect('reset', this._routeLayer.remove_all.bind(this._routeLayer));
+ route.connect('reset', (function() {
+ this._routeLayer.remove_all();
+ this._instructionMarkerLayer.remove_all();
+ }).bind(this));
+
},
setMapType: function(mapType) {
@@ -157,6 +165,13 @@ const MapView = new Lang.Class({
this.emit('user-location-changed');
},
+ showTurnPoint: function(turnPoint) {
+ let instructionMarker = new TurnPointMarker.InstructionMarker({ turnPoint: turnPoint,
+ mapView: this });
+ this._instructionMarkerLayer.add_marker(instructionMarker);
+ instructionMarker.goToAndSelect(false);
+ },
+
showSearchResult: function(place) {
this._searchResultLayer.remove_all();
let searchResultMarker = new SearchResultMarker.SearchResultMarker({ place: place,
@@ -183,9 +198,28 @@ const MapView = new Lang.Class({
right : route.bbox.right })
});
+ this._showDestinationTurnpoints();
new MapWalker.MapWalker(place, this).goTo(true);
},
+ _showDestinationTurnpoints: function() {
+ let route = Application.routeService.route;
+ let query = Application.routeService.query;
+ let pointIndex = 0;
+
+ this._instructionMarkerLayer.remove_all();
+ route.turnPoints.forEach(function(turnPoint) {
+ if (turnPoint.isStop()) {
+ let queryPoint = query.filledPoints[pointIndex];
+ let destinationMarker = new TurnPointMarker.DestinationMarker({ turnPoint: turnPoint,
+ queryPoint: queryPoint,
+ mapView: this });
+ this._instructionMarkerLayer.add_marker(destinationMarker);
+ pointIndex++;
+ }
+ }, this);
+ },
+
_onViewMoved: function() {
this.emit('view-moved');
},
diff --git a/src/route.js b/src/route.js
index 8775443..7fbf0ad 100644
--- a/src/route.js
+++ b/src/route.js
@@ -88,10 +88,14 @@ const TurnPoint = new Lang.Class({
this.iconResource = this._getIconResource();
},
- isDestination: function() {
+ get type() {
+ return this._type;
+ },
+
+ isStop: function() {
return this._type === TurnPointType.START
|| this._type === TurnPointType.VIA
- || this._type === TurnPointType.STOP;
+ || this._type === TurnPointType.END;
},
_getIconResource: function() {
@@ -103,8 +107,6 @@ const TurnPoint = new Lang.Class({
case TurnPointType.SLIGHT_RIGHT: return '/org/gnome/maps/direction-slightright';
case TurnPointType.RIGHT: return '/org/gnome/maps/direction-right';
case TurnPointType.SHARP_RIGHT: return '/org/gnome/maps/direction-sharpright';
- case TurnPointType.END: return '/org/gnome/maps/direction-end';
- case TurnPointType.START: return '/org/gnome/maps/direction-start';
default: return '';
}
}
diff --git a/src/turn-point-bubble.ui b/src/turn-point-bubble.ui
new file mode 100644
index 0000000..7fa0603
--- /dev/null
+++ b/src/turn-point-bubble.ui
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+ <requires lib="gtk+" version="3.12"/>
+ <object class="GtkGrid" id="grid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_start">10</property>
+ <property name="margin_end">15</property>
+ <property name="margin_top">10</property>
+ <property name="margin_bottom">15</property>
+ <child>
+ <object class="GtkImage" id="image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="valign">start</property>
+ <property name="margin_top">5</property>
+ <property name="pixel_size">0</property>
+ <property name="icon_size">0</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="box-right">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_start">15</property>
+ <child>
+ <object class="GtkLabel" id="label-title">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="vexpand">True</property>
+ <style>
+ <class name="bubble-title"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ </object>
+</interface>
diff --git a/src/turnPointBubble.js b/src/turnPointBubble.js
new file mode 100644
index 0000000..e29ccfc
--- /dev/null
+++ b/src/turnPointBubble.js
@@ -0,0 +1,57 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2014 Dario Di Nucci
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Dario Di Nucci <linkin88mail gmail com>
+ */
+
+const Geocode = imports.gi.GeocodeGlib;
+const Gtk = imports.gi.Gtk;
+
+const Lang = imports.lang;
+
+const MapBubble = imports.mapBubble;
+const Utils = imports.utils;
+
+const TurnPointBubble = new Lang.Class({
+ Name: "TurnPointBubble",
+ Extends: MapBubble.MapBubble,
+
+ _init: function(params) {
+ let icon = params.icon;
+ delete params.icon;
+
+ let turnPoint = params.turnPoint;
+ delete params.turnPoint;
+
+ this.parent(params);
+
+ let ui = Utils.getUIObject('turn-point-bubble', [ 'grid',
+ 'box-right',
+ 'image',
+ 'label-title' ]);
+ if (icon)
+ ui.image.icon_name = icon;
+ else
+ ui.image.resource = turnPoint.iconResource;
+
+ ui.labelTitle.label = turnPoint.instruction;
+
+ this.add(ui.grid);
+ }
+});
diff --git a/src/turnPointMarker.js b/src/turnPointMarker.js
new file mode 100644
index 0000000..1ca085c
--- /dev/null
+++ b/src/turnPointMarker.js
@@ -0,0 +1,122 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2014 Dario Di Nucci
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Dario Di Nucci <linkin88mail gmail com>
+ */
+
+const Geocode = imports.gi.GeocodeGlib;
+const GObject = imports.gi.GObject;
+
+const Lang = imports.lang;
+
+const Application = imports.application;
+const MapMarker = imports.mapMarker;
+const Path = imports.path;
+const Route = imports.route;
+const TurnPointBubble = imports.turnPointBubble;
+const Utils = imports.utils;
+
+const TurnPointMarker = new Lang.Class({
+ Name: 'TurnPointMarker',
+ Extends: MapMarker.MapMarker,
+
+ get iconName() {
+ switch(this._turnPoint.type) {
+ case Route.TurnPointType.START: return 'maps-point-start';
+ case Route.TurnPointType.END: return 'maps-point-end';
+ case Route.TurnPointType.VIA: return 'maps-point-end';
+ default: return null;
+ }
+ },
+
+ get turnPoint() {
+ return this._turnPoint;
+ },
+
+ _init: function(params) {
+ this._turnPoint = params.turnPoint
+ delete params.turnPoint;
+
+ params.place = new Geocode.Place({
+ location: new Geocode.Location({
+ latitude: this._turnPoint.coordinate.get_latitude(),
+ longitude: this._turnPoint.coordinate.get_longitude()
+ })
+ });
+
+ this.parent(params);
+ },
+
+ get anchor() {
+ return { x: Math.floor(this.width / 2) - 1,
+ y: Math.floor(this.height / 2) - 1 };
+ },
+
+ _createBubble: function() {
+ return new TurnPointBubble.TurnPointBubble({ icon: this.iconName,
+ turnPoint: this.turnPoint,
+ place: this.place,
+ mapView: this._mapView });
+ }
+});
+
+const InstructionMarker = new Lang.Class({
+ Name: 'InstructionMarker',
+ Extends: TurnPointMarker,
+
+ _init: function(params) {
+ this.parent(params);
+
+ this.bubble.connect_after('closed', (function() {
+ this.destroy();
+ }).bind(this));
+ }
+});
+
+const DestinationMarker = new Lang.Class({
+ Name: 'DestinationMarker',
+ Extends: TurnPointMarker,
+
+ _init: function(params) {
+ this._queryPoint = params.queryPoint;
+ delete params.queryPoint;
+
+ this.parent(params);
+
+ this.draggable = true;
+
+ this.connect('drag-finish', (function() {
+ this._onMarkerDrag();
+ }).bind(this));
+
+ let iconName = Path.ICONS_DIR + '/' + this.iconName + '.svg';
+ this.add_actor(Utils.CreateActorFromImageFile(iconName));
+ },
+
+ _onMarkerDrag: function() {
+ let query = Application.routeService.query;
+ let name = '[' + this.latitude.toFixed(3) + ', ' + this.longitude.toFixed(3) + ']';
+ let place = new Geocode.Place({
+ name: name,
+ location: new Geocode.Location({ latitude: this.latitude,
+ longitude: this.longitude }) });
+
+ this._queryPoint.place = place;
+ }
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]