[gnome-maps/wip/routing2: 2/18] Add Route result model



commit a67ca8fbaa541bb53a2fed9e809dd53ffacabd10
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Thu Aug 22 08:25:04 2013 +0200

    Add Route result model
    
    The Route result model encapsulates all data that makes a route in our
    application.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=728695

 src/gnome-maps.js.gresource.xml |    1 +
 src/route.js                    |  100 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+), 0 deletions(-)
---
diff --git a/src/gnome-maps.js.gresource.xml b/src/gnome-maps.js.gresource.xml
index 07aa483..a46aa9e 100644
--- a/src/gnome-maps.js.gresource.xml
+++ b/src/gnome-maps.js.gresource.xml
@@ -15,6 +15,7 @@
     <file>notification.js</file>
     <file>path.js</file>
     <file>placeStore.js</file>
+    <file>route.js</file>
     <file>searchPopup.js</file>
     <file>settings.js</file>
     <file>sidebar.js</file>
diff --git a/src/route.js b/src/route.js
new file mode 100644
index 0000000..164c6d9
--- /dev/null
+++ b/src/route.js
@@ -0,0 +1,100 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2013 Mattias Bengtsson.
+ *
+ * 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: Mattias Bengtsson <mattias jc bengtsson gmail com>
+ */
+
+const Lang = imports.lang;
+const Champlain = imports.gi.Champlain;
+
+const Utils = imports.utils;
+
+const TurnPointType = {
+    SHARP_LEFT:    0,
+    LEFT:          1,
+    SLIGHT_LEFT:   2,
+    CONTINUE:      3,
+    SLIGHT_RIGHT:  4,
+    RIGHT:         5,
+    SHARP_RIGHT:   6,
+    END:           7,
+    VIA:           8,
+
+    // This one is not in GraphHopper, so choose
+    // a reasonably unlikely number for this
+    START:         10000
+};
+
+const Route = new Lang.Class({
+    Name: 'Route',
+
+    _init: function() {
+        this.reset();
+    },
+
+    update: function({ path, turnPoints, distance, time, bbox }) {
+        this.path = path;
+        this.turnPoints = turnPoints;
+        this.distance = distance;
+        this.time = time;
+        this.bbox = bbox || this._createBBox(path);
+        // TODO: check that the data passed actually means we have a new route
+        this.emit('update');
+    },
+
+    reset: function() {
+        this.path = [];
+        this.turnPoints = [];
+        this.distance = 0;
+        this.time = 0;
+        this.bbox = null;
+        this.emit('reset');
+    },
+
+    _createBBox: function(coordinates) {
+        let bbox = new Champlain.BoundingBox();
+        coordinates.forEach(function({ latitude, longitude }) {
+            bbox.extend(latitude, longitude);
+        }, this);
+        return bbox;
+    }
+});
+Utils.addSignalMethods(Route.prototype);
+
+const TurnPoint = new Lang.Class({
+    Name: 'TurnPoint',
+
+    _init: function({ coordinate, type, direction, distance, instruction }) {
+        this.coordinate = coordinate;
+        this._type = type;
+        this.distance = distance;
+        this.instruction = instruction;
+    },
+
+    isDestination: function() {
+        return this._type === TurnPointType.START
+            || this._type === TurnPointType.VIA
+            || this._type === TurnPointType.STOP;
+    },
+
+    getMarker: function() {
+        // TODO: implement (should depend on isDestination above)
+        return undefined;
+    }
+});


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