[gnome-maps/wip/mlundblad/replace-bbox-and-ensure-visible: 4/4] WIP: Stop using Champlain.BoundingBox




commit 2be7e124b6130b6d8e549cfe63851ef8c18a04f2
Author: Marcus Lundblad <ml update uu se>
Date:   Wed Feb 24 22:03:59 2021 +0100

    WIP: Stop using Champlain.BoundingBox

 src/geoJSONSource.js      |  3 ++-
 src/graphHopper.js        |  6 +++---
 src/mapView.js            | 20 +++++++++-----------
 src/printLayout.js        | 11 ++++++++++-
 src/route.js              |  4 ++--
 src/transitPlan.js        |  8 ++++----
 src/transitPrintLayout.js |  9 ++++++++-
 7 files changed, 38 insertions(+), 23 deletions(-)
---
diff --git a/src/geoJSONSource.js b/src/geoJSONSource.js
index 48fe9e2a..0027ded1 100644
--- a/src/geoJSONSource.js
+++ b/src/geoJSONSource.js
@@ -24,6 +24,7 @@ const Clutter = imports.gi.Clutter;
 const GObject = imports.gi.GObject;
 const Mainloop = imports.mainloop;
 
+const BoundingBox = imports.boundingBox;
 const Geojsonvt = imports.geojsonvt.geojsonvt;
 const Location = imports.location;
 const Place = imports.place;
@@ -45,7 +46,7 @@ class GeoJSONSource extends Champlain.TileSource {
 
         this._mapView = params.mapView;
         this._markerLayer = params.markerLayer;
-        this._bbox = new Champlain.BoundingBox();
+        this._bbox = new BoundingBox.BoundingBox();
         this._tileSize = Service.getService().tiles.street.tile_size;
     }
 
diff --git a/src/graphHopper.js b/src/graphHopper.js
index 41d6bc43..1fb4f479 100644
--- a/src/graphHopper.js
+++ b/src/graphHopper.js
@@ -19,11 +19,11 @@
  * Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
  */
 
-const Champlain = imports.gi.Champlain;
 const GLib = imports.gi.GLib;
 const Mainloop = imports.mainloop;
 const Soup = imports.gi.Soup;
 
+const BoundingBox = imports.boundingBox;
 const EPAF = imports.epaf;
 const HTTP = imports.http;
 const Route = imports.route;
