summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Lundblad <ml@update.uu.se>2021-05-21 21:32:23 +0200
committerMarcus Lundblad <ml@update.uu.se>2021-05-21 21:32:23 +0200
commitfdd4d867f431b85d82a1f932deadd0bb76f0d65a (patch)
tree82a17ae57b71c9df80fd8e37734903e8b14595d8
parent01082452258fd6685896321a713e90530304c9e3 (diff)
downloadgnome-maps-wip/mlundblad/fix-multiple-attribution-logos.tar.gz
mapSource, mapView: Fix handling different attribution logoswip/mlundblad/fix-multiple-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.
-rw-r--r--src/mapSource.js67
-rw-r--r--src/mapView.js2
2 files changed, 45 insertions, 24 deletions
diff --git a/src/mapSource.js b/src/mapSource.js
index 5006ac6b..5feb6298 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 */
@@ -46,31 +46,49 @@ class AttributionLogo extends GtkClutter.Actor {
_init(view) {
super._init();
- if (_attributionImage)
- this.contents = _attributionImage;
- else
- return;
-
+ this._view = view;
this._rtl = Gtk.get_locale_direction() === Gtk.TextDirection.RTL;
- view.connect('notify::width', () => this._updatePosition(view));
- view.connect('notify::height', () => this._updatePosition(view));
+ view.connect('notify::width', () => this._updatePosition());
+ view.connect('notify::height', () => this._updatePosition());
this._updatePosition(view);
}
- _updatePosition(view) {
- let width = _attributionImage.pixbuf.width;
- let height = _attributionImage.pixbuf.height;
- let x = view.width - width - _LOGO_PADDING_X;
- /* TODO: ideally the attribution logo should be aligned to the left
- * side in RTL locales, but I couldn't get that working with Clutter
- * actor positioning, so adjust the padding to fit above the scale
- * for now
- */
- let y = view.height - height -
- (this._rtl ? _LOGO_PADDING_Y_RTL : _LOGO_PADDING_Y);
-
- this.set_position(x, y);
+ setSource(source) {
+ this._id = source.get_id();
+
+ let bin = this.get_widget();
+
+ if (bin.get_child())
+ bin.remove(bin.get_child());
+
+ if (_attributionImages[source.get_id()]) {
+ bin.add(_attributionImages[source.get_id()]);
+ bin.visible = true;
+ } else {
+ bin.visible = false;
+ }
+
+ this._updatePosition();
+ }
+
+ _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;
+ /* TODO: ideally the attribution logo should be aligned to the left
+ * side in RTL locales, but I couldn't get that working with Clutter
+ * actor positioning, so adjust the padding to fit above the scale
+ * for now
+ */
+ let y = this._view.height - height -
+ (this._rtl ? _LOGO_PADDING_Y_RTL : _LOGO_PADDING_Y);
+
+ this.set_position(x, y);
+ }
}
});
@@ -78,12 +96,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 684fa071..95dbe984 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -437,6 +437,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();