[gnome-maps/gnome-3-36] mapSource, mapView: Fix handling different attribution logos



commit 4577e5fdaedbe386d1eab9a1472cb62c04dbac7c
Author: Marcus Lundblad <ml update uu se>
Date:   Fri May 21 21:32:23 2021 +0200

    mapSource, mapView: Fix handling different attribution logos
    
    We previously never had different attribution logos for
    the map sources. Fix this so that it actually works
    to update the logo when switching source now that
    we use different providers for street and aerial.

 src/mapSource.js | 50 ++++++++++++++++++++++++++++++++++----------------
 src/mapView.js   |  2 ++
 2 files changed, 36 insertions(+), 16 deletions(-)
---
diff --git a/src/mapSource.js b/src/mapSource.js
index 49358a94..a736aca0 100644
--- a/src/mapSource.js
+++ b/src/mapSource.js
@@ -30,7 +30,7 @@ const System = imports.system;
 const Service = imports.service;
 const Utils = imports.utils;
 
-let _attributionImage = null;
+let _attributionImages = [];
 
 const _FILE_CACHE_SIZE_LIMIT = (10 * 1024 * 1024); /* 10Mb */
 const _MEMORY_CACHE_SIZE_LIMIT = 100; /* number of tiles */
@@ -44,23 +44,40 @@ class AttributionLogo extends GtkClutter.Actor {
     _init(view) {
         super._init();
 
-        if (_attributionImage)
-            this.contents = _attributionImage;
-        else
-            return;
+        this._view = view;
+        view.connect('notify::width', () => this._updatePosition());
+        view.connect('notify::height', () => this._updatePosition());
+    }
+
+    setSource(source) {
+        this._id = source.get_id();
+
+        let bin = this.get_widget();
 
-        view.connect('notify::width', () => this._updatePosition(view));
-        view.connect('notify::height', () => this._updatePosition(view));
+        if (bin.get_child())
+            bin.remove(bin.get_child());
 
-        this._updatePosition(view);
+        if (_attributionImages[source.get_id()]) {
+            bin.add(_attributionImages[source.get_id()]);
+            bin.visible = true;
+        } else {
+            bin.visible = false;
+        }
+
+        this._updatePosition();
     }
 
-    _updatePosition(view) {
-        let width = _attributionImage.pixbuf.width;
-        let height = _attributionImage.pixbuf.height;
+    _updatePosition() {
+        let image = _attributionImages[this._id];
+
+        if (image) {
+            let width = image.pixbuf.width;
+            let height = image.pixbuf.height;
+            let x = this._view.width  - width  - _LOGO_PADDING_X;
+            let y = this._view.height - height - _LOGO_PADDING_Y;
 
-        this.set_position(view.width  - width  - _LOGO_PADDING_X,
-                          view.height - height - _LOGO_PADDING_Y);
+            this.set_position(x, y);
+        }
     }
 });
 
@@ -68,12 +85,13 @@ function _updateAttributionImage(source) {
     if (!source.attribution_logo || source.attribution_logo === "")
         return;
 
-    if (!_attributionImage)
-        _attributionImage = new Gtk.Image();
+    if (!_attributionImages[source.id])
+        _attributionImages[source.id] = new Gtk.Image({ visible: true });
 
     let data = GLib.base64_decode(source.attribution_logo);
     let stream = Gio.MemoryInputStream.new_from_bytes(GLib.Bytes.new(data));
-    _attributionImage.pixbuf = GdkPixbuf.Pixbuf.new_from_stream(stream, null);
+    _attributionImages[source.id].pixbuf =
+        GdkPixbuf.Pixbuf.new_from_stream(stream, null);
 }
 
 function _createTileSource(source) {
diff --git a/src/mapView.js b/src/mapView.js
index be134c0f..3c27cdf7 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -332,6 +332,8 @@ var MapView = GObject.registerClass({
                 this.view.add_child(this._attribution);
             }
 
+            this._attribution.setSource(this.view.map_source);
+
             Application.settings.set('map-type', mapType);
         } else {
             let renderer = new Champlain.ImageRenderer();


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