[gnome-maps/wip/mlundblad/transit-routing: 10/17] Add map marker for marking boarding points in transit itineraries



commit 6402620216f98ef96f53d62631f0699341c0de5d
Author: Marcus Lundblad <ml update uu se>
Date:   Wed Jun 15 23:24:42 2016 +0200

    Add map marker for marking boarding points in transit itineraries
    
    https://bugzilla.gnome.org/show_bug.cgi?id=755808

 src/org.gnome.Maps.src.gresource.xml |    1 +
 src/transitBoardMarker.js            |  131 ++++++++++++++++++++++++++++++++++
 2 files changed, 132 insertions(+), 0 deletions(-)
---
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index 0d4bb21..ab77571 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -77,6 +77,7 @@
     <file>togeojson/togeojson.js</file>
     <file>transitArrivalMarker.js</file>
     <file>transitArrivalRow.js</file>
+    <file>transitBoardMarker.js</file>
     <file>transitItineraryRow.js</file>
     <file>transitLegRow.js</file>
     <file>transitMoreRow.js</file>
diff --git a/src/transitBoardMarker.js b/src/transitBoardMarker.js
new file mode 100644
index 0000000..7c8cedb
--- /dev/null
+++ b/src/transitBoardMarker.js
@@ -0,0 +1,131 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2016 Marcus Lundblad
+ *
+ * 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: Marcus Lundblad <ml update uu se>
+ */
+
+const Lang = imports.lang;
+
+const Cairo = imports.cairo;
+const Clutter = imports.gi.Clutter;
+const Gdk = imports.gi.Gdk;
+const Gtk = imports.gi.Gtk;
+
+const Location = imports.location;
+const MapMarker = imports.mapMarker;
+const Place = imports.place;
+const Utils = imports.utils;
+
+const ICON_SIZE = 12;
+const ACTOR_SIZE = 20;
+
+/* threashhold for route color luminance when we consider it more or less
+ * as white, and draw an outline around the label */
+const OUTLINE_LUMINANCE_THREASHHOLD = 0.9;
+
+const TransitBoardMarker = new Lang.Class({
+    Name: 'TransitBoardMarker',
+    Extends: MapMarker.MapMarker,
+
+    _init: function(params) {
+        this._leg = params.leg;
+        delete params.leg;
+
+        let firstPoint = this._leg.polyline[0];
+        let location =
+            new Location.Location({ latitude: firstPoint.get_latitude(),
+                                    longitude: firstPoint.get_longitude() });
+
+        params.place = new Place.Place({ location: location });
+        this.parent(params);
+
+        let actor = this._createActor();
+
+        this.add_actor(actor);
+    },
+
+    _createActor: function() {
+        try {
+            let bgColor = this._leg.color ? this._leg.color : '000000';
+            let fgColor =
+                Utils.getContrastingForegroundColor(bgColor, this._leg.textColor ?
+                                                             this._leg.textColor :
+                                                             'ffffff');
+            let hasOutline =
+                Utils.relativeLuminance(bgColor) > OUTLINE_LUMINANCE_THREASHHOLD;
+            let bgRed = parseInt(bgColor.substring(0, 2), 16) / 255;
+            let bgGreen = parseInt(bgColor.substring(2, 4), 16) / 255;
+            let bgBlue = parseInt(bgColor.substring(4, 6), 16) / 255;
+            let fgRed = parseInt(fgColor.substring(0, 2), 16) / 255;
+            let fgGreen = parseInt(fgColor.substring(2, 4), 16) / 255;
+            let fgBlue = parseInt(fgColor.substring(4, 6), 16) / 255;
+            let fgRGBA = new Gdk.RGBA({ red: fgRed,
+                                        green: fgGreen,
+                                        blue: fgBlue,
+                                        alpha: 1.0 });
+            let theme = Gtk.IconTheme.get_default();
+            let info = theme.lookup_icon(this._leg.iconName, ICON_SIZE,
+                                         Gtk.IconLookupFlags.FORCE_SIZE);
+            let pixbuf = info.load_symbolic(fgRGBA, null, null, null, null, null)[0];
+            let canvas = new Clutter.Canvas({ width: ACTOR_SIZE,
+                                              height: ACTOR_SIZE });
+
+
+            canvas.connect('draw', (function(canvas, cr) {
+                cr.setOperator(Cairo.Operator.CLEAR);
+                cr.paint();
+                cr.setOperator(Cairo.Operator.OVER);
+
+                cr.setSourceRGB(bgRed, bgGreen, bgBlue);
+                cr.arc(ACTOR_SIZE / 2, ACTOR_SIZE / 2, ACTOR_SIZE / 2,
+                       0, Math.PI * 2);
+                cr.fillPreserve();
+
+                Gdk.cairo_set_source_pixbuf(cr, pixbuf,
+                                            (ACTOR_SIZE - pixbuf.get_width()) / 2,
+                                            (ACTOR_SIZE - pixbuf.get_height()) / 2);
+                cr.paint();
+
+                if (hasOutline) {
+                    cr.setSourceRGB(fgRed, fgGreen, fgBlue);
+                    cr.setLineWidth(1);
+                    cr.stroke();
+                }
+
+                this._surface = cr.getTarget();
+            }).bind(this));
+
+            let actor = new Clutter.Actor();
+
+            actor.set_content(canvas);
+            actor.set_size(ACTOR_SIZE, ACTOR_SIZE);
+            canvas.invalidate();
+
+            return actor;
+        } catch (e) {
+            Utils.debug('Failed to load image: %s'.format(e.message));
+            return null;
+        }
+    },
+
+    get anchor() {
+        return { x: Math.floor(this.width / 2) - 1,
+                 y: Math.floor(this.height / 2) - 1 };
+    }
+});


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