[gnome-maps/wip/mlundblad/fix-wrap-background] mapView: Don't set dark background pattern when wrapping




commit f9c22cfa98ceb85980278c3371e6947338fa14d4
Author: Marcus Lundblad <ml update uu se>
Date:   Wed Jan 13 22:39:45 2021 +0100

    mapView: Don't set dark background pattern when wrapping
    
    The wrapping code in libchamplain seems to be broken
    when setting a background pattern.
    As a work-around, disable the custom dark background
    pattern when using the dark them if the view is wrapping
    around between 180 and -180 degrees longitude.

 src/mapView.js | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
---
diff --git a/src/mapView.js b/src/mapView.js
index d0324c17..e8e1a710 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -167,6 +167,9 @@ var MapView = GObject.registerClass({
         Application.geoclue.connect('notify::state',
                                     this._updateUserLocation.bind(this));
         this._connectRouteSignals();
+
+        // set dark background if we start up in dark theme
+        this._setBackgroundPatternIfNeeded();
     }
 
     _initScale(view) {
@@ -195,6 +198,8 @@ var MapView = GObject.registerClass({
         view.horizontal_wrap = true;
 
         view.connect('notify::latitude', this._onViewMoved.bind(this));
+        view.connect('notify::longitude',
+                     () => this._setBackgroundPatternIfNeeded());
         // switching map type will set view min-zoom-level from map source
         view.connect('notify::min-zoom-level', () => {
             if (view.min_zoom_level < MapMinZoom) {
@@ -217,12 +222,6 @@ var MapView = GObject.registerClass({
         this._gtkSettings = Gtk.Settings.get_default();
         this._gtkSettings.connect('notify::gtk-application-prefer-dark-theme',
                             this._onPreferDarkThemeChanged.bind(this));
-        // set dark background if we start up in dark theme
-        if (this._gtkSettings.gtk_application_prefer_dark_theme) {
-            if (!this._darkBackgroud)
-                this._createDarkBackground();
-            view.set_background_pattern(this._darkBackground);
-        }
 
         this._initScale(view);
         return view;
@@ -249,8 +248,15 @@ var MapView = GObject.registerClass({
         this._darkBackground.invalidate();
     }
 
-    _onPreferDarkThemeChanged() {
-        if (this._gtkSettings.gtk_application_prefer_dark_theme) {
+    _isWrappingAround() {
+        let bbox = this.view.get_bounding_box();
+
+        return bbox.left > bbox.right;
+    }
+
+    _setBackgroundPatternIfNeeded() {
+        if (this._gtkSettings.gtk_application_prefer_dark_theme &&
+            !this._isWrappingAround()) {
             if (!this._darkBackgroud)
                 this._createDarkBackground();
             this.view.set_background_pattern(this._darkBackground);
@@ -259,6 +265,10 @@ var MapView = GObject.registerClass({
         }
     }
 
+    _onPreferDarkThemeChanged() {
+        this._setBackgroundPatternIfNeeded();
+    }
+
     _onNightModeChanged() {
         if (this._mapType === MapType.STREET) {
             let overlay_sources = this.view.get_overlay_sources();


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