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.
Marcus Lundblad
2 years ago
29 | 29 | const Service = imports.service; |
30 | 30 | const Utils = imports.utils; |
31 | 31 | |
32 | let _attributionImage = null; | |
32 | let _attributionImages = []; | |
33 | 33 | |
34 | 34 | const _FILE_CACHE_SIZE_LIMIT = (10 * 1024 * 1024); /* 10Mb */ |
35 | 35 | const _MEMORY_CACHE_SIZE_LIMIT = 100; /* number of tiles */ |
45 | 45 | _init(view) { |
46 | 46 | super._init(); |
47 | 47 | |
48 | if (_attributionImage) | |
49 | this.contents = _attributionImage; | |
50 | else | |
51 | return; | |
52 | ||
48 | this._view = view; | |
53 | 49 | this._rtl = Gtk.get_locale_direction() === Gtk.TextDirection.RTL; |
54 | view.connect('notify::width', () => this._updatePosition(view)); | |
55 | view.connect('notify::height', () => this._updatePosition(view)); | |
50 | view.connect('notify::width', () => this._updatePosition()); | |
51 | view.connect('notify::height', () => this._updatePosition()); | |
56 | 52 | |
57 | 53 | this._updatePosition(view); |
58 | 54 | } |
59 | 55 | |
60 | _updatePosition(view) { | |
61 | let width = _attributionImage.pixbuf.width; | |
62 | let height = _attributionImage.pixbuf.height; | |
63 | let x = view.width - width - _LOGO_PADDING_X; | |
64 | /* TODO: ideally the attribution logo should be aligned to the left | |
65 | * side in RTL locales, but I couldn't get that working with Clutter | |
66 | * actor positioning, so adjust the padding to fit above the scale | |
67 | * for now | |
68 | */ | |
69 | let y = view.height - height - | |
70 | (this._rtl ? _LOGO_PADDING_Y_RTL : _LOGO_PADDING_Y); | |
56 | setSource(source) { | |
57 | this._id = source.get_id(); | |
71 | 58 | |
72 | this.set_position(x, y); | |
59 | let bin = this.get_widget(); | |
60 | ||
61 | if (bin.get_child()) | |
62 | bin.remove(bin.get_child()); | |
63 | ||
64 | if (_attributionImages[source.get_id()]) { | |
65 | bin.add(_attributionImages[source.get_id()]); | |
66 | bin.visible = true; | |
67 | } else { | |
68 | bin.visible = false; | |
69 | } | |
70 | ||
71 | this._updatePosition(); | |
72 | } | |
73 | ||
74 | _updatePosition() { | |
75 | let image = _attributionImages[this._id]; | |
76 | ||
77 | if (image) { | |
78 | let width = image.pixbuf.width; | |
79 | let height = image.pixbuf.height; | |
80 | let x = this._view.width - width - _LOGO_PADDING_X; | |
81 | /* TODO: ideally the attribution logo should be aligned to the left | |
82 | * side in RTL locales, but I couldn't get that working with Clutter | |
83 | * actor positioning, so adjust the padding to fit above the scale | |
84 | * for now | |
85 | */ | |
86 | let y = this._view.height - height - | |
87 | (this._rtl ? _LOGO_PADDING_Y_RTL : _LOGO_PADDING_Y); | |
88 | ||
89 | this.set_position(x, y); | |
90 | } | |
73 | 91 | } |
74 | 92 | }); |
75 | 93 | |
77 | 95 | if (!source.attribution_logo || source.attribution_logo === "") |
78 | 96 | return; |
79 | 97 | |
80 | if (!_attributionImage) | |
81 | _attributionImage = new Gtk.Image(); | |
98 | if (!_attributionImages[source.id]) | |
99 | _attributionImages[source.id] = new Gtk.Image({ visible: true }); | |
82 | 100 | |
83 | 101 | let data = GLib.base64_decode(source.attribution_logo); |
84 | 102 | let stream = Gio.MemoryInputStream.new_from_bytes(GLib.Bytes.new(data)); |
85 | _attributionImage.pixbuf = GdkPixbuf.Pixbuf.new_from_stream(stream, null); | |
103 | _attributionImages[source.id].pixbuf = | |
104 | GdkPixbuf.Pixbuf.new_from_stream(stream, null); | |
86 | 105 | } |
87 | 106 | |
88 | 107 | function _createTileSource(source) { |