@@ -185,9 +185,9 @@ var GraphHopper = class GraphHopper {
     _createRoute(route) {
         let path       = EPAF.decode(route.points);
         let turnPoints = this._createTurnPoints(path, route.instructions);
-        let bbox       = new Champlain.BoundingBox();
+        let bbox       = new BoundingBox.BoundingBox();
 
-        // GH does lonlat-order and Champlain latlon-order
+        // GH does lonlat-order
         bbox.extend(route.bbox[1], route.bbox[0]);
         bbox.extend(route.bbox[3], route.bbox[2]);
 
diff --git a/src/mapView.js b/src/mapView.js
index 0d407c01..684fa071 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -29,6 +29,7 @@ const GtkChamplain = imports.gi.GtkChamplain;
 const Mainloop = imports.mainloop;
 
 const Application = imports.application;
+const BoundingBox = imports.boundingBox;
 const ContactPlace = imports.contactPlace;
 const Color = imports.color;
 const Geoclue = imports.geoclue;
@@ -527,7 +528,7 @@ var MapView = GObject.registerClass({
     }
 
     _loadShapeLayers(files) {
-        let bbox = new Champlain.BoundingBox();
+        let bbox = new BoundingBox.BoundingBox();
         this._remainingFilesToLoad = files.length;
 
         files.forEach((file) => {
@@ -682,10 +683,10 @@ var MapView = GObject.registerClass({
                 Utils.debug('Invalid initial coordinates: ' + lat + ', ' + lon);
         } else {
             /* bounding box. for backwards compatibility, not used anymore */
-            let bbox = new Champlain.BoundingBox({ top: location[0],
-                                                   bottom: location[1],
-                                                   left: location[2],
-                                                   right: location[3] });
+            let bbox = new BoundingBox.BoundingBox({ top: location[0],
+                                                     bottom: location[1],
+                                                     left: location[2],
+                                                     right: location[3] });
             this.view.connect("notify::realized", () => {
                 if (this.view.realized)
                     this.gotoBBox(bbox, true);
@@ -694,12 +695,12 @@ var MapView = GObject.registerClass({
     }
 
     gotoBBox(bbox, linear) {
-        if (!bbox.is_valid()) {
+        if (!bbox.isValid()) {
             Utils.debug('Bounding box is invalid');
             return;
         }
 
-        let [lat, lon] = bbox.get_center();
+        let [lon, lat] = bbox.getCenter();
         let place = new Place.Place({
             location: new Location.Location({ latitude  : lat,
                                               longitude : lon }),
@@ -777,10 +778,7 @@ var MapView = GObject.registerClass({
             this._placeLayer.add_marker(marker);
         });
 
-        if (places.length > 1)
-            this.gotoBBox(contact.bounding_box);
-        else
-            new MapWalker.MapWalker(places[0], this).goTo(true);
+        new MapWalker.MapWalker(places[0], this).goTo(true);
     }
 
     _showStoredRoute(stored) {
diff --git a/src/printLayout.js b/src/printLayout.js
index 5602612b..e57fac57 100644
--- a/src/printLayout.js
+++ b/src/printLayout.js
@@ -170,7 +170,7 @@ var PrintLayout = GObject.registerClass({
             }
         });
 
-        view.ensure_visible(this._route.createBBox(locations), false);
+        view.ensure_visible(this._createBBox(locations), false);
         if (view.state !== Champlain.State.DONE) {
             let notifyId = view.connect('notify::state', () => {
                 if (view.state === Champlain.State.DONE) {
@@ -187,6 +187,15 @@ var PrintLayout = GObject.registerClass({
         }
     }
 
+    _createBBox(locations) {
+        let bbox = this._route.createBBox(locations);
+
+        return new Champlain.BoundingBox({ top:    bbox.top,
+                                           left:   bbox.left,
+                                           bottom: bbox.bottom,
+                                           right:  bbox.right });
+    }
+
     _createTurnPointArray(startIndex, endIndex) {
         let turnPointArray = [];
         for (let i = startIndex; i < endIndex; i++) {
diff --git a/src/route.js b/src/route.js
index 1c30dfa4..4115a4d4 100644
--- a/src/route.js
+++ b/src/route.js
@@ -19,9 +19,9 @@
  * Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
  */
 
-const Champlain = imports.gi.Champlain;
 const GObject = imports.gi.GObject;
 
+const BoundingBox = imports.boundingBox;
 const Utils = imports.utils;
 
 var TurnPointType = {
@@ -94,7 +94,7 @@ var Route = GObject.registerClass({
     }
 
     createBBox(coordinates) {
-        let bbox = new Champlain.BoundingBox();
+        let bbox = new BoundingBox.BoundingBox();
         coordinates.forEach(function({ latitude, longitude }) {
             bbox.extend(latitude, longitude);
         }, this);
diff --git a/src/transitPlan.js b/src/transitPlan.js
index c6d96ddb..b6556e0f 100644
--- a/src/transitPlan.js
+++ b/src/transitPlan.js
@@ -22,10 +22,10 @@
 const _ = imports.gettext.gettext;
 const ngettext = imports.gettext.ngettext;
 
-const Champlain = imports.gi.Champlain;
 const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
 
+const BoundingBox = imports.boundingBox;
 const HVT = imports.hvt;
 const Time = imports.time;
 const Utils = imports.utils;
@@ -186,7 +186,7 @@ var Plan = GObject.registerClass({
     }
 
     _createBBox() {
-        let bbox = new Champlain.BoundingBox();
+        let bbox = new BoundingBox.BoundingBox();
         this._itineraries.forEach(function(itinerary) {
             bbox.compose(itinerary.bbox);
         });
@@ -284,7 +284,7 @@ class Itinerary extends GObject.Object {
     }
 
     _createBBox() {
-        let bbox = new Champlain.BoundingBox();
+        let bbox = new BoundingBox.BoundingBox();
 
         this._legs.forEach(function(leg) {
             bbox.compose(leg.bbox);
@@ -638,7 +638,7 @@ var Leg = class Leg {
     }
 
     _createBBox() {
-        let bbox = new Champlain.BoundingBox();
+        let bbox = new BoundingBox.BoundingBox();
 
         this.polyline.forEach(function({ latitude, longitude }) {
             bbox.extend(latitude, longitude);
diff --git a/src/transitPrintLayout.js b/src/transitPrintLayout.js
index 323ed1e7..aada2fe0 100644
--- a/src/transitPrintLayout.js
+++ b/src/transitPrintLayout.js
@@ -124,7 +124,7 @@ class TransitPrintLayout extends PrintLayout.PrintLayout {
         if (leg.distance < 10)
             view.center_on(leg.fromCoordinate[0], leg.fromCoordinate[1]);
         else
-            view.ensure_visible(leg.bbox, false);
+            view.ensure_visible(this._createBBox(leg), false);
         if (view.state !== Champlain.State.DONE) {
             let notifyId = view.connect('notify::state', () => {
                 if (view.state === Champlain.State.DONE) {
@@ -141,6 +141,13 @@ class TransitPrintLayout extends PrintLayout.PrintLayout {
         }
     }
 
+    _createBBox(leg) {
+        return Champlain.BoundingBox({ top:    leg.bbox.top,
+                                       left:   leg.bbox.left,
+                                       bottom: leg.bbox.bottom,
+                                       right:  leg.bbox.right });
+    }
+
     _createStartMarker(leg, previousLeg) {
         return new TransitWalkMarker.TransitWalkMarker({ leg: leg,
                                                          previousLeg: previousLeg });


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