[gnome-maps/wip/mlundblad/transit-routing: 27/28] WIP: Add print layout for transit
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/transit-routing: 27/28] WIP: Add print layout for transit
- Date: Tue, 11 Oct 2016 20:44:11 +0000 (UTC)
commit beeb167c0f9c01fe83c206c5026041d7880c51ec
Author: Marcus Lundblad <ml update uu se>
Date: Tue Sep 20 23:27:09 2016 +0200
WIP: Add print layout for transit
src/org.gnome.Maps.src.gresource.xml | 1 +
src/transitPrintLayout.js | 139 ++++++++++++++++++++++++++++++++++
2 files changed, 140 insertions(+), 0 deletions(-)
---
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index fa1b45d..89ff771 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -82,6 +82,7 @@
<file>transitMoreRow.js</file>
<file>transitOptions.js</file>
<file>transitPlan.js</file>
+ <file>transitPrintLayout.js</file>
<file>transitRouteLabel.js</file>
<file>transitStopRow.js</file>
<file>transitWalkMarker.js</file>
diff --git a/src/transitPrintLayout.js b/src/transitPrintLayout.js
new file mode 100644
index 0000000..ccbcbd6
--- /dev/null
+++ b/src/transitPrintLayout.js
@@ -0,0 +1,139 @@
+/* -*- 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Marcus Lundblad <ml update uu se>
+ */
+
+const Lang = imports.lang;
+
+const Champlain = imports.gi.Champlain;
+const Clutter = imports.gi.Clutter;
+
+const PrintLayout = imports.printLayout;
+const TransitBoardMarker = imports.transitBoardMarker;
+const TransitWalkMarker = imports.transitWalkMarker;
+
+/* stroke color for walking paths */
+const _STROKE_COLOR = new Clutter.Color({ red: 0,
+ blue: 0,
+ green: 0,
+ alpha: 255 });
+const _STROKE_WIDTH = 5.0;
+
+/* All following constants are ratios of surface size to page size */
+const _Header = {
+ SCALE_X: 0.9,
+ SCALE_Y: 0.03,
+ SCALE_MARGIN: 0.01
+};
+const _MapView = {
+ SCALE_X: 1.0,
+ SCALE_Y: 0.4,
+ SCALE_MARGIN: 0.04,
+ ZOOM_LEVEL: 18
+};
+
+const TransitPrintLayout = new Lang.Class({
+ Name: 'TransitPrintLayout',
+ Extends: PrintLayout.PrintLayout,
+
+ _init: function(params) {
+ this._itinerary = params.itinerary;
+ delete params.itinerary;
+
+ /* TODO: calculate the actual number of surfaces needed */
+ let totalSurfaces = 1;
+ params.totalSurfaces = totalSurfaces;
+
+ this.parent(params);
+ },
+
+ _drawMapView: function(width, height, zoomLevel, leg, nextLeg) {
+ let pageNum = this.numPages - 1;
+ let x = this._cursorX;
+ let y = this._cursorY;
+ let mapSource = MapSource.createPrintSource();
+ let markerLayer = new Champlain.MarkerLayer();
+ let view = new Champlain.View({ width: width,
+ height: height,
+ zoom_level: zoomLevel });
+ view.set_map_source(mapSource);
+ view.add_layer(markerLayer);
+
+ this._addRouteLayer(view, leg);
+
+ markerLayer.add_marker(this._createStartMarker(leg));
+ if (nextLeg)
+ markerLayer.add_marker(this._createBoardMarker(nextLeg));
+ else
+ markerLayer.add_marker(this._createArrivalMarker(leg));
+
+ view.ensure_visible(leg.bbox, false);
+ if (view.state !== Champlain.State.DONE) {
+ let notifyId = view.connect('notify::state', (function() {
+ if (view.state === Champlain.State.DONE) {
+ view.disconnect(notifyId);
+ let surface = view.to_surface(true);
+ if (surface)
+ this._addSurface(surface, x, y, pageNum);
+ }
+ }).bind(this));
+ } else {
+ let surface = view.to_surface(true);
+ if (surface)
+ this._addSurface(surface, x, y, pageNum);
+ }
+ },
+
+ _createStartMarker: function(leg) {
+ return new TransitWalkMarker.TransitWalkMarker({ leg: leg });
+ },
+
+ _createBoardMarker: function(leg) {
+ return new TransitBoardMarker.TransitBoardMarker({ leg: leg });
+ },
+
+ _createArrivalMarker: function(leg) {
+ return new TransitArrivalMarker.TransitArrivalMarker({ leg: leg });
+ },
+
+ _addRouteLayer: function(view, leg) {
+ let routeLayer = new Champlain.PathLayer({ stroke_width: _STROKE_WIDTH,
+ stroke_color: _STROKE_COLOR });
+ routeLayer.set_dash([5, 5]);
+ view.add_layer(routeLayer);
+ leg.polyline.forEach(routeLayer.add_node.bind(routeLayer));
+ },
+
+ render: function() {
+ let headerWidth = _Header.SCALE_X * this._pageWidth;
+ let headerHeight = _Header.SCALE_Y * this._pageHeight;
+ let headerMargin = _Header.SCALE_MARGIN * this._pageHeight;
+
+ let mapViewWidth = _MapView.SCALE_X * this._pageWidth;
+ let mapViewHeight = _MapView.SCALE_Y * this._pageHeight;
+ let mapViewMargin = _MapView.SCALE_MARGIN * this._pageHeight;
+ let mapViewZoomLevel = _MapView.ZOOM_LEVEL;
+
+ let dy = headerHeight + headerMargin;
+
+ this._createNewPage();
+ this._adjustPage(dy);
+ this._drawHeader(headerWidth, headerHeight);
+ }
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]